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

67 lines
2.7 KiB

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