| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- 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<string> list = new List<string>();
- 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<string>());
- _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<string>(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");
- }
- }
- }
- }
|