SequenceViewModel.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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 (string.IsNullOrEmpty(fullpath))
  161. {
  162. MessageBox.Show("SequenceName cannot be null or empty!");
  163. return;
  164. }
  165. if (this.IsExist(fullpath))
  166. {
  167. MessageBox.Show("Sequence already existed!");
  168. }
  169. else
  170. {
  171. SequenceData sequence = new SequenceData();
  172. sequence.Name = fullpath;
  173. sequence.Creator = "Admin";
  174. sequence.CreateTime = DateTime.Now;
  175. sequence.Revisor = sequence.Creator;
  176. sequence.ReviseTime = DateTime.Now;
  177. sequence.Description = string.Empty;
  178. if (this.Save(sequence))
  179. {
  180. this.CurrentSequence.Name = sequence.Name;
  181. this.CurrentSequence.Creator = sequence.Creator;
  182. this.CurrentSequence.CreateTime = sequence.CreateTime;
  183. this.CurrentSequence.Revisor = sequence.Revisor;
  184. this.CurrentSequence.ReviseTime = sequence.ReviseTime;
  185. this.CurrentSequence.Description = sequence.Description;
  186. this.CurrentSequence.Steps.Clear();
  187. FileNode file = new FileNode();
  188. file.Name = dialog.FileName;
  189. file.FullPath = this.CurrentSequence.Name;
  190. file.IsFile = true;
  191. file.Parent = this.CurrentFileNode.IsFile ? this.CurrentFileNode.Parent : this.CurrentFileNode;
  192. if (this.CurrentFileNode.IsFile)
  193. this.CurrentFileNode.Parent.Files.Insert(this.FindInsertPosition(this.CurrentFileNode.Parent.Files), file);
  194. else
  195. this.CurrentFileNode.Files.Insert(this.FindInsertPosition(this.CurrentFileNode.Files), file);
  196. }
  197. }
  198. }
  199. }
  200. public void RenameSequence()
  201. {
  202. if (this.CurrentFileNode.IsFile)
  203. {
  204. InputFileNameDialogView dialog = new InputFileNameDialogView("Rename Sequence")
  205. {
  206. Owner = Application.Current.MainWindow
  207. };
  208. dialog.FileName = this.CurrentFileNode.Name;
  209. if (dialog.ShowDialog() == true)
  210. {
  211. string fullpath = this.CurrentFileNode.Parent.FullPath == "" ? dialog.FileName : this.CurrentFileNode.Parent.FullPath + "\\" + dialog.FileName;
  212. if (string.IsNullOrEmpty(fullpath))
  213. {
  214. MessageBox.Show("SequenceName cannot be null or empty!");
  215. return;
  216. }
  217. if (this.IsExist(fullpath))
  218. {
  219. MessageBox.Show("Sequence already existed!");
  220. }
  221. else
  222. {
  223. this.CurrentSequence.Revisor = "Admin";
  224. this.CurrentSequence.ReviseTime = DateTime.Now;
  225. if (this.provider.Rename(this.CurrentSequence.Name, fullpath))
  226. {
  227. this.CurrentFileNode.Name = dialog.FileName;
  228. this.CurrentFileNode.FullPath = fullpath;
  229. this.CurrentSequence.Name = fullpath;
  230. }
  231. else
  232. MessageBox.Show("Rename failed!");
  233. }
  234. }
  235. }
  236. }
  237. public void DeleteSequence()
  238. {
  239. if (this.CurrentFileNode.IsFile)
  240. {
  241. if (WPFMessageBox.ShowQuestion($"Do you want to delete this {this.CurrentSequence.Name}?", "删除后无法恢复!!!") == MessageBoxResult.Yes)
  242. {
  243. if (this.provider.Delete(this.CurrentSequence.Name))
  244. {
  245. this.CurrentFileNode.Parent.Files.Remove(this.CurrentFileNode);
  246. }
  247. }
  248. }
  249. }
  250. public void SaveAsSequence()
  251. {
  252. if (this.CurrentFileNode.IsFile)
  253. {
  254. InputFileNameDialogView dialog = new InputFileNameDialogView("Input New Sequence Name")
  255. {
  256. Owner = Application.Current.MainWindow
  257. };
  258. if (dialog.ShowDialog() == true)
  259. {
  260. string fullpath = (this.CurrentFileNode.Parent.FullPath == "" ? dialog.FileName : this.CurrentFileNode.Parent.FullPath + "\\" + dialog.FileName);
  261. if (string.IsNullOrEmpty(fullpath))
  262. {
  263. MessageBox.Show("SequenceName cannot be null or empty!");
  264. return;
  265. }
  266. if (this.IsExist(fullpath))
  267. {
  268. MessageBox.Show("Sequence already existed!");
  269. }
  270. else
  271. {
  272. this.CurrentSequence.Revisor = "Admin";
  273. this.CurrentSequence.ReviseTime = DateTime.Now;
  274. string tempname = this.CurrentSequence.Name;
  275. this.CurrentSequence.Name = fullpath;
  276. if (this.provider.SaveAs(fullpath, this.CurrentSequence))
  277. {
  278. FileNode node = new FileNode();
  279. node.Parent = this.CurrentFileNode.Parent;
  280. node.Name = dialog.FileName;
  281. node.FullPath = fullpath;
  282. node.IsFile = true;
  283. this.CurrentFileNode.Parent.Files.Add(node);
  284. }
  285. else
  286. {
  287. this.CurrentSequence.Name = tempname;
  288. MessageBox.Show("SaveAs failed!");
  289. }
  290. }
  291. }
  292. }
  293. }
  294. public void TreeSelectChanged(object selectItem)
  295. {
  296. FileNode file = (FileNode)selectItem;
  297. if (file != null && file.IsFile)
  298. {
  299. this.LoadData(file.FullPath);
  300. this.CurrentFileNode = file;
  301. }
  302. else
  303. {
  304. this.ClearData();
  305. }
  306. }
  307. private TreeViewItem GetParentObjectEx<TreeViewItem>(DependencyObject obj) where TreeViewItem : FrameworkElement
  308. {
  309. DependencyObject parent = VisualTreeHelper.GetParent(obj);
  310. while (parent != null)
  311. {
  312. if (parent is TreeViewItem)
  313. {
  314. return (TreeViewItem)parent;
  315. }
  316. parent = VisualTreeHelper.GetParent(parent);
  317. }
  318. return null;
  319. }
  320. public void TreeRightMouseDown(MouseButtonEventArgs e)
  321. {
  322. if (e != null)
  323. {
  324. var item = GetParentObjectEx<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
  325. if (item != null)
  326. {
  327. item.Focus();
  328. }
  329. }
  330. }
  331. #endregion
  332. #region sequence action
  333. public void AddStep()
  334. {
  335. this.CurrentSequence.Steps.Add(CurrentSequence.CreateStep(this.Columns));
  336. int index = 1;
  337. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  338. {
  339. (parameters[0] as StepParam).Value = index.ToString();
  340. index++;
  341. }
  342. }
  343. public void InsertStep()
  344. {
  345. int index = -1;
  346. bool found = false;
  347. for (var i = 0; i < this.CurrentSequence.Steps.Count; i++)
  348. {
  349. if (this.CurrentSequence.Steps[i][0] is StepParam && ((StepParam)this.CurrentSequence.Steps[i][0]).Checked)
  350. {
  351. index = i;
  352. found = true;
  353. break;
  354. }
  355. }
  356. if (found)
  357. {
  358. this.CurrentSequence.Steps.Insert(index, this.CurrentSequence.CreateStep(this.Columns));
  359. index = 1;
  360. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  361. {
  362. (parameters[0] as StepParam).Value = index.ToString();
  363. index++;
  364. }
  365. }
  366. }
  367. private ObservableCollection<ObservableCollection<Param>> copySteps = new ObservableCollection<ObservableCollection<Param>>();
  368. public void CopyStep()
  369. {
  370. this.copySteps.Clear();
  371. for (var i = 0; i < this.CurrentSequence.Steps.Count; i++)
  372. {
  373. if (this.CurrentSequence.Steps[i][0] is StepParam && ((StepParam)this.CurrentSequence.Steps[i][0]).Checked)
  374. {
  375. this.copySteps.Add(this.CurrentSequence.CloneStep(this.Columns, this.CurrentSequence.Steps[i]));
  376. }
  377. }
  378. }
  379. public void PasteStep()
  380. {
  381. if (this.copySteps.Count > 0)
  382. {
  383. if (this.CurrentSequence.Steps.Count > 0)
  384. {
  385. for (var i = 0; i < this.CurrentSequence.Steps.Count; i++)
  386. {
  387. if (this.CurrentSequence.Steps[i][0] is StepParam && ((StepParam)this.CurrentSequence.Steps[i][0]).Checked)
  388. {
  389. for (var copyindex = 0; copyindex < this.copySteps.Count; copyindex++)
  390. {
  391. this.CurrentSequence.Steps.Insert(i, this.CurrentSequence.CloneStep(this.Columns, this.copySteps[copyindex]));
  392. i++;
  393. }
  394. break;
  395. }
  396. }
  397. }
  398. else
  399. {
  400. for (var copyindex = 0; copyindex < this.copySteps.Count; copyindex++)
  401. {
  402. this.CurrentSequence.Steps.Insert(copyindex, this.CurrentSequence.CloneStep(this.Columns, this.copySteps[copyindex]));
  403. }
  404. }
  405. SetStepIndex();
  406. }
  407. }
  408. public void DeleteStep()
  409. {
  410. List<ObservableCollection<Param>> steps = this.CurrentSequence.Steps.ToList();
  411. for (var i = 0; i < steps.Count; i++)
  412. {
  413. if (steps[i][0] is StepParam && ((StepParam)steps[i][0]).Checked)
  414. {
  415. this.CurrentSequence.Steps.Remove(steps[i]);
  416. }
  417. }
  418. SetStepIndex();
  419. }
  420. public void ReloadSequence()
  421. {
  422. this.LoadData(this.CurrentSequence.Name);
  423. }
  424. public void SelectRecipe(object select)
  425. {
  426. PathFileParam param = (PathFileParam)select;
  427. RecipeSequenceSelectView dialog = new RecipeSequenceSelectView()
  428. {
  429. Owner = Application.Current.MainWindow
  430. };
  431. dialog.Title = "Select Recipe";
  432. var dataContext = new RecipeSequenceSelectViewModel();
  433. dialog.DataContext = dataContext;
  434. ObservableCollection<Param> parameters = param.Parent;
  435. PositionParam posParam = null;
  436. for (var index = 0; index < parameters.Count; index++)
  437. {
  438. if (parameters[index] is PositionParam)
  439. {
  440. posParam = parameters[index] as PositionParam;
  441. break;
  442. }
  443. }
  444. List<string> lstFiles=new List<string>();
  445. if (param.Name.Contains("Clean"))
  446. {
  447. lstFiles = provider.GetRecipesByPath($"{param.PrefixPath}").Where(x => x.Split('\\')[1] == "Clean").ToList();//m_uiSequenceManager.GetRecipesByPath($"{param.PrefixPath}");
  448. }
  449. else
  450. {
  451. lstFiles = provider.GetRecipesByPath($"{param.PrefixPath}").Where(x => x.Split('\\')[1] == "Process").ToList();//m_uiSequenceManager.GetRecipesByPath($"{param.PrefixPath}");
  452. }
  453. dataContext.Files = new ObservableCollection<FileNode>(RecipeSequenceTreeBuilder.GetFiles("", lstFiles));
  454. if (dialog.ShowDialog() == true)
  455. {
  456. //param.Value = dialog.FullPath;
  457. //param.Value = $"{param.PrefixPath}\\" + dialog.FullPath;
  458. //param.FileName = param.Value;
  459. string path = dialog.FullPath;
  460. int index = path.LastIndexOf("\\");
  461. if (index > -1)
  462. {
  463. param.FileName = path.Substring(index + 1);
  464. param.Value = path.Substring(index + 1);
  465. }
  466. else
  467. {
  468. param.FileName = path;
  469. param.Value = path;
  470. }
  471. param.IsSaved = false;
  472. }
  473. }
  474. public void SaveSequence()
  475. {
  476. this.Save(this.CurrentSequence);
  477. }
  478. private void SetStepIndex()
  479. {
  480. int index = 1;
  481. foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  482. {
  483. (parameters[0] as StepParam).Value = index.ToString();
  484. index++;
  485. }
  486. }
  487. #endregion
  488. #region private
  489. private void ApplyFilter()
  490. {
  491. var sequenceList = provider.GetSequenceNameList() ?? new List<string>();
  492. GetFiles(sequenceList.Where(p => {
  493. return string.IsNullOrWhiteSpace(SequenceName) || p.IndexOf(SequenceName, StringComparison.OrdinalIgnoreCase) > -1;
  494. }).ToList());
  495. }
  496. private void ClearData()
  497. {
  498. this.CurrentSequence.Steps.Clear();
  499. this.CurrentSequence.Name = string.Empty;
  500. this.CurrentSequence.Description = string.Empty;
  501. }
  502. private bool Save(SequenceData seq)
  503. {
  504. bool result = false;
  505. if (string.IsNullOrEmpty(seq.Name))
  506. {
  507. MessageBox.Show("Sequence name can't be empty");
  508. return false;
  509. }
  510. string ruleCheckMessage = null;
  511. if (!ValidateSequenceRules(seq, ref ruleCheckMessage))
  512. {
  513. MessageBox.Show(string.Format($"{seq.Name} rules check failed, don't allow to save: {ruleCheckMessage}"));
  514. return false;
  515. }
  516. seq.Revisor = "Admin";
  517. seq.ReviseTime = DateTime.Now;
  518. result = this.provider.Save(seq);
  519. if (result)
  520. {
  521. foreach (ObservableCollection<Param> parameters in seq.Steps)
  522. {
  523. parameters.Apply(param => param.IsSaved = true);
  524. }
  525. }
  526. else
  527. MessageBox.Show("Save failed!");
  528. return result;
  529. }
  530. private bool ValidateSequenceRules(SequenceData currentSequence, ref string ruleCheckMessage)
  531. {
  532. int preIndex = -1;
  533. for (var i = 0; i < currentSequence.Steps.Count; i++)
  534. {
  535. var stepInfo = currentSequence.Steps[i];
  536. if (string.IsNullOrEmpty((stepInfo[1] as PositionParam).Value))
  537. {
  538. ruleCheckMessage = $"Step{(stepInfo[0] as StepParam).Value}, Position Is Empty";
  539. return false;
  540. }
  541. if ((stepInfo[1] as PositionParam).Value == "LL")
  542. {
  543. if (preIndex != -1 && (i - preIndex) == 1)
  544. {
  545. ruleCheckMessage = $"Step{(stepInfo[0] as StepParam).Value}, The LL is set around the pm ";
  546. return false;
  547. }
  548. preIndex = i;
  549. }
  550. }
  551. return true;
  552. }
  553. private XmlAttribute CreateAttribute(XmlNode node, string attributeName, string value)
  554. {
  555. try
  556. {
  557. XmlDocument doc = node.OwnerDocument;
  558. XmlAttribute attr = null;
  559. attr = doc.CreateAttribute(attributeName);
  560. attr.Value = value;
  561. node.Attributes.SetNamedItem(attr);
  562. return attr;
  563. }
  564. catch (Exception err)
  565. {
  566. string desc = err.Message;
  567. return null;
  568. }
  569. }
  570. private void SelectDefault(FileNode node)
  571. {
  572. if (!node.IsFile)
  573. {
  574. if (node.Files.Count > 0)
  575. {
  576. foreach (FileNode file in node.Files)
  577. {
  578. if (file.IsFile)
  579. {
  580. this.TreeSelectChanged(file);
  581. //break;
  582. }
  583. }
  584. }
  585. }
  586. }
  587. public void TreeSelectChanged(FileNode file)
  588. {
  589. if (file != null && file.IsFile)
  590. {
  591. //if (this.IsChanged)
  592. // if (MessageBox.Show("This sequence is changed,do you want to save it?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  593. // this.Save(this.CurrentSequence);
  594. this.LoadData(file.FullPath);
  595. this.CurrentFileNode = file;
  596. }
  597. else
  598. {
  599. //this.ClearData();
  600. //this.editMode = EditMode.None;
  601. this.CurrentSequence.Steps.Clear();
  602. }
  603. //this.UpdateView();
  604. }
  605. private void LoadData(string newSeqName)
  606. {
  607. SequenceData Sequence = this.provider.GetSequenceByName(this.Columns, newSeqName);
  608. this.CurrentSequence.Name = Sequence.Name;
  609. this.CurrentSequence.Creator = Sequence.Creator;
  610. this.CurrentSequence.CreateTime = Sequence.CreateTime;
  611. this.CurrentSequence.Revisor = Sequence.Revisor;
  612. this.CurrentSequence.ReviseTime = Sequence.ReviseTime;
  613. this.CurrentSequence.Description = Sequence.Description;
  614. this.CurrentSequence.Steps.Clear();
  615. Sequence.Steps.ToList().ForEach(step =>
  616. this.CurrentSequence.Steps.Add(step));
  617. //int index = 1;
  618. //foreach (ObservableCollection<Param> parameters in this.CurrentSequence.Steps)
  619. //{
  620. // (parameters[0] as StepParam).Value = index.ToString();
  621. // index++;
  622. // foreach (var para in parameters)
  623. // {
  624. // var pathFile = para as PathFileParam;
  625. // if (pathFile != null)
  626. // {
  627. // pathFile.Value = pathFile.Value.Replace($"{pathFile.PrefixPath}\\", "");
  628. // }
  629. // }
  630. //}
  631. //this.IsSavedDesc = true;
  632. //this.NotifyOfPropertyChange("IsSavedDesc");
  633. //this.editMode = EditMode.Normal;
  634. }
  635. private bool IsExist(string sequencename)
  636. {
  637. bool existed = false;
  638. FileNode filenode = this.CurrentFileNode.IsFile ? this.CurrentFileNode.Parent : this.CurrentFileNode;
  639. for (var index = 0; index < filenode.Files.Count; index++)
  640. {
  641. if (filenode.Files[index].FullPath.ToLower() == sequencename.ToLower())
  642. {
  643. existed = true;
  644. break;
  645. }
  646. }
  647. return existed;
  648. }
  649. private int FindInsertPosition(ObservableCollection<FileNode> files)
  650. {
  651. int pos = -1;
  652. if (files.Count == 0)
  653. pos = 0;
  654. else
  655. {
  656. bool foundfolder = false;
  657. for (var index = 0; index < files.Count; index++)
  658. {
  659. if (!files[index].IsFile)
  660. {
  661. foundfolder = true;
  662. pos = index;
  663. break;
  664. }
  665. }
  666. if (!foundfolder)
  667. pos = files.Count;
  668. }
  669. return pos;
  670. }
  671. #endregion
  672. }
  673. }