终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

62 lines
2.6 KiB

  1. using BPA.Helper;
  2. using BPASmartClient.CustomResource.UserControls;
  3. using BPASmartClient.CustomResource.UserControls.MessageShow;
  4. using System.Collections.ObjectModel;
  5. using System.Linq;
  6. namespace BPASmartClient.DosingSystem.ViewModel
  7. {
  8. public class DeviceMaterialParViewModel : ViewModelBase
  9. {
  10. public DeviceMaterialParViewModel()
  11. {
  12. deviceParModels = Json<DevicePar>.Data.deviceParModels;
  13. RemoveCommand = new BPARelayCommand<object>((o) =>
  14. {
  15. var res = deviceParModels.FirstOrDefault(p => p.MaterialName == o?.ToString());
  16. if (res != null) deviceParModels.Remove(res);
  17. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{o.ToString()}:原料删除成功!");
  18. });
  19. AddCommand = new BPARelayCommand(() => { deviceParModels.Add(new DeviceParModel()); });
  20. SaveCommand = new BPARelayCommand(() =>
  21. {
  22. if (deviceParModels == null || deviceParModels.Count <= 0)
  23. {
  24. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", $"没有可保存的参数!");
  25. return;
  26. }
  27. for (int i = 0; i < deviceParModels.Count; i++)
  28. {
  29. if (deviceParModels.Where(p => p.MaterialName == deviceParModels.ElementAt(i).MaterialName)?.ToList()?.Count >= 2)
  30. deviceParModels.ElementAt(i).IsRedundant = true;
  31. else
  32. deviceParModels.ElementAt(i).IsRedundant = false;
  33. }
  34. if (deviceParModels.FirstOrDefault(p => p.IsRedundant == true) != null)
  35. {
  36. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"原料名称冲突,请检查后重试!");
  37. return;
  38. }
  39. deviceParModels.Where(P => P.MaterialName.Length <= 0)?.ToList()?.ForEach(item =>
  40. {
  41. Json<DevicePar>.Data.deviceParModels.Remove(item);
  42. });
  43. Json<DevicePar>.Save();
  44. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"原料参数保存成功!");
  45. });
  46. }
  47. public ObservableCollection<DeviceParModel> deviceParModels { get; set; }
  48. //public BPARelayCommand<object> RemoveCommand { get; set; }
  49. //public BPARelayCommand AddCommand { get; set; }
  50. //public BPARelayCommand SaveCommand { get; set; }
  51. }
  52. }