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

78 lines
3.5 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.CustomResource.UserControls;
  3. using BPASmartClient.CustomResource.UserControls.MessageShow;
  4. using BPASmartClient.FoodStationTest.Model;
  5. using BPASmartClient.FoodStationTest.Model.Bom;
  6. using BPA.Helper;
  7. using BPA.Helper;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. namespace BPASmartClient.FoodStationTest.ViewModel
  11. {
  12. public class BomOfMaterialViewModel : NotifyBase
  13. {
  14. public BomOfMaterialViewModel()
  15. {
  16. RawMaterialInfo = Json<DevicePar>.Data.BomMaterial;
  17. AddMaterial = new BPARelayCommand(() =>
  18. {
  19. RawMaterialInfo.Add(new BomMaterial()
  20. {
  21. Count = Json<DevicePar>.Data.BomMaterial.Count + 1,
  22. });
  23. });
  24. SaveMaterials = new BPARelayCommand(() =>
  25. {
  26. if (MessageNotify.GetInstance.ShowDialog("请确认是否保存!") == true)
  27. {
  28. Json<DevicePar>.Save();
  29. MessageNotify.GetInstance.ShowUserLog($"西门子物料清单保存成功");
  30. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"原料与料仓对应关系保存成功");
  31. }
  32. });
  33. GetBomMaterialData = new BPARelayCommand(() =>
  34. {
  35. Json<DevicePar>.Data.BomMaterial.Clear();
  36. ProcessControl.GetInstance.RawMaterialNameWithCode();//原料的名称和编码对应 :西门子mes定义的物料编码
  37. foreach (var item in GVL_SmallStation.GetInstance.RawMaterialsNameCode)
  38. {
  39. Json<DevicePar>.Data.BomMaterial.Add(new BomMaterial() { Count = Json<DevicePar>.Data.BomMaterial.Count + 1, MaterialCode = item.Key, MaterialName = item.Value });
  40. }
  41. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"读取程序的Bom清单");
  42. });
  43. DeleteAllMaterial = new BPARelayCommand(() =>
  44. {
  45. if (MessageNotify.GetInstance.ShowDialog("请确认是否删除所有原料数据!") == true)
  46. {
  47. Json<DevicePar>.Data.BomMaterial.Clear();
  48. MessageNotify.GetInstance.ShowUserLog($"西门子物料清单删除完成");
  49. }
  50. });
  51. RemoveCommand = new BPARelayCommand<int>((Count) =>
  52. {
  53. if (Count is int cnt)
  54. {
  55. var res = RawMaterialInfo.FirstOrDefault(p => p.Count == cnt);
  56. if (res != null)
  57. {
  58. if (MessageNotify.GetInstance.ShowDialog($"请确认是否删除[{res.MaterialCode}],[{res.MaterialName}]!") == true)
  59. {
  60. RawMaterialInfo.Remove(res);
  61. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"删除成功");
  62. }
  63. }
  64. }
  65. });
  66. }
  67. public ObservableCollection<BomMaterial> RawMaterialInfo { get; set; } = new ObservableCollection<BomMaterial>();
  68. public BPARelayCommand AddMaterial { get; set; }
  69. public BPARelayCommand SaveMaterials { get; set; }
  70. public BPARelayCommand<int> RemoveCommand { get; set; }
  71. public BPARelayCommand GetBomMaterialData { get; set; }
  72. public BPARelayCommand DeleteAllMaterial { get; set; }
  73. }
  74. }