123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using Caliburn.Micro;
- using Caliburn.Micro.Core;
- using FurnaceUI.Controls.Common;
- using FurnaceUI.Views.Editors;
- using MECF.Framework.Common.CommonData;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
- using MECF.Framework.UI.Client.ClientBase;
- using OpenSEMI.ClientBase;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Input;
- namespace FurnaceUI.Views.Recipes
- {
- public class RecipeHistoryViewModel : ModuleUiViewModelBase
- {
- public List<RecipeHistory> RecipeHistories;
- private RecipeProvider _recipeProvider = new RecipeProvider();
- public ObservableCollection<ShowRecipeHistory> ObservableRecipeHistory { get; set; } = new ObservableCollection<ShowRecipeHistory>();
- public ShowRecipeHistory SelectedItemShowRecipeHistory { get; set; }
- public string FilePath { get; set; } = "";
- public RecipeDataBase CurrentRecipe { get; set; }
- public RecipeHistoryViewModel()
- {
- }
- protected override void OnViewLoaded(object view)
- {
- base.OnViewLoaded(view);
- GetRecipeHistoryByDB(FilePath, 20);
- ShowRecipeHistory();
- }
- private void GetRecipeHistoryByDB(string RecipePath, int row = 20)
- {
- RecipeHistories = QueryDataClient.Instance.Service.QueryByRecipePathHistory(RecipePath, row);
- }
- private void ShowRecipeHistory()
- {
- ObservableRecipeHistory.Clear();
- if (RecipeHistories != null && RecipeHistories.Count > 0)
- {
- RecipeHistories.OrderByDescending(x => x.LastRevisionTime).ToList().ForEach(x =>
- {
- ObservableRecipeHistory.Add(new ShowRecipeHistory(x));
- });
- }
- }
- public void RecipeViewClick()
- {
- if (SelectedItemShowRecipeHistory != null)
- {
- CGlobal.RecipeProcessEditViewEnable = false;
- MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = false;
- var wm = IoC.Get<IWindowManager>();
- //var viewProcessRecipe = new RecipeProcessEditViewModel(SelectedItemShowRecipeHistory);
- //viewProcessRecipe.RecipeType = "process";
- //(wm as WindowManager)?.ShowDialogWithTitle(viewProcessRecipe, null, "View Process Recpie");
- //CGlobal.RecipeProcessEditViewEnable = true;
- //MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = true;
- }
- }
- RelayCommand _recipeCompareCommand;
- public ICommand RecipeCompareCommand
- {
- get
- {
- if (_recipeCompareCommand == null)
- {
- _recipeCompareCommand = new RelayCommand(param => this.RecipeCompareClick(), param => this.CanRecipeCompareClick());
- }
- return _recipeCompareCommand;
- }
- }
- private bool CanRecipeCompareClick()
- {
- bool isEnable = false;
- if (ObservableRecipeHistory != null)
- {
- int count = ObservableRecipeHistory.Count(p => p.IsSelected == true);
- if (0 < count && count <= 2)
- {
- isEnable = true;
- }
- }
- return isEnable;
- }
- private void RecipeCompareClick()
- {
- if (ObservableRecipeHistory != null)
- {
- var selectedItems = ObservableRecipeHistory.Where(p => p.IsSelected == true).ToList();
- var wm = IoC.Get<IWindowManager>();
- ShowRecipeHistory showRecipeHistoryA = null;
- ShowRecipeHistory showRecipeHistoryB = null;
- if (selectedItems.Count == 1)
- {
- showRecipeHistoryA = selectedItems.FirstOrDefault();
- showRecipeHistoryB = ObservableRecipeHistory.OrderBy(p => p.LastRevisionTime).LastOrDefault();
- }
- if (selectedItems.Count == 2)
- {
- showRecipeHistoryA = selectedItems.LastOrDefault();
- showRecipeHistoryB = selectedItems.FirstOrDefault();
- }
- if (showRecipeHistoryA != null && showRecipeHistoryB != null)
- {
- var recipesHistoryCompareViewModel = new RecipesCompareTwoViewModel(showRecipeHistoryA, showRecipeHistoryB);
- recipesHistoryCompareViewModel.DisplayName = "Compare Recipes History";
- IDictionary<string, object> settings = new Dictionary<string, object>() { { "Height", 900 }, { "Width", 1200 }, { "WindowStartupLocation", WindowStartupLocation.CenterScreen }, { "SizeToContent", System.Windows.SizeToContent.Manual } };
- (wm as WindowManager)?.ShowDialog(recipesHistoryCompareViewModel, null, settings);
- }
- }
- }
- RelayCommand _recipeRollbackClickCommand;
- public ICommand RecipeRollbackClickCommand
- {
- get
- {
- if (_recipeRollbackClickCommand == null)
- {
- _recipeRollbackClickCommand = new RelayCommand(param => this.RecipeRollbackClick(), param => this.CanRecipeRollbackClick());
- }
- return _recipeRollbackClickCommand;
- }
- }
- private bool CanRecipeRollbackClick()
- {
- bool isEnable = false;
- if (ObservableRecipeHistory != null)
- {
- int count = ObservableRecipeHistory.Count(p => p.IsSelected == true);
- if (count == 1)
- {
- isEnable = true;
- }
- }
- return isEnable;
- }
- private void RecipeRollbackClick()
- {
- if (SelectedItemShowRecipeHistory != null)
- {
- if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} content is changed, do you want to save it?") == DialogButton.Yes)
- {
- InvokeClient.Instance.Service.DoOperation("SetRecipeEditHistory", this.CurrentRecipe.GetRecipeHistory());
- var result = this._recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, SelectedItemShowRecipeHistory.Recipe_Content);
- }
- }
- }
- }
- }
|