AutoJudgeCtrl.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Tool;
  3. using Core.StlMes.Client.Judge.Commons;
  4. using CoreFS.CA06;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Diagnostics;
  9. using System.Threading;
  10. using System.Windows.Forms;
  11. namespace Core.StlMes.Client.Judge.Controls
  12. {
  13. public partial class AutoJudgeCtrl : UserControl
  14. {
  15. private readonly Dal _d;
  16. private Thread _thread = null;
  17. public Thread Thread
  18. {
  19. get { return _thread; }
  20. set { _thread = value; }
  21. }
  22. private string customInfo;
  23. public string CustomInfo
  24. {
  25. get { return customInfo; }
  26. set { customInfo = value; }
  27. }
  28. private readonly string _userId;
  29. public AutoJudgeCtrl(Control container, OpeBase ob, string userId,string customerInfo)
  30. {
  31. InitializeComponent();
  32. _d = new Dal(ob);
  33. _userId = userId;
  34. customInfo=customerInfo;
  35. container.Controls.Add(this);
  36. this.Dock = DockStyle.Fill;
  37. _thread = new Thread(TaskMethod);
  38. _thread.Start();
  39. timer1.Start();
  40. }
  41. public void Quey()
  42. {
  43. try
  44. {
  45. this.TopLevelControl.Cursor = Cursors.WaitCursor;
  46. DataTable dt = _d.GetTableByXmlId("JdgQcmAutoJudge.get", new object[] { new string[] { customInfo } });
  47. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  48. GridHelper.RefreshAndAutoSize(ultraGrid1);
  49. BindDataTable2(dt.Rows[0]);
  50. GridHelper.RefreshAndAutoSize(ultraGrid2);
  51. foreach (DataRow drAuto in dt.Rows)
  52. {
  53. DataTable dtApply;
  54. string processCode = drAuto["processCode"].ToString();
  55. if (processCode == "A")
  56. {
  57. dtApply = _d.GetTableByXmlId("QcmGpJugdeApplyDAL.QuerySteelMakingP", "", "", "", "",
  58. "", 0, new string[] { }, "0", "", 0, new string[] { }, customInfo);
  59. }
  60. else
  61. {
  62. dtApply = GetTable(processCode);
  63. }
  64. Statistics(processCode, dtApply);
  65. }
  66. }
  67. finally
  68. {
  69. this.TopLevelControl.Cursor = Cursors.Default;
  70. }
  71. }
  72. private void BindDataTable2(DataRow dr)
  73. {
  74. dataTable2.Clear();
  75. DataRow newRow = dataTable2.NewRow();
  76. newRow["opUser"] = dr["opUser"].ToString();
  77. newRow["opTime"] = dr["opTime"].ToString();
  78. newRow["status"] = dr["status"].ToString();
  79. dataTable2.Rows.Add(newRow);
  80. }
  81. public void Save()
  82. {
  83. List<string> list = new List<string>();
  84. foreach (var row in ultraGrid1.Rows)
  85. {
  86. list.Add(JsonHelper.ToJson(row));
  87. }
  88. var result = _d.Set("com.steering.pss.judge.Bll.BllQcmAutoJudge.save", list, _userId);
  89. if (result.ReturnInfo.ToString2() != "")
  90. {
  91. MessageUtil.ShowWarning(result.ReturnInfo.ToString2());
  92. return;
  93. }
  94. MessageUtil.ShowTips("保存成功!");
  95. }
  96. private void TaskMethod()
  97. {
  98. while (_thread.IsAlive)
  99. {
  100. try
  101. {
  102. DataTable dtAuto = _d.GetTableByXmlId("JdgQcmAutoJudge.get", new object[] { new string[] { customInfo } });
  103. if (dtAuto == null)
  104. {
  105. Thread.Sleep(5 * 1000);
  106. continue;
  107. }
  108. foreach (DataRow drAuto in dtAuto.Rows)
  109. {
  110. if (drAuto["isAuto"].ToString() == "True" && drAuto["opUserId"].ToString() != _userId) continue;
  111. if (drAuto["isAuto"].ToString() != "True") continue;
  112. string processCode = drAuto["processCode"].ToString();
  113. if (processCode.Equals("A"))
  114. {
  115. LgJudge(drAuto);
  116. }
  117. else
  118. {
  119. BcJudge(drAuto, processCode);
  120. }
  121. }
  122. int judgeCnt = 0;
  123. foreach (var row in ultraGrid1.Rows)
  124. {
  125. if (row.GetValue("isAuto") == "True")
  126. {
  127. if (row.GetValue("totalCount").TryParseInt() && row.GetValue("failJudgeCount").TryParseInt())
  128. {
  129. judgeCnt += int.Parse(row.GetValue("totalCount")) - int.Parse(row.GetValue("failJudgeCount"));
  130. }
  131. }
  132. }
  133. if (judgeCnt == 0)
  134. {
  135. //懒惰模式
  136. Thread.Sleep(10 * 1000);
  137. Debug.WriteLine("懒惰模式10s");
  138. }
  139. else
  140. {
  141. //积极模式
  142. Thread.Sleep(1000);
  143. Debug.WriteLine("积极模式1s");
  144. }
  145. }
  146. catch (Exception ex)
  147. {
  148. Debug.WriteLine(ex.Message);
  149. Thread.Sleep(5 * 1000);
  150. }
  151. }
  152. }
  153. private void LgJudge(DataRow drAuto)
  154. {
  155. DataTable drLgApply = _d.GetTableByXmlId("QcmGpJugdeApplyDAL.QuerySteelMakingP", "", "", "", "",
  156. "", 0, new string[] { }, "0", "", 0, new string[] { }, customInfo);
  157. Statistics("A", drLgApply);//统计
  158. DataRow[] drApplys = drLgApply.Select("autoJudge = '0' or autoJudge is null");
  159. if (drApplys.Length == 0) return;
  160. DataRow drApply = drApplys[0];
  161. string judgeApplyCode = drApply["jugdeApplyCode"].ToString();
  162. string judgeApplySeq = drApply["jugdeApplySqe"].ToString();
  163. string judgeStoveNo = drApply["judgeStoveNo"].ToString();
  164. string judgeMemo = drApply["judgeMemo"].ToString();
  165. string judgeMemo2 = drApply["judgeMemo2"].ToString();
  166. DataRow drAutoNew2 = _d.GetRowByXmlId("JdgQcmAutoJudge.getById", drAuto["id"].ToString());
  167. if (drAutoNew2["isAuto"].ToString() == "True" && drAutoNew2["opUserId"].ToString() != _userId) return;
  168. if (drAutoNew2["isAuto"].ToString() != "True") return;
  169. if (drApply["autoJudge"].ToString() == "1") return;
  170. //Debug.WriteLine($"{drAuto["processDesc"].ToString()} {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
  171. _d.Set("com.steering.pss.judge.Bll.BllSteelMakingColligateJudge.JudgeSteelMaking", judgeApplyCode,
  172. judgeApplySeq, judgeStoveNo, "SYSTEM", "", "", judgeMemo, judgeMemo2, ((int)JudgeType.SteelMakingColligate).ToString());
  173. _d.Set("com.steering.pss.judge.Bll.BllSteelMakingColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo);
  174. }
  175. private void BcJudge(DataRow drAuto, string processCode)
  176. {
  177. DataTable dtApply = GetTable(processCode);
  178. Statistics(processCode, dtApply);//统计
  179. DataRow[] drApplys = dtApply.Select("autoJudge = '0' or autoJudge is null");
  180. if ("120504" == customInfo)
  181. drApplys = dtApply.Select(" (autoJudge = '0' or autoJudge is null) ");//注释and applyMemo is null
  182. if (drApplys.Length == 0) return;
  183. DataRow drApply = drApplys[0];
  184. string judgeApplyCode = drApply["jugdeApplyCode"].ToString();
  185. string judgeStoveNo = drApply["judgeStoveNo"].ToString();
  186. string batchNo = drApply["batchNo"].ToString();
  187. string memo = drApply["memo"].ToString();
  188. string judgeMemo = drApply["judgeMemo"].ToString();
  189. DataRow drAutoNew2 = _d.GetRowByXmlId("JdgQcmAutoJudge.getById", drAuto["id"].ToString());
  190. if (drAutoNew2["isAuto"].ToString() == "True" && drAutoNew2["opUserId"].ToString() != _userId) return;
  191. if (drAutoNew2["isAuto"].ToString() != "True") return;
  192. if (drApply["autoJudge"].ToString() == "1") return;
  193. DataRow drExistJudge = _d.GetRowByXmlId("QcmZgJugdeApplyDAL.existJudgeQualified", judgeApplyCode,
  194. judgeStoveNo, batchNo, processCode);
  195. if (drExistJudge["ordLnDlyPk"].ToString() == "")
  196. return;
  197. if (drExistJudge["judgeResultCode"].ToString() == "40740701" || drExistJudge["judgeResultCode"].ToString() == "40740706"
  198. || drExistJudge["judgeResultCode"].ToString() == "40740707") //如果已经判定则不判。 AND T.JUDGE_RESULT_CODE IN ('40740701', '40740702')
  199. {
  200. _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo);
  201. return;
  202. }
  203. //验证是否符合取样数量
  204. var sampleCountResult = _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.checkSampleCount",
  205. judgeApplyCode, judgeStoveNo, batchNo, "0");
  206. var sampleCntResultFd = _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.checkSampleCount",
  207. judgeApplyCode, judgeStoveNo, batchNo, "1");
  208. //验证是否复取样,如果复取样则不自动判定
  209. var checkFsample = _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.checkFsample",
  210. judgeApplyCode, judgeStoveNo, batchNo, processCode);
  211. if (sampleCountResult.ReturnObject.ToString2() != "")
  212. {
  213. _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo);
  214. return;
  215. }
  216. else if (processCode == "F" && sampleCntResultFd.ReturnObject.ToString2() != "")
  217. {
  218. _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo);
  219. return;
  220. }
  221. else if (checkFsample.ReturnInfo.ToString2() != "")
  222. {
  223. _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo);
  224. return;
  225. }
  226. else if (sampleCountResult.ReturnInfo.ToString2() != "")
  227. {
  228. _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo);
  229. return;
  230. }
  231. CoreClientParam ccpDetect = _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.checkDetect", judgeApplyCode,
  232. judgeStoveNo, batchNo);
  233. if (ccpDetect.ReturnInfo.ToString2() != "")
  234. {
  235. _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo);
  236. return;
  237. }
  238. else
  239. {
  240. if (ccpDetect.ReturnObject.ToString2() != "")
  241. {
  242. _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo);
  243. return;
  244. }
  245. }
  246. // Debug.WriteLine($"{drAuto["processDesc"].ToString()} {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
  247. _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.judge", judgeApplyCode,
  248. judgeStoveNo, batchNo, processCode, "SYSTEM", "", "", memo, judgeMemo, "1", new List<string>());
  249. _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo);
  250. }
  251. private void Statistics(string processCode, DataTable dtApply)
  252. {
  253. DataRow dr = dataTable1.Select("processCode = '" + processCode + "'")[0];
  254. int failCount = 0;
  255. foreach (DataRow drApply in dtApply.Rows)
  256. {
  257. if (drApply["autoJudge"].ToString() == "1") failCount++;
  258. }
  259. this.BeginInvoke(new Func<string>(delegate ()
  260. {
  261. dr["totalCount"] = dtApply.Rows.Count;
  262. dr["failJudgeCount"] = failCount;
  263. return "";
  264. }));
  265. }
  266. private DataTable GetTable(string processCode)
  267. {
  268. string[] judgeStates = new string[] { "0" };
  269. string judgeCondition = "1";
  270. string timeType = "1";
  271. DataTable dt = _d.GetTableByXmlId("QcmZgJugdeApplyDAL.QueryBcColligate", "", "", judgeStates.Length, judgeStates,
  272. "", "", 0, new string[] { }, processCode, judgeCondition, "", "", timeType, CustomInfo);
  273. return dt;
  274. }
  275. private void UltraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  276. {
  277. e.Cell.Row.Update();
  278. }
  279. private void Timer1_Tick(object sender, EventArgs e)
  280. {
  281. String id = "1";
  282. if (customInfo == "120504")
  283. id = "7";
  284. DataRow drAuto = _d.GetRowByXmlId("JdgQcmAutoJudge.getById", id);
  285. BindDataTable2(drAuto);
  286. if (drAuto["opUserId"].ToString() == _userId)
  287. {
  288. _d.Set("com.steering.pss.judge.Bll.BllQcmAutoJudge.setLastOnlineTime");
  289. }
  290. }
  291. }
  292. }