终端一体化运控平台
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

71 řádky
2.8 KiB

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