1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252 |
- 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();
- UpdateRecipeFileListClean();
- 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 = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- 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 = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- 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 = treeViewRcpListClean;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- }
- 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 = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- 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 = treeViewRcpListClean;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- }
- 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("Process"));
-
- treeViewRcpList.Items.Clear();
- CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
- }
- private void UpdateRecipeFileListClean()
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(_viewModel.GetXmlRecipeList("Clean"));
- treeViewRcpListClean.Items.Clear();
- CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpListClean);
- }
- 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 = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- if (_viewModel.SaveAsRecipe(newName,rcpType, _viewModel.LoadRecipe(oldName,rcpType)))
- {
- UpdateRecipeFileList();
- UpdateRecipeFileListClean();
- 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;
- var rcp = treeViewRcpListClean;
- string rcpType = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- rcpType = "Process";
- }
- 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);
- UpdateRecipeFileListClean();
- UpdateRecipeFileList();
- 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
- {
- var rcp = treeViewRcpListClean;
- string rcpType = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- rcpType = "Process";
- }
- 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();
- UpdateRecipeFileListClean();
- 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 = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- 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();
- UpdateRecipeFileListClean();
- }
- }
- }
- 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 = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- 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();
- UpdateRecipeFileListClean();
- 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 = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- this._viewModel.DeleteRecipe(origin,rcpType);
- this.UpdateRecipeFileList();
- UpdateRecipeFileListClean();
- }
- }
- 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);
- var rcp = treeViewRcpListClean;
- string rcpType = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- rcpType = "Process";
- }
- 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();
- UpdateRecipeFileListClean();
- 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 = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- 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 = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- 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 = treeViewRcpListClean;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- }
- 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 = treeViewRcpListClean;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- }
- 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 = treeViewRcpListClean;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- }
- 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 = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcpType = "Process";
- }
- 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();
- UpdateRecipeFileListClean();
- 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
- {
- var rcp = treeViewRcpListClean;
- string rcpType = "Clean";
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- rcpType = "Process";
- }
- TreeViewItem itemRemoved = rcp.SelectedItem as TreeViewItem;
- #region
- //foreach (TreeViewItem item in treeViewRcpList.Items)
- //{
- // if (itemRemoved.Equals(item))
- // {
- // treeViewRcpList.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();
- UpdateRecipeFileListClean();
- 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 = treeViewRcpListClean;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- }
- if (e.ChangedButton == MouseButton.Left)
- {
- _lastMouseDown = e.GetPosition(rcp);
- }
- }
- private void TreeViewRcpList_MouseMove(object sender, MouseEventArgs e)
- {
- try
- {
- var rcp = treeViewRcpListClean;
- if (Rcptype.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:Process Content:")
- {
- rcp = treeViewRcpList;
- }
- 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 ((treeViewRcpList.SelectedItem as TreeViewItem) != null)
- {
- //DragDropEffects finalDropEffect = DragDrop.DoDragDrop(treeViewRcpList, treeViewRcpList.SelectedItem, DragDropEffects.Move);
- DragDropEffects finalDropEffect = DragDrop.DoDragDrop(treeViewRcpList.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);
- }
- }
|