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

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