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

270 rivejä
12 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.CustomResource.UserControls.MessageShow;
  3. using BPASmartClient.MorkCL.Model.DB;
  4. using BPASmartClient.MorkCL.Server;
  5. namespace BPASmartClient.MorkCL.ViewModel
  6. {
  7. public class EditRawMaterialViewModel : NotifyBase
  8. {
  9. public EditRawMaterialViewModel()
  10. {
  11. ActionManage.GetInstance.Register((object o) =>
  12. {
  13. //为Null代表是新增。
  14. if (o != null && o is MaterialBase material)
  15. {
  16. if (String.IsNullOrEmpty(material.Id) || material.Id.Length <= 0)
  17. {
  18. IsNewAdd = true;
  19. }
  20. else
  21. {
  22. IsNewAdd = false;
  23. if (material is AccessoriesTB)
  24. {
  25. CurrentMaterialType = "辅料";
  26. }
  27. else if (material is IngredientsTB)
  28. {
  29. CurrentMaterialType = "主料";
  30. }
  31. else if (material is SeasoningTB)
  32. {
  33. CurrentMaterialType = "调料";
  34. }
  35. else
  36. {
  37. throw new Exception($"参数不是物料数据类型");
  38. }
  39. MaterialName = material.Name;
  40. MaterialLoc = material.Loc;
  41. _materialID = material.Id;
  42. MaterialDescription = material.Description;
  43. }
  44. }
  45. }, "OpenEditRawMaterialView", true);
  46. ActionManage.GetInstance.Register((object o) =>
  47. {
  48. string materialType = o is String ? (String)o : null;
  49. CurrentMaterialType = materialType!;
  50. }, "ChangeMaterialType", true);
  51. SaveParamCommand = new BPARelayCommand(() =>
  52. {
  53. #region 数据验证
  54. if (!MessageNotify.GetInstance.ShowDialog("请确认,是否保存该物料信息?"))
  55. {
  56. return;
  57. }
  58. if (string.IsNullOrEmpty(MaterialName) || MaterialName.Length <= 0)
  59. {
  60. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"失败,物料名称不正确!");
  61. return;
  62. }
  63. if (MaterialLoc <= 0 && CurrentMaterialType != "主料")
  64. {
  65. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"失败,物料位置应为正整数!");
  66. return;
  67. }
  68. if (CurrentMaterialType == "调料" && (MaterialLoc <= 0 || MaterialLoc>3))
  69. {
  70. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"失败,调料位置应大于0 且小于等于 3 !");
  71. return;
  72. }
  73. if (CurrentMaterialType == "辅料" && (MaterialLoc <= 0 || MaterialLoc > 8))
  74. {
  75. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"失败,调料位置应大于0 且小于等于 8 !");
  76. return;
  77. }
  78. #endregion 数据验证
  79. //新增
  80. if (IsNewAdd)
  81. {
  82. try
  83. {
  84. switch (CurrentMaterialType)
  85. {
  86. case "主料":
  87. //if (SqliteHelper.GetInstance.GetIngredientsInfoByLoc(MaterialLoc))
  88. //{
  89. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"添加失败,该位置已有物料!");
  90. // return;
  91. //}
  92. IngredientsTB ingredients = new IngredientsTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
  93. SqliteHelper.GetInstance.AddIngredients(ingredients);
  94. ActionManage.GetInstance.Send("RefreshIngredients");
  95. break;
  96. case "辅料":
  97. if (SqliteHelper.GetInstance.GetAccessoriesInfoByLoc(MaterialLoc))
  98. {
  99. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"添加失败,该位置已有物料!");
  100. return;
  101. }
  102. AccessoriesTB accessories = new AccessoriesTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
  103. SqliteHelper.GetInstance.AddAccessories(accessories);
  104. break;
  105. case "调料":
  106. if (SqliteHelper.GetInstance.GetSeasoningInfoByLoc(MaterialLoc))
  107. {
  108. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"添加失败,该位置已有物料!");
  109. return;
  110. }
  111. SeasoningTB seasoning = new SeasoningTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
  112. SqliteHelper.GetInstance.AddSeasoning(seasoning);
  113. break;
  114. }
  115. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"新增物料:{MaterialName} 成功!");
  116. }
  117. catch (Exception ex)
  118. {
  119. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"新增一条物料:{MaterialName} 失败!");
  120. }
  121. }
  122. else
  123. {
  124. try
  125. {
  126. switch (CurrentMaterialType)
  127. {
  128. case "主料":
  129. //if (SqliteHelper.GetInstance.GetIngredientsInfoByLoc(MaterialLoc))
  130. //{
  131. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"修改失败,该位置已有物料!");
  132. // return;
  133. //}
  134. IngredientsTB ingredients = new IngredientsTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
  135. SqliteHelper.GetInstance.EditIngredients(ingredients);
  136. break;
  137. case "辅料":
  138. //if (SqliteHelper.GetInstance.GetAccessoriesInfoByLoc(MaterialLoc))
  139. //{
  140. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"修改失败,该位置已有物料!");
  141. // return;
  142. //}
  143. AccessoriesTB accessories = new AccessoriesTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
  144. SqliteHelper.GetInstance.EditAccessories(accessories);
  145. break;
  146. case "调料":
  147. //if (SqliteHelper.GetInstance.GetSeasoningInfoByLoc(MaterialLoc))
  148. //{
  149. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"修改失败,该位置已有物料!");
  150. // return;
  151. //}
  152. SeasoningTB seasoning = new SeasoningTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
  153. SqliteHelper.GetInstance.EditSeasoning(seasoning);
  154. break;
  155. }
  156. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"修改物料:{MaterialName} 成功!");
  157. }
  158. catch
  159. {
  160. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"修改物料:{MaterialName} 失败!");
  161. }
  162. }
  163. //保存处理。
  164. ActionManage.GetInstance.Send("CloseEditRawMaterialView", true);
  165. });
  166. CancelCommand = new BPARelayCommand(() =>
  167. {
  168. ActionManage.GetInstance.Send("CloseEditRawMaterialView", false);
  169. });
  170. }
  171. public BPARelayCommand SaveParamCommand { get; set; }
  172. public BPARelayCommand CancelCommand { get; set; }
  173. private string _materialID;
  174. public ObservableCollection<string> MaterialType { get; set; } = new ObservableCollection<string>() { "主料", "辅料", "调料" };
  175. private bool _IsNewAdd;
  176. public bool IsNewAdd
  177. {
  178. get { return _IsNewAdd; }
  179. set
  180. {
  181. _IsNewAdd = value;
  182. if (value == true)
  183. {
  184. MaterialTypeVis = Visibility.Visible;
  185. }
  186. else
  187. MaterialTypeVis = Visibility.Hidden;
  188. OnPropertyChanged();
  189. }
  190. }
  191. private string _CurrentMaterialType;
  192. /// <summary>物料类型</summary>
  193. public string CurrentMaterialType
  194. {
  195. get { return _CurrentMaterialType; }
  196. set
  197. {
  198. _CurrentMaterialType = value;
  199. if (value == "主料")
  200. {
  201. LocationVis = Visibility.Hidden;
  202. }
  203. else
  204. LocationVis = Visibility.Visible;
  205. OnPropertyChanged();
  206. }
  207. }
  208. private string _MaterialName;
  209. /// <summary>物料名称</summary>
  210. public string MaterialName
  211. {
  212. get { return _MaterialName; }
  213. set { _MaterialName = value; OnPropertyChanged(); }
  214. }
  215. private int _MaterialLoc;
  216. /// <summary>物料位置</summary>
  217. public int MaterialLoc
  218. {
  219. get { return _MaterialLoc; }
  220. set { _MaterialLoc = value; OnPropertyChanged(); }
  221. }
  222. private string _MaterialDescription;
  223. public string MaterialDescription
  224. {
  225. get { return _MaterialDescription; }
  226. set { _MaterialDescription = value; }
  227. }
  228. private Visibility _MaterialTypeVis;
  229. /// <summary>是否新增,如果是新增,则显示主料类型框。反之,则不显示。</summary>
  230. public Visibility MaterialTypeVis
  231. {
  232. get { return _MaterialTypeVis; }
  233. set { _MaterialTypeVis = value; OnPropertyChanged(); }
  234. }
  235. private Visibility _LocationVis;
  236. /// <summary>是否显示位置框,如果为主料,则不显示。反之,则显示。</summary>
  237. public Visibility LocationVis
  238. {
  239. get { return _LocationVis; }
  240. set { _LocationVis = value; OnPropertyChanged(); }
  241. }
  242. }
  243. }