using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.Judge.Commons; using CoreFS.CA06; using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Threading; using System.Windows.Forms; namespace Core.StlMes.Client.Judge.Controls { public partial class AutoJudgeCtrl : UserControl { private readonly Dal _d; private Thread _thread = null; public Thread Thread { get { return _thread; } set { _thread = value; } } private string customInfo; public string CustomInfo { get { return customInfo; } set { customInfo = value; } } private readonly string _userId; public AutoJudgeCtrl(Control container, OpeBase ob, string userId,string customerInfo) { InitializeComponent(); _d = new Dal(ob); _userId = userId; customInfo=customerInfo; container.Controls.Add(this); this.Dock = DockStyle.Fill; _thread = new Thread(TaskMethod); _thread.Start(); timer1.Start(); } public void Quey() { try { this.TopLevelControl.Cursor = Cursors.WaitCursor; DataTable dt = _d.GetTableByXmlId("JdgQcmAutoJudge.get", new object[] { new string[] { customInfo } }); GridHelper.CopyDataToDatatable(dt, dataTable1, true); GridHelper.RefreshAndAutoSize(ultraGrid1); BindDataTable2(dt.Rows[0]); GridHelper.RefreshAndAutoSize(ultraGrid2); foreach (DataRow drAuto in dt.Rows) { DataTable dtApply; string processCode = drAuto["processCode"].ToString(); if (processCode == "A") { dtApply = _d.GetTableByXmlId("QcmGpJugdeApplyDAL.QuerySteelMakingP", "", "", "", "", "", 0, new string[] { }, "0", "", 0, new string[] { }, customInfo); } else { dtApply = GetTable(processCode); } Statistics(processCode, dtApply); } } finally { this.TopLevelControl.Cursor = Cursors.Default; } } private void BindDataTable2(DataRow dr) { dataTable2.Clear(); DataRow newRow = dataTable2.NewRow(); newRow["opUser"] = dr["opUser"].ToString(); newRow["opTime"] = dr["opTime"].ToString(); newRow["status"] = dr["status"].ToString(); dataTable2.Rows.Add(newRow); } public void Save() { List list = new List(); foreach (var row in ultraGrid1.Rows) { list.Add(JsonHelper.ToJson(row)); } var result = _d.Set("com.steering.pss.judge.Bll.BllQcmAutoJudge.save", list, _userId); if (result.ReturnInfo.ToString2() != "") { MessageUtil.ShowWarning(result.ReturnInfo.ToString2()); return; } MessageUtil.ShowTips("保存成功!"); } private void TaskMethod() { while (_thread.IsAlive) { try { DataTable dtAuto = _d.GetTableByXmlId("JdgQcmAutoJudge.get", new object[] { new string[] { customInfo } }); if (dtAuto == null) { Thread.Sleep(5 * 1000); continue; } foreach (DataRow drAuto in dtAuto.Rows) { if (drAuto["isAuto"].ToString() == "True" && drAuto["opUserId"].ToString() != _userId) continue; if (drAuto["isAuto"].ToString() != "True") continue; string processCode = drAuto["processCode"].ToString(); if (processCode.Equals("A")) { LgJudge(drAuto); } else { BcJudge(drAuto, processCode); } } int judgeCnt = 0; foreach (var row in ultraGrid1.Rows) { if (row.GetValue("isAuto") == "True") { if (row.GetValue("totalCount").TryParseInt() && row.GetValue("failJudgeCount").TryParseInt()) { judgeCnt += int.Parse(row.GetValue("totalCount")) - int.Parse(row.GetValue("failJudgeCount")); } } } if (judgeCnt == 0) { //懒惰模式 Thread.Sleep(10 * 1000); Debug.WriteLine("懒惰模式10s"); } else { //积极模式 Thread.Sleep(1000); Debug.WriteLine("积极模式1s"); } } catch (Exception ex) { Debug.WriteLine(ex.Message); Thread.Sleep(5 * 1000); } } } private void LgJudge(DataRow drAuto) { DataTable drLgApply = _d.GetTableByXmlId("QcmGpJugdeApplyDAL.QuerySteelMakingP", "", "", "", "", "", 0, new string[] { }, "0", "", 0, new string[] { }, customInfo); Statistics("A", drLgApply);//统计 DataRow[] drApplys = drLgApply.Select("autoJudge = '0' or autoJudge is null"); if (drApplys.Length == 0) return; DataRow drApply = drApplys[0]; string judgeApplyCode = drApply["jugdeApplyCode"].ToString(); string judgeApplySeq = drApply["jugdeApplySqe"].ToString(); string judgeStoveNo = drApply["judgeStoveNo"].ToString(); string judgeMemo = drApply["judgeMemo"].ToString(); string judgeMemo2 = drApply["judgeMemo2"].ToString(); DataRow drAutoNew2 = _d.GetRowByXmlId("JdgQcmAutoJudge.getById", drAuto["id"].ToString()); if (drAutoNew2["isAuto"].ToString() == "True" && drAutoNew2["opUserId"].ToString() != _userId) return; if (drAutoNew2["isAuto"].ToString() != "True") return; if (drApply["autoJudge"].ToString() == "1") return; //Debug.WriteLine($"{drAuto["processDesc"].ToString()} {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); _d.Set("com.steering.pss.judge.Bll.BllSteelMakingColligateJudge.JudgeSteelMaking", judgeApplyCode, judgeApplySeq, judgeStoveNo, "SYSTEM", "", "", judgeMemo, judgeMemo2, ((int)JudgeType.SteelMakingColligate).ToString()); _d.Set("com.steering.pss.judge.Bll.BllSteelMakingColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo); } private void BcJudge(DataRow drAuto, string processCode) { DataTable dtApply = GetTable(processCode); Statistics(processCode, dtApply);//统计 DataRow[] drApplys = dtApply.Select("autoJudge = '0' or autoJudge is null"); if ("120504" == customInfo) drApplys = dtApply.Select(" (autoJudge = '0' or autoJudge is null) ");//注释and applyMemo is null if (drApplys.Length == 0) return; DataRow drApply = drApplys[0]; string judgeApplyCode = drApply["jugdeApplyCode"].ToString(); string judgeStoveNo = drApply["judgeStoveNo"].ToString(); string batchNo = drApply["batchNo"].ToString(); string memo = drApply["memo"].ToString(); string judgeMemo = drApply["judgeMemo"].ToString(); DataRow drAutoNew2 = _d.GetRowByXmlId("JdgQcmAutoJudge.getById", drAuto["id"].ToString()); if (drAutoNew2["isAuto"].ToString() == "True" && drAutoNew2["opUserId"].ToString() != _userId) return; if (drAutoNew2["isAuto"].ToString() != "True") return; if (drApply["autoJudge"].ToString() == "1") return; DataRow drExistJudge = _d.GetRowByXmlId("QcmZgJugdeApplyDAL.existJudgeQualified", judgeApplyCode, judgeStoveNo, batchNo, processCode); if (drExistJudge["ordLnDlyPk"].ToString() == "") return; if (drExistJudge["judgeResultCode"].ToString() == "40740701" || drExistJudge["judgeResultCode"].ToString() == "40740706" || drExistJudge["judgeResultCode"].ToString() == "40740707") //如果已经判定则不判。 AND T.JUDGE_RESULT_CODE IN ('40740701', '40740702') { _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo); return; } //验证是否符合取样数量 var sampleCountResult = _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.checkSampleCount", judgeApplyCode, judgeStoveNo, batchNo, "0"); var sampleCntResultFd = _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.checkSampleCount", judgeApplyCode, judgeStoveNo, batchNo, "1"); //验证是否复取样,如果复取样则不自动判定 var checkFsample = _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.checkFsample", judgeApplyCode, judgeStoveNo, batchNo, processCode); if (sampleCountResult.ReturnObject.ToString2() != "") { _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo); return; } else if (processCode == "F" && sampleCntResultFd.ReturnObject.ToString2() != "") { _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo); return; } else if (checkFsample.ReturnInfo.ToString2() != "") { _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo); return; } else if (sampleCountResult.ReturnInfo.ToString2() != "") { _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo); return; } CoreClientParam ccpDetect = _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.checkDetect", judgeApplyCode, judgeStoveNo, batchNo); if (ccpDetect.ReturnInfo.ToString2() != "") { _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo); return; } else { if (ccpDetect.ReturnObject.ToString2() != "") { _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo); return; } } // Debug.WriteLine($"{drAuto["processDesc"].ToString()} {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.judge", judgeApplyCode, judgeStoveNo, batchNo, processCode, "SYSTEM", "", "", memo, judgeMemo, "1", new List()); _d.Set("com.steering.pss.judge.Bll.BllRolledTubeColligateJudge.setAutoJudge", judgeApplyCode, judgeStoveNo, batchNo); } private void Statistics(string processCode, DataTable dtApply) { DataRow dr = dataTable1.Select("processCode = '" + processCode + "'")[0]; int failCount = 0; foreach (DataRow drApply in dtApply.Rows) { if (drApply["autoJudge"].ToString() == "1") failCount++; } this.BeginInvoke(new Func(delegate () { dr["totalCount"] = dtApply.Rows.Count; dr["failJudgeCount"] = failCount; return ""; })); } private DataTable GetTable(string processCode) { string[] judgeStates = new string[] { "0" }; string judgeCondition = "1"; string timeType = "1"; DataTable dt = _d.GetTableByXmlId("QcmZgJugdeApplyDAL.QueryBcColligate", "", "", judgeStates.Length, judgeStates, "", "", 0, new string[] { }, processCode, judgeCondition, "", "", timeType, CustomInfo); return dt; } private void UltraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { e.Cell.Row.Update(); } private void Timer1_Tick(object sender, EventArgs e) { String id = "1"; if (customInfo == "120504") id = "7"; DataRow drAuto = _d.GetRowByXmlId("JdgQcmAutoJudge.getById", id); BindDataTable2(drAuto); if (drAuto["opUserId"].ToString() == _userId) { _d.Set("com.steering.pss.judge.Bll.BllQcmAutoJudge.setLastOnlineTime"); } } } }