SequenceViewModel.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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 = Venus_MainPages.Unity.GlobalUser.Instance.User.Name; ;
  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 = Venus_MainPages.Unity.GlobalUser.Instance.User.Name; ;
  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 = Venus_MainPages.Unity.GlobalUser.Instance.User.Name; ;
  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. VenusRecipeSequenceSelectView dialog = new VenusRecipeSequenceSelectView(param.Value)
  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. string moduleName = param.Name.Substring(0, 3);
  456. var Clean = provider.GetRecipesByPath($"{param.PrefixPath}").Where(x => x.Split('\\')[0] == moduleName && x.Split('\\')[1] == "Clean").ToList();//m_uiSequenceManager.GetRecipesByPath($"{param.PrefixPath}");
  457. Clean.Add($"{moduleName}\\Clean\\");
  458. var Process = provider.GetRecipesByPath($"{param.PrefixPath}").Where(x => x.Split('\\')[0] == moduleName && x.Split('\\')[1] == "Process").ToList();
  459. Process.Add($"{moduleName}\\Process\\");
  460. dataContext.Files.AddRange(new ObservableCollection<FileNode>(RecipeSequenceTreeBuilder.GetFiles("", Clean)));
  461. dataContext.Files.AddRange(new ObservableCollection<FileNode>(RecipeSequenceTreeBuilder.GetFiles("", Process)));
  462. if (dialog.ShowDialog() == true)
  463. {
  464. string path = dialog.FullPath;
  465. param.FileName = path;
  466. param.Value = path;
  467. param.IsSaved = false;
  468. }
  469. }
  470. public void SaveSequence()
  471. {
  472. this.Save(this.CurrentSequence);
  473. }
  474. private void SetStepIndex()
  475. {
  476. int index = 1;
  477. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  478. {
  479. (parameters[0] as StepParam).Value = index.ToString();
  480. index++;
  481. }
  482. }
  483. #endregion
  484. #region private
  485. private void ApplyFilter()
  486. {
  487. var sequenceList = provider.GetSequenceNameList() ?? new List<string>();
  488. GetFiles(sequenceList.Where(p => {
  489. return string.IsNullOrWhiteSpace(SequenceName) || p.IndexOf(SequenceName, StringComparison.OrdinalIgnoreCase) > -1;
  490. }).ToList());
  491. }
  492. private void ClearData()
  493. {
  494. this.CurrentSequence.Steps.Clear();
  495. this.CurrentSequence.Name = string.Empty;
  496. this.CurrentSequence.Description = string.Empty;
  497. }
  498. private bool Save(SequenceData seq)
  499. {
  500. bool result = false;
  501. if (string.IsNullOrEmpty(seq.Name))
  502. {
  503. MessageBox.Show("Sequence name can't be empty");
  504. return false;
  505. }
  506. string ruleCheckMessage = null;
  507. if (!ValidateSequenceRules(seq, ref ruleCheckMessage))
  508. {
  509. MessageBox.Show(string.Format($"{seq.Name} rules check failed, don't allow to save: {ruleCheckMessage}"));
  510. return false;
  511. }
  512. seq.Revisor = Venus_MainPages.Unity.GlobalUser.Instance.User.Name;
  513. seq.ReviseTime = DateTime.Now;
  514. result = this.provider.Save(seq);
  515. if (result)
  516. {
  517. foreach (ObservableCollection<Param> parameters in seq.Steps)
  518. {
  519. parameters.Apply(param => param.IsSaved = true);
  520. }
  521. }
  522. else
  523. MessageBox.Show("Save failed!");
  524. return result;
  525. }
  526. private bool ValidateSequenceRules(SequenceData currentSequence, ref string ruleCheckMessage)
  527. {
  528. int preIndex = -1;
  529. for (var i = 0; i < currentSequence.Steps.Count; i++)
  530. {
  531. var stepInfo = currentSequence.Steps[i];
  532. if (string.IsNullOrEmpty((stepInfo[1] as PositionParam).Value))
  533. {
  534. ruleCheckMessage = $"Step{(stepInfo[0] as StepParam).Value}, Position Is Empty";
  535. return false;
  536. }
  537. if ((stepInfo[1] as PositionParam).Value == "LL")
  538. {
  539. if (preIndex != -1 && (i - preIndex) == 1)
  540. {
  541. ruleCheckMessage = $"Step{(stepInfo[0] as StepParam).Value}, The LL is set around the pm ";
  542. return false;
  543. }
  544. preIndex = i;
  545. }
  546. }
  547. return true;
  548. }
  549. private XmlAttribute CreateAttribute(XmlNode node, string attributeName, string value)
  550. {
  551. try
  552. {
  553. XmlDocument doc = node.OwnerDocument;
  554. XmlAttribute attr = null;
  555. attr = doc.CreateAttribute(attributeName);
  556. attr.Value = value;
  557. node.Attributes.SetNamedItem(attr);
  558. return attr;
  559. }
  560. catch (Exception err)
  561. {
  562. string desc = err.Message;
  563. return null;
  564. }
  565. }
  566. private void SelectDefault(FileNode node)
  567. {
  568. if (!node.IsFile)
  569. {
  570. if (node.Files.Count > 0)
  571. {
  572. foreach (FileNode file in node.Files)
  573. {
  574. if (file.IsFile)
  575. {
  576. this.TreeSelectChanged(file);
  577. //break;
  578. }
  579. }
  580. }
  581. }
  582. }
  583. public void TreeSelectChanged(FileNode file)
  584. {
  585. if (file != null && file.IsFile)
  586. {
  587. //if (this.IsChanged)
  588. // if (MessageBox.Show("This sequence is changed,do you want to save it?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  589. // this.Save(this.CurrentSequence);
  590. this.LoadData(file.FullPath);
  591. this.CurrentFileNode = file;
  592. }
  593. else
  594. {
  595. //this.ClearData();
  596. //this.editMode = EditMode.None;
  597. this.CurrentSequence.Steps.Clear();
  598. }
  599. //this.UpdateView();
  600. }
  601. private void LoadData(string newSeqName)
  602. {
  603. SequenceData Sequence = this.provider.GetSequenceByName(this.Columns, newSeqName);
  604. this.CurrentSequence.Name = Sequence.Name;
  605. this.CurrentSequence.Creator = Sequence.Creator;
  606. this.CurrentSequence.CreateTime = Sequence.CreateTime;
  607. this.CurrentSequence.Revisor = Sequence.Revisor;
  608. this.CurrentSequence.ReviseTime = Sequence.ReviseTime;
  609. this.CurrentSequence.Description = Sequence.Description;
  610. this.CurrentSequence.Steps.Clear();
  611. Sequence.Steps.ToList().ForEach(step =>
  612. this.CurrentSequence.Steps.Add(step));
  613. //int index = 1;
  614. //foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  615. //{
  616. // (parameters[0] as StepParam).Value = index.ToString();
  617. // index++;
  618. // foreach (var para in parameters)
  619. // {
  620. // var pathFile = para as PathFileParam;
  621. // if (pathFile != null)
  622. // {
  623. // pathFile.Value = pathFile.Value.Replace($"{pathFile.PrefixPath}\\", "");
  624. // }
  625. // }
  626. //}
  627. //this.IsSavedDesc = true;
  628. //this.NotifyOfPropertyChange("IsSavedDesc");
  629. //this.editMode = EditMode.Normal;
  630. }
  631. private bool IsExist(string sequencename)
  632. {
  633. bool existed = false;
  634. FileNode filenode = this.CurrentFileNode.IsFile ? this.CurrentFileNode.Parent : this.CurrentFileNode;
  635. for (var index = 0; index < filenode.Files.Count; index++)
  636. {
  637. if (filenode.Files[index].FullPath.ToLower() == sequencename.ToLower())
  638. {
  639. existed = true;
  640. break;
  641. }
  642. }
  643. return existed;
  644. }
  645. private int FindInsertPosition(ObservableCollection<FileNode> files)
  646. {
  647. int pos = -1;
  648. if (files.Count == 0)
  649. pos = 0;
  650. else
  651. {
  652. bool foundfolder = false;
  653. for (var index = 0; index < files.Count; index++)
  654. {
  655. if (!files[index].IsFile)
  656. {
  657. foundfolder = true;
  658. pos = index;
  659. break;
  660. }
  661. }
  662. if (!foundfolder)
  663. pos = files.Count;
  664. }
  665. return pos;
  666. }
  667. #endregion
  668. }
  669. }