SequenceViewModel.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Xml;
  8. using Caliburn.Micro;
  9. using Caliburn.Micro.Core;
  10. using OpenSEMI.ClientBase;
  11. using RecipeEditorLib.DGExtension.CustomColumn;
  12. using RecipeEditorLib.RecipeModel.Params;
  13. using MECF.Framework.Common.RecipeCenter;
  14. using VirgoUI.Client.Dialog;
  15. using MECF.Framework.Common.Equipment;
  16. using OpenSEMI.ClientBase.Command;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using MECF.Framework.Common.DataCenter;
  20. using VirgoUI.Client.Models.Operate;
  21. namespace VirgoUI.Client.Models.Recipe.Sequence
  22. {
  23. public class SequenceViewModel : BaseModel
  24. {
  25. private int MenuPermission;
  26. public ObservableCollection<FileNode> Files { get; set; }
  27. private EfemType _efemType = EfemType.FutureEfem;
  28. private bool _enableThickness = true;
  29. public Visibility ThicknessVisibility
  30. {
  31. get { return (_efemType == EfemType.JetEfem && _enableThickness) ? Visibility.Visible : Visibility.Collapsed; }
  32. }
  33. protected override void OnInitialize()
  34. {
  35. base.OnInitialize();
  36. this.CurrentSequence = new SequenceData();
  37. this.Columns = this.columnBuilder.Build();
  38. this.editMode = EditMode.None;
  39. this.IsSavedDesc = true;
  40. List<string> names = this.provider.GetSequences();
  41. this.Files = new ObservableCollection<FileNode>(RecipeSequenceTreeBuilder.GetFiles(names));
  42. this.CurrentFileNode = this.Files[0];
  43. this.SelectDefault(this.CurrentFileNode);
  44. }
  45. protected override void OnActivate()
  46. {
  47. MenuPermission = ClientApp.Instance.GetPermission("Sequence");
  48. _efemType = (int)QueryDataClient.Instance.Service.GetConfig("EFEM.EfemType") == 1 ? EfemType.FutureEfem : EfemType.JetEfem;
  49. _enableThickness = (bool)QueryDataClient.Instance.Service.GetConfig("System.WaferThickness.EnableThickness");
  50. NotifyOfPropertyChange(nameof(ThicknessVisibility));
  51. base.OnActivate();
  52. }
  53. protected override void OnDeactivate(bool close)
  54. {
  55. base.OnDeactivate(close);
  56. if (this.IsChanged)
  57. {
  58. if (MessageBox.Show("This sequence is changed,do you want to save it?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  59. this.SaveSequence();
  60. }
  61. }
  62. protected override void OnViewLoaded(object view)
  63. {
  64. base.OnViewLoaded(view);
  65. SequenceColumnBuilder.ApplyTemplate((UserControl)view, this.Columns);
  66. SequenceView u = (SequenceView)view;
  67. this.Columns.Apply((c) =>
  68. {
  69. c.Header = c;
  70. u.dgCustom.Columns.Add(c);
  71. });
  72. u.dgCustom.ItemsSource = CurrentSequence.Steps;
  73. this.UpdateView();
  74. }
  75. #region Sequence selection
  76. public void TreeSelectChanged(FileNode file)
  77. {
  78. if (file.IsFile)
  79. {
  80. if (this.IsChanged)
  81. {
  82. if (MessageBox.Show("This sequence is changed,do you want to save it?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  83. {
  84. this.Save(this.CurrentSequence);
  85. }
  86. }
  87. this.LoadData(file.FullPath);
  88. }
  89. else
  90. {
  91. this.ClearData();
  92. this.editMode = EditMode.None;
  93. }
  94. this.UpdateView();
  95. this.CurrentFileNode = file;
  96. }
  97. private TreeViewItem GetParentObjectEx<TreeViewItem>(DependencyObject obj) where TreeViewItem : FrameworkElement
  98. {
  99. DependencyObject parent = VisualTreeHelper.GetParent(obj);
  100. while (parent != null)
  101. {
  102. if (parent is TreeViewItem)
  103. {
  104. return (TreeViewItem)parent;
  105. }
  106. parent = VisualTreeHelper.GetParent(parent);
  107. }
  108. return null;
  109. }
  110. public void TreeRightMouseDown(MouseButtonEventArgs e)
  111. {
  112. var item = GetParentObjectEx<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
  113. if (item != null)
  114. {
  115. item.Focus();
  116. }
  117. }
  118. #endregion
  119. private ICommand _NotImplementCommand;
  120. public ICommand NotImplementCommand
  121. {
  122. get
  123. {
  124. if (this._NotImplementCommand == null)
  125. this._NotImplementCommand = new BaseCommand(() => this.NotImplement());
  126. return this._NotImplementCommand;
  127. }
  128. }
  129. public void NotImplement()
  130. {
  131. MessageBox.Show("Not Implement");
  132. }
  133. #region Sequence operation
  134. private ICommand _NewFolderCommand;
  135. public ICommand NewFolderCommand
  136. {
  137. get
  138. {
  139. if (this._NewFolderCommand == null)
  140. this._NewFolderCommand = new BaseCommand(() => this.NewFolder());
  141. return this._NewFolderCommand;
  142. }
  143. }
  144. public void NewFolder()
  145. {
  146. if (!this.CurrentFileNode.IsFile)
  147. {
  148. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input Folder Name");
  149. WindowManager wm = new WindowManager();
  150. bool? bret = wm.ShowDialog(dialog);
  151. if (!(bool)bret)
  152. return;
  153. string fullpath = (this.CurrentFileNode.FullPath == "" ? dialog.DialogResult : this.CurrentFileNode.FullPath + "\\" + dialog.DialogResult);
  154. if (this.provider.CreateSequenceFolder(fullpath))
  155. {
  156. FileNode folder = new FileNode();
  157. folder.Name = dialog.DialogResult;
  158. folder.FullPath = fullpath;
  159. folder.Parent = this.CurrentFileNode;
  160. this.CurrentFileNode.Files.Add(folder);
  161. }
  162. else
  163. MessageBox.Show("Create folder failed!");
  164. }
  165. }
  166. private ICommand _NewFolderInParentCommand;
  167. public ICommand NewFolderInParentCommand
  168. {
  169. get
  170. {
  171. if (this._NewFolderInParentCommand == null)
  172. this._NewFolderInParentCommand = new BaseCommand(() => this.NewFolderInParent());
  173. return this._NewFolderInParentCommand;
  174. }
  175. }
  176. public void NewFolderInParent()
  177. {
  178. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input Folder Name");
  179. WindowManager wm = new WindowManager();
  180. bool? bret = wm.ShowDialog(dialog);
  181. if (!(bool)bret)
  182. return;
  183. string fullpath = dialog.DialogResult;
  184. if (this.provider.CreateSequenceFolder(fullpath))
  185. {
  186. FileNode folder = new FileNode();
  187. folder.Name = dialog.DialogResult;
  188. folder.FullPath = fullpath;
  189. folder.Parent = this.Files[0];
  190. this.Files[0].Files.Add(folder);
  191. }
  192. else
  193. MessageBox.Show("Create folder failed!");
  194. }
  195. private ICommand _NewSequenceInParentCommand;
  196. public ICommand NewSequenceInParentCommand
  197. {
  198. get
  199. {
  200. if (this._NewSequenceInParentCommand == null)
  201. this._NewSequenceInParentCommand = new BaseCommand(() => this.NewSequenceInParent());
  202. return this._NewSequenceInParentCommand;
  203. }
  204. }
  205. public void NewSequenceInParent()
  206. {
  207. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Sequence Name");
  208. WindowManager wm = new WindowManager();
  209. bool? bret = wm.ShowDialog(dialog);
  210. if ((bool)bret)
  211. {
  212. if (this.IsChanged)
  213. {
  214. if (MessageBox.Show("This sequence is changed,do you want to save it?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  215. {
  216. this.CurrentSequence.Revisor = BaseApp.Instance.UserContext.LoginName;
  217. this.CurrentSequence.ReviseTime = DateTime.Now;
  218. this.Save(this.CurrentSequence);
  219. }
  220. }
  221. else
  222. {
  223. string fullpath = dialog.DialogResult;
  224. if (this.IsExist(fullpath))
  225. {
  226. MessageBox.Show("Sequence already existed!");
  227. }
  228. else
  229. {
  230. SequenceData sequence = new SequenceData();
  231. sequence.Name = fullpath;
  232. sequence.Creator = BaseApp.Instance.UserContext.LoginName;
  233. sequence.CreateTime = DateTime.Now;
  234. sequence.Revisor = BaseApp.Instance.UserContext.LoginName;
  235. sequence.ReviseTime = DateTime.Now;
  236. sequence.Description = string.Empty;
  237. if (this.Save(sequence))
  238. {
  239. this.CurrentSequence.Name = sequence.Name;
  240. this.CurrentSequence.Creator = sequence.Creator;
  241. this.CurrentSequence.CreateTime = sequence.CreateTime;
  242. this.CurrentSequence.Revisor = sequence.Revisor;
  243. this.CurrentSequence.ReviseTime = sequence.ReviseTime;
  244. this.CurrentSequence.Description = sequence.Description;
  245. this.CurrentSequence.IsThick = sequence.IsThick;
  246. this.CurrentSequence.Steps.Clear();
  247. CurrentSequence.IsChanged = false;
  248. FileNode file = new FileNode();
  249. file.Name = dialog.DialogResult;
  250. file.FullPath = this.CurrentSequence.Name;
  251. file.IsFile = true;
  252. file.Parent = this.Files[0];
  253. this.Files[0].Files.Insert(this.findInsertPosition(this.Files[0].Files), file);
  254. this.editMode = EditMode.Normal;
  255. this.UpdateView();
  256. }
  257. }
  258. }
  259. }
  260. }
  261. public int findInsertPosition(ObservableCollection<FileNode> files)
  262. {
  263. int pos = -1;
  264. if (files.Count == 0)
  265. pos = 0;
  266. else
  267. {
  268. bool foundfolder = false;
  269. for (var index = 0; index < files.Count; index++)
  270. {
  271. if (!files[index].IsFile)
  272. {
  273. foundfolder = true;
  274. pos = index;
  275. break;
  276. }
  277. }
  278. if (!foundfolder)
  279. pos = files.Count;
  280. }
  281. return pos;
  282. }
  283. private ICommand _SaveAsCommand;
  284. public ICommand SaveAsCommand
  285. {
  286. get
  287. {
  288. if (this._SaveAsCommand == null)
  289. this._SaveAsCommand = new BaseCommand(() => this.SaveAsSequence());
  290. return this._SaveAsCommand;
  291. }
  292. }
  293. public void SaveAsSequence()
  294. {
  295. if (this.CurrentFileNode.IsFile)
  296. {
  297. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("SaveAs Sequence");
  298. WindowManager wm = new WindowManager();
  299. dialog.FileName = this.CurrentFileNode.Name;
  300. bool? bret = wm.ShowDialog(dialog);
  301. if (!(bool)bret)
  302. return;
  303. string fullpath = (this.CurrentFileNode.Parent.FullPath == "" ? dialog.DialogResult : this.CurrentFileNode.Parent.FullPath + "\\" + dialog.DialogResult);
  304. if (this.IsExist(fullpath))
  305. {
  306. MessageBox.Show("Sequence already existed!");
  307. }
  308. else
  309. {
  310. if (this.IsChanged)
  311. {
  312. if (MessageBox.Show("This sequence is changed,do you want to save it?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  313. {
  314. this.Save(this.CurrentSequence);
  315. }
  316. }
  317. this.CurrentSequence.Revisor = BaseApp.Instance.UserContext.LoginName;
  318. this.CurrentSequence.ReviseTime = DateTime.Now;
  319. string tempname = this.CurrentSequence.Name;
  320. this.CurrentSequence.Name = fullpath;
  321. if (this.provider.SaveAs(fullpath, this.CurrentSequence))
  322. {
  323. FileNode node = new FileNode();
  324. node.Parent = this.CurrentFileNode.Parent;
  325. node.Name = dialog.DialogResult;
  326. node.FullPath = fullpath;
  327. node.IsFile = true;
  328. this.CurrentFileNode.Parent.Files.Add(node);
  329. }
  330. else
  331. {
  332. this.CurrentSequence.Name = tempname;
  333. MessageBox.Show("SaveAs failed!");
  334. }
  335. }
  336. }
  337. }
  338. private ICommand _DeleteFolderCommand;
  339. public ICommand DeleteFolderCommand
  340. {
  341. get
  342. {
  343. if (this._DeleteFolderCommand == null)
  344. this._DeleteFolderCommand = new BaseCommand(() => this.DeleteFolder());
  345. return this._DeleteFolderCommand;
  346. }
  347. }
  348. public void DeleteFolder()
  349. {
  350. if (!this.CurrentFileNode.IsFile && this.CurrentFileNode.FullPath != "")
  351. {
  352. if (DialogBox.Confirm("Do you want to delete this folder? this operation will delete all files in this folder."))
  353. {
  354. if (this.provider.DeleteSequenceFolder(this.CurrentFileNode.FullPath))
  355. {
  356. this.CurrentFileNode.Parent.Files.Remove(this.CurrentFileNode);
  357. }
  358. else
  359. DialogBox.ShowInfo("Delete folder failed!");
  360. }
  361. }
  362. }
  363. private ICommand _NewSequenceCommand;
  364. public ICommand NewSequenceCommand
  365. {
  366. get
  367. {
  368. if (this._NewSequenceCommand == null)
  369. this._NewSequenceCommand = new BaseCommand(() => this.NewSequence());
  370. return this._NewSequenceCommand;
  371. }
  372. }
  373. public void NewSequence()
  374. {
  375. if (MenuPermission != 3) return;
  376. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Sequence Name");
  377. WindowManager wm = new WindowManager();
  378. bool? bret = wm.ShowDialog(dialog);
  379. if ((bool)bret)
  380. {
  381. if (this.IsChanged)
  382. {
  383. if (MessageBox.Show("This sequence is changed,do you want to save it?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  384. {
  385. this.CurrentSequence.Revisor = BaseApp.Instance.UserContext.LoginName;
  386. this.CurrentSequence.ReviseTime = DateTime.Now;
  387. this.Save(this.CurrentSequence);
  388. }
  389. }
  390. else
  391. {
  392. string fullpath = "";
  393. if (this.CurrentFileNode.IsFile)
  394. fullpath = (this.CurrentFileNode.Parent.FullPath == "" ? dialog.DialogResult : this.CurrentFileNode.Parent.FullPath + "\\" + dialog.DialogResult);
  395. else
  396. fullpath = (this.CurrentFileNode.FullPath == "" ? dialog.DialogResult : this.CurrentFileNode.FullPath + "\\" + dialog.DialogResult);
  397. if (this.IsExist(fullpath))
  398. {
  399. MessageBox.Show("Sequence already existed!");
  400. }
  401. else
  402. {
  403. SequenceData sequence = new SequenceData();
  404. sequence.Name = fullpath;
  405. sequence.Creator = BaseApp.Instance.UserContext.LoginName;
  406. sequence.CreateTime = DateTime.Now;
  407. sequence.Revisor = BaseApp.Instance.UserContext.LoginName;
  408. sequence.ReviseTime = DateTime.Now;
  409. sequence.Description = string.Empty;
  410. if (this.Save(sequence))
  411. {
  412. this.CurrentSequence.Name = sequence.Name;
  413. this.CurrentSequence.Creator = sequence.Creator;
  414. this.CurrentSequence.CreateTime = sequence.CreateTime;
  415. this.CurrentSequence.Revisor = sequence.Revisor;
  416. this.CurrentSequence.ReviseTime = sequence.ReviseTime;
  417. this.CurrentSequence.Description = sequence.Description;
  418. this.CurrentSequence.Steps.Clear();
  419. FileNode file = new FileNode();
  420. file.Name = dialog.DialogResult;
  421. file.FullPath = this.CurrentSequence.Name;
  422. file.IsFile = true;
  423. file.Parent = this.CurrentFileNode.IsFile ? this.CurrentFileNode.Parent : this.CurrentFileNode;
  424. if (this.CurrentFileNode.IsFile)
  425. this.CurrentFileNode.Parent.Files.Insert(this.findInsertPosition(this.CurrentFileNode.Parent.Files), file);
  426. else
  427. this.CurrentFileNode.Files.Insert(this.findInsertPosition(this.CurrentFileNode.Files), file);
  428. this.editMode = EditMode.Normal;
  429. this.UpdateView();
  430. }
  431. }
  432. }
  433. }
  434. }
  435. private ICommand _RenameCommand;
  436. public ICommand RenameCommand
  437. {
  438. get
  439. {
  440. if (this._RenameCommand == null)
  441. this._RenameCommand = new BaseCommand(() => this.RenameSequence());
  442. return this._RenameCommand;
  443. }
  444. }
  445. public void RenameSequence()
  446. {
  447. if (MenuPermission != 3) return;
  448. if (this.CurrentFileNode.IsFile)
  449. {
  450. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Rename Sequence");
  451. WindowManager wm = new WindowManager();
  452. dialog.FileName = this.CurrentFileNode.Name;
  453. bool? bret = wm.ShowDialog(dialog);
  454. if (!(bool)bret)
  455. return;
  456. string fullpath = this.CurrentFileNode.Parent.FullPath == "" ? dialog.DialogResult : this.CurrentFileNode.Parent.FullPath + "\\" + dialog.DialogResult;
  457. if (this.IsExist(fullpath))
  458. {
  459. MessageBox.Show("Sequence already existed!");
  460. }
  461. else
  462. {
  463. if (this.IsChanged)
  464. {
  465. if (MessageBox.Show("This sequence is changed,do you want to save it?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  466. {
  467. this.Save(this.CurrentSequence);
  468. }
  469. }
  470. this.CurrentSequence.Revisor = BaseApp.Instance.UserContext.LoginName;
  471. this.CurrentSequence.ReviseTime = DateTime.Now;
  472. if (this.provider.Rename(this.CurrentSequence.Name, fullpath))
  473. {
  474. this.CurrentFileNode.Name = dialog.DialogResult;
  475. this.CurrentFileNode.FullPath = fullpath;
  476. this.CurrentSequence.Name = fullpath;
  477. }
  478. else
  479. MessageBox.Show("Rename failed!");
  480. }
  481. }
  482. }
  483. public void SaveSequence()
  484. {
  485. if (this.IsChanged)
  486. {
  487. this.Save(this.CurrentSequence);
  488. }
  489. }
  490. private ICommand _DeleteCommand;
  491. public ICommand DeleteSequenceCommand
  492. {
  493. get
  494. {
  495. if (this._DeleteCommand == null)
  496. this._DeleteCommand = new BaseCommand(() => this.DeleteSequence());
  497. return this._DeleteCommand;
  498. }
  499. }
  500. public void DeleteSequence()
  501. {
  502. if (MenuPermission != 3) return;
  503. if (this.CurrentFileNode.IsFile)
  504. {
  505. if (DialogBox.Confirm("Do you want to delete this sequence?"))
  506. {
  507. if (this.provider.Delete(this.CurrentSequence.Name))
  508. {
  509. this.CurrentFileNode.Parent.Files.Remove(this.CurrentFileNode);
  510. }
  511. }
  512. }
  513. }
  514. public void ReloadSequence()
  515. {
  516. if (MenuPermission != 3) return;
  517. if (this.editMode == EditMode.Normal || this.editMode == EditMode.Edit)
  518. {
  519. this.LoadData(this.CurrentSequence.Name);
  520. this.UpdateView();
  521. }
  522. }
  523. private bool Save(SequenceData seq)
  524. {
  525. if (MenuPermission != 3) return false;
  526. bool result = false;
  527. if (string.IsNullOrEmpty(seq.Name))
  528. {
  529. MessageBox.Show("Sequence name can't be empty");
  530. return false;
  531. }
  532. string ruleCheckMessage = null;
  533. if (!ValidateSequenceRules(seq, ref ruleCheckMessage))
  534. {
  535. MessageBox.Show(string.Format($"{seq.Name} rules check failed, don't allow to save: {ruleCheckMessage}"));
  536. return false;
  537. }
  538. seq.Revisor = BaseApp.Instance.UserContext.LoginName;
  539. seq.ReviseTime = DateTime.Now;
  540. result = this.provider.Save(seq);
  541. if (result)
  542. {
  543. foreach (ObservableCollection<Param> parameters in seq.Steps)
  544. {
  545. parameters.Apply(param => param.IsSaved = true);
  546. }
  547. this.editMode = EditMode.Normal;
  548. this.IsSavedDesc = true;
  549. this.CurrentSequence.IsChanged = false;
  550. this.NotifyOfPropertyChange("IsSavedDesc");
  551. this.UpdateView();
  552. }
  553. else
  554. MessageBox.Show("Save failed!");
  555. return result;
  556. }
  557. private bool IsExist(string sequencename)
  558. {
  559. bool existed = false;
  560. FileNode filenode = this.CurrentFileNode.IsFile ? this.CurrentFileNode.Parent : this.CurrentFileNode;
  561. for (var index = 0; index < filenode.Files.Count; index++)
  562. {
  563. if (filenode.Files[index].FullPath.ToLower() == sequencename.ToLower())
  564. {
  565. existed = true;
  566. break;
  567. }
  568. }
  569. return existed;
  570. }
  571. private bool ValidateSequenceRules(SequenceData currentSequence, ref string ruleCheckMessage)
  572. {
  573. return true;
  574. }
  575. #endregion
  576. #region Steps operation
  577. public void AddStep()
  578. {
  579. if (MenuPermission != 3) return;
  580. this.CurrentSequence.Steps.Add(CurrentSequence.CreateStep(this.Columns));
  581. if (this.editMode != EditMode.New && this.editMode != EditMode.ReName)
  582. this.editMode = EditMode.Edit;
  583. int index = 1;
  584. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  585. {
  586. (parameters[0] as StepParam).Value = index.ToString();
  587. index++;
  588. }
  589. this.UpdateView();
  590. }
  591. public void AppendStep()
  592. {
  593. if (MenuPermission != 3) return;
  594. int index = -1;
  595. bool found = false;
  596. for (var i = 0; i < this.CurrentSequence.Steps.Count; i++)
  597. {
  598. if (this.CurrentSequence.Steps[i][0] is StepParam && ((StepParam)this.CurrentSequence.Steps[i][0]).Checked)
  599. {
  600. index = i;
  601. found = true;
  602. break;
  603. }
  604. }
  605. if (found)
  606. {
  607. if (this.editMode != EditMode.New && this.editMode != EditMode.ReName)
  608. this.editMode = EditMode.Edit;
  609. this.CurrentSequence.Steps.Insert(index, this.CurrentSequence.CreateStep(this.Columns));
  610. index = 1;
  611. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  612. {
  613. (parameters[0] as StepParam).Value = index.ToString();
  614. index++;
  615. }
  616. }
  617. }
  618. private ObservableCollection<ObservableCollection<Param>> copySteps = new ObservableCollection<ObservableCollection<Param>>();
  619. public void CopyStep()
  620. {
  621. if (MenuPermission != 3) return;
  622. this.copySteps.Clear();
  623. for (var i = 0; i < this.CurrentSequence.Steps.Count; i++)
  624. {
  625. if (this.CurrentSequence.Steps[i][0] is StepParam && ((StepParam)this.CurrentSequence.Steps[i][0]).Checked)
  626. {
  627. this.copySteps.Add(this.CurrentSequence.CloneStep(this.Columns, this.CurrentSequence.Steps[i]));
  628. }
  629. }
  630. }
  631. public void PasteStep()
  632. {
  633. if (MenuPermission != 3) return;
  634. if (this.copySteps.Count > 0)
  635. {
  636. if (this.editMode != EditMode.New && this.editMode != EditMode.ReName)
  637. this.editMode = EditMode.Edit;
  638. for (var i = 0; i < this.CurrentSequence.Steps.Count; i++)
  639. {
  640. if (this.CurrentSequence.Steps[i][0] is StepParam && ((StepParam)this.CurrentSequence.Steps[i][0]).Checked)
  641. {
  642. for (var copyindex = 0; copyindex < this.copySteps.Count; copyindex++)
  643. {
  644. this.CurrentSequence.Steps.Insert(i, this.CurrentSequence.CloneStep(this.Columns, this.copySteps[copyindex]));
  645. i++;
  646. }
  647. break;
  648. }
  649. }
  650. int index = 1;
  651. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  652. {
  653. (parameters[0] as StepParam).Value = index.ToString();
  654. index++;
  655. }
  656. this.UpdateView();
  657. }
  658. }
  659. public void DeleteStep()
  660. {
  661. if (MenuPermission != 3) return;
  662. if (this.editMode != EditMode.New && this.editMode != EditMode.ReName)
  663. this.editMode = EditMode.Edit;
  664. List<ObservableCollection<Param>> steps = this.CurrentSequence.Steps.ToList();
  665. for (var i = 0; i < steps.Count; i++)
  666. {
  667. if (steps[i][0] is StepParam && ((StepParam)steps[i][0]).Checked)
  668. {
  669. this.CurrentSequence.Steps.Remove(steps[i]);
  670. }
  671. }
  672. int index = 1;
  673. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  674. {
  675. (parameters[0] as StepParam).Value = index.ToString();
  676. index++;
  677. }
  678. }
  679. public void SelectRecipe(PathFileParam param)
  680. {
  681. RecipeSequenceSelectDialogViewModel dialog = new RecipeSequenceSelectDialogViewModel();
  682. dialog.DisplayName = "Select Recipe";
  683. ObservableCollection<Param> parameters = param.Parent;
  684. PositionParam posParam = null;
  685. for (var index = 0; index < parameters.Count; index++)
  686. {
  687. if (parameters[index] is PositionParam)
  688. {
  689. posParam = parameters[index] as PositionParam;
  690. break;
  691. }
  692. }
  693. string module = ModuleName.System.ToString();
  694. List<string> lstFiles;
  695. if (Enum.TryParse<ModuleName>(posParam.Value, out ModuleName mod))
  696. module = posParam.Value;
  697. if (string.IsNullOrEmpty(param.Path))
  698. {
  699. lstFiles = RecipeClient.Instance.Service.GetRecipesByPath($"{module}", false).ToList();
  700. }
  701. else
  702. {
  703. lstFiles = RecipeClient.Instance.Service.GetRecipesByPath($"{param.Path}", false).ToList();
  704. }
  705. dialog.Files = new ObservableCollection<FileNode>(RecipeSequenceTreeBuilder.GetFiles(lstFiles));
  706. WindowManager wm = new WindowManager();
  707. bool? bret = wm.ShowDialog(dialog);
  708. if ((bool)bret)
  709. {
  710. param.Value = dialog.DialogResult;
  711. param.IsSaved = false;
  712. }
  713. }
  714. #endregion
  715. private void SelectDefault(FileNode node)
  716. {
  717. if (!node.IsFile)
  718. {
  719. if (node.Files.Count > 0)
  720. {
  721. foreach (FileNode file in node.Files)
  722. {
  723. if (file.IsFile)
  724. {
  725. this.TreeSelectChanged(file);
  726. break;
  727. }
  728. }
  729. }
  730. }
  731. }
  732. private void LoadData(string newSeqName)
  733. {
  734. SequenceData Sequence = this.provider.GetSequenceByName(this.Columns, newSeqName);
  735. this.CurrentSequence.Name = Sequence.Name;
  736. this.CurrentSequence.Creator = Sequence.Creator;
  737. this.CurrentSequence.CreateTime = Sequence.CreateTime;
  738. this.CurrentSequence.Revisor = Sequence.Revisor;
  739. this.CurrentSequence.ReviseTime = Sequence.ReviseTime;
  740. this.CurrentSequence.Description = Sequence.Description;
  741. this.CurrentSequence.IsThick = Sequence.IsThick;
  742. this.CurrentSequence.IsChanged = false;
  743. this.CurrentSequence.Steps.Clear();
  744. Sequence.Steps.ToList().ForEach(step =>
  745. this.CurrentSequence.Steps.Add(step));
  746. int index = 1;
  747. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  748. {
  749. (parameters[0] as StepParam).Value = index.ToString();
  750. index++;
  751. }
  752. this.IsSavedDesc = true;
  753. this.NotifyOfPropertyChange("IsSavedDesc");
  754. this.editMode = EditMode.Normal;
  755. }
  756. private void ClearData()
  757. {
  758. this.editMode = EditMode.None;
  759. this.CurrentSequence.Steps.Clear();
  760. this.CurrentSequence.Name = string.Empty;
  761. this.CurrentSequence.Description = string.Empty;
  762. this.CurrentSequence.IsChanged = false;
  763. this.IsSavedDesc = true;
  764. this.NotifyOfPropertyChange("IsSavedGroup");
  765. this.NotifyOfPropertyChange("IsSavedDesc");
  766. }
  767. public void UpdateView()
  768. {
  769. this.EnableSequenceName = false;
  770. this.NotifyOfPropertyChange("EnableSequenceName");
  771. this.EnableNew = true;
  772. this.EnableReName = true;
  773. this.EnableCopy = true;
  774. this.EnableDelete = true;
  775. this.EnableSave = true;
  776. this.EnableStep = true;
  777. this.NotifyOfPropertyChange("EnableNew");
  778. this.NotifyOfPropertyChange("EnableReName");
  779. this.NotifyOfPropertyChange("EnableCopy");
  780. this.NotifyOfPropertyChange("EnableDelete");
  781. this.NotifyOfPropertyChange("EnableSave");
  782. this.NotifyOfPropertyChange("EnableStep");
  783. if (this.editMode == EditMode.None)
  784. {
  785. this.EnableNew = true;
  786. this.EnableReName = false;
  787. this.EnableCopy = false;
  788. this.EnableDelete = false;
  789. this.EnableStep = false;
  790. this.EnableSave = false;
  791. this.NotifyOfPropertyChange("EnableNew");
  792. this.NotifyOfPropertyChange("EnableReName");
  793. this.NotifyOfPropertyChange("EnableCopy");
  794. this.NotifyOfPropertyChange("EnableDelete");
  795. this.NotifyOfPropertyChange("EnableSave");
  796. this.NotifyOfPropertyChange("EnableStep");
  797. }
  798. }
  799. private bool IsChanged
  800. {
  801. get
  802. {
  803. bool changed = false;
  804. if (!this.IsSavedDesc || this.editMode == EditMode.Edit || CurrentSequence.IsChanged)
  805. {
  806. changed = true;
  807. }
  808. else
  809. {
  810. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  811. {
  812. if (parameters.Where(param => param.IsSaved == false).Count() > 0)
  813. {
  814. changed = true;
  815. break;
  816. }
  817. }
  818. }
  819. return changed;
  820. }
  821. }
  822. public bool EnableNew { get; set; }
  823. public bool EnableReName { get; set; }
  824. public bool EnableCopy { get; set; }
  825. public bool EnableDelete { get; set; }
  826. public bool EnableSave { get; set; }
  827. public bool EnableStep { get; set; }
  828. public bool IsSavedDesc { get; set; }
  829. public FileNode CurrentFileNode { get; private set; }
  830. public SequenceData CurrentSequence { get; private set; }
  831. public ObservableCollection<ColumnBase> Columns { get; set; }
  832. public bool EnableSequenceName { get; set; }
  833. private string selectedSequenceName = string.Empty;
  834. private string SequenceNameBeforeRename = string.Empty;
  835. private string lastSequenceName = string.Empty;
  836. private SequenceColumnBuilder columnBuilder = new SequenceColumnBuilder();
  837. private EditMode editMode;
  838. private SequenceDataProvider provider = new SequenceDataProvider();
  839. }
  840. }