RecipeEditManager.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using Aitex.Core.RT.ConfigCenter;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.OperationCenter;
  4. using Aitex.Core.Util;
  5. using MECF.Framework.Common.CommonData;
  6. using MECF.Framework.Common.DBCore;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace MECF.Framework.Common.RecipeCenter
  13. {
  14. public class RecipeEditManager : Singleton<RecipeEditManager>
  15. {
  16. public string CurrentRecipeName { get; set; }
  17. public int CurrentStepID { get; set; }
  18. public string CurrentStepName { get; set; }
  19. public bool IsEnablePrevious { get; set; }
  20. public bool IsEnableNext { get; set; }
  21. public List<Tuple<string, int>> StepNames { get; set; }
  22. public void Initialize()
  23. {
  24. DATA.Subscribe("RecipeEdit", "CurrentRecipeName", () => CurrentRecipeName);
  25. DATA.Subscribe("RecipeEdit", "CurrentStepName", () => CurrentStepName);
  26. DATA.Subscribe("RecipeEdit", "CurrentStepID", () => CurrentStepID);
  27. DATA.Subscribe("RecipeEdit", "IsEnablePrevious", () => IsEnablePrevious);
  28. DATA.Subscribe("RecipeEdit", "IsEnableNext", () => IsEnableNext);
  29. DATA.Subscribe("RecipeEdit", "StepNames", () => StepNames);
  30. OP.Subscribe("SetCurrentRecipeName", SetCurrentRecipeName);
  31. OP.Subscribe("SetCurrentStepName", SetCurrentStepName);
  32. OP.Subscribe("SetRecipeSteps", SetRecipeSteps);
  33. OP.Subscribe("SetPreviousStep", SetPreviousStep);
  34. OP.Subscribe("SetNextStep", SetNextStep);
  35. OP.Subscribe("SetRecipeEditHistory", SetRecipeEditHistory);
  36. }
  37. private bool SetRecipeEditHistory(string arg1, object[] arg2)
  38. {
  39. if (arg2 != null && arg2.Count() > 0)
  40. {
  41. var recipeHistory = (RecipeHistory)arg2[0];
  42. RecipeEditHistoryRecorder.SaveRecipeHistory(recipeHistory);
  43. }
  44. return true;
  45. }
  46. private bool SetCurrentRecipeName(string arg1, object[] arg2)
  47. {
  48. if (arg2 != null && arg2.Count() > 0)
  49. {
  50. CurrentRecipeName = (string)arg2[0];
  51. }
  52. return true;
  53. }
  54. private bool SetCurrentStepName(string arg1, object[] arg2)
  55. {
  56. if (arg2 != null && arg2.Count() > 0)
  57. {
  58. var arg = arg2[0] as Tuple<string, int>;
  59. CurrentStepName = arg.Item1;
  60. CurrentStepID = arg.Item2;
  61. if (StepNames != null && StepNames.Count > 0)
  62. {
  63. if (StepNames.Count < 2)
  64. {
  65. IsEnablePrevious = false;
  66. IsEnableNext = false;
  67. }
  68. else if (StepNames[0].Item2 >= CurrentStepID)
  69. {
  70. IsEnablePrevious = false;
  71. IsEnableNext = true;
  72. }
  73. else if (StepNames[StepNames.Count - 1].Item2 <= CurrentStepID)
  74. {
  75. IsEnablePrevious = true;
  76. IsEnableNext = false;
  77. }
  78. else
  79. {
  80. IsEnablePrevious = true;
  81. IsEnableNext = true;
  82. }
  83. }
  84. }
  85. return true;
  86. }
  87. private bool SetRecipeSteps(string arg1, object[] arg2)
  88. {
  89. if (arg2 != null && arg2.Count() > 0)
  90. {
  91. StepNames = (List<Tuple<string, int>>)arg2[0];
  92. if (StepNames == null || StepNames.Count < 2)
  93. {
  94. IsEnablePrevious = false;
  95. IsEnableNext = false;
  96. }
  97. else
  98. {
  99. IsEnablePrevious = false;
  100. IsEnableNext = true;
  101. }
  102. }
  103. return true;
  104. }
  105. private bool SetPreviousStep(string arg1, object[] arg2)
  106. {
  107. if (StepNames == null && StepNames.Count < 2)
  108. {
  109. IsEnablePrevious = false;
  110. IsEnableNext = false;
  111. }
  112. else
  113. {
  114. int temp = CurrentStepID - 1;
  115. while (temp > -1)
  116. {
  117. Tuple<string, int> tuple = StepNames.Where(x => x.Item2 == temp).FirstOrDefault();
  118. if (tuple != null)
  119. {
  120. CurrentStepName = tuple.Item1;
  121. CurrentStepID = tuple.Item2;
  122. if (temp == 0)
  123. {
  124. IsEnablePrevious = false;
  125. }
  126. else
  127. {
  128. IsEnablePrevious = true;
  129. IsEnableNext = true;
  130. }
  131. break;
  132. }
  133. temp--;
  134. }
  135. }
  136. return true;
  137. }
  138. private bool SetNextStep(string arg1, object[] arg2)
  139. {
  140. if (StepNames == null && StepNames.Count < 2)
  141. {
  142. IsEnablePrevious = false;
  143. IsEnableNext = false;
  144. }
  145. else
  146. {
  147. int temp = CurrentStepID + 1;
  148. while (temp < StepNames.Count)
  149. {
  150. Tuple<string, int> tuple = StepNames.Where(x => x.Item2 == temp).FirstOrDefault();
  151. if (tuple != null)
  152. {
  153. CurrentStepName = tuple.Item1;
  154. CurrentStepID = tuple.Item2;
  155. if (temp == StepNames.Count)
  156. {
  157. IsEnableNext = false;
  158. }
  159. else
  160. {
  161. IsEnablePrevious = true;
  162. IsEnableNext = true;
  163. }
  164. break;
  165. }
  166. temp++;
  167. }
  168. }
  169. return true;
  170. }
  171. }
  172. }