RecipeTableSelectDialogViewModel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using FurnaceUI.Models;
  2. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  3. using OpenSEMI.ClientBase;
  4. using System.Windows;
  5. using System.Linq;
  6. using MECF.Framework.Common.Utilities;
  7. namespace FurnaceUI.Views.Recipes
  8. {
  9. public class RecipeTableSelectDialogViewModel : FurnaceUIViewModelBase
  10. {
  11. private RecipeTable _copyTable;
  12. public RecipeDataBase Recipe { get; set; }
  13. private int _SelectedIndex;
  14. public int SelectedIndex
  15. {
  16. get { return _SelectedIndex; }
  17. set
  18. {
  19. _SelectedIndex = value;
  20. this.NotifyOfPropertyChange(nameof(SelectedIndex));
  21. this.NotifyOfPropertyChange(nameof(SelectedTable));
  22. }
  23. }
  24. public RecipeTable SelectedTable => (Recipe.Tables.Count > SelectedIndex && SelectedIndex >= 0) ? Recipe.Tables[SelectedIndex] : null;
  25. public bool IsEditEnable { get; set; } = true;
  26. public bool IsAlarmRecipe { get; set; }
  27. protected override void OnInitialize()
  28. {
  29. base.OnInitialize();
  30. SelectedIndex = Recipe.TableIndex - 1;
  31. }
  32. public void Copy()
  33. {
  34. if (!DialogBox.Confirm("Copy this table?"))
  35. return;
  36. _copyTable = SelectedTable;
  37. }
  38. public void Paste()
  39. {
  40. if (!DialogBox.Confirm("Paste the copied table?"))
  41. return;
  42. if (_copyTable != null)
  43. {
  44. var table = Recipe.Tables[SelectedIndex];
  45. table.Name = _copyTable.Name;
  46. table.EndStatus = _copyTable.EndStatus;
  47. table.TableData = (RecipeDataBase)CloneUtil.CloneObject(_copyTable.TableData);
  48. int index = 1;
  49. foreach (var item in table.TableData.Steps)
  50. {
  51. item.StepNo = index;
  52. index++;
  53. }
  54. }
  55. }
  56. public void Clear()
  57. {
  58. if (!DialogBox.Confirm("Clear this table?"))
  59. return;
  60. // SelectedTable.Name = "";
  61. SelectedTable.EndStatus = "";
  62. if (SelectedTable.TableData.Steps.Count > 1)
  63. {
  64. while (SelectedTable.TableData.Steps.Count > 1)
  65. {
  66. SelectedTable.TableData.Steps.RemoveAt(1);
  67. }
  68. }
  69. else
  70. {
  71. SelectedTable.TableData = new RecipeDataBase();
  72. }
  73. }
  74. public void NotSelect()
  75. {
  76. SelectedIndex = -1;
  77. }
  78. public void CancelCmd()
  79. {
  80. ((Window)GetView()).DialogResult = false;
  81. }
  82. public void SaveCmd()
  83. {
  84. if (SelectedIndex < 0)
  85. {
  86. Recipe.TableIndex = -1;
  87. Recipe.Steps = null;
  88. }
  89. else
  90. {
  91. Recipe.TableIndex = SelectedTable.Index;
  92. Recipe.Steps.Clear();
  93. SelectedTable.TableData.Steps.ToList().ForEach(x =>
  94. {
  95. var tempStep = (Step)CloneUtil.CloneObject(x);
  96. tempStep.StepNo = x.StepNo;
  97. Recipe.Steps.Add(tempStep);
  98. });
  99. }
  100. ((Window)GetView()).DialogResult = true;
  101. }
  102. }
  103. }