KeplerSequenceViewModel.cs 30 KB

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