|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BPA.Helper;
- using System.Collections.ObjectModel;
- using BPASmartClient.JXJFoodSmallStation.Model;
- using BPA.Helper;
-
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.CustomResource.UserControls;
- using System.Diagnostics;
- using BPASmartClient.CustomResource.Pages.Model;
-
- namespace BPASmartClient.JXJFoodSmallStation.ViewModel
- {
- public class DeviceMaterialParViewModel : NotifyBase
- {
- public DeviceMaterialParViewModel()
- {
- deviceParModels = Json<DevicePar>.Data.deviceParModels;
- RemoveCommand = new BPARelayCommand<object>((o) =>
- {
- var res = deviceParModels.FirstOrDefault(p => p.MaterialName == o?.ToString());
- if (res != null) deviceParModels.Remove(res);
- MessageNotify.GetInstance.ShowUserLog($"删除一条味魔方原料参数设置。原料名称:{o.ToString()}");
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"原料:【{o.ToString()}】删除成功!");
- });
-
- AddCommand = new BPARelayCommand(() => { deviceParModels.Add(new DeviceParMode());
- MessageNotify.GetInstance.ShowUserLog($"新增一条味魔方原料参数设置。");
- });
- SaveCommand = new BPARelayCommand(() =>
- {
- if (deviceParModels == null || deviceParModels.Count <= 0)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", $"没有可保存的参数!");
- return;
- }
-
- for (int i = 0; i < deviceParModels.Count; i++)
- {
- if (deviceParModels.Where(p => p.MaterialName == deviceParModels.ElementAt(i).MaterialName)?.ToList()?.Count >= 2)
- deviceParModels.ElementAt(i).IsRedundant = true;
- else
- deviceParModels.ElementAt(i).IsRedundant = false;
- }
-
- if (deviceParModels.FirstOrDefault(p => p.IsRedundant == true) != null)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"原料名称冲突,请检查后重试!");
- return;
- }
-
- deviceParModels.Where(P => P.MaterialName.Length <= 0)?.ToList()?.ForEach(item =>
- {
- Json<DevicePar>.Data.deviceParModels.Remove(item);
- });
- Json<DevicePar>.Save();
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"原料参数保存成功!");
- MessageNotify.GetInstance.ShowUserLog("保存味魔法原料参数设置。");
- });
- }
-
- public ObservableCollection<DeviceParMode> deviceParModels { get; set; }
-
- public BPARelayCommand<object> RemoveCommand { get; set; }
-
- public BPARelayCommand AddCommand { get; set; }
- public BPARelayCommand SaveCommand { get; set; }
-
- }
- }
|