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.CustomResource.UserControls.MessageShow; using BPASmartClient.CustomResource.UserControls; using System.Diagnostics; namespace BPASmartClient.DosingSystemSingle.ViewModel { public class DeviceMaterialParViewModel : ViewModelBase { public DeviceMaterialParViewModel() { deviceParModels = Json.Data.deviceParModels; RemoveCommand = new BPARelayCommand((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.Data.deviceParModels.Remove(item); }); Json.Save(); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"原料参数保存成功!"); }); } public ObservableCollection deviceParModels { get; set; } //public BPARelayCommand RemoveCommand { get; set; } //public BPARelayCommand AddCommand { get; set; } //public BPARelayCommand SaveCommand { get; set; } } }