SequenceViewModel.cs 33 KB

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