SequenceViewModel.cs 27 KB

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