RecipeTableSelectDialogViewModel.cs 4.8 KB

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