RecipeHistoryViewModel.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using Caliburn.Micro;
  2. using Caliburn.Micro.Core;
  3. using FurnaceUI.Controls.Common;
  4. using FurnaceUI.Views.Editors;
  5. using MECF.Framework.Common.CommonData;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.OperationCenter;
  8. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  9. using MECF.Framework.UI.Client.ClientBase;
  10. using OpenSEMI.ClientBase;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.Linq;
  14. using System.Windows;
  15. using System.Windows.Input;
  16. namespace FurnaceUI.Views.Recipes
  17. {
  18. public class RecipeHistoryViewModel : ModuleUiViewModelBase
  19. {
  20. public List<RecipeHistory> RecipeHistories;
  21. private RecipeProvider _recipeProvider = new RecipeProvider();
  22. public ObservableCollection<ShowRecipeHistory> ObservableRecipeHistory { get; set; } = new ObservableCollection<ShowRecipeHistory>();
  23. public ShowRecipeHistory SelectedItemShowRecipeHistory { get; set; }
  24. public string FilePath { get; set; } = "";
  25. public RecipeDataBase CurrentRecipe { get; set; }
  26. public RecipeHistoryViewModel()
  27. {
  28. }
  29. protected override void OnViewLoaded(object view)
  30. {
  31. base.OnViewLoaded(view);
  32. GetRecipeHistoryByDB(FilePath, 20);
  33. ShowRecipeHistory();
  34. }
  35. private void GetRecipeHistoryByDB(string RecipePath, int row = 20)
  36. {
  37. RecipeHistories = QueryDataClient.Instance.Service.QueryByRecipePathHistory(RecipePath, row);
  38. }
  39. private void ShowRecipeHistory()
  40. {
  41. ObservableRecipeHistory.Clear();
  42. if (RecipeHistories != null && RecipeHistories.Count > 0)
  43. {
  44. RecipeHistories.OrderByDescending(x => x.LastRevisionTime).ToList().ForEach(x =>
  45. {
  46. ObservableRecipeHistory.Add(new ShowRecipeHistory(x));
  47. });
  48. }
  49. }
  50. public void RecipeViewClick()
  51. {
  52. if (SelectedItemShowRecipeHistory != null)
  53. {
  54. CGlobal.RecipeProcessEditViewEnable = false;
  55. MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = false;
  56. var wm = IoC.Get<IWindowManager>();
  57. //var viewProcessRecipe = new RecipeProcessEditViewModel(SelectedItemShowRecipeHistory);
  58. //viewProcessRecipe.RecipeType = "process";
  59. //(wm as WindowManager)?.ShowDialogWithTitle(viewProcessRecipe, null, "View Process Recpie");
  60. //CGlobal.RecipeProcessEditViewEnable = true;
  61. //MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = true;
  62. }
  63. }
  64. RelayCommand _recipeCompareCommand;
  65. public ICommand RecipeCompareCommand
  66. {
  67. get
  68. {
  69. if (_recipeCompareCommand == null)
  70. {
  71. _recipeCompareCommand = new RelayCommand(param => this.RecipeCompareClick(), param => this.CanRecipeCompareClick());
  72. }
  73. return _recipeCompareCommand;
  74. }
  75. }
  76. private bool CanRecipeCompareClick()
  77. {
  78. bool isEnable = false;
  79. if (ObservableRecipeHistory != null)
  80. {
  81. int count = ObservableRecipeHistory.Count(p => p.IsSelected == true);
  82. if (0 < count && count <= 2)
  83. {
  84. isEnable = true;
  85. }
  86. }
  87. return isEnable;
  88. }
  89. private void RecipeCompareClick()
  90. {
  91. if (ObservableRecipeHistory != null)
  92. {
  93. var selectedItems = ObservableRecipeHistory.Where(p => p.IsSelected == true).ToList();
  94. var wm = IoC.Get<IWindowManager>();
  95. ShowRecipeHistory showRecipeHistoryA = null;
  96. ShowRecipeHistory showRecipeHistoryB = null;
  97. if (selectedItems.Count == 1)
  98. {
  99. showRecipeHistoryA = selectedItems.FirstOrDefault();
  100. showRecipeHistoryB = ObservableRecipeHistory.OrderBy(p => p.LastRevisionTime).LastOrDefault();
  101. }
  102. if (selectedItems.Count == 2)
  103. {
  104. showRecipeHistoryA = selectedItems.LastOrDefault();
  105. showRecipeHistoryB = selectedItems.FirstOrDefault();
  106. }
  107. if (showRecipeHistoryA != null && showRecipeHistoryB != null)
  108. {
  109. var recipesHistoryCompareViewModel = new RecipesCompareTwoViewModel(showRecipeHistoryA, showRecipeHistoryB);
  110. recipesHistoryCompareViewModel.DisplayName = "Compare Recipes History";
  111. IDictionary<string, object> settings = new Dictionary<string, object>() { { "Height", 900 }, { "Width", 1200 }, { "WindowStartupLocation", WindowStartupLocation.CenterScreen }, { "SizeToContent", System.Windows.SizeToContent.Manual } };
  112. (wm as WindowManager)?.ShowDialog(recipesHistoryCompareViewModel, null, settings);
  113. }
  114. }
  115. }
  116. RelayCommand _recipeRollbackClickCommand;
  117. public ICommand RecipeRollbackClickCommand
  118. {
  119. get
  120. {
  121. if (_recipeRollbackClickCommand == null)
  122. {
  123. _recipeRollbackClickCommand = new RelayCommand(param => this.RecipeRollbackClick(), param => this.CanRecipeRollbackClick());
  124. }
  125. return _recipeRollbackClickCommand;
  126. }
  127. }
  128. private bool CanRecipeRollbackClick()
  129. {
  130. bool isEnable = false;
  131. if (ObservableRecipeHistory != null)
  132. {
  133. int count = ObservableRecipeHistory.Count(p => p.IsSelected == true);
  134. if (count == 1)
  135. {
  136. isEnable = true;
  137. }
  138. }
  139. return isEnable;
  140. }
  141. private void RecipeRollbackClick()
  142. {
  143. if (SelectedItemShowRecipeHistory != null)
  144. {
  145. if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} content is changed, do you want to save it?") == DialogButton.Yes)
  146. {
  147. InvokeClient.Instance.Service.DoOperation("SetRecipeEditHistory", this.CurrentRecipe.GetRecipeHistory());
  148. var result = this._recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, SelectedItemShowRecipeHistory.Recipe_Content);
  149. }
  150. }
  151. }
  152. }
  153. }