终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

180 satır
8.4 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 Microsoft.Toolkit.Mvvm.Input;
  9. using BPASmartClient.Helper;
  10. using BPASmartClient.JXJFoodBigStation.Model;
  11. using BPASmartClient.CustomResource.Pages.Model;
  12. using BPASmartClient.JXJFoodBigStation.Model.Siemens;
  13. using System.Windows.Forms;
  14. using BPASmartClient.CustomResource.UserControls;
  15. using BPASmartClient.CustomResource.UserControls.MessageShow;
  16. namespace BPASmartClient.JXJFoodBigStation.ViewModel
  17. {
  18. public class RecipeInfosViewModel : ObservableObject
  19. {
  20. public RecipeInfosViewModel()
  21. {
  22. foreach (var item in ProcessControl.GetInstance.RawMaterialsInfo)
  23. {
  24. RawMaterialLocation.Add(item.RawMaterialLocation);
  25. }
  26. ActionManage.GetInstance.Register(new Action<object>((o) =>
  27. {
  28. if (o != null && o is RecipeData rm)
  29. {
  30. RecipeName = rm.RecipeName;
  31. RecipeCode = rm.RecipeCode;
  32. TrayCode = rm.TrayCode;
  33. IsWashingBarrel = rm.IsWashingBarrel;
  34. RecipeCategory = rm.RecipeCategory;
  35. foreach (var item in rm.RawMaterial)
  36. {
  37. //item.RawMaterialCount = Array.FindIndex(ProcessControl.GetInstance.RawMaterialsInfo.ToArray(), p => p.RawMaterialName == item.RawMaterialName);
  38. RawMaterialsInfo.Add(item);
  39. }
  40. }
  41. }), "RecipeInfo");
  42. ActionManage.GetInstance.Register(new Action(() =>
  43. {
  44. foreach (var item in RawMaterialsInfo)
  45. {
  46. if (RawMaterialLocation.Contains(item.RawMaterialLocation))
  47. {
  48. int index = Array.FindIndex(ProcessControl.GetInstance.RawMaterialsInfo.ToArray(), p => p.RawMaterialLocation == item.RawMaterialLocation);
  49. item.RawMaterialName = ProcessControl.GetInstance.RawMaterialsInfo.ElementAt(index).RawMaterialName;
  50. item.RawMaterialChineseName = ProcessControl.GetInstance.RawMaterialsInfo.ElementAt(index).RawMaterialChineseName;
  51. }
  52. }
  53. }), "RawMaterialNames",true);
  54. AddRecipe = new RelayCommand(() => {
  55. RawMaterialsInfo.Add(new RawMaterial());
  56. });
  57. Comfirm = new RelayCommand(() =>
  58. {
  59. if (!MessageNotify.GetInstance.ShowDialog($"是否保存该配方?"))
  60. {
  61. return;
  62. }
  63. var bom= Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == RecipeCode);
  64. if (bom == null)//新配方
  65. {
  66. var name= Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == RecipeName);
  67. if (name == null)
  68. {
  69. go:
  70. string recipeCode = new Random().Next(10000, 32767).ToString();
  71. var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode);
  72. if (res == null)
  73. {
  74. if (IsWashingBarrel)
  75. {
  76. var newRecipeData = new RecipeData { RecipeCode = recipeCode, RecipeName = RecipeName, TrayCode = TrayCode, IsWashingBarrel = IsWashingBarrel, OrderType = "洗桶", RecipeCategory = RecipeCategory };
  77. Json<LocalRecipe>.Data.Recipes.Add(newRecipeData);
  78. Json<LocalRecipe>.Data.SelectedRecipes.Add(newRecipeData);
  79. if (RawMaterialsInfo.Count > 0)
  80. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, App.MainWindow, "提示", $"订单类型为洗桶,不保存原料信息");
  81. }
  82. else
  83. {
  84. var newRecipeData = new RecipeData { RecipeCode = recipeCode, RawMaterial = RawMaterialsInfo, RecipeName = RecipeName, TrayCode = TrayCode, IsWashingBarrel = IsWashingBarrel, OrderType = "配料", RecipeCategory = RecipeCategory };
  85. Json<LocalRecipe>.Data.Recipes.Add(newRecipeData);
  86. Json<LocalRecipe>.Data.SelectedRecipes.Add(newRecipeData) ;
  87. }
  88. Json<LocalRecipe>.Save();
  89. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"配方保存完成");
  90. MessageNotify.GetInstance.ShowUserLog($"新增【{RecipeName}】配方,订单号为【{recipeCode}】。");
  91. }
  92. else
  93. {
  94. goto go;
  95. }
  96. ActionManage.GetInstance.Send("CloseRecipeInfosView");
  97. }
  98. else
  99. {
  100. MessageBox.Show("配方名称重复,请重命名!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  101. }
  102. }
  103. else//编辑已有配方
  104. {
  105. bom.RawMaterial.Clear();
  106. foreach (var item in RawMaterialsInfo)
  107. {
  108. bom.RawMaterial.Add(item);
  109. }
  110. bom.RecipeName = RecipeName;
  111. bom.TrayCode = TrayCode;
  112. bom.IsWashingBarrel = IsWashingBarrel;
  113. bom.RecipeCategory = RecipeCategory;
  114. if (IsWashingBarrel)
  115. {
  116. bom.RawMaterial.Clear();
  117. }
  118. Json<LocalRecipe>.Save();
  119. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"配方保存完成");
  120. MessageNotify.GetInstance.ShowUserLog($"修改【{RecipeName}】配方。");
  121. ActionManage.GetInstance.Send("CloseRecipeInfosView");
  122. }
  123. });
  124. RemoveRecipe = new RelayCommand<int>((index) => {
  125. var res = RawMaterialsInfo.FirstOrDefault(p => p.RawMaterialLocation == index);
  126. if (res != null)
  127. RawMaterialsInfo.Remove(res);
  128. });
  129. foreach (var item in Json<LocalRecipe>.Data.Recipes)
  130. {
  131. if (!Categorys.Contains(item.RecipeCategory))
  132. {
  133. Categorys.Add(item.RecipeCategory);
  134. }
  135. }
  136. }
  137. public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } }
  138. private string _mRecipeName;
  139. public string RecipeCode { get { return _mRecipeCode; } set { _mRecipeCode = value; OnPropertyChanged(); } }
  140. private string _mRecipeCode;
  141. public int TrayCode { get { return _mTrayCode; } set { _mTrayCode = value; OnPropertyChanged(); } }
  142. private int _mTrayCode;
  143. public int SelectIndex { get { return _mSelectIndex; } set { _mSelectIndex = value; OnPropertyChanged(); } }
  144. private int _mSelectIndex;
  145. public bool IsWashingBarrel { get { return _mIsWashingBarrel; } set { _mIsWashingBarrel = value; OnPropertyChanged(); } }
  146. private bool _mIsWashingBarrel;
  147. public string RecipeCategory { get { return _RecipeCategory; } set { _RecipeCategory = value; OnPropertyChanged(); } }
  148. private string _RecipeCategory;
  149. private ObservableCollection<string> _Categorys=new();
  150. public ObservableCollection<string> Categorys
  151. {
  152. get { return _Categorys; }
  153. set { _Categorys = value; OnPropertyChanged(); }
  154. }
  155. public RelayCommand ReturnPage { get; set; }
  156. public RelayCommand AddRecipe { get; set; }
  157. public RelayCommand Comfirm { get; set; }
  158. public RelayCommand<int> RemoveRecipe { get; set; }
  159. public ObservableCollection<RawMaterial> RawMaterialsInfo { get; set; } = new ObservableCollection<RawMaterial>() ;
  160. public ObservableCollection<int> RawMaterialLocation { get; set; } = new ObservableCollection<int>();
  161. }
  162. }