12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Xml;
- using Aitex.Core.Account;
- using Aitex.Core.RT.Log;
- using Aitex.Core.UI.View.Common;
- using Aitex.UI.RecipeEditor.View;
- using ExcelLibrary.SpreadSheet;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.UI.Core.Accounts;
- namespace VirgoUI.Client.Models.PMs
- {
- /// <summary>
- /// Interaction logic for RecipeEditorView.xaml
- /// </summary>
- public partial class RecipeEditorView : UserControl
- {
- private string _culture;
- private string tragetFilePath = "";
- private object OriginalItem;
- private RecipeEditorViewModel _viewModel;
- private int MenuPermission;
- private ViewPermission _permission;
- private Point _lastMouseDown;
- public RecipeEditorView()
- {
- InitializeComponent();
- this.buttonSaveTableRecipe.ContextMenu = null;
- this.DataContext = _viewModel = new RecipeEditorViewModel(new UiRecipeManager(), ModuleName.System.ToString());
- this.Loaded += new RoutedEventHandler(RecipeEditorView_Loaded);
- this.Unloaded += new RoutedEventHandler(RecipeEditorView_Unloaded);
- //VirgoUiSystem.Instance.CultureChanged += CultureChanged;
- }
- private void CultureChanged(string s)
- {
- _culture = s;
- this.tableRecipeGrid.UpdateCultureResource(s);
- }
- static DependencyObject VisualUpwardSearch<T>(DependencyObject source)
- {
- while (source != null && source.GetType() != typeof(T))
- source = VisualTreeHelper.GetParent(source);
- return source;
- }
- void RecipeEditorView_Unloaded(object sender, RoutedEventArgs e)
- {
- }
- void RecipeEditorView_Loaded(object sender, RoutedEventArgs e)
- {
- buttonSaveTableRecipe.Click += (obj, args) => { SetMenu.IsOpen = true; };
- SaveToSingle.Header = $"Save To {((RecipeEditorViewModel)this.DataContext).SystemName}";
- //SaveToDouble.Header = "Save To PMA And PMB";
- _viewModel.ChamberId = ((RecipeEditorViewModel)this.DataContext).SystemName;
- MenuPermission = ClientApp.Instance.GetPermission($"Recipe{_viewModel.ChamberId}");
- if (_culture != Thread.CurrentThread.CurrentCulture.Name)
- {
- _culture = Thread.CurrentThread.CurrentCulture.Name;
- this.tableRecipeGrid.UpdateCultureResource(_culture);
- }
- _viewModel.UpdateAllConfig();
- tableRecipeGrid.SetEnableBarcode(_viewModel.IsBarcodeEnabled);
- tableRecipeGrid.SetUser(ClientApp.Instance.UserContext.LoginName);
- tableRecipeGrid.SetEndPointDefaultValue((string)QueryDataClient.Instance.Service.GetConfig("System.EndPoint.EndPointDefaultValue"));
- UpdateRecipeFileList();
- UpdateProcessRecipeFileList();
- UpdateCleanRecipeFileList();
- this.Name = "recipeEditor";
- _permission = ViewPermission.FullyControl;//this.GetPermission();
- switch (_permission)
- {
- case ViewPermission.Readonly:
- buttonReloadTableRecipe.IsEnabled = false;
- tableRecipeGrid.IsEnabled = false;
- buttonSaveTableRecipe.IsEnabled = false;
- break;
- default:
- break;
- }
- }
- private void treeViewRcpList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
- {
- //var permission = this.GetPermission();
- if (tableRecipeGrid.IsRecipeModified)
- {
- //if (permission == ViewPermission.FullyControl)
- {
- switch (MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgSaveCurrentRecipe"].ToString(), _viewModel.CurrentRecipeName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.YesNo, MessageBoxImage.Question))
- {
- case MessageBoxResult.Yes:
- if (SaveRecipe())
- {
- var item = e.NewValue as TreeViewFileItem;
- if (item != null)
- item.IsSelected = true;
- }
- else
- {
- var item = e.OldValue as TreeViewFileItem;
- if (item != null)
- item.IsSelected = true;
- return;
- }
- break;
- case MessageBoxResult.No:
- {
- var item = e.NewValue as TreeViewFileItem;
- if (item != null)
- item.IsSelected = true;
- }
- break;
- }
- }
- }
- var selectedItem = e.NewValue as TreeViewFileItem;
- if (selectedItem == null)
- return;
- try
- {
- this._viewModel.CurrentRecipeName = selectedItem.FileName;
- string rcpType = "";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcpType = "Clean";
- }
- string xmlRecipeData = _viewModel.LoadRecipe(selectedItem.FileName, rcpType);
- this.tableRecipeGrid.ControlViewModel.LoadRecipe(_viewModel.RecipeFormat, xmlRecipeData);
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- private bool SaveRecipe(string flag = "Single")
- {
- bool ret = true;
- try
- {
- var hasErr = this.tableRecipeGrid.ControlViewModel.Errors.Count > 0;
- if (!hasErr ||
- MessageBox.Show(Application.Current.Resources["GlobalLableMsgRecipeSaveInfo"].ToString(), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.YesNoCancel, MessageBoxImage.Warning) == MessageBoxResult.Yes)
- {
- string rcpType = "";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcpType = "Clean";
- }
- if (flag == "Single")
- ret = _viewModel.SaveRecipe(this._viewModel.CurrentRecipeName, rcpType, this.tableRecipeGrid.ControlViewModel.GetRecipeContentString());
- else if (flag == "Double")
- ret = _viewModel.SaveRecipeDouble(this._viewModel.CurrentRecipeName, rcpType, this.tableRecipeGrid.ControlViewModel.GetRecipeContentString());
- if (ret)
- {
- tableRecipeGrid.Dispatcher.Invoke(new System.Action(() =>
- {
- this.tableRecipeGrid.ControlViewModel.LoadRecipe(_viewModel.RecipeFormat, _viewModel.LoadRecipe(_viewModel.CurrentRecipeName, rcpType));
- }));
- }
- }
- else
- {
- ret = false;
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(Application.Current.Resources["GlobalLableMsgRecipeSaveException"].ToString(), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
- ret = false;
- }
- return ret;
- }
- private void treeViewRcpList_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
- {
- if (_permission != ViewPermission.FullyControl)
- return;
- //black place right mouse click
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- }
- rcp.ContextMenu = new ContextMenu();
- MenuItem menuItem = new MenuItem();
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateRecipe);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuNewRecipe"];
- rcp.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_ImportRecipe);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuImportRecipe"];
- rcp.ContextMenu.Items.Add(menuItem);
- rcp.ContextMenu.Items.Add(new Separator());
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateFolder);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuNewFolder"];
- rcp.ContextMenu.Items.Add(menuItem);
- rcp.ContextMenu.Visibility = Visibility.Visible;
- }
- private void TreeViewItem_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
- {
- if (_permission != ViewPermission.FullyControl)
- return;
- var treeViewFileItem = VisualUpwardSearch<TreeViewFileItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
- if (treeViewFileItem != null)
- {
- treeViewFileItem.Focus();
- treeViewFileItem.IsSelected = true;
- treeViewFileItem.ContextMenu = new ContextMenu();
- MenuItem menuItem = null;
- menuItem = new MenuItem();
- menuItem.Tag = treeViewFileItem.Tag as string;
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_ExportRecipe);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuExportRecipe"];
- treeViewFileItem.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = treeViewFileItem.Tag as string;
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_ExportExcel);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuExportRecipeAsExcel"];
- treeViewFileItem.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = treeViewFileItem.Tag as string;
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_SaveAs);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuSaveAs"];
- treeViewFileItem.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = treeViewFileItem.Tag as string;
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_RenameRecipe);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuRenameRecipe"];
- treeViewFileItem.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = treeViewFileItem.Tag as string;
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_DeleteRecipe);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuDeleteRecipe"];
- treeViewFileItem.ContextMenu.Items.Add(menuItem);
- treeViewFileItem.ContextMenu.Visibility = Visibility.Visible;
- }
- else
- {
- var treeViewFolderItem = VisualUpwardSearch<TreeViewFolderItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
- if (treeViewFolderItem != null)
- {
- treeViewFolderItem.Focus();
- treeViewFolderItem.IsSelected = true;
- treeViewFolderItem.ContextMenu = new ContextMenu();
- MenuItem menuItem = null;
- menuItem = new MenuItem();
- menuItem.Tag = treeViewFolderItem.Tag as string;
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateRecipe);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuNewRecipe"];
- treeViewFolderItem.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = treeViewFolderItem.Tag as string;
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_ImportRecipe);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuImportRecipe"];
- treeViewFolderItem.ContextMenu.Items.Add(menuItem);
- treeViewFolderItem.ContextMenu.Items.Add(new Separator());
- menuItem = new MenuItem();
- menuItem.Tag = treeViewFolderItem.Tag as string;
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateFolder);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuNewFolder"];
- treeViewFolderItem.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = treeViewFolderItem.Tag as string;
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_RenameFolder);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuRenameFolder"];
- treeViewFolderItem.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = treeViewFolderItem.Tag as string;
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_DeleteFolder);
- menuItem.Header = Application.Current.Resources["GlobalLableMenuDeleteFolder"];
- treeViewFolderItem.ContextMenu.Items.Add(menuItem);
- treeViewFolderItem.ContextMenu.Visibility = Visibility.Visible;
- }
- }
- }
- /// <summary>
- /// reload current recipe content
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonCodeReload_Click(object sender, RoutedEventArgs e)
- {
- if (MenuPermission != 3) return;
- if (MessageBox.Show(Application.Current.Resources["GlobalLableMsgRecipeReloadInfo"].ToString(), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.YesNoCancel) == MessageBoxResult.Yes)
- {
- this.tableRecipeGrid.Dispatcher.Invoke(new System.Action(() =>
- {
- string rcpType = "";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcpType = "Clean";
- }
- this.tableRecipeGrid.ControlViewModel.LoadRecipe(_viewModel.RecipeFormat, _viewModel.LoadRecipe(_viewModel.CurrentRecipeName, rcpType));
- }));
- }
- }
- ///// <summary>
- ///// Save recipe file
- ///// </summary>
- ///// <param name="sender"></param>
- ///// <param name="e"></param>
- //private void buttonCodeSave_Click(object sender, RoutedEventArgs e)
- //{
- // SaveRecipe();
- //}
- /// <summary>
- /// Save recipe file
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SaveToSingle_Click(object sender, RoutedEventArgs e)
- {
- if (MenuPermission != 3) return;
- SaveRecipe();
- }
- /// <summary>
- /// Save recipe file
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SaveToDouble_Click(object sender, RoutedEventArgs e)
- {
- if (MenuPermission != 3) return;
- SaveRecipe("Double");
- }
- void SelectRecipe(string recipeName)
- {
- try
- {
- string[] paths = recipeName.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
- string fileName = "";
- for (int i = 0; i < paths.Length - 1; i++)
- fileName += paths[i] + "\\";
- fileName += paths[paths.Length - 1];
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- }
- selectRecipe(rcp, paths, 0, fileName);
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- }
- ItemsControl selectRecipe(ItemsControl currentNode, string[] paths, int index, string fileName)
- {
- if (currentNode == null)
- return null;
- if (index == paths.Length - 1)
- {
- foreach (var item in currentNode.Items)
- {
- TreeViewFileItem tvf = item as TreeViewFileItem;
- if (tvf != null && tvf.FileName == fileName)
- {
- tvf.IsSelected = true;
- return null;
- }
- }
- }
- foreach (var item in currentNode.Items)
- {
- TreeViewFolderItem tvf = item as TreeViewFolderItem;
- if (tvf != null && tvf.FolderName == paths[index])
- {
- tvf.IsExpanded = true;
- selectRecipe(tvf, paths, index + 1, fileName);
- break;
- }
- }
- return null;
- }
- private void UpdateRecipeFileList()
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(_viewModel.GetXmlRecipeList(""));
- treeViewRcpList.Items.Clear();
- CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
- }
- private void UpdateProcessRecipeFileList()
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(_viewModel.GetXmlRecipeList("Process"));
- treeViewProcessRcpList.Items.Clear();
- CreateTreeViewItems(doc.DocumentElement, this.treeViewProcessRcpList);
- }
- private void UpdateCleanRecipeFileList()
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(_viewModel.GetXmlRecipeList("Clean"));
- treeViewCleanRcpList.Items.Clear();
- CreateTreeViewItems(doc.DocumentElement, this.treeViewCleanRcpList);
- }
- void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
- {
- foreach (XmlElement ele in curElementNode.ChildNodes)
- {
- if (ele.Name == "File")
- {
- string fileName = ele.Attributes["Name"].Value;
- fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
- TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
- item.Tag = ele.Attributes["Name"].Value;
- item.ToolTip = fileName;
- itemsControl.Items.Add(item);
- }
- else if (ele.Name == "Folder")
- {
- string folderName = ele.Attributes["Name"].Value;
- folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
- TreeViewFolderItem item = new TreeViewFolderItem(folderName);
- item.Tag = ele.Attributes["Name"].Value;
- CreateTreeViewItems(ele, item);
- item.IsExpanded = false;
- itemsControl.Items.Add(item);
- }
- }
- }
- void menuItem_MouseClick_SaveAs(object sender, RoutedEventArgs e)
- {
- try
- {
- MenuItem mit = sender as MenuItem;
- var oldName = mit.Tag as string;
- RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
- {
- InputText = oldName,
- Owner = Application.Current.MainWindow
- };
- var ret = dlg.ShowDialog();
- if (ret.HasValue && ret.Value)
- {
- var newName = dlg.InputText;
- string rcpType = "";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcpType = "Clean";
- }
- if (_viewModel.SaveAsRecipe(newName, rcpType, _viewModel.LoadRecipe(oldName, rcpType)))
- {
- UpdateRecipeFileList();
- UpdateProcessRecipeFileList();
- UpdateCleanRecipeFileList();
- SelectRecipe(newName);
- }
- else
- {
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeSaveAsFailed"].ToString(), newName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeSaveAsException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- void menuItem_MouseClick_CreateFolder(object sender, RoutedEventArgs e)
- {
- try
- {
- MenuItem mit = sender as MenuItem;
- string folderName = mit.Tag as string;
- string rcpType = "";
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- rcpType = "Clean";
- }
- var selectedRecipeItem = rcp.SelectedItem as TreeViewFileItem;
- RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputFolderName"].ToString())
- {
- Owner = Application.Current.MainWindow
- };
- if (dlg.ShowDialog() == true)
- {
- this._viewModel.CreateFolder(folderName + "\\" + dlg.InputText, rcpType);
- UpdateRecipeFileList();
- UpdateCleanRecipeFileList();
- UpdateProcessRecipeFileList();
- if (selectedRecipeItem != null)
- SelectRecipe(selectedRecipeItem.FileName);
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeFolderNewFailed"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString());
- }
- }
- /// <summary>
- /// Create new recipe
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void menuItem_MouseClick_CreateRecipe(object sender, RoutedEventArgs e)
- {
- MenuItem mit = sender as MenuItem;
- string folderName = mit.Tag as string;
- PerformCreateRecipe(folderName);
- }
- /// <summary>
- /// delete folder
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void menuItem_MouseClick_DeleteFolder(object sender, RoutedEventArgs e)
- {
- MenuItem mit = sender as MenuItem;
- string folderName = mit.Tag as string;
- PerformDeleteFolder(folderName);
- }
- private void PerformDeleteFolder(string folderName)
- {
- try
- {
- string rcpType = "";
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- rcpType = "Clean";
- }
- var selectedRecipeItem = rcp.SelectedItem as TreeViewFileItem;
- if (MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeDeleteFolderInfo"].ToString(), folderName),
- Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- this._viewModel.DeleteFolder(folderName, rcpType);
- UpdateRecipeFileList();
- UpdateProcessRecipeFileList();
- UpdateCleanRecipeFileList();
- if (selectedRecipeItem != null)
- SelectRecipe(selectedRecipeItem.FileName);
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeDeleteFolderException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- /// <summary>
- /// rename folder
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void menuItem_MouseClick_RenameFolder(object sender, RoutedEventArgs e)
- {
- MenuItem mit = sender as MenuItem;
- string folderName = mit.Tag as string;
- PerformRenameFolder(folderName);
- }
- private void PerformRenameFolder(string folderName)
- {
- try
- {
- int lastSlashIndex = folderName.LastIndexOf('\\');
- string shortName = folderName.Substring(lastSlashIndex + 1);
- RecipeNameInputDlg dlg =
- new RecipeNameInputDlg(
- string.Format(Application.Current.Resources["GlobalLableMsgRecipeRenameFolderInfo"].ToString(),
- shortName), Application.Current.Resources["GlobalLableMsgInputFolderName"].ToString())
- {
- Owner = Application.Current.MainWindow
- };
- if (dlg.ShowDialog() == true)
- {
- string dir = lastSlashIndex == -1 ? "" : folderName.Substring(0, lastSlashIndex);
- string rcpType = "";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcpType = "Clean";
- }
- if (!_viewModel.RenameFolder(folderName, rcpType, dir + "\\" + dlg.InputText))
- {
- MessageBox.Show(Application.Current.Resources["GlobalLableMsgRecipeRenameFolderFailed"].ToString(),
- Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK,
- MessageBoxImage.Warning);
- }
- else
- {
- UpdateRecipeFileList();
- UpdateProcessRecipeFileList();
- UpdateCleanRecipeFileList();
- }
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(
- string.Format(Application.Current.Resources["GlobalLableMsgRecipeRenameFolderException"].ToString(),
- ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(),
- MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- /// <summary>
- /// import external recipe file into selected folder
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void menuItem_MouseClick_ImportRecipe(object sender, RoutedEventArgs e)
- {
- try
- {
- MenuItem mit = sender as MenuItem;
- string folderName = mit.Tag as string;
- Microsoft.Win32.OpenFileDialog openDlg = new Microsoft.Win32.OpenFileDialog();
- openDlg.DefaultExt = ".rcp";
- openDlg.Filter = "Recipe file (.rcp)|*.rcp";
- openDlg.Multiselect = true;
- if (openDlg.ShowDialog() == true)
- {
- foreach (var openDlgFileName in openDlg.FileNames)
- {
- using (StreamReader srd = new StreamReader(openDlgFileName))
- {
- bool importFailed = false;
- string rcpContent = srd.ReadToEnd();
- RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgRecipeImportInfo"].ToString(), Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
- {
- Owner = Application.Current.MainWindow
- };
- dlg.InputText = System.IO.Path.GetFileNameWithoutExtension(openDlgFileName);
- if (dlg.ShowDialog() == true)
- {
- var recipeName = mit.Tag as string + "\\" + dlg.InputText;
- XmlDocument rcpDoc = new XmlDocument();
- rcpDoc.LoadXml(rcpContent);
- rcpDoc.DocumentElement.SetAttribute("RecipeVersion", _viewModel.RecipeVersion());
- string rcpType = "";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcpType = "Clean";
- }
- if (!this._viewModel.SaveAsRecipe(recipeName, rcpType, rcpDoc.OuterXml))
- {
- importFailed = true;
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeImportFailed"].ToString(), recipeName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- }
- srd.Close();
- if (!importFailed) File.Delete(openDlgFileName);
- UpdateRecipeFileList();
- UpdateProcessRecipeFileList();
- UpdateCleanRecipeFileList();
- SelectRecipe(mit.Tag as string + "\\" + dlg.InputText);
- }
- }
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeImportException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- /// <summary>
- /// delete selected recipe files
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void menuItem_MouseClick_DeleteRecipe(object sender, RoutedEventArgs e)
- {
- MenuItem mit = sender as MenuItem;
- string recipeName = mit.Tag as string;
- recipeName = PerformDeleteRecipe(recipeName);
- }
- private string PerformDeleteRecipe(string recipeName)
- {
- try
- {
- string origin = recipeName;
- int sepIndex = recipeName.LastIndexOf("\\");
- if (sepIndex < 0)
- sepIndex = 0;
- else
- sepIndex++;
- recipeName = recipeName.Substring(sepIndex);
- if (MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeDeleteInfo"].ToString(), recipeName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(),
- MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- string rcpType = "";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcpType = "Clean";
- }
- this._viewModel.DeleteRecipe(origin, rcpType);
- UpdateRecipeFileList();
- UpdateProcessRecipeFileList();
- UpdateCleanRecipeFileList();
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeDeleteException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- return recipeName;
- }
- /// <summary>
- /// rename selected recipe files
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void menuItem_MouseClick_RenameRecipe(object sender, RoutedEventArgs e)
- {
- MenuItem mit = sender as MenuItem;
- string recipeName = mit.Tag as string;
- PerformRenameRecipe(recipeName);
- }
- private void PerformRenameRecipe(string recipeName)
- {
- try
- {
- int lastSlashIndex = recipeName.LastIndexOf('\\');
- string shortName = recipeName.Substring(lastSlashIndex + 1);
- string rcpType = "";
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- rcpType = "Clean";
- }
- TreeViewItem rightClickedItem = rcp.SelectedItem as TreeViewItem;
- RecipeNameInputDlg dlg = new RecipeNameInputDlg(string.Format(Application.Current.Resources["GlobalLableMsgRecipeRenameInfo"].ToString(), shortName), Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
- {
- InputText = shortName,
- Owner = Application.Current.MainWindow
- };
- if (dlg.ShowDialog() == true)
- {
- string newRecipeName = lastSlashIndex == -1 ? dlg.InputText : (recipeName.Substring(0, lastSlashIndex) + "\\" + dlg.InputText);
- var ret = this._viewModel.RenameRecipe(recipeName, rcpType, newRecipeName);
- if (ret)
- {
- UpdateRecipeFileList();
- UpdateProcessRecipeFileList();
- UpdateCleanRecipeFileList();
- SelectRecipe(newRecipeName);
- }
- else
- {
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeRenameFailed"].ToString(), newRecipeName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeRenameException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- /// <summary>
- /// export selected recipe files
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void menuItem_MouseClick_ExportRecipe(object sender, RoutedEventArgs e)
- {
- try
- {
- MenuItem mit = sender as MenuItem;
- string recipeName = mit.Tag as string;
- var dlg = new Microsoft.Win32.SaveFileDialog();
- dlg.FileName = recipeName.Substring(recipeName.LastIndexOf('\\') + 1);
- dlg.DefaultExt = ".rcp";
- dlg.Filter = Application.Current.Resources["GlobalLableMsgRecipeExportFilter"].ToString();
- if (dlg.ShowDialog() == true)
- {
- using (StreamWriter sw = new StreamWriter(dlg.FileName))
- {
- string rcpType = "";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcpType = "Clean";
- }
- sw.Write(this._viewModel.LoadRecipe(recipeName, rcpType));
- sw.Close();
- }
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeExportFailed"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- void menuItem_MouseClick_ExportExcel(object sender, RoutedEventArgs e)
- {
- MenuItem mit = sender as MenuItem;
- string recipeName = mit.Tag as string;
- var dlg = new Microsoft.Win32.SaveFileDialog();
- dlg.FileName = recipeName.Substring(recipeName.LastIndexOf('\\') + 1);
- dlg.DefaultExt = ".xls";
- dlg.Filter = Application.Current.Resources["GlobalLableMsgRecipeExportExcelFilter"].ToString();
- var ret = dlg.ShowDialog();
- if (!ret.HasValue || !ret.Value)
- return;
- string fileName = dlg.FileName;
- this._viewModel.CurrentRecipeName = recipeName;
- string rcpType = "";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcpType = "Clean";
- }
- string xmlRecipeData = _viewModel.LoadRecipe(recipeName, rcpType);
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(_viewModel.RecipeFormat);
- Task.Factory.StartNew(() =>
- {
- try
- {
- if (File.Exists(fileName))
- File.Delete(fileName);
- Workbook workbook = new Workbook();
- Worksheet worksheet = new Worksheet("First Sheet");
- var catalogNodes = doc.SelectNodes("/TableRecipeFormat/Catalog");
- int groupRowIndex = 0;
- int stepRowIndex = 0;
- int catalogRowIndex = 0;
- List<string> excelRowHeaderName = new List<string>();
- foreach (XmlElement cNode in catalogNodes)
- {
- XmlNodeList sNodes = cNode.SelectNodes("Group/Step");
- string catalogHeader = cNode.Attributes["DisplayName"].Value;
- worksheet.Cells[catalogRowIndex + 1, 0] = new Cell(catalogHeader);
- catalogRowIndex += sNodes.Count;
- XmlNodeList gNodes = cNode.SelectNodes("Group");
- foreach (XmlElement gNode in gNodes)
- {
- XmlNodeList stepNodes = gNode.SelectNodes("Step");
- string groupHeader = gNode.Attributes["DisplayName"].Value;
- worksheet.Cells[groupRowIndex + 1, 1] = new Cell(groupHeader);
- groupRowIndex += stepNodes.Count;
- foreach (XmlElement nd in stepNodes)
- {
- string stepHeader = nd.Attributes["DisplayName"].Value;
- worksheet.Cells[stepRowIndex + 1, 2] = new Cell(stepHeader);
- excelRowHeaderName.Add(nd.Attributes["ControlName"].Value);
- stepRowIndex++;
- }
- }
- }
- XmlDocument rcp = new XmlDocument();
- rcp.LoadXml(xmlRecipeData);
- XmlNodeList stepNodeList = rcp.SelectNodes("/TableRecipeData/Step");
- for (int stepNo = 0; stepNo < stepNodeList.Count; stepNo++)
- {
- var dataDic = new Dictionary<string, string>();
- foreach (XmlAttribute att in (stepNodeList[stepNo] as XmlElement).Attributes)
- {
- dataDic.Add(att.Name, att.Value);
- }
- //fill sub node's attributes
- foreach (XmlElement subStep in stepNodeList[stepNo].ChildNodes)
- {
- foreach (XmlAttribute att in subStep.Attributes)
- {
- dataDic.Add(att.Name, att.Value);
- }
- foreach (XmlElement subsubStep in subStep.ChildNodes)
- {
- foreach (XmlAttribute att2 in subsubStep.Attributes)
- {
- dataDic.Add(att2.Name, att2.Value);
- }
- }
- }
- long length = dataDic.LongCount();
- worksheet.Cells[0, 3] = new Cell(recipeName);
- for (int rowIndex = 0; rowIndex < excelRowHeaderName.Count; rowIndex++)
- {
- worksheet.Cells.ColumnWidth[(ushort)(rowIndex + 1)] = 4000;
- string cellValueString = dataDic[excelRowHeaderName[rowIndex]];
- double cellValue;
- if (double.TryParse(cellValueString, out cellValue))
- {
- worksheet.Cells[rowIndex + 1, stepNo + 3] = new Cell(cellValue);
- }
- else
- {
- worksheet.Cells[rowIndex + 1, stepNo + 3] = new Cell(cellValueString);
- }
- }
- }
- workbook.Worksheets.Add(worksheet);
- workbook.Save(fileName);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeExportExcelOk"].ToString(), recipeName, fileName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Information);
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeExportExcelFailed"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- });
- }
- private void ButtonNew(object sender, RoutedEventArgs e)
- {
- if (MenuPermission != 3) return;
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- }
- var focus = rcp.SelectedItem;
- string folder = "";
- if (focus is TreeViewFileItem file)
- {
- var name = file.FileName;
- if (name.Contains("\\"))
- folder = name.Substring(0, name.LastIndexOf('\\'));
- }
- else if (focus is TreeViewFolderItem folderItem)
- {
- folder = folderItem.FolderName;
- }
- PerformCreateRecipe(folder);
- }
- private void ButtonRename(object sender, RoutedEventArgs e)
- {
- if (MenuPermission != 3) return;
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- }
- var focus = rcp.SelectedItem;
- if (focus is TreeViewFileItem file)
- {
- var name = file.FileName;
- PerformRenameRecipe(file.FileName);
- }
- else if (focus is TreeViewFolderItem folderItem)
- {
- PerformRenameFolder(folderItem.FolderName);
- }
- }
- private void ButtonDelete(object sender, RoutedEventArgs e)
- {
- if (MenuPermission != 3) return;
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- }
- var focus = rcp.SelectedItem;
- if (focus is TreeViewFileItem file)
- {
- var name = file.FileName;
- PerformDeleteRecipe(file.FileName);
- }
- else if (focus is TreeViewFolderItem folderItem)
- {
- PerformDeleteFolder(folderItem.FolderName);
- }
- }
- private void PerformCreateRecipe(string folderName)
- {
- try
- {
- RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
- {
- Owner = Application.Current.MainWindow
- };
- if (dlg.ShowDialog() == true)
- {
- var recipeName = folderName + "\\" + dlg.InputText;
- string rcpType = "";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcpType = "Clean";
- }
- if (!this._viewModel.SaveAsRecipe(recipeName, rcpType, this._viewModel.RecipeTemplate))
- {
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateFailed"].ToString(), recipeName), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- else
- {
- UpdateRecipeFileList();
- UpdateProcessRecipeFileList();
- UpdateCleanRecipeFileList();
- SelectRecipe(folderName + "\\" + dlg.InputText);
- }
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- private void TreeViewRcpList_DragEnter(object sender, DragEventArgs e)
- {
- try
- {
- if (GetAncestor<TreeViewFileItem>((DependencyObject)e.Source) != null)
- {
- if (GetAncestor<TreeViewFileItem>((DependencyObject)e.Source) == GetAncestor<TreeViewFileItem>((DependencyObject)OriginalItem)
- || VisualTreeHelper.GetParent(GetAncestor<TreeViewFileItem>((DependencyObject)e.Source)) == VisualTreeHelper.GetParent(GetAncestor<TreeViewFileItem>((DependencyObject)OriginalItem)))
- e.Effects = DragDropEffects.None;
- }
- else if (GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source) != null)
- {
- if (GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source) == GetAncestor<TreeViewFolderItem>((DependencyObject)OriginalItem))
- e.Effects = DragDropEffects.None;
- }
- else if (e.Source is TreeView)
- {
- e.Effects = DragDropEffects.None;
- }
- e.Handled = true;
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- }
- private void TreeViewRcpList_Drop(object sender, DragEventArgs e)
- {
- try
- {
- string rcpType = "";
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- rcpType = "Process";
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- rcpType = "Clean";
- }
- TreeViewItem itemRemoved = rcp.SelectedItem as TreeViewItem;
- #region
- //foreach (TreeViewItem item in treeViewProcessRcpList.Items)
- //{
- // if (itemRemoved.Equals(item))
- // {
- // treeViewProcessRcpList.Items.Remove(itemRemoved);
- // break;
- // }
- // if (item.Items.Count > 0)
- // {
- // foreach (TreeViewItem subItem in item.Items)
- // {
- // if (itemRemoved.Equals(subItem))
- // {
- // item.Items.Remove(itemRemoved);
- // break;
- // }
- // }
- // }
- //}
- //(getTreeViewFolderItem as TreeViewFolderItem).Items.Add(itemRemoved);
- #endregion
- if (GetAncestor<TreeViewFileItem>((DependencyObject)e.Source) != null)
- {
- if (GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source) != null)
- {
- TreeViewFolderItem getTreeViewFolderItem = GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source);
- tragetFilePath = getTreeViewFolderItem.FolderName;
- GetAncestor<TreeView>(getTreeViewFolderItem);
- _viewModel.MoveRecipeFile(((TreeViewFileItem)itemRemoved).FileName, rcpType, tragetFilePath);
- }
- else
- {
- tragetFilePath = "";
- GetAncestor<TreeView>((DependencyObject)e.Source);
- _viewModel.MoveRecipeFile(((TreeViewFileItem)itemRemoved).FileName, rcpType, tragetFilePath);
- }
- }
- else if (GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source) != null)
- {
- TreeViewFolderItem getTreeViewFolderItem = GetAncestor<TreeViewFolderItem>((DependencyObject)e.Source);
- tragetFilePath = getTreeViewFolderItem.FolderName;
- GetAncestor<TreeView>(getTreeViewFolderItem);
- _viewModel.MoveRecipeFile(((TreeViewFileItem)itemRemoved).FileName, rcpType, tragetFilePath);
- }
- UpdateRecipeFileList();
- UpdateProcessRecipeFileList();
- UpdateCleanRecipeFileList();
- SelectRecipe(tragetFilePath + "\\" + System.IO.Path.GetFileNameWithoutExtension(((TreeViewFileItem)itemRemoved).FileName));
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- }
- private void TreeViewRcpList_MouseDown(object sender, MouseButtonEventArgs e)
- {
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- }
- if (e.ChangedButton == MouseButton.Left)
- {
- _lastMouseDown = e.GetPosition(rcp);
- }
- }
- private void TreeViewRcpList_MouseMove(object sender, MouseEventArgs e)
- {
- try
- {
- var rcp = treeViewRcpList;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewProcessRcpList;
- }
- else if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Clean Content:")
- {
- rcp = treeViewCleanRcpList;
- }
- if (e.LeftButton == MouseButtonState.Pressed)
- {
- Point currentPosition = e.GetPosition(rcp);
- OriginalItem = e.OriginalSource;
- if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 2.0) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 2.0))
- {
- if ((treeViewProcessRcpList.SelectedItem as TreeViewItem) != null)
- {
- //DragDropEffects finalDropEffect = DragDrop.DoDragDrop(treeViewProcessRcpList, treeViewProcessRcpList.SelectedItem, DragDropEffects.Move);
- DragDropEffects finalDropEffect = DragDrop.DoDragDrop(treeViewProcessRcpList.SelectedItem as TreeViewItem, sender, DragDropEffects.Move);
- }
- }
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- }
- /// <summary>
- /// 子页面获取父类窗体
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="reference"></param>
- /// <returns></returns>
- public T GetAncestor<T>(DependencyObject reference) where T : DependencyObject
- {
- DependencyObject parent = VisualTreeHelper.GetParent(reference);
- while (!(parent is T) && parent != null)
- {
- parent = VisualTreeHelper.GetParent(parent);
- if (parent is TreeViewFolderItem)
- tragetFilePath = tragetFilePath.Insert(0, $"{((TreeViewFolderItem)parent).FolderName}\\");
- }
- if (parent != null)
- return (T)parent;
- else
- return null;
- }//在子页面中调用GetAncestor<MainWindow>(this);
- }
- }
|