SequenceViewModel.cs 27 KB

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