RecipeEditorView.xaml.cs 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Xml;
  12. using Aitex.Core.Account;
  13. using Aitex.Core.RT.Log;
  14. using Aitex.Core.UI.View.Common;
  15. using Aitex.UI.RecipeEditor.View;
  16. using ExcelLibrary.SpreadSheet;
  17. using MECF.Framework.Common.DataCenter;
  18. using MECF.Framework.Common.Equipment;
  19. using MECF.Framework.UI.Core.Accounts;
  20. namespace VirgoUI.Client.Models.PMs
  21. {
  22. /// <summary>
  23. /// Interaction logic for RecipeEditorView.xaml
  24. /// </summary>
  25. public partial class RecipeEditorView : UserControl
  26. {
  27. private string _culture;
  28. private string tragetFilePath = "";
  29. private object OriginalItem;
  30. private RecipeEditorViewModel _viewModel;
  31. private int MenuPermission;
  32. private ViewPermission _permission;
  33. private Point _lastMouseDown;
  34. public RecipeEditorView()
  35. {
  36. InitializeComponent();
  37. this.buttonSaveTableRecipe.ContextMenu = null;
  38. this.DataContext = _viewModel = new RecipeEditorViewModel(new UiRecipeManager(), ModuleName.System.ToString());
  39. this.Loaded += new RoutedEventHandler(RecipeEditorView_Loaded);
  40. this.Unloaded += new RoutedEventHandler(RecipeEditorView_Unloaded);
  41. //VirgoUiSystem.Instance.CultureChanged += CultureChanged;
  42. }
  43. private void CultureChanged(string s)
  44. {
  45. _culture = s;
  46. this.tableRecipeGrid.UpdateCultureResource(s);
  47. }
  48. static DependencyObject VisualUpwardSearch<T>(DependencyObject source)
  49. {
  50. while (source != null && source.GetType() != typeof(T))
  51. source = VisualTreeHelper.GetParent(source);
  52. return source;
  53. }
  54. void RecipeEditorView_Unloaded(object sender, RoutedEventArgs e)
  55. {
  56. }
  57. void RecipeEditorView_Loaded(object sender, RoutedEventArgs e)
  58. {
  59. buttonSaveTableRecipe.Click += (obj, args) => { SetMenu.IsOpen = true; };
  60. SaveToSingle.Header = $"Save To {((RecipeEditorViewModel)this.DataContext).SystemName}";
  61. //SaveToDouble.Header = "Save To PMA And PMB";
  62. _viewModel.ChamberId = ((RecipeEditorViewModel)this.DataContext).SystemName;
  63. MenuPermission = ClientApp.Instance.GetPermission($"Recipe{_viewModel.ChamberId}");
  64. if (_culture != Thread.CurrentThread.CurrentCulture.Name)
  65. {
  66. _culture = Thread.CurrentThread.CurrentCulture.Name;
  67. this.tableRecipeGrid.UpdateCultureResource(_culture);
  68. }
  69. _viewModel.UpdateAllConfig();
  70. tableRecipeGrid.SetEnableBarcode(_viewModel.IsBarcodeEnabled);
  71. tableRecipeGrid.SetUser(ClientApp.Instance.UserContext.LoginName);
  72. tableRecipeGrid.SetEndPointDefaultValue((string)QueryDataClient.Instance.Service.GetConfig("System.EndPoint.EndPointDefaultValue"));
  73. UpdateRecipeFileList();
  74. UpdateProcessRecipeFileList();
  75. UpdateCleanRecipeFileList();
  76. this.Name = "recipeEditor";
  77. _permission = ViewPermission.FullyControl;//this.GetPermission();
  78. switch (_permission)
  79. {
  80. case ViewPermission.Readonly:
  81. buttonReloadTableRecipe.IsEnabled = false;
  82. tableRecipeGrid.IsEnabled = false;
  83. buttonSaveTableRecipe.IsEnabled = false;
  84. break;
  85. default:
  86. break;
  87. }
  88. }
  89. private void treeViewRcpList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  90. {
  91. //var permission = this.GetPermission();
  92. if (tableRecipeGrid.IsRecipeModified)
  93. {
  94. //if (permission == ViewPermission.FullyControl)
  95. {
  96. switch (MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgSaveCurrentRecipe"].ToString(), _viewModel.CurrentRecipeName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.YesNo, MessageBoxImage.Question))
  97. {
  98. case MessageBoxResult.Yes:
  99. if (SaveRecipe())
  100. {
  101. var item = e.NewValue as TreeViewFileItem;
  102. if (item != null)
  103. item.IsSelected = true;
  104. }
  105. else
  106. {
  107. var item = e.OldValue as TreeViewFileItem;
  108. if (item != null)
  109. item.IsSelected = true;
  110. return;
  111. }
  112. break;
  113. case MessageBoxResult.No:
  114. {
  115. var item = e.NewValue as TreeViewFileItem;
  116. if (item != null)
  117. item.IsSelected = true;
  118. }
  119. break;
  120. }
  121. }
  122. }
  123. var selectedItem = e.NewValue as TreeViewFileItem;
  124. if (selectedItem == null)
  125. return;
  126. try
  127. {
  128. this._viewModel.CurrentRecipeName = selectedItem.FileName;
  129. string rcpType = "";
  130. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  131. {
  132. rcpType = "Process";
  133. }
  134. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  135. {
  136. rcpType = "Clean";
  137. }
  138. string xmlRecipeData = _viewModel.LoadRecipe(selectedItem.FileName, rcpType);
  139. this.tableRecipeGrid.ControlViewModel.LoadRecipe(_viewModel.RecipeFormat, xmlRecipeData);
  140. }
  141. catch (Exception ex)
  142. {
  143. LOG.Write(ex);
  144. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  145. }
  146. }
  147. private bool SaveRecipe(string flag = "Single")
  148. {
  149. bool ret = true;
  150. try
  151. {
  152. var hasErr = this.tableRecipeGrid.ControlViewModel.Errors.Count > 0;
  153. if (!hasErr ||
  154. MessageBox.Show(Application.Current.Resources["GlobalLableMsgRecipeSaveInfo"].ToString(), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.YesNoCancel, MessageBoxImage.Warning) == MessageBoxResult.Yes)
  155. {
  156. string rcpType = "";
  157. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  158. {
  159. rcpType = "Process";
  160. }
  161. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  162. {
  163. rcpType = "Clean";
  164. }
  165. if (flag == "Single")
  166. ret = _viewModel.SaveRecipe(this._viewModel.CurrentRecipeName, rcpType, this.tableRecipeGrid.ControlViewModel.GetRecipeContentString());
  167. else if (flag == "Double")
  168. ret = _viewModel.SaveRecipeDouble(this._viewModel.CurrentRecipeName, rcpType, this.tableRecipeGrid.ControlViewModel.GetRecipeContentString());
  169. if (ret)
  170. {
  171. tableRecipeGrid.Dispatcher.Invoke(new System.Action(() =>
  172. {
  173. this.tableRecipeGrid.ControlViewModel.LoadRecipe(_viewModel.RecipeFormat, _viewModel.LoadRecipe(_viewModel.CurrentRecipeName, rcpType));
  174. }));
  175. }
  176. }
  177. else
  178. {
  179. ret = false;
  180. }
  181. }
  182. catch (Exception ex)
  183. {
  184. LOG.Write(ex);
  185. MessageBox.Show(Application.Current.Resources["GlobalLableMsgRecipeSaveException"].ToString(), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
  186. ret = false;
  187. }
  188. return ret;
  189. }
  190. private void treeViewRcpList_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  191. {
  192. if (_permission != ViewPermission.FullyControl)
  193. return;
  194. //black place right mouse click
  195. var rcp = treeViewRcpList;
  196. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  197. {
  198. rcp = treeViewProcessRcpList;
  199. }
  200. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  201. {
  202. rcp = treeViewCleanRcpList;
  203. }
  204. rcp.ContextMenu = new ContextMenu();
  205. MenuItem menuItem = new MenuItem();
  206. menuItem = new MenuItem();
  207. menuItem.Tag = "\\";
  208. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateRecipe);
  209. menuItem.Header = Application.Current.Resources["GlobalLableMenuNewRecipe"];
  210. rcp.ContextMenu.Items.Add(menuItem);
  211. menuItem = new MenuItem();
  212. menuItem.Tag = "\\";
  213. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_ImportRecipe);
  214. menuItem.Header = Application.Current.Resources["GlobalLableMenuImportRecipe"];
  215. rcp.ContextMenu.Items.Add(menuItem);
  216. rcp.ContextMenu.Items.Add(new Separator());
  217. menuItem = new MenuItem();
  218. menuItem.Tag = "\\";
  219. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateFolder);
  220. menuItem.Header = Application.Current.Resources["GlobalLableMenuNewFolder"];
  221. rcp.ContextMenu.Items.Add(menuItem);
  222. rcp.ContextMenu.Visibility = Visibility.Visible;
  223. }
  224. private void TreeViewItem_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  225. {
  226. if (_permission != ViewPermission.FullyControl)
  227. return;
  228. var treeViewFileItem = VisualUpwardSearch<TreeViewFileItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
  229. if (treeViewFileItem != null)
  230. {
  231. treeViewFileItem.Focus();
  232. treeViewFileItem.IsSelected = true;
  233. treeViewFileItem.ContextMenu = new ContextMenu();
  234. MenuItem menuItem = null;
  235. menuItem = new MenuItem();
  236. menuItem.Tag = treeViewFileItem.Tag as string;
  237. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_ExportRecipe);
  238. menuItem.Header = Application.Current.Resources["GlobalLableMenuExportRecipe"];
  239. treeViewFileItem.ContextMenu.Items.Add(menuItem);
  240. menuItem = new MenuItem();
  241. menuItem.Tag = treeViewFileItem.Tag as string;
  242. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_ExportExcel);
  243. menuItem.Header = Application.Current.Resources["GlobalLableMenuExportRecipeAsExcel"];
  244. treeViewFileItem.ContextMenu.Items.Add(menuItem);
  245. menuItem = new MenuItem();
  246. menuItem.Tag = treeViewFileItem.Tag as string;
  247. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_SaveAs);
  248. menuItem.Header = Application.Current.Resources["GlobalLableMenuSaveAs"];
  249. treeViewFileItem.ContextMenu.Items.Add(menuItem);
  250. menuItem = new MenuItem();
  251. menuItem.Tag = treeViewFileItem.Tag as string;
  252. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_RenameRecipe);
  253. menuItem.Header = Application.Current.Resources["GlobalLableMenuRenameRecipe"];
  254. treeViewFileItem.ContextMenu.Items.Add(menuItem);
  255. menuItem = new MenuItem();
  256. menuItem.Tag = treeViewFileItem.Tag as string;
  257. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_DeleteRecipe);
  258. menuItem.Header = Application.Current.Resources["GlobalLableMenuDeleteRecipe"];
  259. treeViewFileItem.ContextMenu.Items.Add(menuItem);
  260. treeViewFileItem.ContextMenu.Visibility = Visibility.Visible;
  261. }
  262. else
  263. {
  264. var treeViewFolderItem = VisualUpwardSearch<TreeViewFolderItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
  265. if (treeViewFolderItem != null)
  266. {
  267. treeViewFolderItem.Focus();
  268. treeViewFolderItem.IsSelected = true;
  269. treeViewFolderItem.ContextMenu = new ContextMenu();
  270. MenuItem menuItem = null;
  271. menuItem = new MenuItem();
  272. menuItem.Tag = treeViewFolderItem.Tag as string;
  273. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateRecipe);
  274. menuItem.Header = Application.Current.Resources["GlobalLableMenuNewRecipe"];
  275. treeViewFolderItem.ContextMenu.Items.Add(menuItem);
  276. menuItem = new MenuItem();
  277. menuItem.Tag = treeViewFolderItem.Tag as string;
  278. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_ImportRecipe);
  279. menuItem.Header = Application.Current.Resources["GlobalLableMenuImportRecipe"];
  280. treeViewFolderItem.ContextMenu.Items.Add(menuItem);
  281. treeViewFolderItem.ContextMenu.Items.Add(new Separator());
  282. menuItem = new MenuItem();
  283. menuItem.Tag = treeViewFolderItem.Tag as string;
  284. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateFolder);
  285. menuItem.Header = Application.Current.Resources["GlobalLableMenuNewFolder"];
  286. treeViewFolderItem.ContextMenu.Items.Add(menuItem);
  287. menuItem = new MenuItem();
  288. menuItem.Tag = treeViewFolderItem.Tag as string;
  289. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_RenameFolder);
  290. menuItem.Header = Application.Current.Resources["GlobalLableMenuRenameFolder"];
  291. treeViewFolderItem.ContextMenu.Items.Add(menuItem);
  292. menuItem = new MenuItem();
  293. menuItem.Tag = treeViewFolderItem.Tag as string;
  294. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_DeleteFolder);
  295. menuItem.Header = Application.Current.Resources["GlobalLableMenuDeleteFolder"];
  296. treeViewFolderItem.ContextMenu.Items.Add(menuItem);
  297. treeViewFolderItem.ContextMenu.Visibility = Visibility.Visible;
  298. }
  299. }
  300. }
  301. /// <summary>
  302. /// reload current recipe content
  303. /// </summary>
  304. /// <param name="sender"></param>
  305. /// <param name="e"></param>
  306. private void buttonCodeReload_Click(object sender, RoutedEventArgs e)
  307. {
  308. if (MenuPermission != 3) return;
  309. if (MessageBox.Show(Application.Current.Resources["GlobalLableMsgRecipeReloadInfo"].ToString(), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.YesNoCancel) == MessageBoxResult.Yes)
  310. {
  311. this.tableRecipeGrid.Dispatcher.Invoke(new System.Action(() =>
  312. {
  313. string rcpType = "";
  314. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  315. {
  316. rcpType = "Process";
  317. }
  318. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  319. {
  320. rcpType = "Clean";
  321. }
  322. this.tableRecipeGrid.ControlViewModel.LoadRecipe(_viewModel.RecipeFormat, _viewModel.LoadRecipe(_viewModel.CurrentRecipeName, rcpType));
  323. }));
  324. }
  325. }
  326. ///// <summary>
  327. ///// Save recipe file
  328. ///// </summary>
  329. ///// <param name="sender"></param>
  330. ///// <param name="e"></param>
  331. //private void buttonCodeSave_Click(object sender, RoutedEventArgs e)
  332. //{
  333. // SaveRecipe();
  334. //}
  335. /// <summary>
  336. /// Save recipe file
  337. /// </summary>
  338. /// <param name="sender"></param>
  339. /// <param name="e"></param>
  340. private void SaveToSingle_Click(object sender, RoutedEventArgs e)
  341. {
  342. if (MenuPermission != 3) return;
  343. SaveRecipe();
  344. }
  345. /// <summary>
  346. /// Save recipe file
  347. /// </summary>
  348. /// <param name="sender"></param>
  349. /// <param name="e"></param>
  350. private void SaveToDouble_Click(object sender, RoutedEventArgs e)
  351. {
  352. if (MenuPermission != 3) return;
  353. SaveRecipe("Double");
  354. }
  355. void SelectRecipe(string recipeName)
  356. {
  357. try
  358. {
  359. string[] paths = recipeName.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
  360. string fileName = "";
  361. for (int i = 0; i < paths.Length - 1; i++)
  362. fileName += paths[i] + "\\";
  363. fileName += paths[paths.Length - 1];
  364. var rcp = treeViewRcpList;
  365. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  366. {
  367. rcp = treeViewProcessRcpList;
  368. }
  369. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  370. {
  371. rcp = treeViewCleanRcpList;
  372. }
  373. selectRecipe(rcp, paths, 0, fileName);
  374. }
  375. catch (Exception ex)
  376. {
  377. LOG.Write(ex);
  378. }
  379. }
  380. ItemsControl selectRecipe(ItemsControl currentNode, string[] paths, int index, string fileName)
  381. {
  382. if (currentNode == null)
  383. return null;
  384. if (index == paths.Length - 1)
  385. {
  386. foreach (var item in currentNode.Items)
  387. {
  388. TreeViewFileItem tvf = item as TreeViewFileItem;
  389. if (tvf != null && tvf.FileName == fileName)
  390. {
  391. tvf.IsSelected = true;
  392. return null;
  393. }
  394. }
  395. }
  396. foreach (var item in currentNode.Items)
  397. {
  398. TreeViewFolderItem tvf = item as TreeViewFolderItem;
  399. if (tvf != null && tvf.FolderName == paths[index])
  400. {
  401. tvf.IsExpanded = true;
  402. selectRecipe(tvf, paths, index + 1, fileName);
  403. break;
  404. }
  405. }
  406. return null;
  407. }
  408. private void UpdateRecipeFileList()
  409. {
  410. XmlDocument doc = new XmlDocument();
  411. doc.LoadXml(_viewModel.GetXmlRecipeList(""));
  412. treeViewRcpList.Items.Clear();
  413. CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
  414. }
  415. private void UpdateProcessRecipeFileList()
  416. {
  417. XmlDocument doc = new XmlDocument();
  418. doc.LoadXml(_viewModel.GetXmlRecipeList("Process"));
  419. treeViewProcessRcpList.Items.Clear();
  420. CreateTreeViewItems(doc.DocumentElement, this.treeViewProcessRcpList);
  421. }
  422. private void UpdateCleanRecipeFileList()
  423. {
  424. XmlDocument doc = new XmlDocument();
  425. doc.LoadXml(_viewModel.GetXmlRecipeList("Clean"));
  426. treeViewCleanRcpList.Items.Clear();
  427. CreateTreeViewItems(doc.DocumentElement, this.treeViewCleanRcpList);
  428. }
  429. void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
  430. {
  431. foreach (XmlElement ele in curElementNode.ChildNodes)
  432. {
  433. if (ele.Name == "File")
  434. {
  435. string fileName = ele.Attributes["Name"].Value;
  436. fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
  437. TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
  438. item.Tag = ele.Attributes["Name"].Value;
  439. item.ToolTip = fileName;
  440. itemsControl.Items.Add(item);
  441. }
  442. else if (ele.Name == "Folder")
  443. {
  444. string folderName = ele.Attributes["Name"].Value;
  445. folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
  446. TreeViewFolderItem item = new TreeViewFolderItem(folderName);
  447. item.Tag = ele.Attributes["Name"].Value;
  448. CreateTreeViewItems(ele, item);
  449. item.IsExpanded = false;
  450. itemsControl.Items.Add(item);
  451. }
  452. }
  453. }
  454. void menuItem_MouseClick_SaveAs(object sender, RoutedEventArgs e)
  455. {
  456. try
  457. {
  458. MenuItem mit = sender as MenuItem;
  459. var oldName = mit.Tag as string;
  460. RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
  461. {
  462. InputText = oldName,
  463. Owner = Application.Current.MainWindow
  464. };
  465. var ret = dlg.ShowDialog();
  466. if (ret.HasValue && ret.Value)
  467. {
  468. var newName = dlg.InputText;
  469. string rcpType = "";
  470. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  471. {
  472. rcpType = "Process";
  473. }
  474. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  475. {
  476. rcpType = "Clean";
  477. }
  478. if (_viewModel.SaveAsRecipe(newName, rcpType, _viewModel.LoadRecipe(oldName, rcpType)))
  479. {
  480. UpdateRecipeFileList();
  481. UpdateProcessRecipeFileList();
  482. UpdateCleanRecipeFileList();
  483. SelectRecipe(newName);
  484. }
  485. else
  486. {
  487. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeSaveAsFailed"].ToString(), newName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
  488. }
  489. }
  490. }
  491. catch (Exception ex)
  492. {
  493. LOG.Write(ex);
  494. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeSaveAsException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  495. }
  496. }
  497. void menuItem_MouseClick_CreateFolder(object sender, RoutedEventArgs e)
  498. {
  499. try
  500. {
  501. MenuItem mit = sender as MenuItem;
  502. string folderName = mit.Tag as string;
  503. string rcpType = "";
  504. var rcp = treeViewRcpList;
  505. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  506. {
  507. rcp = treeViewProcessRcpList;
  508. rcpType = "Process";
  509. }
  510. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  511. {
  512. rcp = treeViewCleanRcpList;
  513. rcpType = "Clean";
  514. }
  515. var selectedRecipeItem = rcp.SelectedItem as TreeViewFileItem;
  516. RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputFolderName"].ToString())
  517. {
  518. Owner = Application.Current.MainWindow
  519. };
  520. if (dlg.ShowDialog() == true)
  521. {
  522. this._viewModel.CreateFolder(folderName + "\\" + dlg.InputText, rcpType);
  523. UpdateRecipeFileList();
  524. UpdateCleanRecipeFileList();
  525. UpdateProcessRecipeFileList();
  526. if (selectedRecipeItem != null)
  527. SelectRecipe(selectedRecipeItem.FileName);
  528. }
  529. }
  530. catch (Exception ex)
  531. {
  532. LOG.Write(ex);
  533. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeFolderNewFailed"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString());
  534. }
  535. }
  536. /// <summary>
  537. /// Create new recipe
  538. /// </summary>
  539. /// <param name="sender"></param>
  540. /// <param name="e"></param>
  541. void menuItem_MouseClick_CreateRecipe(object sender, RoutedEventArgs e)
  542. {
  543. MenuItem mit = sender as MenuItem;
  544. string folderName = mit.Tag as string;
  545. PerformCreateRecipe(folderName);
  546. }
  547. /// <summary>
  548. /// delete folder
  549. /// </summary>
  550. /// <param name="sender"></param>
  551. /// <param name="e"></param>
  552. void menuItem_MouseClick_DeleteFolder(object sender, RoutedEventArgs e)
  553. {
  554. MenuItem mit = sender as MenuItem;
  555. string folderName = mit.Tag as string;
  556. PerformDeleteFolder(folderName);
  557. }
  558. private void PerformDeleteFolder(string folderName)
  559. {
  560. try
  561. {
  562. string rcpType = "";
  563. var rcp = treeViewRcpList;
  564. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  565. {
  566. rcp = treeViewProcessRcpList;
  567. rcpType = "Process";
  568. }
  569. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  570. {
  571. rcp = treeViewCleanRcpList;
  572. rcpType = "Clean";
  573. }
  574. var selectedRecipeItem = rcp.SelectedItem as TreeViewFileItem;
  575. if (MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeDeleteFolderInfo"].ToString(), folderName),
  576. Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  577. {
  578. this._viewModel.DeleteFolder(folderName, rcpType);
  579. UpdateRecipeFileList();
  580. UpdateProcessRecipeFileList();
  581. UpdateCleanRecipeFileList();
  582. if (selectedRecipeItem != null)
  583. SelectRecipe(selectedRecipeItem.FileName);
  584. }
  585. }
  586. catch (Exception ex)
  587. {
  588. LOG.Write(ex);
  589. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeDeleteFolderException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  590. }
  591. }
  592. /// <summary>
  593. /// rename folder
  594. /// </summary>
  595. /// <param name="sender"></param>
  596. /// <param name="e"></param>
  597. void menuItem_MouseClick_RenameFolder(object sender, RoutedEventArgs e)
  598. {
  599. MenuItem mit = sender as MenuItem;
  600. string folderName = mit.Tag as string;
  601. PerformRenameFolder(folderName);
  602. }
  603. private void PerformRenameFolder(string folderName)
  604. {
  605. try
  606. {
  607. int lastSlashIndex = folderName.LastIndexOf('\\');
  608. string shortName = folderName.Substring(lastSlashIndex + 1);
  609. RecipeNameInputDlg dlg =
  610. new RecipeNameInputDlg(
  611. string.Format(Application.Current.Resources["GlobalLableMsgRecipeRenameFolderInfo"].ToString(),
  612. shortName), Application.Current.Resources["GlobalLableMsgInputFolderName"].ToString())
  613. {
  614. Owner = Application.Current.MainWindow
  615. };
  616. if (dlg.ShowDialog() == true)
  617. {
  618. string dir = lastSlashIndex == -1 ? "" : folderName.Substring(0, lastSlashIndex);
  619. string rcpType = "";
  620. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  621. {
  622. rcpType = "Process";
  623. }
  624. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  625. {
  626. rcpType = "Clean";
  627. }
  628. if (!_viewModel.RenameFolder(folderName, rcpType, dir + "\\" + dlg.InputText))
  629. {
  630. MessageBox.Show(Application.Current.Resources["GlobalLableMsgRecipeRenameFolderFailed"].ToString(),
  631. Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK,
  632. MessageBoxImage.Warning);
  633. }
  634. else
  635. {
  636. UpdateRecipeFileList();
  637. UpdateProcessRecipeFileList();
  638. UpdateCleanRecipeFileList();
  639. }
  640. }
  641. }
  642. catch (Exception ex)
  643. {
  644. LOG.Write(ex);
  645. MessageBox.Show(
  646. string.Format(Application.Current.Resources["GlobalLableMsgRecipeRenameFolderException"].ToString(),
  647. ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(),
  648. MessageBoxButton.OK, MessageBoxImage.Error);
  649. }
  650. }
  651. /// <summary>
  652. /// import external recipe file into selected folder
  653. /// </summary>
  654. /// <param name="sender"></param>
  655. /// <param name="e"></param>
  656. void menuItem_MouseClick_ImportRecipe(object sender, RoutedEventArgs e)
  657. {
  658. try
  659. {
  660. MenuItem mit = sender as MenuItem;
  661. string folderName = mit.Tag as string;
  662. Microsoft.Win32.OpenFileDialog openDlg = new Microsoft.Win32.OpenFileDialog();
  663. openDlg.DefaultExt = ".rcp";
  664. openDlg.Filter = "Recipe file (.rcp)|*.rcp";
  665. openDlg.Multiselect = true;
  666. if (openDlg.ShowDialog() == true)
  667. {
  668. foreach (var openDlgFileName in openDlg.FileNames)
  669. {
  670. using (StreamReader srd = new StreamReader(openDlgFileName))
  671. {
  672. bool importFailed = false;
  673. string rcpContent = srd.ReadToEnd();
  674. RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgRecipeImportInfo"].ToString(), Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
  675. {
  676. Owner = Application.Current.MainWindow
  677. };
  678. dlg.InputText = System.IO.Path.GetFileNameWithoutExtension(openDlgFileName);
  679. if (dlg.ShowDialog() == true)
  680. {
  681. var recipeName = mit.Tag as string + "\\" + dlg.InputText;
  682. XmlDocument rcpDoc = new XmlDocument();
  683. rcpDoc.LoadXml(rcpContent);
  684. rcpDoc.DocumentElement.SetAttribute("RecipeVersion", _viewModel.RecipeVersion());
  685. string rcpType = "";
  686. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  687. {
  688. rcpType = "Process";
  689. }
  690. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  691. {
  692. rcpType = "Clean";
  693. }
  694. if (!this._viewModel.SaveAsRecipe(recipeName, rcpType, rcpDoc.OuterXml))
  695. {
  696. importFailed = true;
  697. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeImportFailed"].ToString(), recipeName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
  698. }
  699. }
  700. srd.Close();
  701. if (!importFailed) File.Delete(openDlgFileName);
  702. UpdateRecipeFileList();
  703. UpdateProcessRecipeFileList();
  704. UpdateCleanRecipeFileList();
  705. SelectRecipe(mit.Tag as string + "\\" + dlg.InputText);
  706. }
  707. }
  708. }
  709. }
  710. catch (Exception ex)
  711. {
  712. LOG.Write(ex);
  713. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeImportException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  714. }
  715. }
  716. /// <summary>
  717. /// delete selected recipe files
  718. /// </summary>
  719. /// <param name="sender"></param>
  720. /// <param name="e"></param>
  721. void menuItem_MouseClick_DeleteRecipe(object sender, RoutedEventArgs e)
  722. {
  723. MenuItem mit = sender as MenuItem;
  724. string recipeName = mit.Tag as string;
  725. recipeName = PerformDeleteRecipe(recipeName);
  726. }
  727. private string PerformDeleteRecipe(string recipeName)
  728. {
  729. try
  730. {
  731. string origin = recipeName;
  732. int sepIndex = recipeName.LastIndexOf("\\");
  733. if (sepIndex < 0)
  734. sepIndex = 0;
  735. else
  736. sepIndex++;
  737. recipeName = recipeName.Substring(sepIndex);
  738. if (MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeDeleteInfo"].ToString(), recipeName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(),
  739. MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  740. {
  741. string rcpType = "";
  742. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  743. {
  744. rcpType = "Process";
  745. }
  746. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  747. {
  748. rcpType = "Clean";
  749. }
  750. this._viewModel.DeleteRecipe(origin, rcpType);
  751. UpdateRecipeFileList();
  752. UpdateProcessRecipeFileList();
  753. UpdateCleanRecipeFileList();
  754. }
  755. }
  756. catch (Exception ex)
  757. {
  758. LOG.Write(ex);
  759. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeDeleteException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  760. }
  761. return recipeName;
  762. }
  763. /// <summary>
  764. /// rename selected recipe files
  765. /// </summary>
  766. /// <param name="sender"></param>
  767. /// <param name="e"></param>
  768. void menuItem_MouseClick_RenameRecipe(object sender, RoutedEventArgs e)
  769. {
  770. MenuItem mit = sender as MenuItem;
  771. string recipeName = mit.Tag as string;
  772. PerformRenameRecipe(recipeName);
  773. }
  774. private void PerformRenameRecipe(string recipeName)
  775. {
  776. try
  777. {
  778. int lastSlashIndex = recipeName.LastIndexOf('\\');
  779. string shortName = recipeName.Substring(lastSlashIndex + 1);
  780. string rcpType = "";
  781. var rcp = treeViewRcpList;
  782. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  783. {
  784. rcp = treeViewProcessRcpList;
  785. rcpType = "Process";
  786. }
  787. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  788. {
  789. rcp = treeViewCleanRcpList;
  790. rcpType = "Clean";
  791. }
  792. TreeViewItem rightClickedItem = rcp.SelectedItem as TreeViewItem;
  793. RecipeNameInputDlg dlg = new RecipeNameInputDlg(string.Format(Application.Current.Resources["GlobalLableMsgRecipeRenameInfo"].ToString(), shortName), Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
  794. {
  795. InputText = shortName,
  796. Owner = Application.Current.MainWindow
  797. };
  798. if (dlg.ShowDialog() == true)
  799. {
  800. string newRecipeName = lastSlashIndex == -1 ? dlg.InputText : (recipeName.Substring(0, lastSlashIndex) + "\\" + dlg.InputText);
  801. var ret = this._viewModel.RenameRecipe(recipeName, rcpType, newRecipeName);
  802. if (ret)
  803. {
  804. UpdateRecipeFileList();
  805. UpdateProcessRecipeFileList();
  806. UpdateCleanRecipeFileList();
  807. SelectRecipe(newRecipeName);
  808. }
  809. else
  810. {
  811. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeRenameFailed"].ToString(), newRecipeName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
  812. }
  813. }
  814. }
  815. catch (Exception ex)
  816. {
  817. LOG.Write(ex);
  818. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeRenameException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  819. }
  820. }
  821. /// <summary>
  822. /// export selected recipe files
  823. /// </summary>
  824. /// <param name="sender"></param>
  825. /// <param name="e"></param>
  826. void menuItem_MouseClick_ExportRecipe(object sender, RoutedEventArgs e)
  827. {
  828. try
  829. {
  830. MenuItem mit = sender as MenuItem;
  831. string recipeName = mit.Tag as string;
  832. var dlg = new Microsoft.Win32.SaveFileDialog();
  833. dlg.FileName = recipeName.Substring(recipeName.LastIndexOf('\\') + 1);
  834. dlg.DefaultExt = ".rcp";
  835. dlg.Filter = Application.Current.Resources["GlobalLableMsgRecipeExportFilter"].ToString();
  836. if (dlg.ShowDialog() == true)
  837. {
  838. using (StreamWriter sw = new StreamWriter(dlg.FileName))
  839. {
  840. string rcpType = "";
  841. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  842. {
  843. rcpType = "Process";
  844. }
  845. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  846. {
  847. rcpType = "Clean";
  848. }
  849. sw.Write(this._viewModel.LoadRecipe(recipeName, rcpType));
  850. sw.Close();
  851. }
  852. }
  853. }
  854. catch (Exception ex)
  855. {
  856. LOG.Write(ex);
  857. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeExportFailed"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  858. }
  859. }
  860. void menuItem_MouseClick_ExportExcel(object sender, RoutedEventArgs e)
  861. {
  862. MenuItem mit = sender as MenuItem;
  863. string recipeName = mit.Tag as string;
  864. var dlg = new Microsoft.Win32.SaveFileDialog();
  865. dlg.FileName = recipeName.Substring(recipeName.LastIndexOf('\\') + 1);
  866. dlg.DefaultExt = ".xls";
  867. dlg.Filter = Application.Current.Resources["GlobalLableMsgRecipeExportExcelFilter"].ToString();
  868. var ret = dlg.ShowDialog();
  869. if (!ret.HasValue || !ret.Value)
  870. return;
  871. string fileName = dlg.FileName;
  872. this._viewModel.CurrentRecipeName = recipeName;
  873. string rcpType = "";
  874. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  875. {
  876. rcpType = "Process";
  877. }
  878. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  879. {
  880. rcpType = "Clean";
  881. }
  882. string xmlRecipeData = _viewModel.LoadRecipe(recipeName, rcpType);
  883. XmlDocument doc = new XmlDocument();
  884. doc.LoadXml(_viewModel.RecipeFormat);
  885. Task.Factory.StartNew(() =>
  886. {
  887. try
  888. {
  889. if (File.Exists(fileName))
  890. File.Delete(fileName);
  891. Workbook workbook = new Workbook();
  892. Worksheet worksheet = new Worksheet("First Sheet");
  893. var catalogNodes = doc.SelectNodes("/TableRecipeFormat/Catalog");
  894. int groupRowIndex = 0;
  895. int stepRowIndex = 0;
  896. int catalogRowIndex = 0;
  897. List<string> excelRowHeaderName = new List<string>();
  898. foreach (XmlElement cNode in catalogNodes)
  899. {
  900. XmlNodeList sNodes = cNode.SelectNodes("Group/Step");
  901. string catalogHeader = cNode.Attributes["DisplayName"].Value;
  902. worksheet.Cells[catalogRowIndex + 1, 0] = new Cell(catalogHeader);
  903. catalogRowIndex += sNodes.Count;
  904. XmlNodeList gNodes = cNode.SelectNodes("Group");
  905. foreach (XmlElement gNode in gNodes)
  906. {
  907. XmlNodeList stepNodes = gNode.SelectNodes("Step");
  908. string groupHeader = gNode.Attributes["DisplayName"].Value;
  909. worksheet.Cells[groupRowIndex + 1, 1] = new Cell(groupHeader);
  910. groupRowIndex += stepNodes.Count;
  911. foreach (XmlElement nd in stepNodes)
  912. {
  913. string stepHeader = nd.Attributes["DisplayName"].Value;
  914. worksheet.Cells[stepRowIndex + 1, 2] = new Cell(stepHeader);
  915. excelRowHeaderName.Add(nd.Attributes["ControlName"].Value);
  916. stepRowIndex++;
  917. }
  918. }
  919. }
  920. XmlDocument rcp = new XmlDocument();
  921. rcp.LoadXml(xmlRecipeData);
  922. XmlNodeList stepNodeList = rcp.SelectNodes("/TableRecipeData/Step");
  923. for (int stepNo = 0; stepNo < stepNodeList.Count; stepNo++)
  924. {
  925. var dataDic = new Dictionary<string, string>();
  926. foreach (XmlAttribute att in (stepNodeList[stepNo] as XmlElement).Attributes)
  927. {
  928. dataDic.Add(att.Name, att.Value);
  929. }
  930. //fill sub node's attributes
  931. foreach (XmlElement subStep in stepNodeList[stepNo].ChildNodes)
  932. {
  933. foreach (XmlAttribute att in subStep.Attributes)
  934. {
  935. dataDic.Add(att.Name, att.Value);
  936. }
  937. foreach (XmlElement subsubStep in subStep.ChildNodes)
  938. {
  939. foreach (XmlAttribute att2 in subsubStep.Attributes)
  940. {
  941. dataDic.Add(att2.Name, att2.Value);
  942. }
  943. }
  944. }
  945. long length = dataDic.LongCount();
  946. worksheet.Cells[0, 3] = new Cell(recipeName);
  947. for (int rowIndex = 0; rowIndex < excelRowHeaderName.Count; rowIndex++)
  948. {
  949. worksheet.Cells.ColumnWidth[(ushort)(rowIndex + 1)] = 4000;
  950. string cellValueString = dataDic[excelRowHeaderName[rowIndex]];
  951. double cellValue;
  952. if (double.TryParse(cellValueString, out cellValue))
  953. {
  954. worksheet.Cells[rowIndex + 1, stepNo + 3] = new Cell(cellValue);
  955. }
  956. else
  957. {
  958. worksheet.Cells[rowIndex + 1, stepNo + 3] = new Cell(cellValueString);
  959. }
  960. }
  961. }
  962. workbook.Worksheets.Add(worksheet);
  963. workbook.Save(fileName);
  964. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeExportExcelOk"].ToString(), recipeName, fileName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Information);
  965. }
  966. catch (Exception ex)
  967. {
  968. LOG.Write(ex);
  969. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeExportExcelFailed"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  970. }
  971. });
  972. }
  973. private void ButtonNew(object sender, RoutedEventArgs e)
  974. {
  975. if (MenuPermission != 3) return;
  976. var rcp = treeViewRcpList;
  977. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  978. {
  979. rcp = treeViewProcessRcpList;
  980. }
  981. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  982. {
  983. rcp = treeViewCleanRcpList;
  984. }
  985. var focus = rcp.SelectedItem;
  986. string folder = "";
  987. if (focus is TreeViewFileItem file)
  988. {
  989. var name = file.FileName;
  990. if (name.Contains("\\"))
  991. folder = name.Substring(0, name.LastIndexOf('\\'));
  992. }
  993. else if (focus is TreeViewFolderItem folderItem)
  994. {
  995. folder = folderItem.FolderName;
  996. }
  997. PerformCreateRecipe(folder);
  998. }
  999. private void ButtonRename(object sender, RoutedEventArgs e)
  1000. {
  1001. if (MenuPermission != 3) return;
  1002. var rcp = treeViewRcpList;
  1003. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  1004. {
  1005. rcp = treeViewProcessRcpList;
  1006. }
  1007. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  1008. {
  1009. rcp = treeViewCleanRcpList;
  1010. }
  1011. var focus = rcp.SelectedItem;
  1012. if (focus is TreeViewFileItem file)
  1013. {
  1014. var name = file.FileName;
  1015. PerformRenameRecipe(file.FileName);
  1016. }
  1017. else if (focus is TreeViewFolderItem folderItem)
  1018. {
  1019. PerformRenameFolder(folderItem.FolderName);
  1020. }
  1021. }
  1022. private void ButtonDelete(object sender, RoutedEventArgs e)
  1023. {
  1024. if (MenuPermission != 3) return;
  1025. var rcp = treeViewRcpList;
  1026. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  1027. {
  1028. rcp = treeViewProcessRcpList;
  1029. }
  1030. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  1031. {
  1032. rcp = treeViewCleanRcpList;
  1033. }
  1034. var focus = rcp.SelectedItem;
  1035. if (focus is TreeViewFileItem file)
  1036. {
  1037. var name = file.FileName;
  1038. PerformDeleteRecipe(file.FileName);
  1039. }
  1040. else if (focus is TreeViewFolderItem folderItem)
  1041. {
  1042. PerformDeleteFolder(folderItem.FolderName);
  1043. }
  1044. }
  1045. private void PerformCreateRecipe(string folderName)
  1046. {
  1047. try
  1048. {
  1049. RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
  1050. {
  1051. Owner = Application.Current.MainWindow
  1052. };
  1053. if (dlg.ShowDialog() == true)
  1054. {
  1055. var recipeName = folderName + "\\" + dlg.InputText;
  1056. string rcpType = "";
  1057. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  1058. {
  1059. rcpType = "Process";
  1060. }
  1061. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  1062. {
  1063. rcpType = "Clean";
  1064. }
  1065. if (!this._viewModel.SaveAsRecipe(recipeName, rcpType, this._viewModel.RecipeTemplate))
  1066. {
  1067. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateFailed"].ToString(), recipeName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
  1068. }
  1069. else
  1070. {
  1071. UpdateRecipeFileList();
  1072. UpdateProcessRecipeFileList();
  1073. UpdateCleanRecipeFileList();
  1074. SelectRecipe(folderName + "\\" + dlg.InputText);
  1075. }
  1076. }
  1077. }
  1078. catch (Exception ex)
  1079. {
  1080. LOG.Write(ex);
  1081. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  1082. }
  1083. }
  1084. private void TreeViewRcpList_DragEnter(object sender, DragEventArgs e)
  1085. {
  1086. try
  1087. {
  1088. if (GetAncestor<TreeViewFileItem>((DependencyObject)e.Source) != null)
  1089. {
  1090. if (GetAncestor<TreeViewFileItem>((DependencyObject)e.Source) == GetAncestor<TreeViewFileItem>((DependencyObject)OriginalItem)
  1091. || VisualTreeHelper.GetParent(GetAncestor<TreeViewFileItem>((DependencyObject)e.Source)) == VisualTreeHelper.GetParent(GetAncestor<TreeViewFileItem>((DependencyObject)OriginalItem)))
  1092. e.Effects = DragDropEffects.None;
  1093. }
  1094. else if (GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source) != null)
  1095. {
  1096. if (GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source) == GetAncestor<TreeViewFolderItem>((DependencyObject)OriginalItem))
  1097. e.Effects = DragDropEffects.None;
  1098. }
  1099. else if (e.Source is TreeView)
  1100. {
  1101. e.Effects = DragDropEffects.None;
  1102. }
  1103. e.Handled = true;
  1104. }
  1105. catch (Exception ex)
  1106. {
  1107. LOG.Write(ex);
  1108. }
  1109. }
  1110. private void TreeViewRcpList_Drop(object sender, DragEventArgs e)
  1111. {
  1112. try
  1113. {
  1114. string rcpType = "";
  1115. var rcp = treeViewRcpList;
  1116. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  1117. {
  1118. rcp = treeViewProcessRcpList;
  1119. rcpType = "Process";
  1120. }
  1121. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  1122. {
  1123. rcp = treeViewCleanRcpList;
  1124. rcpType = "Clean";
  1125. }
  1126. TreeViewItem itemRemoved = rcp.SelectedItem as TreeViewItem;
  1127. #region
  1128. //foreach (TreeViewItem item in treeViewProcessRcpList.Items)
  1129. //{
  1130. // if (itemRemoved.Equals(item))
  1131. // {
  1132. // treeViewProcessRcpList.Items.Remove(itemRemoved);
  1133. // break;
  1134. // }
  1135. // if (item.Items.Count > 0)
  1136. // {
  1137. // foreach (TreeViewItem subItem in item.Items)
  1138. // {
  1139. // if (itemRemoved.Equals(subItem))
  1140. // {
  1141. // item.Items.Remove(itemRemoved);
  1142. // break;
  1143. // }
  1144. // }
  1145. // }
  1146. //}
  1147. //(getTreeViewFolderItem as TreeViewFolderItem).Items.Add(itemRemoved);
  1148. #endregion
  1149. if (GetAncestor<TreeViewFileItem>((DependencyObject)e.Source) != null)
  1150. {
  1151. if (GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source) != null)
  1152. {
  1153. TreeViewFolderItem getTreeViewFolderItem = GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source);
  1154. tragetFilePath = getTreeViewFolderItem.FolderName;
  1155. GetAncestor<TreeView>(getTreeViewFolderItem);
  1156. _viewModel.MoveRecipeFile(((TreeViewFileItem)itemRemoved).FileName, rcpType, tragetFilePath);
  1157. }
  1158. else
  1159. {
  1160. tragetFilePath = "";
  1161. GetAncestor<TreeView>((DependencyObject)e.Source);
  1162. _viewModel.MoveRecipeFile(((TreeViewFileItem)itemRemoved).FileName, rcpType, tragetFilePath);
  1163. }
  1164. }
  1165. else if (GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source) != null)
  1166. {
  1167. TreeViewFolderItem getTreeViewFolderItem = GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source);
  1168. tragetFilePath = getTreeViewFolderItem.FolderName;
  1169. GetAncestor<TreeView>(getTreeViewFolderItem);
  1170. _viewModel.MoveRecipeFile(((TreeViewFileItem)itemRemoved).FileName, rcpType, tragetFilePath);
  1171. }
  1172. UpdateRecipeFileList();
  1173. UpdateProcessRecipeFileList();
  1174. UpdateCleanRecipeFileList();
  1175. SelectRecipe(tragetFilePath + "\\" + System.IO.Path.GetFileNameWithoutExtension(((TreeViewFileItem)itemRemoved).FileName));
  1176. }
  1177. catch (Exception ex)
  1178. {
  1179. LOG.Write(ex);
  1180. }
  1181. }
  1182. private void TreeViewRcpList_MouseDown(object sender, MouseButtonEventArgs e)
  1183. {
  1184. var rcp = treeViewRcpList;
  1185. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  1186. {
  1187. rcp = treeViewProcessRcpList;
  1188. }
  1189. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  1190. {
  1191. rcp = treeViewCleanRcpList;
  1192. }
  1193. if (e.ChangedButton == MouseButton.Left)
  1194. {
  1195. _lastMouseDown = e.GetPosition(rcp);
  1196. }
  1197. }
  1198. private void TreeViewRcpList_MouseMove(object sender, MouseEventArgs e)
  1199. {
  1200. try
  1201. {
  1202. var rcp = treeViewRcpList;
  1203. if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
  1204. {
  1205. rcp = treeViewProcessRcpList;
  1206. }
  1207. else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
  1208. {
  1209. rcp = treeViewCleanRcpList;
  1210. }
  1211. if (e.LeftButton == MouseButtonState.Pressed)
  1212. {
  1213. Point currentPosition = e.GetPosition(rcp);
  1214. OriginalItem = e.OriginalSource;
  1215. if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 2.0) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 2.0))
  1216. {
  1217. if ((treeViewProcessRcpList.SelectedItem as TreeViewItem) != null)
  1218. {
  1219. //DragDropEffects finalDropEffect = DragDrop.DoDragDrop(treeViewProcessRcpList, treeViewProcessRcpList.SelectedItem, DragDropEffects.Move);
  1220. DragDropEffects finalDropEffect = DragDrop.DoDragDrop(treeViewProcessRcpList.SelectedItem as TreeViewItem, sender, DragDropEffects.Move);
  1221. }
  1222. }
  1223. }
  1224. }
  1225. catch (Exception ex)
  1226. {
  1227. LOG.Write(ex);
  1228. }
  1229. }
  1230. /// <summary>
  1231. /// 子页面获取父类窗体
  1232. /// </summary>
  1233. /// <typeparam name="T"></typeparam>
  1234. /// <param name="reference"></param>
  1235. /// <returns></returns>
  1236. public T GetAncestor<T>(DependencyObject reference) where T : DependencyObject
  1237. {
  1238. DependencyObject parent = VisualTreeHelper.GetParent(reference);
  1239. while (!(parent is T) && parent != null)
  1240. {
  1241. parent = VisualTreeHelper.GetParent(parent);
  1242. if (parent is TreeViewFolderItem)
  1243. tragetFilePath = tragetFilePath.Insert(0, $"{((TreeViewFolderItem)parent).FolderName}\\");
  1244. }
  1245. if (parent != null)
  1246. return (T)parent;
  1247. else
  1248. return null;
  1249. }//在子页面中调用GetAncestor<MainWindow>(this);
  1250. }
  1251. }