终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

70 строки
2.9 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.JXJFoodSmallStation.Model.WindSend;
  15. namespace BPASmartClient.JXJFoodSmallStation.ViewModel
  16. {
  17. public class WindSendParViewModel : ObservableObject
  18. {
  19. public WindSendParViewModel()
  20. {
  21. deviceParModels = Json<WindSendDevicePar>.Data.WindSendPar;
  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 WindSendDeviceParMode()); });
  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<WindSendDevicePar>.Data.WindSendPar.Remove(item);
  51. });
  52. Json<WindSendDevicePar>.Save();
  53. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"原料参数保存成功!");
  54. });
  55. }
  56. public ObservableCollection<WindSendDeviceParMode> deviceParModels { get; set; }
  57. public RelayCommand<object> RemoveCommand { get; set; }
  58. public RelayCommand AddCommand { get; set; }
  59. public RelayCommand SaveCommand { get; set; }
  60. }
  61. }