|
- using BPA.Helper;
- using BPASmartClient.CustomResource.UserControls;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using System.Collections.ObjectModel;
- using System.Linq;
-
- namespace BPASmartClient.DosingSystem.ViewModel
- {
- public class DeviceMaterialParViewModel : ViewModelBase
- {
- 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);
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{o.ToString()}:原料删除成功!");
- });
-
- AddCommand = new BPARelayCommand(() => { deviceParModels.Add(new DeviceParModel()); });
- 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, "提示", $"原料参数保存成功!");
- });
- }
-
- public ObservableCollection<DeviceParModel> deviceParModels { get; set; }
-
- //public BPARelayCommand<object> RemoveCommand { get; set; }
-
- //public BPARelayCommand AddCommand { get; set; }
- //public BPARelayCommand SaveCommand { get; set; }
-
- }
- }
|