SequenceViewModel.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.UI.View.Common;
  3. using Caliburn.Micro.Core;
  4. using MECF.Framework.Common.DataCenter;
  5. using MECF.Framework.Common.Equipment;
  6. using Microsoft.VisualBasic;
  7. using Microsoft.Win32;
  8. using Prism.Commands;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using Prism.Services.Dialogs;
  12. using RecipeEditorLib.DGExtension.CustomColumn;
  13. using RecipeEditorLib.RecipeModel.Params;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Collections.ObjectModel;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows;
  22. using System.Windows.Controls;
  23. using System.Windows.Input;
  24. using System.Windows.Media;
  25. using System.Xml;
  26. using Venus_Core;
  27. using Venus_MainPages.PMs;
  28. using Venus_MainPages.Sequence;
  29. using Venus_MainPages.Views;
  30. using WPF.Themes.UserControls;
  31. namespace Venus_MainPages.ViewModels
  32. {
  33. internal class SequenceViewModel : BindableBase
  34. {
  35. #region 私有字段
  36. //private IUiSequenceManager m_uiSequenceManager = new UiSequenceManager();
  37. private SequenceView m_SequenceView;
  38. private bool m_IsPageLoad = true;
  39. private SequenceData m_CurrentSequence;
  40. private SequenceColumnBuilder columnBuilder = new SequenceColumnBuilder();
  41. private SequenceDataProvider provider = new SequenceDataProvider(new UiSequenceManager());
  42. #endregion
  43. #region 命令
  44. private DelegateCommand<Object> m_LoadedCommand;
  45. public DelegateCommand<Object> LoadedCommand =>
  46. m_LoadedCommand ?? (m_LoadedCommand = new DelegateCommand<Object>(OnLoaded));
  47. private DelegateCommand m_AddStepCommand;
  48. public DelegateCommand AddStepCommand =>
  49. m_AddStepCommand ?? (m_AddStepCommand = new DelegateCommand(AddStep));
  50. private DelegateCommand m_InsertCommand;
  51. public DelegateCommand InsertCommand =>
  52. m_InsertCommand ?? (m_InsertCommand = new DelegateCommand(InsertStep));
  53. private DelegateCommand m_CopyCommand;
  54. public DelegateCommand CopyCommand =>
  55. m_CopyCommand ?? (m_CopyCommand = new DelegateCommand(CopyStep));
  56. private DelegateCommand m_PasteCommand;
  57. public DelegateCommand PasteCommand =>
  58. m_PasteCommand ?? (m_PasteCommand = new DelegateCommand(PasteStep));
  59. private DelegateCommand m_DeleteStepCommand;
  60. public DelegateCommand DeleteStepCommand =>
  61. m_DeleteStepCommand ?? (m_DeleteStepCommand = new DelegateCommand(DeleteStep));
  62. private DelegateCommand m_ReloadSequenceCommand;
  63. public DelegateCommand ReloadSequenceCommand =>
  64. m_ReloadSequenceCommand ?? (m_ReloadSequenceCommand = new DelegateCommand(ReloadSequence));
  65. private DelegateCommand m_SaveSequenceCommand;
  66. public DelegateCommand SaveSequenceCommand =>
  67. m_SaveSequenceCommand ?? (m_SaveSequenceCommand = new DelegateCommand(SaveSequence));
  68. private DelegateCommand<object> m_SelectRecipeCommand;
  69. public DelegateCommand<object> SelectRecipeCommand =>
  70. m_SelectRecipeCommand ?? (m_SelectRecipeCommand = new DelegateCommand<object>(SelectRecipe));
  71. private DelegateCommand<Object> m_TreeSelectChangedCommand;
  72. public DelegateCommand<Object> TreeSelectChangedCommand =>
  73. m_TreeSelectChangedCommand ?? (m_TreeSelectChangedCommand = new DelegateCommand<Object>(TreeSelectChanged));
  74. private DelegateCommand<MouseButtonEventArgs> m_TreeRightMouseDownCommand;
  75. public DelegateCommand<MouseButtonEventArgs> TreeRightMouseDownCommand =>
  76. m_TreeRightMouseDownCommand ?? (m_TreeRightMouseDownCommand = new DelegateCommand<MouseButtonEventArgs>(TreeRightMouseDown));
  77. private DelegateCommand m_NewSequenceCommand;
  78. public DelegateCommand NewSequenceCommand =>
  79. m_NewSequenceCommand ?? (m_NewSequenceCommand = new DelegateCommand(NewSequence));
  80. private DelegateCommand m_RenameCommand;
  81. public DelegateCommand RenameCommand =>
  82. m_RenameCommand ?? (m_RenameCommand = new DelegateCommand(RenameSequence));
  83. private DelegateCommand m_DeleteCommand;
  84. public DelegateCommand DeleteSequenceCommand =>
  85. m_DeleteCommand ?? (m_DeleteCommand = new DelegateCommand(DeleteSequence));
  86. private DelegateCommand m_SaveAsCommand;
  87. public DelegateCommand SaveAsCommand =>
  88. m_SaveAsCommand ?? (m_SaveAsCommand = new DelegateCommand(SaveAsSequence));
  89. #endregion
  90. #region 属性
  91. ObservableCollection<FileNode> m_Files = new ObservableCollection<FileNode>();
  92. public ObservableCollection<FileNode> Files
  93. {
  94. get { return m_Files; }
  95. set { SetProperty(ref m_Files, value); }
  96. }
  97. private string m_SequenceName = String.Empty;
  98. public string SequenceName
  99. {
  100. get { return m_SequenceName; }
  101. set
  102. {
  103. if (value == m_SequenceName)
  104. return;
  105. SetProperty(ref m_SequenceName, value);
  106. ApplyFilter();
  107. }
  108. }
  109. public SequenceData CurrentSequence
  110. {
  111. get { return m_CurrentSequence; }
  112. set { SetProperty(ref m_CurrentSequence, value); }
  113. }
  114. public FileNode CurrentFileNode { get; private set; }
  115. public ObservableCollection<EditorDataGridTemplateColumnBase> Columns { get; private set; }
  116. #endregion
  117. #region page_load
  118. private void OnLoaded(Object sequenceView)
  119. {
  120. if (m_IsPageLoad)
  121. {
  122. m_IsPageLoad = false;
  123. GetFiles(provider.GetSequenceNameList());
  124. this.CurrentSequence = new SequenceData();
  125. this.Columns = this.columnBuilder.Build();
  126. SequenceColumnBuilder.ApplyTemplate((UserControl)sequenceView, this.Columns);
  127. m_SequenceView = sequenceView as SequenceView;
  128. this.Columns.Apply((c) =>
  129. {
  130. c.Header = c;
  131. m_SequenceView.dgCustom.Columns.Add(c);
  132. });
  133. m_SequenceView.dgCustom.ItemsSource = CurrentSequence.Steps;
  134. if (Files.Count > 0)
  135. {
  136. this.CurrentFileNode = this.Files[0];
  137. this.SelectDefault(this.CurrentFileNode);
  138. }
  139. }
  140. }
  141. private void GetFiles(List<string> names)
  142. {
  143. Files = new ObservableCollection<FileNode>(RecipeSequenceTreeBuilder.GetFiles("", names));
  144. }
  145. #endregion
  146. #region tree action
  147. public void NewSequence()
  148. {
  149. InputFileNameDialogView dialog = new InputFileNameDialogView("Input New Sequence Name")
  150. {
  151. Owner = Application.Current.MainWindow
  152. };
  153. if (dialog.ShowDialog() == true)
  154. {
  155. string fullpath = dialog.FileName;
  156. if (this.CurrentFileNode.IsFile)
  157. fullpath = (string.IsNullOrEmpty(this.CurrentFileNode.Parent.FullPath) ? dialog.FileName : this.CurrentFileNode.Parent.FullPath + "\\" + dialog.FileName);
  158. else
  159. fullpath = (string.IsNullOrEmpty(this.CurrentFileNode.FullPath) ? dialog.FileName : this.CurrentFileNode.FullPath + "\\" + dialog.FileName);
  160. if (fullpath.Length > 25)
  161. {
  162. WPFMessageBox.ShowError("SequenceName Length can not over 25");
  163. return;
  164. }
  165. if (string.IsNullOrEmpty(fullpath))
  166. {
  167. MessageBox.Show("SequenceName cannot be null or empty!");
  168. return;
  169. }
  170. if (this.IsExist(fullpath))
  171. {
  172. MessageBox.Show("Sequence already existed!");
  173. }
  174. else
  175. {
  176. SequenceData sequence = new SequenceData();
  177. sequence.Name = fullpath;
  178. sequence.Creator = "Admin";
  179. sequence.CreateTime = DateTime.Now;
  180. sequence.Revisor = sequence.Creator;
  181. sequence.ReviseTime = DateTime.Now;
  182. sequence.Description = string.Empty;
  183. if (this.Save(sequence))
  184. {
  185. this.CurrentSequence.Name = sequence.Name;
  186. this.CurrentSequence.Creator = sequence.Creator;
  187. this.CurrentSequence.CreateTime = sequence.CreateTime;
  188. this.CurrentSequence.Revisor = sequence.Revisor;
  189. this.CurrentSequence.ReviseTime = sequence.ReviseTime;
  190. this.CurrentSequence.Description = sequence.Description;
  191. this.CurrentSequence.Steps.Clear();
  192. FileNode file = new FileNode();
  193. file.Name = dialog.FileName;
  194. file.FullPath = this.CurrentSequence.Name;
  195. file.IsFile = true;
  196. file.Parent = this.CurrentFileNode.IsFile ? this.CurrentFileNode.Parent : this.CurrentFileNode;
  197. if (this.CurrentFileNode.IsFile)
  198. this.CurrentFileNode.Parent.Files.Insert(this.FindInsertPosition(this.CurrentFileNode.Parent.Files), file);
  199. else
  200. this.CurrentFileNode.Files.Insert(this.FindInsertPosition(this.CurrentFileNode.Files), file);
  201. }
  202. }
  203. }
  204. }
  205. public void RenameSequence()
  206. {
  207. if (this.CurrentFileNode.IsFile)
  208. {
  209. InputFileNameDialogView dialog = new InputFileNameDialogView("Rename Sequence")
  210. {
  211. Owner = Application.Current.MainWindow
  212. };
  213. dialog.FileName = this.CurrentFileNode.Name;
  214. if (dialog.ShowDialog() == true)
  215. {
  216. string fullpath = this.CurrentFileNode.Parent.FullPath == "" ? dialog.FileName : this.CurrentFileNode.Parent.FullPath + "\\" + dialog.FileName;
  217. if (fullpath.Length > 25)
  218. {
  219. WPFMessageBox.ShowError("SequenceName Length can not over 25");
  220. return;
  221. }
  222. if (string.IsNullOrEmpty(fullpath))
  223. {
  224. MessageBox.Show("SequenceName cannot be null or empty!");
  225. return;
  226. }
  227. if (this.IsExist(fullpath))
  228. {
  229. MessageBox.Show("Sequence already existed!");
  230. }
  231. else
  232. {
  233. this.CurrentSequence.Revisor = "Admin";
  234. this.CurrentSequence.ReviseTime = DateTime.Now;
  235. if (this.provider.Rename(this.CurrentSequence.Name, fullpath))
  236. {
  237. this.CurrentFileNode.Name = dialog.FileName;
  238. this.CurrentFileNode.FullPath = fullpath;
  239. this.CurrentSequence.Name = fullpath;
  240. }
  241. else
  242. MessageBox.Show("Rename failed!");
  243. }
  244. }
  245. }
  246. }
  247. public void DeleteSequence()
  248. {
  249. if (this.CurrentFileNode.IsFile)
  250. {
  251. if (WPFMessageBox.ShowQuestion($"Do you want to delete this {this.CurrentSequence.Name}?", "删除后无法恢复!!!") == MessageBoxResult.Yes)
  252. {
  253. if (this.provider.Delete(this.CurrentSequence.Name))
  254. {
  255. this.CurrentFileNode.Parent.Files.Remove(this.CurrentFileNode);
  256. }
  257. }
  258. }
  259. }
  260. public void SaveAsSequence()
  261. {
  262. if (this.CurrentFileNode.IsFile)
  263. {
  264. InputFileNameDialogView dialog = new InputFileNameDialogView("Input New Sequence Name")
  265. {
  266. Owner = Application.Current.MainWindow
  267. };
  268. if (dialog.ShowDialog() == true)
  269. {
  270. string fullpath = (this.CurrentFileNode.Parent.FullPath == "" ? dialog.FileName : this.CurrentFileNode.Parent.FullPath + "\\" + dialog.FileName);
  271. if (string.IsNullOrEmpty(fullpath))
  272. {
  273. MessageBox.Show("SequenceName cannot be null or empty!");
  274. return;
  275. }
  276. if (this.IsExist(fullpath))
  277. {
  278. MessageBox.Show("Sequence already existed!");
  279. }
  280. else
  281. {
  282. this.CurrentSequence.Revisor = "Admin";
  283. this.CurrentSequence.ReviseTime = DateTime.Now;
  284. string tempname = this.CurrentSequence.Name;
  285. this.CurrentSequence.Name = fullpath;
  286. if (this.provider.SaveAs(fullpath, this.CurrentSequence))
  287. {
  288. FileNode node = new FileNode();
  289. node.Parent = this.CurrentFileNode.Parent;
  290. node.Name = dialog.FileName;
  291. node.FullPath = fullpath;
  292. node.IsFile = true;
  293. this.CurrentFileNode.Parent.Files.Add(node);
  294. }
  295. else
  296. {
  297. this.CurrentSequence.Name = tempname;
  298. MessageBox.Show("SaveAs failed!");
  299. }
  300. }
  301. }
  302. }
  303. }
  304. public void TreeSelectChanged(object selectItem)
  305. {
  306. FileNode file = (FileNode)selectItem;
  307. if (file != null && file.IsFile)
  308. {
  309. this.LoadData(file.FullPath);
  310. this.CurrentFileNode = file;
  311. }
  312. else
  313. {
  314. this.ClearData();
  315. }
  316. }
  317. private TreeViewItem GetParentObjectEx<TreeViewItem>(DependencyObject obj) where TreeViewItem : FrameworkElement
  318. {
  319. DependencyObject parent = VisualTreeHelper.GetParent(obj);
  320. while (parent != null)
  321. {
  322. if (parent is TreeViewItem)
  323. {
  324. return (TreeViewItem)parent;
  325. }
  326. parent = VisualTreeHelper.GetParent(parent);
  327. }
  328. return null;
  329. }
  330. public void TreeRightMouseDown(MouseButtonEventArgs e)
  331. {
  332. if (e != null)
  333. {
  334. var item = GetParentObjectEx<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
  335. if (item != null)
  336. {
  337. item.Focus();
  338. }
  339. }
  340. }
  341. #endregion
  342. #region sequence action
  343. public void AddStep()
  344. {
  345. this.CurrentSequence.Steps.Add(CurrentSequence.CreateStep(this.Columns));
  346. int index = 1;
  347. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  348. {
  349. (parameters[0] as StepParam).Value = index.ToString();
  350. index++;
  351. }
  352. }
  353. public void InsertStep()
  354. {
  355. int index = -1;
  356. bool found = false;
  357. for (var i = 0; i < this.CurrentSequence.Steps.Count; i++)
  358. {
  359. if (this.CurrentSequence.Steps[i][0] is StepParam && ((StepParam)this.CurrentSequence.Steps[i][0]).Checked)
  360. {
  361. index = i;
  362. found = true;
  363. break;
  364. }
  365. }
  366. if (found)
  367. {
  368. this.CurrentSequence.Steps.Insert(index, this.CurrentSequence.CreateStep(this.Columns));
  369. index = 1;
  370. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  371. {
  372. (parameters[0] as StepParam).Value = index.ToString();
  373. index++;
  374. }
  375. }
  376. }
  377. private ObservableCollection<ObservableCollection<Param>> copySteps = new ObservableCollection<ObservableCollection<Param>>();
  378. public void CopyStep()
  379. {
  380. this.copySteps.Clear();
  381. for (var i = 0; i < this.CurrentSequence.Steps.Count; i++)
  382. {
  383. if (this.CurrentSequence.Steps[i][0] is StepParam && ((StepParam)this.CurrentSequence.Steps[i][0]).Checked)
  384. {
  385. this.copySteps.Add(this.CurrentSequence.CloneStep(this.Columns, this.CurrentSequence.Steps[i]));
  386. }
  387. }
  388. }
  389. public void PasteStep()
  390. {
  391. if (this.copySteps.Count > 0)
  392. {
  393. if (this.CurrentSequence.Steps.Count > 0)
  394. {
  395. for (var i = 0; i < this.CurrentSequence.Steps.Count; i++)
  396. {
  397. if (this.CurrentSequence.Steps[i][0] is StepParam && ((StepParam)this.CurrentSequence.Steps[i][0]).Checked)
  398. {
  399. for (var copyindex = 0; copyindex < this.copySteps.Count; copyindex++)
  400. {
  401. this.CurrentSequence.Steps.Insert(i, this.CurrentSequence.CloneStep(this.Columns, this.copySteps[copyindex]));
  402. i++;
  403. }
  404. break;
  405. }
  406. }
  407. }
  408. else
  409. {
  410. for (var copyindex = 0; copyindex < this.copySteps.Count; copyindex++)
  411. {
  412. this.CurrentSequence.Steps.Insert(copyindex, this.CurrentSequence.CloneStep(this.Columns, this.copySteps[copyindex]));
  413. }
  414. }
  415. SetStepIndex();
  416. }
  417. }
  418. public void DeleteStep()
  419. {
  420. List<ObservableCollection<Param>> steps = this.CurrentSequence.Steps.ToList();
  421. for (var i = 0; i < steps.Count; i++)
  422. {
  423. if (steps[i][0] is StepParam && ((StepParam)steps[i][0]).Checked)
  424. {
  425. this.CurrentSequence.Steps.Remove(steps[i]);
  426. }
  427. }
  428. SetStepIndex();
  429. }
  430. public void ReloadSequence()
  431. {
  432. this.LoadData(this.CurrentSequence.Name);
  433. }
  434. public void SelectRecipe(object select)
  435. {
  436. PathFileParam param = (PathFileParam)select;
  437. RecipeSequenceSelectView dialog = new RecipeSequenceSelectView()
  438. {
  439. Owner = Application.Current.MainWindow
  440. };
  441. dialog.Title = "Select Recipe";
  442. var dataContext = new RecipeSequenceSelectViewModel();
  443. dialog.DataContext = dataContext;
  444. ObservableCollection<Param> parameters = param.Parent;
  445. PositionParam posParam = null;
  446. for (var index = 0; index < parameters.Count; index++)
  447. {
  448. if (parameters[index] is PositionParam)
  449. {
  450. posParam = parameters[index] as PositionParam;
  451. break;
  452. }
  453. }
  454. List<string> lstFiles = new List<string>();
  455. if (param.Name.Contains("Clean"))
  456. {
  457. lstFiles = provider.GetRecipesByPath($"{param.PrefixPath}").Where(x => x.Split('\\')[1] == "Clean").ToList();//m_uiSequenceManager.GetRecipesByPath($"{param.PrefixPath}");
  458. }
  459. else
  460. {
  461. if (param.Name.Contains("PMA"))
  462. {
  463. lstFiles = provider.GetRecipesByPath($"{param.PrefixPath}").Where(x => x.Split('\\')[0] == "PMA" && x.Split('\\')[1] == "Process").ToList();
  464. }
  465. else if (param.Name.Contains("PMB"))
  466. {
  467. lstFiles = provider.GetRecipesByPath($"{param.PrefixPath}").Where(x => x.Split('\\')[0] == "PMB" && x.Split('\\')[1] == "Process").ToList();
  468. }
  469. else if (param.Name.Contains("PMC"))
  470. {
  471. lstFiles = provider.GetRecipesByPath($"{param.PrefixPath}").Where(x => x.Split('\\')[0] == "PMC" && x.Split('\\')[1] == "Process").ToList();
  472. }
  473. else if (param.Name.Contains("PMD"))
  474. {
  475. lstFiles = provider.GetRecipesByPath($"{param.PrefixPath}").Where(x => x.Split('\\')[0] == "PMD" && x.Split('\\')[1] == "Process").ToList();
  476. }
  477. else
  478. {
  479. lstFiles = provider.GetRecipesByPath($"{param.PrefixPath}").Where(x => x.Split('\\')[1] == "Process").ToList();
  480. }
  481. }
  482. dataContext.Files = new ObservableCollection<FileNode>(RecipeSequenceTreeBuilder.GetFiles("", lstFiles));
  483. if (dialog.ShowDialog() == true)
  484. {
  485. //param.Value = dialog.FullPath;
  486. //param.Value = $"{param.PrefixPath}\\" + dialog.FullPath;
  487. //param.FileName = param.Value;
  488. string path = dialog.FullPath;
  489. int index = path.LastIndexOf("\\");
  490. if (index > -1)
  491. {
  492. param.FileName = path.Substring(index + 1);
  493. param.Value = path.Substring(index + 1);
  494. }
  495. else
  496. {
  497. param.FileName = path;
  498. param.Value = path;
  499. }
  500. param.IsSaved = false;
  501. }
  502. }
  503. public void SaveSequence()
  504. {
  505. this.Save(this.CurrentSequence);
  506. }
  507. private void SetStepIndex()
  508. {
  509. int index = 1;
  510. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  511. {
  512. (parameters[0] as StepParam).Value = index.ToString();
  513. index++;
  514. }
  515. }
  516. #endregion
  517. #region private
  518. private void ApplyFilter()
  519. {
  520. var sequenceList = provider.GetSequenceNameList() ?? new List<string>();
  521. GetFiles(sequenceList.Where(p => {
  522. return string.IsNullOrWhiteSpace(SequenceName) || p.IndexOf(SequenceName, StringComparison.OrdinalIgnoreCase) > -1;
  523. }).ToList());
  524. }
  525. private void ClearData()
  526. {
  527. this.CurrentSequence.Steps.Clear();
  528. this.CurrentSequence.Name = string.Empty;
  529. this.CurrentSequence.Description = string.Empty;
  530. }
  531. private bool Save(SequenceData seq)
  532. {
  533. bool result = false;
  534. if (string.IsNullOrEmpty(seq.Name))
  535. {
  536. MessageBox.Show("Sequence name can't be empty");
  537. return false;
  538. }
  539. string ruleCheckMessage = null;
  540. if (!ValidateSequenceRules(seq, ref ruleCheckMessage))
  541. {
  542. MessageBox.Show(string.Format($"{seq.Name} rules check failed, don't allow to save: {ruleCheckMessage}"));
  543. return false;
  544. }
  545. seq.Revisor = "Admin";
  546. seq.ReviseTime = DateTime.Now;
  547. result = this.provider.Save(seq);
  548. if (result)
  549. {
  550. foreach (ObservableCollection<Param> parameters in seq.Steps)
  551. {
  552. parameters.Apply(param => param.IsSaved = true);
  553. }
  554. }
  555. else
  556. MessageBox.Show("Save failed!");
  557. return result;
  558. }
  559. private bool ValidateSequenceRules(SequenceData currentSequence, ref string ruleCheckMessage)
  560. {
  561. int preIndex = -1;
  562. for (var i = 0; i < currentSequence.Steps.Count; i++)
  563. {
  564. var stepInfo = currentSequence.Steps[i];
  565. if (string.IsNullOrEmpty((stepInfo[1] as PositionParam).Value))
  566. {
  567. ruleCheckMessage = $"Step{(stepInfo[0] as StepParam).Value}, Position Is Empty";
  568. return false;
  569. }
  570. if ((stepInfo[1] as PositionParam).Value == "LL")
  571. {
  572. if (preIndex != -1 && (i - preIndex) == 1)
  573. {
  574. ruleCheckMessage = $"Step{(stepInfo[0] as StepParam).Value}, The LL is set around the pm ";
  575. return false;
  576. }
  577. preIndex = i;
  578. }
  579. }
  580. return true;
  581. }
  582. private XmlAttribute CreateAttribute(XmlNode node, string attributeName, string value)
  583. {
  584. try
  585. {
  586. XmlDocument doc = node.OwnerDocument;
  587. XmlAttribute attr = null;
  588. attr = doc.CreateAttribute(attributeName);
  589. attr.Value = value;
  590. node.Attributes.SetNamedItem(attr);
  591. return attr;
  592. }
  593. catch (Exception err)
  594. {
  595. string desc = err.Message;
  596. return null;
  597. }
  598. }
  599. private void SelectDefault(FileNode node)
  600. {
  601. if (!node.IsFile)
  602. {
  603. if (node.Files.Count > 0)
  604. {
  605. foreach (FileNode file in node.Files)
  606. {
  607. if (file.IsFile)
  608. {
  609. this.TreeSelectChanged(file);
  610. //break;
  611. }
  612. }
  613. }
  614. }
  615. }
  616. public void TreeSelectChanged(FileNode file)
  617. {
  618. if (file != null && file.IsFile)
  619. {
  620. //if (this.IsChanged)
  621. // if (MessageBox.Show("This sequence is changed,do you want to save it?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  622. // this.Save(this.CurrentSequence);
  623. this.LoadData(file.FullPath);
  624. this.CurrentFileNode = file;
  625. }
  626. else
  627. {
  628. //this.ClearData();
  629. //this.editMode = EditMode.None;
  630. this.CurrentSequence.Steps.Clear();
  631. }
  632. //this.UpdateView();
  633. }
  634. private void LoadData(string newSeqName)
  635. {
  636. SequenceData Sequence = this.provider.GetSequenceByName(this.Columns, newSeqName);
  637. this.CurrentSequence.Name = Sequence.Name;
  638. this.CurrentSequence.Creator = Sequence.Creator;
  639. this.CurrentSequence.CreateTime = Sequence.CreateTime;
  640. this.CurrentSequence.Revisor = Sequence.Revisor;
  641. this.CurrentSequence.ReviseTime = Sequence.ReviseTime;
  642. this.CurrentSequence.Description = Sequence.Description;
  643. this.CurrentSequence.Steps.Clear();
  644. Sequence.Steps.ToList().ForEach(step =>
  645. this.CurrentSequence.Steps.Add(step));
  646. //int index = 1;
  647. //foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  648. //{
  649. // (parameters[0] as StepParam).Value = index.ToString();
  650. // index++;
  651. // foreach (var para in parameters)
  652. // {
  653. // var pathFile = para as PathFileParam;
  654. // if (pathFile != null)
  655. // {
  656. // pathFile.Value = pathFile.Value.Replace($"{pathFile.PrefixPath}\\", "");
  657. // }
  658. // }
  659. //}
  660. //this.IsSavedDesc = true;
  661. //this.NotifyOfPropertyChange("IsSavedDesc");
  662. //this.editMode = EditMode.Normal;
  663. }
  664. private bool IsExist(string sequencename)
  665. {
  666. bool existed = false;
  667. FileNode filenode = this.CurrentFileNode.IsFile ? this.CurrentFileNode.Parent : this.CurrentFileNode;
  668. for (var index = 0; index < filenode.Files.Count; index++)
  669. {
  670. if (filenode.Files[index].FullPath.ToLower() == sequencename.ToLower())
  671. {
  672. existed = true;
  673. break;
  674. }
  675. }
  676. return existed;
  677. }
  678. private int FindInsertPosition(ObservableCollection<FileNode> files)
  679. {
  680. int pos = -1;
  681. if (files.Count == 0)
  682. pos = 0;
  683. else
  684. {
  685. bool foundfolder = false;
  686. for (var index = 0; index < files.Count; index++)
  687. {
  688. if (!files[index].IsFile)
  689. {
  690. foundfolder = true;
  691. pos = index;
  692. break;
  693. }
  694. }
  695. if (!foundfolder)
  696. pos = files.Count;
  697. }
  698. return pos;
  699. }
  700. #endregion
  701. }
  702. }