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

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