RecipeTableSelectDialogViewModel.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 (SelectedIndex < 0)
  59. {
  60. DialogBox.ShowWarning("No table is selected");
  61. return;
  62. }
  63. if (!DialogBox.Confirm("Clear this table?"))
  64. return;
  65. // SelectedTable.Name = "";
  66. SelectedTable.EndStatus = "";
  67. if (SelectedTable.TableData.Steps.Count > 0)
  68. {
  69. if (SelectedIndex == 0)
  70. {
  71. if (SelectedTable.TableData.Steps.Count < 2)
  72. {
  73. DialogBox.ShowInfo("Table1 have one step at least");
  74. return;
  75. }
  76. var step = SelectedTable.TableData.Steps.First();
  77. if (step != null)
  78. {
  79. SelectedTable.TableData.Steps.Clear();
  80. SelectedTable.TableData.Steps.Add(step);
  81. }
  82. }
  83. else SelectedTable.TableData.Steps.Clear();
  84. }
  85. }
  86. public void NotSelect()
  87. {
  88. SelectedIndex = -1;
  89. }
  90. public void CancelCmd()
  91. {
  92. ((Window)GetView()).DialogResult = false;
  93. }
  94. public void SaveCmd()
  95. {
  96. if (SelectedIndex < 0)
  97. {
  98. Recipe.TableIndex = -1;
  99. Recipe.Steps = null;
  100. }
  101. else
  102. {
  103. //table名不能重复
  104. for (int i = 0; i < Recipe.Tables.Count; i++)
  105. {
  106. if (Recipe.Tables[i].TableData?.Steps?.Count > 0)
  107. {
  108. var tablename = Recipe.Tables[i].Name.Trim();
  109. for (int j = i + 1; j < Recipe.Tables.Count; j++)
  110. {
  111. if (Recipe.Tables[j].TableData?.Steps?.Count > 0)
  112. {
  113. if (tablename == Recipe.Tables[j].Name.Trim())
  114. {
  115. DialogBox.ShowError($"Table{i + 1} and Table{j + 1} couldn't have same table name [{tablename}]");
  116. return;
  117. }
  118. }
  119. }
  120. }
  121. }
  122. Recipe.TableIndex = SelectedTable.Index;
  123. Recipe.Steps.Clear();
  124. SelectedTable.TableData.Steps.ToList().ForEach(x =>
  125. {
  126. var tempStep = (Step)CloneUtil.CloneObject(x);
  127. tempStep.StepNo = x.StepNo;
  128. Recipe.Steps.Add(tempStep);
  129. });
  130. }
  131. ((Window)GetView()).DialogResult = true;
  132. }
  133. }
  134. }