DqdrRecipeViewModel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. using Aitex.Core.UI.MVVM;
  2. using Aitex.Core.Utilities;
  3. using MECF.Framework.Common.DataCenter;
  4. using MECF.Framework.Common.Equipment;
  5. using MECF.Framework.Common.RecipeCenter;
  6. using MECF.Framework.Common.Utilities;
  7. using Prism.Mvvm;
  8. using PunkHPX8_MainPages.PMs;
  9. using PunkHPX8_Themes.UserControls;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Input;
  18. namespace PunkHPX8_MainPages.ViewModels
  19. {
  20. public class DqdrRecipeViewModel : BindableBase
  21. {
  22. #region 常量
  23. private const string ENGINEERING = "Engineering";
  24. private const string DQDR = "dqdr";
  25. private const string DEP = "dep";
  26. #endregion
  27. #region 内部变量
  28. /// <summary>
  29. /// Recipe节点字典
  30. /// </summary>
  31. private Dictionary<string, RecipeNode> _recipeNodeDic = new Dictionary<string, RecipeNode>();
  32. /// <summary>
  33. /// 属性检验结果字典
  34. /// </summary>
  35. private Dictionary<string, bool> _propertyValidResultDic = new Dictionary<string, bool>();
  36. /// <summary>
  37. /// Recipe节点集合
  38. /// </summary>
  39. private ObservableCollection<RecipeNode> _recipeNodes;
  40. /// <summary>
  41. /// DepRecipe节点集合
  42. /// </summary>
  43. private ObservableCollection<RecipeNode> _depRecipeNodes;
  44. /// <summary>
  45. /// Plating Cell List
  46. /// </summary>
  47. private ObservableCollection<string> _platingCellList = new ObservableCollection<string>();
  48. /// <summary>
  49. /// DepRecipe Name List
  50. /// </summary>
  51. private ObservableCollection<string> _depRecipeNameList = new ObservableCollection<string>();
  52. /// <summary>
  53. /// uiRecipeManager
  54. /// </summary>
  55. private UiRecipeManager _uiRecipeManager = new UiRecipeManager();
  56. /// <summary>
  57. /// recipe
  58. /// </summary>
  59. private DqdrRecipe _recipe;
  60. /// <summary>
  61. /// 编辑可用性
  62. /// </summary>
  63. private bool _editEnable;
  64. /// <summary>
  65. /// 创建可用性
  66. /// </summary>
  67. private bool _createEnable;
  68. /// <summary>
  69. /// 当前节点
  70. /// </summary>
  71. private RecipeNode _currentNode;
  72. /// <summary>
  73. /// 是否可用
  74. /// </summary>
  75. private bool _enable = false;
  76. /// <summary>
  77. /// 是否为编辑(true-Edit,false-add)
  78. /// </summary>
  79. private bool _isEdit = false;
  80. #endregion
  81. #region 属性
  82. public ObservableCollection<RecipeNode> RecipeNodes
  83. {
  84. get { return _recipeNodes; }
  85. set { SetProperty(ref _recipeNodes, value); }
  86. }
  87. public ObservableCollection<RecipeNode> DepRecipeNodes
  88. {
  89. get { return _depRecipeNodes; }
  90. set { SetProperty(ref _depRecipeNodes, value); }
  91. }
  92. public ObservableCollection<string> PlatingCellList
  93. {
  94. get { return _platingCellList; }
  95. set { SetProperty(ref _platingCellList, value); }
  96. }
  97. public ObservableCollection<string> DepRecipeNameList
  98. {
  99. get { return _depRecipeNameList; }
  100. set { SetProperty(ref _depRecipeNameList, value); }
  101. }
  102. /// <summary>
  103. /// Recipe
  104. /// </summary>
  105. public DqdrRecipe Recipe
  106. {
  107. get { return _recipe; }
  108. set { SetProperty(ref _recipe, value); }
  109. }
  110. /// <summary>
  111. /// 创建可用性
  112. /// </summary>
  113. public bool CreateEnable
  114. {
  115. get { return _createEnable; }
  116. set { SetProperty(ref _createEnable, value); }
  117. }
  118. /// <summary>
  119. /// 编辑可用性
  120. /// </summary>
  121. public bool EditEnable
  122. {
  123. get { return _editEnable; }
  124. set { SetProperty(ref _editEnable, value); }
  125. }
  126. /// <summary>
  127. /// 当前节点
  128. /// </summary>
  129. public RecipeNode CurrentNode
  130. {
  131. get { return _currentNode; }
  132. set { SetProperty(ref _currentNode, value); }
  133. }
  134. /// <summary>
  135. /// 可用性
  136. /// </summary>
  137. public bool Enable
  138. {
  139. get { return _enable; }
  140. set { SetProperty(ref _enable, value); }
  141. }
  142. /// <summary>
  143. /// 属性数据检验结果
  144. /// </summary>
  145. public Dictionary<string, bool> PropertyValidResultDic
  146. {
  147. get { return _propertyValidResultDic; }
  148. set { SetProperty(ref _propertyValidResultDic, value); }
  149. }
  150. #endregion
  151. #region 指令
  152. [IgnorePropertyChange]
  153. public ICommand OperationCommand
  154. {
  155. get;
  156. private set;
  157. }
  158. [IgnorePropertyChange]
  159. public ICommand CreateCommand { get; private set; }
  160. [IgnorePropertyChange]
  161. public ICommand EditCommand { get; private set; }
  162. [IgnorePropertyChange]
  163. public ICommand SaveRecipeCommand { get; private set; }
  164. [IgnorePropertyChange]
  165. public ICommand SaveAsRecipeCommand { get; private set; }
  166. public ICommand LinkedDepRecipeChangeCommand { get; private set; }
  167. #endregion
  168. /// <summary>
  169. /// 构造函数
  170. /// </summary>
  171. public DqdrRecipeViewModel()
  172. {
  173. OperationCommand = new DelegateCommand<object>(SelectionChangedAction);
  174. CreateCommand = new DelegateCommand<object>(CreateAction);
  175. EditCommand = new DelegateCommand<object>(EditAction);
  176. SaveRecipeCommand = new DelegateCommand<object>(SaveAction);
  177. SaveAsRecipeCommand = new DelegateCommand<object>(SaveAsAction);
  178. LinkedDepRecipeChangeCommand = new DelegateCommand<object>(LinkedDepRecipeChangeAction);
  179. InitializeProprtyValidResultDictionary();
  180. InitializePlatingCellNameList();
  181. }
  182. /// <summary>
  183. /// 初始化属性数据检验结果字典
  184. /// </summary>
  185. private void InitializeProprtyValidResultDictionary()
  186. {
  187. PropertyValidResultDic["ReclaimSpeed"] = false;
  188. PropertyValidResultDic["ReclaimTime"] = false;
  189. PropertyValidResultDic["RinseSpeed"] = false;
  190. PropertyValidResultDic["RinseTime"] = false;
  191. PropertyValidResultDic["DrySpeed"] = false;
  192. PropertyValidResultDic["DryTime"] = false;
  193. PropertyValidResultDic["IntervalRinseSpeed"] = false;
  194. PropertyValidResultDic["IntervalRinseTime"] = false;
  195. }
  196. /// <summary>
  197. /// 加载数据
  198. /// </summary>
  199. public void LoadRecipeData()
  200. {
  201. RecipeNodes = _uiRecipeManager.GetRecipesByType(DQDR);
  202. DepRecipeNodes = _uiRecipeManager.GetRecipesByType(DEP);
  203. _recipeNodeDic.Clear();
  204. InitializeDictionary(RecipeNodes);
  205. InitializeDepRecipeList();
  206. }
  207. /// <summary>
  208. /// 初始化字典
  209. /// </summary>
  210. /// <param name="nodes"></param>
  211. private void InitializeDictionary(ObservableCollection<RecipeNode> nodes)
  212. {
  213. if (nodes != null)
  214. {
  215. foreach (var node in nodes)
  216. {
  217. if (node.NodeType == RecipeNodeType.File)
  218. {
  219. _recipeNodeDic[node.Name] = node;
  220. }
  221. InitializeDictionary(node.Children);
  222. }
  223. }
  224. }
  225. /// <summary>
  226. /// 初始化DEP recipe名字列表
  227. /// </summary>
  228. private void InitializeDepRecipeList()
  229. {
  230. DepRecipeNameList.Clear();
  231. if (DepRecipeNodes != null && DepRecipeNodes.Count > 0)
  232. {
  233. foreach (var item in DepRecipeNodes[0].Children)
  234. {
  235. DepRecipeNameList.Add(item.FileName);
  236. }
  237. }
  238. }
  239. /// <summary>
  240. /// 初始化platingcell list
  241. /// </summary>
  242. private void InitializePlatingCellNameList()
  243. {
  244. PlatingCellList.Clear();
  245. PlatingCellList.Add(ModuleName.PlatingCell1.ToString());
  246. PlatingCellList.Add(ModuleName.PlatingCell2.ToString());
  247. PlatingCellList.Add(ModuleName.PlatingCell2.ToString());
  248. PlatingCellList.Add(ModuleName.PlatingCell4.ToString());
  249. }
  250. /// <summary>
  251. /// 操作
  252. /// </summary>
  253. /// <param name="param"></param>
  254. private void SelectionChangedAction(object param)
  255. {
  256. if (_recipeNodeDic.ContainsKey(param.ToString()))
  257. {
  258. CurrentNode = _recipeNodeDic[param.ToString()];
  259. if (CurrentNode.NodeType == RecipeNodeType.File)
  260. {
  261. if (CurrentNode.RecipeLocation == ENGINEERING)
  262. {
  263. EditEnable = true;
  264. CreateEnable = true;
  265. }
  266. else
  267. {
  268. EditEnable = false;
  269. CreateEnable = false;
  270. }
  271. }
  272. Recipe = _uiRecipeManager.LoadRecipe<DqdrRecipe>(CurrentNode.RecipeFullFileName);
  273. if (Recipe == null)
  274. {
  275. MessageBox.Show("Invalid Recipe", "Load Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  276. EditEnable = false;
  277. CreateEnable = false;
  278. }
  279. Enable = false;
  280. }
  281. else
  282. {
  283. if (param.ToString() == ENGINEERING)
  284. {
  285. CreateEnable = true;
  286. }
  287. else
  288. {
  289. CreateEnable = false;
  290. }
  291. CurrentNode = null;
  292. Recipe = null;
  293. EditEnable = false;
  294. Enable = false;
  295. }
  296. }
  297. #region Action
  298. /// <summary>
  299. /// 创建
  300. /// </summary>
  301. /// <param name="param"></param>
  302. private void CreateAction(object param)
  303. {
  304. RecipeNameDialog recipeNameDialog = new RecipeNameDialog();
  305. if (recipeNameDialog.ShowDialog().Value)
  306. {
  307. Recipe = new DqdrRecipe();
  308. Recipe.CreateDate = DateTime.Now;
  309. Recipe.Ppid = recipeNameDialog.RecipeName;
  310. Recipe.Description = recipeNameDialog.RecipeDescription;
  311. Enable = true;
  312. _isEdit = false;
  313. }
  314. }
  315. /// <summary>
  316. /// 编辑
  317. /// </summary>
  318. /// <param name="param"></param>
  319. private void EditAction(object param)
  320. {
  321. Enable = true;
  322. _isEdit = false;
  323. }
  324. /// <summary>
  325. /// 确认当前dummy rinse recipe与关联的dep recipe的时间是否相等
  326. /// </summary>
  327. /// <param name="dqdr"></param>
  328. /// <param name="depRecipe"></param>
  329. /// <returns></returns>
  330. private void LinkedDepRecipeChangeAction(object param)
  331. {
  332. Recipe.IsIdentical = false;
  333. string linkedDepRecipeName = Recipe.LinkedDepRecipeName;
  334. string fullName = DepRecipeNodes[0].Children.FirstOrDefault(node => node.FileName == linkedDepRecipeName)?.RecipeFullFileName;
  335. DepRecipe deprecipe = _uiRecipeManager.LoadRecipe<DepRecipe>(fullName);
  336. if (deprecipe != null)
  337. {
  338. if (deprecipe.ReclaimTime == Recipe.ReclaimTime
  339. && deprecipe.RinseTime == Recipe.RinseTime
  340. && deprecipe.DryTime == Recipe.DryTime
  341. && deprecipe.RinseBeforeEntryEnable == Recipe.RinseBeforeEntryEnable
  342. && deprecipe.IntervalRinseTime == Recipe.IntervalRinseTime)
  343. {
  344. Recipe.IsIdentical = true;
  345. }
  346. }
  347. }
  348. /// <summary>
  349. /// 保存
  350. /// </summary>
  351. /// <param name="param"></param>
  352. private void SaveAction(object param)
  353. {
  354. if (CheckValid(_isEdit))
  355. {
  356. Recipe.SaveDate = DateTime.Now;
  357. try
  358. {
  359. _uiRecipeManager.SaveRecipe<DqdrRecipe>(ENGINEERING, Recipe.Ppid, "dqdr", Recipe);
  360. LoadRecipeData();
  361. MessageBox.Show("Save Recipe Success", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Information);
  362. Enable = false;
  363. }
  364. catch (Exception ex)
  365. {
  366. MessageBox.Show(ex.Message, "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// 另存为
  372. /// </summary>
  373. /// <param name="param"></param>
  374. private void SaveAsAction(object param)
  375. {
  376. if (Recipe == null)
  377. {
  378. MessageBox.Show("Select a Recipe first", "SaveAs Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  379. return;
  380. }
  381. DqdrRecipe recipe = new DqdrRecipe();
  382. if (CheckValid(_isEdit))
  383. {
  384. RecipeNameDialog recipeNameDialog = new RecipeNameDialog();
  385. if (recipeNameDialog.ShowDialog().Value)
  386. {
  387. if (!CheckNameExist(recipeNameDialog.RecipeName))
  388. {
  389. recipe = new DqdrRecipe();
  390. recipe = (DqdrRecipe)PropertyUtil.Clone(Recipe);
  391. recipe.CreateDate = DateTime.Now;
  392. recipe.Ppid = recipeNameDialog.RecipeName;
  393. recipe.Description = recipeNameDialog.RecipeDescription;
  394. }
  395. else if (recipeNameDialog.RecipeName != null)
  396. {
  397. MessageBox.Show("Name can not be Null", "Create Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  398. return;
  399. }
  400. else
  401. {
  402. return;
  403. }
  404. }
  405. try
  406. {
  407. _uiRecipeManager.SaveRecipe<DqdrRecipe>(ENGINEERING, recipe.Ppid, "dqdr", recipe);
  408. LoadRecipeData();
  409. MessageBox.Show("Save As Recipe Success", "SaveAs Recipe", MessageBoxButton.OK, MessageBoxImage.Information);
  410. Enable = false;
  411. }
  412. catch (Exception ex)
  413. {
  414. MessageBox.Show(ex.Message, "Save As Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  415. }
  416. }
  417. }
  418. /// <summary>
  419. /// 检验名称是否已经存在
  420. /// </summary>
  421. /// <param name="name"></param>
  422. /// <returns></returns>
  423. private bool CheckNameExist(string name)
  424. {
  425. foreach (string item in _recipeNodeDic.Keys)
  426. {
  427. if (item == name)
  428. {
  429. MessageBox.Show($"{name} is exsit", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  430. return true;
  431. }
  432. }
  433. return false;
  434. }
  435. /// <summary>
  436. /// 检验合法性
  437. /// </summary>
  438. /// <param name="editType"></param>
  439. /// <returns></returns>
  440. private bool CheckValid(bool editType)
  441. {
  442. foreach (string key in _propertyValidResultDic.Keys)
  443. {
  444. bool valid = _propertyValidResultDic[key];
  445. if (!valid)
  446. {
  447. MessageBox.Show($"{key} data invalid", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  448. return false;
  449. }
  450. }
  451. return true;
  452. }
  453. #endregion
  454. }
  455. }