终端一体化运控平台
Você não pode selecionar mais de 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.
 
 
 

75 linhas
3.2 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. using BPASmartClient.CustomResource.Pages.Model;
  15. namespace BPASmartClient.JXJFoodSmallStation.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. MessageNotify.GetInstance.ShowUserLog($"删除一条味魔方原料参数设置。原料名称:{o.ToString()}");
  27. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"原料:【{o.ToString()}】删除成功!");
  28. });
  29. AddCommand = new RelayCommand(() => { deviceParModels.Add(new DeviceParMode());
  30. MessageNotify.GetInstance.ShowUserLog($"新增一条味魔方原料参数设置。");
  31. });
  32. SaveCommand = new RelayCommand(() =>
  33. {
  34. if (deviceParModels == null || deviceParModels.Count <= 0)
  35. {
  36. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", $"没有可保存的参数!");
  37. return;
  38. }
  39. for (int i = 0; i < deviceParModels.Count; i++)
  40. {
  41. if (deviceParModels.Where(p => p.MaterialName == deviceParModels.ElementAt(i).MaterialName)?.ToList()?.Count >= 2)
  42. deviceParModels.ElementAt(i).IsRedundant = true;
  43. else
  44. deviceParModels.ElementAt(i).IsRedundant = false;
  45. }
  46. if (deviceParModels.FirstOrDefault(p => p.IsRedundant == true) != null)
  47. {
  48. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"原料名称冲突,请检查后重试!");
  49. return;
  50. }
  51. deviceParModels.Where(P => P.MaterialName.Length <= 0)?.ToList()?.ForEach(item =>
  52. {
  53. Json<DevicePar>.Data.deviceParModels.Remove(item);
  54. });
  55. Json<DevicePar>.Save();
  56. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"原料参数保存成功!");
  57. MessageNotify.GetInstance.ShowUserLog("保存味魔法原料参数设置。");
  58. });
  59. }
  60. public ObservableCollection<DeviceParMode> deviceParModels { get; set; }
  61. public RelayCommand<object> RemoveCommand { get; set; }
  62. public RelayCommand AddCommand { get; set; }
  63. public RelayCommand SaveCommand { get; set; }
  64. }
  65. }