ValveInterlockTimeViewModel.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. using Aitex.Core.RT.SCCore;
  2. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  3. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Text.RegularExpressions;
  12. using System.Windows.Media;
  13. using MECF.Framework.UI.Client.ClientBase;
  14. using FurnaceUI.Models;
  15. namespace FurnaceUI.Views.Operations
  16. {
  17. public class ValveInterlockTimeViewModel : FurnaceUIViewModelBase
  18. {
  19. public Dictionary<string, string> RecipeStepTime = new Dictionary<string, string>();
  20. public bool IsSave { get; set; } = false;
  21. private string _selectTime;
  22. public string SelectTime
  23. {
  24. get => _selectTime;
  25. set
  26. {
  27. _selectTime = value;
  28. if (!string.IsNullOrEmpty(value) && !value.Contains(" ") && value.Contains(":"))
  29. {
  30. SelectValueTime = value;
  31. SelectValueTimeM = value.Split(':')[0];
  32. SelectValueTimeS = value.Split(':')[1];
  33. }
  34. else if (!string.IsNullOrEmpty(value) && RecipeStepTime.ContainsKey(value))
  35. {
  36. SelectValueTime = RecipeStepTime[value];
  37. SelectValueTimeM = SelectValueTime.Split(':')[0];
  38. SelectValueTimeS = SelectValueTime.Split(':')[1];
  39. }
  40. }
  41. }
  42. private string _selectValueTime = "00:10.0";
  43. public string SelectValueTime
  44. {
  45. get
  46. {
  47. return _selectValueTime;
  48. }
  49. set
  50. {
  51. _selectValueTime = value;
  52. NotifyOfPropertyChange(SelectValueTime);
  53. }
  54. }
  55. private string _selectValueTimeM = "00";
  56. public string SelectValueTimeM
  57. {
  58. get
  59. {
  60. return _selectValueTimeM;
  61. }
  62. set
  63. {
  64. _selectValueTimeM = value;
  65. NotifyOfPropertyChange(SelectValueTimeM);
  66. }
  67. }
  68. private string _selectValueTimeS = "10";
  69. public string SelectValueTimeS
  70. {
  71. get
  72. {
  73. return _selectValueTimeS;
  74. }
  75. set
  76. {
  77. _selectValueTimeS = value;
  78. NotifyOfPropertyChange(SelectValueTimeS);
  79. }
  80. }
  81. private string _TimeModel;
  82. public string TimeModel { get { return _TimeModel; } set { _TimeModel = value; NotifyOfPropertyChange(nameof(TimeModel)); } }
  83. public string TimeParam { get; set; }
  84. public bool IsEnable => CGlobal.RecipeProcessEditViewEnable;//是否是View模式
  85. private void GetDataOfConfigItems()
  86. {
  87. if (SelectTime != null && SelectTime.Length > 1 && SelectTime.Split(':').Length > 2)
  88. {
  89. SelectValueTimeM = SelectTime.Split(':')[0];
  90. SelectValueTimeS = SelectTime.Split(':')[1];
  91. }
  92. var temp = generate();
  93. foreach (var item in temp)
  94. {
  95. RecipeStepTime[item] = SystemConfigProvider.Instance.GetValueByName($"PM1.RecipeEditParameter.{TimeParam}.{item}");
  96. }
  97. }
  98. public ValveInterlockTimeViewModel(string timeParam)
  99. {
  100. TimeParam = timeParam;
  101. Initialize();
  102. }
  103. protected override void OnInitialize()
  104. {
  105. base.OnInitialize();
  106. InitTime();
  107. }
  108. protected override void OnViewLoaded(object view)
  109. {
  110. GetDataOfConfigItems();
  111. base.OnViewLoaded(view);
  112. foreach (var item in RecipeStepTime.Keys)
  113. {
  114. object Txt = ((ValveInterlockTimeView)(((Window)GetView()).Content)).FindName("Txt" + item);
  115. if (Txt is TextBlock)
  116. {
  117. ((TextBlock)Txt).Text = RecipeStepTime[item];
  118. }
  119. }
  120. }
  121. public void SetValue(object sender, string isFullKeyboard = "")
  122. {
  123. string value = ((TextBox)sender).Text;
  124. if (!string.IsNullOrEmpty(isFullKeyboard))
  125. {
  126. FullKeyboard fullKeyboard1 = new FullKeyboard("", value);
  127. if ((bool)fullKeyboard1.ShowDialog())
  128. {
  129. ((TextBox)sender).Text = fullKeyboard1.ValueString;
  130. }
  131. }
  132. else
  133. {
  134. NumberKeyboard fullKeyboard = new NumberKeyboard("", value);
  135. if ((bool)fullKeyboard.ShowDialog())
  136. {
  137. ((TextBox)sender).Text = fullKeyboard.ValueString;
  138. }
  139. }
  140. }
  141. public void InitTime()
  142. {
  143. if (string.IsNullOrEmpty(SelectValueTime))
  144. {
  145. return;
  146. }
  147. var timeList = SelectValueTime.Split(':').ToList();
  148. var first = timeList[0];
  149. string pattern = "^[0-9]*$";
  150. Regex rex = new Regex(pattern);
  151. if (!rex.IsMatch(first))
  152. {
  153. timeList.Remove(first);
  154. }
  155. SelectValueTimeM = timeList.FirstOrDefault();
  156. SelectValueTimeS = timeList.LastOrDefault();
  157. SetTimeValue("Value");
  158. }
  159. public void Initialize()
  160. {
  161. var temp = generate();
  162. foreach (var item in temp)
  163. {
  164. RecipeStepTime.Add(item, "00:00.0");
  165. }
  166. }
  167. IEnumerable<string> generate()
  168. {
  169. for (char c = 'A'; c <= 'Z'; c++)
  170. yield return new string(c, 1);
  171. }
  172. public void SetTimeValue(string nameCmd)
  173. {
  174. SelectTime = nameCmd;
  175. TimeModel = nameCmd;
  176. if (TimeModel != "Value")
  177. {
  178. object Txt = ((ValveInterlockTimeView)(((Window)GetView()).Content)).FindName("TxtTime");
  179. if (Txt is TextBox)
  180. {
  181. ((TextBox)Txt).Foreground = new SolidColorBrush(Colors.Black);
  182. }
  183. }
  184. }
  185. public void SetTimeCmd(string nameCmd)
  186. {
  187. SelectValueTime = SelectValueTimeM + ":" + SelectValueTimeS;
  188. switch (nameCmd)
  189. {
  190. case "Save":
  191. if (!CheckTimeFormat( SelectValueTimeM, SelectValueTimeS)) return;
  192. IsSave = true;
  193. break;
  194. case "Close":
  195. IsSave = false;
  196. break;
  197. default:
  198. break;
  199. }
  200. ((Window)GetView()).Close();
  201. }
  202. private bool CheckTimeFormat(string strTimeM, string strTimeS)
  203. {
  204. bool bResult = true, bTimeM = true, bTimeS = true;
  205. string pattern = "^[0-9]*$";
  206. Regex rex = new Regex(pattern);
  207. //秒需要设置小数
  208. Regex reg = new Regex(@"^\d+(\.\d+)?$");
  209. object TxtM = ((ValveInterlockTimeView)(((Window)GetView()).Content)).FindName("TxtTimeM");
  210. object TxtS = ((ValveInterlockTimeView)(((Window)GetView()).Content)).FindName("TxtTimeS");
  211. if (!rex.IsMatch(strTimeM)|| double.Parse(strTimeM) > 59)
  212. {
  213. bTimeM = false;
  214. }
  215. if (!bTimeM)
  216. {
  217. if (TxtM is TextBox)((TextBox)TxtM).Foreground = new SolidColorBrush(Colors.Red);
  218. }
  219. else
  220. {
  221. if (TxtM is TextBox) ((TextBox)TxtM).Foreground = new SolidColorBrush(Colors.Black);
  222. }
  223. double value;
  224. if (!double.TryParse(strTimeS, out value))
  225. {
  226. bTimeS = false;
  227. }
  228. //if (Convert.ToDouble(value) < 0)
  229. //{
  230. // bTimeS = false;
  231. //}
  232. if (!reg.IsMatch(strTimeS) || double.Parse(strTimeS) >= 60)
  233. {
  234. bTimeS = false;
  235. }
  236. if (!bTimeS)
  237. {
  238. if (TxtS is TextBox) ((TextBox)TxtS).Foreground = new SolidColorBrush(Colors.Red);
  239. }
  240. else
  241. {
  242. if (TxtS is TextBox) ((TextBox)TxtS).Foreground = new SolidColorBrush(Colors.Black);
  243. }
  244. bResult = bTimeM && bTimeS;
  245. return bResult;
  246. }
  247. }
  248. }