SequenceViewModel.cs 36 KB

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