终端一体化运控平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

70 linhas
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.JXJFoodSmallStation.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. namespace BPASmartClient.JXJFoodSmallStation.ViewModel
  15. {
  16. public class DeviceMaterialParViewModel : ObservableObject
  17. {
  18. public DeviceMaterialParViewModel()
  19. {
  20. deviceParModels = Json<DevicePar>.Data.deviceParModels;
  21. RemoveCommand = new RelayCommand<object>((o) =>
  22. {
  23. var res = deviceParModels.FirstOrDefault(p => p.MaterialName == o?.ToString());
  24. if (res != null) deviceParModels.Remove(res);
  25. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{o.ToString()}:原料删除成功!");
  26. });
  27. AddCommand = new RelayCommand(() => { deviceParModels.Add(new DeviceParMode()); });
  28. SaveCommand = new RelayCommand(() =>
  29. {
  30. if (deviceParModels == null || deviceParModels.Count <= 0)
  31. {
  32. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", $"没有可保存的参数!");
  33. return;
  34. }
  35. for (int i = 0; i < deviceParModels.Count; i++)
  36. {
  37. if (deviceParModels.Where(p => p.MaterialName == deviceParModels.ElementAt(i).MaterialName)?.ToList()?.Count >= 2)
  38. deviceParModels.ElementAt(i).IsRedundant = true;
  39. else
  40. deviceParModels.ElementAt(i).IsRedundant = false;
  41. }
  42. if (deviceParModels.FirstOrDefault(p => p.IsRedundant == true) != null)
  43. {
  44. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"原料名称冲突,请检查后重试!");
  45. return;
  46. }
  47. deviceParModels.Where(P => P.MaterialName.Length <= 0)?.ToList()?.ForEach(item =>
  48. {
  49. Json<DevicePar>.Data.deviceParModels.Remove(item);
  50. });
  51. Json<DevicePar>.Save();
  52. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"原料参数保存成功!");
  53. });
  54. }
  55. public ObservableCollection<DeviceParMode> deviceParModels { get; set; }
  56. public RelayCommand<object> RemoveCommand { get; set; }
  57. public RelayCommand AddCommand { get; set; }
  58. public RelayCommand SaveCommand { get; set; }
  59. }
  60. }