终端一体化运控平台
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.
 
 
 

66 line
2.6 KiB

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