|
@@ -4,6 +4,7 @@ using Aitex.UI.RecipeEditor;
|
|
|
using Aitex.UI.RecipeEditor.View;
|
|
|
using Prism.Commands;
|
|
|
using Prism.Mvvm;
|
|
|
+using Prism.Regions;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -36,6 +37,8 @@ namespace Venus_MainPages.ViewModels
|
|
|
|
|
|
private Recipe m_currentRecipe;
|
|
|
private string m_recipeType;
|
|
|
+ private bool firstLoad=true;
|
|
|
+
|
|
|
|
|
|
#endregion
|
|
|
|
|
@@ -96,12 +99,21 @@ namespace Venus_MainPages.ViewModels
|
|
|
private DelegateCommand _AddStepCommand;
|
|
|
public DelegateCommand AddStepCommand =>
|
|
|
_AddStepCommand ?? (_AddStepCommand = new DelegateCommand(OnAddStep));
|
|
|
+
|
|
|
+ private DelegateCommand _DeleteStepCommand;
|
|
|
+ public DelegateCommand DeleteStepCommand =>
|
|
|
+ _DeleteStepCommand ?? (_DeleteStepCommand = new DelegateCommand(OnDeleteStep));
|
|
|
+
|
|
|
+ //private DelegateCommand _ReLoadCommand;
|
|
|
+ //public DelegateCommand ReLoadCommand =>
|
|
|
+ // _ReLoadCommand ?? (_ReLoadCommand = new DelegateCommand(OnReLoad));
|
|
|
#endregion
|
|
|
|
|
|
#region 构造函数
|
|
|
public RecipeViewModel()
|
|
|
{
|
|
|
Title = "配方管理";
|
|
|
+
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
@@ -120,8 +132,16 @@ namespace Venus_MainPages.ViewModels
|
|
|
}
|
|
|
|
|
|
private void OnAddStep()
|
|
|
- {
|
|
|
-
|
|
|
+ {
|
|
|
+ this.tableRecipeGrid.ControlViewModel.OnAddStep();
|
|
|
+ }
|
|
|
+ private void OnDeleteStep()
|
|
|
+ {
|
|
|
+ this.tableRecipeGrid.ControlViewModel.OnDeleteStep();
|
|
|
+ }
|
|
|
+ private void OnReLoad()
|
|
|
+ {
|
|
|
+ this.tableRecipeGrid.ControlViewModel.LoadRecipe(CurrentRecipe);
|
|
|
}
|
|
|
private void OnSaveRecipe()
|
|
|
{
|
|
@@ -129,11 +149,16 @@ namespace Venus_MainPages.ViewModels
|
|
|
}
|
|
|
private void OnLoaded(Object myrecipeView)
|
|
|
{
|
|
|
- recipeView = myrecipeView as RecipeView;
|
|
|
- treeViewRcpList = recipeView.treeViewRcpList;
|
|
|
- tableRecipeGrid = recipeView.tableRecipeGrid;
|
|
|
- UpdateRecipeFileList();
|
|
|
- treeViewRcpList.SelectedItemChanged += TreeViewRcpList_SelectedItemChanged;
|
|
|
+ if (firstLoad == true)
|
|
|
+ {
|
|
|
+ firstLoad = false;
|
|
|
+ recipeView = myrecipeView as RecipeView;
|
|
|
+ treeViewRcpList = recipeView.treeViewRcpList;
|
|
|
+ tableRecipeGrid = recipeView.tableRecipeGrid;
|
|
|
+ UpdateRecipeFileList();
|
|
|
+
|
|
|
+ treeViewRcpList.SelectedItemChanged += TreeViewRcpList_SelectedItemChanged;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void TreeViewRcpList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
|
@@ -144,8 +169,13 @@ namespace Venus_MainPages.ViewModels
|
|
|
try
|
|
|
{
|
|
|
CurrentRecipeName = selectedItem.FileName;
|
|
|
- string xmlRecipeData = m_uiRecipeManager.LoadRecipe(m_chamId,selectedItem.FileName);
|
|
|
- CurrentRecipe= Recipe.Load(xmlRecipeData);
|
|
|
+ string xmlRecipeData = m_uiRecipeManager.LoadRecipe(m_chamId, selectedItem.FileName);
|
|
|
+ if (xmlRecipeData == "")
|
|
|
+ {
|
|
|
+ treeViewRcpList.Items.Remove(selectedItem);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CurrentRecipe = Recipe.Load(xmlRecipeData);
|
|
|
this.tableRecipeGrid.ControlViewModel.LoadRecipe(CurrentRecipe);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -204,7 +234,7 @@ namespace Venus_MainPages.ViewModels
|
|
|
menuItem.Header = Application.Current.Resources["GlobalLableMenuImportRecipe"];
|
|
|
treeViewRcpList.ContextMenu.Items.Add(menuItem);
|
|
|
|
|
|
- treeViewRcpList.ContextMenu.Items.Add(new Separator());
|
|
|
+ treeViewRcpList.ContextMenu.Items.Add(new Separator());
|
|
|
|
|
|
menuItem = new MenuItem();
|
|
|
menuItem.Tag = "\\";
|
|
@@ -239,15 +269,16 @@ namespace Venus_MainPages.ViewModels
|
|
|
{
|
|
|
var recipeName = folderName + "\\" + dlg.InputText;
|
|
|
RecipeType type = (RecipeType)Enum.Parse(typeof(RecipeType), dlg.SelectedType);
|
|
|
- string newRecipe =RecipeUnity.CreateRecipe(type);
|
|
|
+ string newRecipe =RecipeUnity.CreateRecipe(type, dlg.InputText);
|
|
|
|
|
|
//string recipeContent = m_uiRecipeManager.GetRecipeTemplate(m_chamId);
|
|
|
|
|
|
//m_uiRecipeManager.SaveAsRecipe(m_chamId, recipeName, m_uiRecipeManager.LoadRecipe("system",folderName));
|
|
|
if (SaveAsRecipe(recipeName, newRecipe))
|
|
|
{
|
|
|
- UpdateRecipeFileList();
|
|
|
+ //UpdateRecipeFileList();
|
|
|
//SelectRecipe(recipeName);
|
|
|
+ treeViewRcpList.Items.Add(new TreeViewFileItem(dlg.InputText));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -312,7 +343,7 @@ namespace Venus_MainPages.ViewModels
|
|
|
fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
|
|
|
TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
|
|
|
item.Tag = ele.Attributes["Name"].Value;
|
|
|
- item.ToolTip = fileName;
|
|
|
+ //item.ToolTip = fileName;
|
|
|
itemsControl.Items.Add(item);
|
|
|
}
|
|
|
else if (ele.Name == "Folder")
|
|
@@ -328,51 +359,51 @@ namespace Venus_MainPages.ViewModels
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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];
|
|
|
- selectRecipe(treeViewRcpList, 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;
|
|
|
- }
|
|
|
+ //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];
|
|
|
+ // selectRecipe(treeViewRcpList, 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;
|
|
|
+ //}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|