From f802acfd18214d9c745d44544fcb0124e5d119c5 Mon Sep 17 00:00:00 2001 From: gongxh Date: Wed, 19 Jan 2022 13:27:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BA=BF=E7=A8=8BUI=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FrmUserControl/frmMainDetail.cs | 613 +++++++++--------- NX_LogUtility/LogHelper.cs | 51 +- 2 files changed, 340 insertions(+), 324 deletions(-) diff --git a/CleanMachineHMI/FrmUserControl/frmMainDetail.cs b/CleanMachineHMI/FrmUserControl/frmMainDetail.cs index 770a071..82eb2c2 100644 --- a/CleanMachineHMI/FrmUserControl/frmMainDetail.cs +++ b/CleanMachineHMI/FrmUserControl/frmMainDetail.cs @@ -483,103 +483,108 @@ namespace CleanMachineHMI.FrmUserControl /// private void FinishWorkingPallet() { + +#if !DEBUG try { - //满料标识 - bool isFinishWorkingPallet = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("FinishWorkingPallet", PlcItemTypeDesc.M)); - //ToDo: 根据满料的方式,增加相应的满料判断代码 - bool fullPalletMode = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("FullPalletMode", PlcItemTypeDesc.M)); +#endif + //满料标识 + bool isFinishWorkingPallet = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("FinishWorkingPallet", PlcItemTypeDesc.M)); + //ToDo: 根据满料的方式,增加相应的满料判断代码 + bool fullPalletMode = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("FullPalletMode", PlcItemTypeDesc.M)); - int countFullNum = Convert.ToInt32(PlcOperationHelper.Instance.ReadPlcItem("WorkedFullPalletNum", PlcItemTypeDesc.D)); - //是否强制满料 - bool isForceFullPallet = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("ForceFullPallet", PlcItemTypeDesc.M)); + int countFullNum = Convert.ToInt32(PlcOperationHelper.Instance.ReadPlcItem("WorkedFullPalletNum", PlcItemTypeDesc.D)); + //是否强制满料 + bool isForceFullPallet = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("ForceFullPallet", PlcItemTypeDesc.M)); - string sql_CurrPalletmsg = $@"SELECT * FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0"; - DataTable dt_CurrPalletmsg = LeadDbHelperSQLite.Query(sql_CurrPalletmsg).Tables[0]; + string sql_CurrPalletmsg = $@"SELECT * FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0"; + DataTable dt_CurrPalletmsg = LeadDbHelperSQLite.Query(sql_CurrPalletmsg).Tables[0]; - if (fullPalletMode)// 延时满料 + if (fullPalletMode)// 延时满料 + { + //if (dt_CurrPalletmsg != null && dt_CurrPalletmsg.Rows.Count > 0 && isFinishWorkingPallet) + //{ + // string palletCodeMsg = dt_CurrPalletmsg.Rows[0]["WORKING_PALLET_CODE"].ToString(); + // LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,开始处理延时满料业务。", LogTypeEum.Run); + // string sqlWorkingIrMsg = $@"SELECT DISTINCT IR_CODE FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}'"; + + // DataTable dt_workingIrMsg = LeadDbHelperSQLite.Query(sqlWorkingIrMsg).Tables[0]; + // if (dt_workingIrMsg != null && dt_workingIrMsg.Rows.Count > 0) + // { + // PrintPalletData(dt_workingIrMsg, palletCodeMsg); + // LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,延时满料业务处理完成,数据打印完成。", LogTypeEum.Run); + // } + //} + } + else //计数满料 + { + if (dt_CurrPalletmsg != null && dt_CurrPalletmsg.Rows.Count > 0) { - //if (dt_CurrPalletmsg != null && dt_CurrPalletmsg.Rows.Count > 0 && isFinishWorkingPallet) - //{ - // string palletCodeMsg = dt_CurrPalletmsg.Rows[0]["WORKING_PALLET_CODE"].ToString(); - // LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,开始处理延时满料业务。", LogTypeEum.Run); - // string sqlWorkingIrMsg = $@"SELECT DISTINCT IR_CODE FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}'"; - - // DataTable dt_workingIrMsg = LeadDbHelperSQLite.Query(sqlWorkingIrMsg).Tables[0]; - // if (dt_workingIrMsg != null && dt_workingIrMsg.Rows.Count > 0) - // { - // PrintPalletData(dt_workingIrMsg, palletCodeMsg); - // LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,延时满料业务处理完成,数据打印完成。", LogTypeEum.Run); - // } - //} - } - else //计数满料 - { - if (dt_CurrPalletmsg != null && dt_CurrPalletmsg.Rows.Count > 0) + string palletCodeMsg = dt_CurrPalletmsg.Rows[0]["WORKING_PALLET_CODE"].ToString(); + string sqlCurrNumMsg = $@"SELECT ifnull(SUM(CURRENT_NUMBER),0) FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}' and CLEAN_MODE_CODE = 'SortedCleaned'"; + DataTable dt_CurrNumMsg = LeadDbHelperSQLite.Query(sqlCurrNumMsg).Tables[0]; + if (dt_CurrNumMsg != null && dt_CurrNumMsg.Rows.Count > 0) { - string palletCodeMsg = dt_CurrPalletmsg.Rows[0]["WORKING_PALLET_CODE"].ToString(); - string sqlCurrNumMsg = $@"SELECT SUM(CURRENT_NUMBER) FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}' and CLEAN_MODE_CODE = 'SortedCleaned'"; - DataTable dt_CurrNumMsg = LeadDbHelperSQLite.Query(sqlCurrNumMsg).Tables[0]; - if (dt_CurrNumMsg != null && dt_CurrNumMsg.Rows.Count > 0) + //这个值只包含托盘在这个IR下个数量 + int currentNum = Convert.ToInt32(dt_CurrNumMsg.Rows[0][0]); + + currentNum += this.lastPaltteRemain; + + string sqlWorkingIrMsg = $@"SELECT DISTINCT IR_CODE FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}'"; + DataTable dt_workingIrMsg = LeadDbHelperSQLite.Query(sqlWorkingIrMsg).Tables[0]; + if (currentNum >= countFullNum && isFinishWorkingPallet && countFullNum > 0) //正常满料 { - //这个值只包含托盘在这个IR下个数量 - int currentNum = Convert.ToInt32(dt_CurrNumMsg.Rows[0][0]); + LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,开始处理计数满料业务。满料方式:【正常满料】", LogTypeEum.Run); + if (dt_workingIrMsg != null && dt_workingIrMsg.Rows.Count > 0) + PrintPalletData(dt_workingIrMsg.Rows[0][0].ToString(), palletCodeMsg, false); + LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,计数满料业务正常处理完成,数据打印完成。", LogTypeEum.Run); - currentNum += this.lastPaltteRemain; + } + else if (currentNum < countFullNum && isFinishWorkingPallet && isForceFullPallet && countFullNum > 0)//强制满料 + { + LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,开始处理计数满料业务。满料方式:【强制满料】", LogTypeEum.Run); + if (dt_workingIrMsg != null && dt_workingIrMsg.Rows.Count > 0) + PrintPalletData(dt_workingIrMsg.Rows[0][0].ToString(), palletCodeMsg, true); + LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,计数满料业务强制处理完成,数据打印完成。", LogTypeEum.Run); - string sqlWorkingIrMsg = $@"SELECT DISTINCT IR_CODE FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}'"; - DataTable dt_workingIrMsg = LeadDbHelperSQLite.Query(sqlWorkingIrMsg).Tables[0]; - if (currentNum >= countFullNum && isFinishWorkingPallet && countFullNum > 0) //正常满料 - { - LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,开始处理计数满料业务。满料方式:【正常满料】", LogTypeEum.Run); - if (dt_workingIrMsg != null && dt_workingIrMsg.Rows.Count > 0) - PrintPalletData(dt_workingIrMsg.Rows[0][0].ToString(), palletCodeMsg, false); - LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,计数满料业务正常处理完成,数据打印完成。", LogTypeEum.Run); - - } - else if (currentNum < countFullNum && isFinishWorkingPallet && isForceFullPallet && countFullNum > 0)//强制满料 - { - LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,开始处理计数满料业务。满料方式:【强制满料】", LogTypeEum.Run); - if (dt_workingIrMsg != null && dt_workingIrMsg.Rows.Count > 0) - PrintPalletData(dt_workingIrMsg.Rows[0][0].ToString(), palletCodeMsg, true); - LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,计数满料业务强制处理完成,数据打印完成。", LogTypeEum.Run); - - } } } } + } - if (!isFinishWorkingPallet) + if (!isFinishWorkingPallet) + { + + string sql = $@"select * from CM_WORKING_PALLET where WORKING_STATUS = '-1'"; + DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; + if (dt != null && dt.Rows.Count > 0) { - - string sql = $@"select * from CM_WORKING_PALLET where WORKING_STATUS = '-1'"; - DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; - if (dt != null && dt.Rows.Count > 0) + string sql1 = $@"Update CM_WORKING_PALLET set WORKING_STATUS = 0 where WORKING_STATUS = '-1'"; + string sql2 = $@"Update CM_WORKING_PALLET_DTL set WORKING_DTL_STATUS = 0 where WORKING_DTL_STATUS = '-1'"; + LeadDbHelperSQLite.ExecuteSql(sql1); + LeadDbHelperSQLite.ExecuteSql(sql2); + BeginInvoke(new Action(() => { - string sql1 = $@"Update CM_WORKING_PALLET set WORKING_STATUS = 0 where WORKING_STATUS = '-1'"; - string sql2 = $@"Update CM_WORKING_PALLET_DTL set WORKING_DTL_STATUS = 0 where WORKING_DTL_STATUS = '-1'"; - LeadDbHelperSQLite.ExecuteSql(sql1); - LeadDbHelperSQLite.ExecuteSql(sql2); - BeginInvoke(new Action(() => - { - //污染类型操作禁用 - //kryptonGroupBox10.Enabled = false; - kryptonGroupBox2.Enabled = true; - kryptonGroupBox3.Enabled = true; - kryptonGroupBox4.Enabled = true; - kryptonGroupBox5.Enabled = true; - kbtn_Scrap.Enabled = true; - kbtn_Scrap_1.Enabled = true; - kbtn_forceFinish.Enabled = true; + //污染类型操作禁用 + //kryptonGroupBox10.Enabled = false; + kryptonGroupBox2.Enabled = true; + kryptonGroupBox3.Enabled = true; + kryptonGroupBox4.Enabled = true; + kryptonGroupBox5.Enabled = true; + kbtn_Scrap.Enabled = true; + kbtn_Scrap_1.Enabled = true; + kbtn_forceFinish.Enabled = true; - })); - } + })); } } +#if !DEBUG + } catch (Exception ex) { LogHelper.WriteLog($"~~~~~~~~~~~~~~托盘结束发生异常!【{ex.Message}】。~~~~~~~~~~~~~~", LogTypeEum.Run); } +#endif } /// @@ -803,8 +808,7 @@ namespace CleanMachineHMI.FrmUserControl { #region 生成的新的组盘信息,等待计数作业。 string trayCode = GlobalHelper.GetPalletCode(); - string sqlInsertWorkPallet = $@" - INSERT INTO [CM_WORKING_PALLET] ( + string sqlInsertWorkPallet = $@" INSERT INTO [CM_WORKING_PALLET] ( [WORKING_PALLET_CODE], [WORKING_PALLET_DESC], [WORKING_STATUS], @@ -820,10 +824,18 @@ namespace CleanMachineHMI.FrmUserControl '{GlobalHelper.UserInfo.UserId}', '{GlobalHelper.UserInfo.UserId}', '{0}' - ); - "; + );"; LeadDbHelperSQLite.ExecuteSql(sqlInsertWorkPallet); + string SheetTypeCode = ""; + this.Invoke(new Action(() => + + { + + SheetTypeCode = ((ListItem)kcmb_SheetType.SelectedItem).Value; + })); + + foreach (BasCleanTypeMsg item in basCleanTypeMsgList) { string sqlInsertWorkPalletDtl = $@" @@ -853,8 +865,8 @@ namespace CleanMachineHMI.FrmUserControl VALUES ( '{trayCode}', - '{ktb_IR.Text.Trim()}', - '{((ListItem)kcmb_SheetType.SelectedItem).Value}', + '{workingIrMsg}', + '{SheetTypeCode}', (datetime('now','localtime')), '{item.CleanModeCode}', '{item.ContaminationTypeCode}', @@ -873,15 +885,14 @@ namespace CleanMachineHMI.FrmUserControl NULL, NULL, NULL - ); - "; + );"; LeadDbHelperSQLite.ExecuteSql(sqlInsertWorkPalletDtl); } Invoke(new Action(() => { ktb_CurrPalletCode.Text = trayCode; })); - LogHelper.WriteLog($"新增作业托盘:【{trayCode}】数据成功!新增板材:【{((ListItem)kcmb_SheetType.SelectedItem).Value}】,IR条码:【{ktb_IR.Text.Trim()}】的作业明细记录成功!", LogTypeEum.Run); + LogHelper.WriteLog($"新增作业托盘:【{trayCode}】数据成功!新增板材:【{SheetTypeCode}】,IR条码:【{workingIrMsg}】的作业明细记录成功!", LogTypeEum.Run); #endregion Invoke(new Action(() => @@ -3134,248 +3145,254 @@ namespace CleanMachineHMI.FrmUserControl private void kbtn_forceFinish_Click_1(object sender, EventArgs e) { kbtn_forceFinish.Enabled = false; + +#if !DEBUG + try { - if (isManualStatus()) +#endif + if (isManualStatus()) + { + + KryptonMessageBox.Show("The manual operation interface has been opened and is currently in manual mode."); + return; + } + + if (!PlcOperationHelper.Instance.isConn) + { + KryptonMessageBox.Show("The PLC is disconnected and unable to operate the equipment."); + return; + } + + if (ktb_SaveIR.Enabled) + { + KryptonMessageBox.Show("If IR information is not entered, the termination cannot be forced."); + return; + } + DialogResult dr = KryptonMessageBox.Show("Are you sure you want to force the end of the current IR assignment? If you continue to reset the current job information, you will need to enter new IR and sheet information. Please carefully operation!!!", "Prompt", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (dr == DialogResult.Yes) + { + // + string sql = $@"select sum(CURRENT_NUMBER) from VW_WORKING_PALLET_MSG where IR_CODE = '{ktb_IR.Text}'"; + + DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; + if (dt != null && dt.Rows.Count > 0) { - KryptonMessageBox.Show("The manual operation interface has been opened and is currently in manual mode."); - return; - } - - if (!PlcOperationHelper.Instance.isConn) - { - KryptonMessageBox.Show("The PLC is disconnected and unable to operate the equipment."); - return; - } - - if (ktb_SaveIR.Enabled) - { - KryptonMessageBox.Show("If IR information is not entered, the termination cannot be forced."); - return; - } - DialogResult dr = KryptonMessageBox.Show("Are you sure you want to force the end of the current IR assignment? If you continue to reset the current job information, you will need to enter new IR and sheet information. Please carefully operation!!!", "Prompt", MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (dr == DialogResult.Yes) - { - // - string sql = $@"select sum(CURRENT_NUMBER) from VW_WORKING_PALLET_MSG where IR_CODE = '{ktb_IR.Text}'"; - - DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; - if (dt != null && dt.Rows.Count > 0) + int num = Convert.ToInt32(dt.Rows[0][0]); + if (num == 0) { - - int num = Convert.ToInt32(dt.Rows[0][0]); - if (num == 0) + dr = KryptonMessageBox.Show("There is no plate count in the current IR. If the confirmation continues, all information in the current IR will be deleted. Please carefully operation!!!", "Prompt", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (dr == DialogResult.Yes) { - dr = KryptonMessageBox.Show("There is no plate count in the current IR. If the confirmation continues, all information in the current IR will be deleted. Please carefully operation!!!", "Prompt", MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (dr == DialogResult.Yes) + string sql1 = $@"delete from CM_WORKING_PALLET where WORKING_PALLET_CODE in (select WORKING_PALLET_CODE from CM_WORKING_PALLET_DTL where IR_CODE = '{ktb_IR.Text}')"; + string sql2 = $@"delete from CM_WORKING_PALLET_DTL where IR_CODE = '{ktb_IR.Text}'"; + LeadDbHelperSQLite.ExecuteSql(sql1); + LeadDbHelperSQLite.ExecuteSql(sql2); + KryptonMessageBox.Show("Delete IR information success!"); + + Invoke(new Action(() => { - string sql1 = $@"delete from CM_WORKING_PALLET where WORKING_PALLET_CODE in (select WORKING_PALLET_CODE from CM_WORKING_PALLET_DTL where IR_CODE = '{ktb_IR.Text}')"; - string sql2 = $@"delete from CM_WORKING_PALLET_DTL where IR_CODE = '{ktb_IR.Text}'"; - LeadDbHelperSQLite.ExecuteSql(sql1); - LeadDbHelperSQLite.ExecuteSql(sql2); - KryptonMessageBox.Show("Delete IR information success!"); + //批次信息按钮可操作 + ktb_SaveIR.Enabled = true; + kcmb_SheetType.Enabled = true; + ktb_IR.Enabled = true; + kdtp_RecordDate.Enabled = true; + kbtn_forceFinish.Enabled = true; - Invoke(new Action(() => - { - //批次信息按钮可操作 - ktb_SaveIR.Enabled = true; - kcmb_SheetType.Enabled = true; - ktb_IR.Enabled = true; - kdtp_RecordDate.Enabled = true; - kbtn_forceFinish.Enabled = true; + //污染类型操作禁用 + //kryptonGroupBox10.Enabled = false; + kryptonGroupBox2.Enabled = false; + kryptonGroupBox3.Enabled = false; + kryptonGroupBox4.Enabled = false; + kryptonGroupBox5.Enabled = false; + kbtn_Scrap.Enabled = false; + kbtn_Scrap_1.Enabled = false; - //污染类型操作禁用 - //kryptonGroupBox10.Enabled = false; - kryptonGroupBox2.Enabled = false; - kryptonGroupBox3.Enabled = false; - kryptonGroupBox4.Enabled = false; - kryptonGroupBox5.Enabled = false; - kbtn_Scrap.Enabled = false; - kbtn_Scrap_1.Enabled = false; + //清空历史批次信息 + kcmb_SheetType.SelectedIndex = 0; + ktb_IR.Text = ""; + kdtp_RecordDate.Text = ""; + kdtp_RecordDate.Checked = false; - //清空历史批次信息 - kcmb_SheetType.SelectedIndex = 0; - ktb_IR.Text = ""; - kdtp_RecordDate.Text = ""; - kdtp_RecordDate.Checked = false; + ktb_CompleteNum.Text = "0"; + ktb_ScrapNum.Text = "0"; + })); - ktb_CompleteNum.Text = "0"; - ktb_ScrapNum.Text = "0"; - })); - - //清空当前内存污染计数 - foreach (BasCleanTypeMsg item in basCleanTypeMsgList) - { - if (string.IsNullOrEmpty(item.ContaminationDtlCode)) - {//常规清洗 清零(其他污染) - Invoke(new Action(() => - { - if (this.Controls.Find("knud_" + item.CleanModeCode, true).Length > 0) - { - KryptonNumericUpDown knudmd = this.Controls.Find("knud_" + item.CleanModeCode, true)[0] as KryptonNumericUpDown; - knudmd.Value = 0; - } - })); - } - else - {//特殊清洗 清零 - Invoke(new Action(() => - { - if (this.Controls.Find("knud_" + item.ContaminationDtlCode, true).Length > 0) - { - KryptonNumericUpDown knudmd = this.Controls.Find("knud_" + item.ContaminationDtlCode, true)[0] as KryptonNumericUpDown; - knudmd.Value = 0; - } - })); - } - } - } - } - else - { - string sql1 = $@"select CURRENT_NUMBER from CM_WORKING_PALLET_DTL where WORKING_PALLET_CODE = '{ktb_CurrPalletCode.Text.Trim()}' and CLEAN_MODE_CODE = 'SortedCleaned'"; - DataTable dt1 = LeadDbHelperSQLite.Query(sql1).Tables[0]; - if (dt1 != null && dt1.Rows.Count > 0) + //清空当前内存污染计数 + foreach (BasCleanTypeMsg item in basCleanTypeMsgList) { - //当前托盘在本IR中的数量 - int cleanMacNum = Convert.ToInt32(dt1.Rows[0][0]); - //当前托盘在之前IR的数量之和 - - if (cleanMacNum > 0) - { - var isUseForceFullPallet = KryptonMessageBox.Show("Continue stack on current pallet?", "", MessageBoxButtons.YesNo) == DialogResult.Yes; - - if (!isUseForceFullPallet) //使用强制满料方式结束IR + if (string.IsNullOrEmpty(item.ContaminationDtlCode)) + {//常规清洗 清零(其他污染) + Invoke(new Action(() => { - if (PlcOperationHelper.Instance.WritePlcItem("ForceFullPallet", "True", PlcItemTypeDesc.M)) + if (this.Controls.Find("knud_" + item.CleanModeCode, true).Length > 0) { - LogHelper.WriteLog($"作业IR:【{ktb_IR.Text}】强制完成,发送PLC强制满料信号成功。", LogTypeEum.Run); + KryptonNumericUpDown knudmd = this.Controls.Find("knud_" + item.CleanModeCode, true)[0] as KryptonNumericUpDown; + knudmd.Value = 0; } - else + })); + } + else + {//特殊清洗 清零 + Invoke(new Action(() => + { + if (this.Controls.Find("knud_" + item.ContaminationDtlCode, true).Length > 0) { - LogHelper.WriteLog($"作业IR:【{ktb_IR.Text}】已满料,发送PLC强制满料信号失败。", LogTypeEum.Err); + KryptonNumericUpDown knudmd = this.Controls.Find("knud_" + item.ContaminationDtlCode, true)[0] as KryptonNumericUpDown; + knudmd.Value = 0; } - - } - else - { - //IR结束 托盘保留 - //停止设备运行.防止设备继续过料 - // cbt_StopTran_MouseDown(null, null); - this.lastPaltteRemain += cleanMacNum;//设置当前托盘之前已经装载的数量 - SubPrintPalletData(ktb_IR.Text, ktb_CurrPalletCode.Text.Trim()); - // cbt_StartClean_MouseDown(null, null); - - } - return; + })); } - //如果最后依托没有计数 - string sqlUpdateWorkingPallet = $@"UPDATE CM_WORKING_PALLET SET WORKING_STATUS = 1,UPDATE_BY = '{GlobalHelper.UserInfo.UserId}',UPDATE_TIME = datetime('now', 'localtime'),DATA_VERSION = DATA_VERSION + 1 where WORKING_PALLET_CODE = '{ktb_CurrPalletCode.Text.Trim()}';"; - string sqlUpdateWorkingPalletDtl = $@"UPDATE CM_WORKING_PALLET_DTL SET WORKING_DTL_STATUS = 1,UPDATE_BY = '{GlobalHelper.UserInfo.UserId}',UPDATE_TIME = datetime('now', 'localtime'),DATA_VERSION = DATA_VERSION + 1 where WORKING_PALLET_CODE = '{ktb_CurrPalletCode.Text.Trim()}';"; - int row1 = LeadDbHelperSQLite.ExecuteSql(sqlUpdateWorkingPallet); - int row2 = LeadDbHelperSQLite.ExecuteSql(sqlUpdateWorkingPalletDtl); - string sql2 = $@"SELECT WORKING_PALLET_CODE from CM_WORKING_PALLET_DTL GROUP BY WORKING_PALLET_CODE HAVING SUM(CURRENT_NUMBER) = 0"; - DataTable dt2 = LeadDbHelperSQLite.Query(sql2).Tables[0]; - if (dt2 != null && dt2.Rows.Count > 0) - { - foreach (DataRow item in dt2.Rows) - { - string sqlTmp = $@"delete from CM_WORKING_PALLET where WORKING_PALLET_CODE = '{item["WORKING_PALLET_CODE"].ToString()}'"; - string sqlTmp1 = $@"delete from CM_WORKING_PALLET_DTL where WORKING_PALLET_CODE = '{item["WORKING_PALLET_CODE"].ToString()}'"; - LeadDbHelperSQLite.ExecuteSql(sqlTmp); - LeadDbHelperSQLite.ExecuteSql(sqlTmp1); - } - } - PrintWorkedIrMsg(ktb_IR.Text); - //保存打印数据 - string sqlInsertZbkWorkingPallet = $@"INSERT INTO ZBK_WORKING_PALLET SELECT * FROM CM_WORKING_PALLET WHERE WORKING_PALLET_CODE in (select WORKING_PALLET_CODE from CM_WORKING_PALLET_DTL where IR_CODE = '{ktb_IR.Text}' and WORKING_DTL_STATUS = 1)"; - string sqlInsertZbkWorkingPalletDtl = $@"INSERT INTO ZBK_WORKING_PALLET_DTL SELECT * FROM CM_WORKING_PALLET_DTL WHERE WORKING_DTL_STATUS = 1 and IR_CODE = '{ktb_IR.Text}';"; - string sqlDeleteWorkingPallet = $@"delete from CM_WORKING_PALLET where WORKING_PALLET_CODE in (select WORKING_PALLET_CODE from CM_WORKING_PALLET_DTL where IR_CODE = '{ktb_IR.Text}' and WORKING_DTL_STATUS = 1);"; - string sqlDeleteWorkingPalletDtl = $@"delete from CM_WORKING_PALLET_DTL where WORKING_DTL_STATUS = 1 and IR_CODE = '{ktb_IR.Text}';"; - - LeadDbHelperSQLite.ExecuteSql(sqlInsertZbkWorkingPalletDtl); - LeadDbHelperSQLite.ExecuteSql(sqlInsertZbkWorkingPallet); - LeadDbHelperSQLite.ExecuteSql(sqlDeleteWorkingPallet); - LeadDbHelperSQLite.ExecuteSql(sqlDeleteWorkingPalletDtl); - - - LogHelper.WriteLog($"作业IR:【{ktb_IR.Text}】已经结束,数据库信息重置完成。", LogTypeEum.Run); - - Invoke(new Action(() => - { - //批次信息按钮可操作 - ktb_SaveIR.Enabled = true; - kcmb_SheetType.Enabled = true; - ktb_IR.Enabled = true; - kdtp_RecordDate.Enabled = true; - kbtn_forceFinish.Enabled = true; - - //污染类型操作禁用 - //kryptonGroupBox10.Enabled = false; - kryptonGroupBox2.Enabled = false; - kryptonGroupBox3.Enabled = false; - kryptonGroupBox4.Enabled = false; - kryptonGroupBox5.Enabled = false; - kbtn_Scrap.Enabled = false; - kbtn_Scrap_1.Enabled = false; - - //清空历史批次信息 - kcmb_SheetType.SelectedIndex = 0; - ktb_IR.Text = ""; - kdtp_RecordDate.Text = ""; - kdtp_RecordDate.Checked = false; - - ktb_CompleteNum.Text = "0"; - ktb_ScrapNum.Text = "0"; - ktb_CurrPalletCode.Text = ""; - ktb_CurrentPalletNum.Text = "0"; - ktb_FinishedPalletNum.Text = "0"; - - })); - - //清空当前内存污染计数 - foreach (BasCleanTypeMsg item in basCleanTypeMsgList) - { - if (string.IsNullOrEmpty(item.ContaminationDtlCode)) - {//常规清洗 清零(其他污染) - Invoke(new Action(() => - { - if (this.Controls.Find("knud_" + item.CleanModeCode, true).Length > 0) - { - KryptonNumericUpDown knudmd = this.Controls.Find("knud_" + item.CleanModeCode, true)[0] as KryptonNumericUpDown; - knudmd.Value = 0; - } - })); - } - else - {//特殊清洗 清零 - Invoke(new Action(() => - { - if (this.Controls.Find("knud_" + item.ContaminationDtlCode, true).Length > 0) - { - KryptonNumericUpDown knudmd = this.Controls.Find("knud_" + item.ContaminationDtlCode, true)[0] as KryptonNumericUpDown; - knudmd.Value = 0; - } - })); - } - } - - KryptonMessageBox.Show("Completed IR job successfully!"); - } - else - { - KryptonMessageBox.Show("Completed IR job failed!"); } } } + else + { + string sql1 = $@"select CURRENT_NUMBER from CM_WORKING_PALLET_DTL where WORKING_PALLET_CODE = '{ktb_CurrPalletCode.Text.Trim()}' and CLEAN_MODE_CODE = 'SortedCleaned'"; + DataTable dt1 = LeadDbHelperSQLite.Query(sql1).Tables[0]; + if (dt1 != null && dt1.Rows.Count > 0) + { + //当前托盘在本IR中的数量 + int cleanMacNum = Convert.ToInt32(dt1.Rows[0][0]); + //当前托盘在之前IR的数量之和 + + if (cleanMacNum > 0) + { + var isUseForceFullPallet = KryptonMessageBox.Show("Continue stack on current pallet?", "", MessageBoxButtons.YesNo) == DialogResult.Yes; + + if (!isUseForceFullPallet) //使用强制满料方式结束IR + { + if (PlcOperationHelper.Instance.WritePlcItem("ForceFullPallet", "True", PlcItemTypeDesc.M)) + { + LogHelper.WriteLog($"作业IR:【{ktb_IR.Text}】强制完成,发送PLC强制满料信号成功。", LogTypeEum.Run); + } + else + { + LogHelper.WriteLog($"作业IR:【{ktb_IR.Text}】已满料,发送PLC强制满料信号失败。", LogTypeEum.Err); + } + + } + else + { + //IR结束 托盘保留 + //停止设备运行.防止设备继续过料 + // cbt_StopTran_MouseDown(null, null); + this.lastPaltteRemain += cleanMacNum;//设置当前托盘之前已经装载的数量 + SubPrintPalletData(ktb_IR.Text, ktb_CurrPalletCode.Text.Trim()); + // cbt_StartClean_MouseDown(null, null); + + } + return; + } + //如果最后依托没有计数 + string sqlUpdateWorkingPallet = $@"UPDATE CM_WORKING_PALLET SET WORKING_STATUS = 1,UPDATE_BY = '{GlobalHelper.UserInfo.UserId}',UPDATE_TIME = datetime('now', 'localtime'),DATA_VERSION = DATA_VERSION + 1 where WORKING_PALLET_CODE = '{ktb_CurrPalletCode.Text.Trim()}';"; + string sqlUpdateWorkingPalletDtl = $@"UPDATE CM_WORKING_PALLET_DTL SET WORKING_DTL_STATUS = 1,UPDATE_BY = '{GlobalHelper.UserInfo.UserId}',UPDATE_TIME = datetime('now', 'localtime'),DATA_VERSION = DATA_VERSION + 1 where WORKING_PALLET_CODE = '{ktb_CurrPalletCode.Text.Trim()}';"; + int row1 = LeadDbHelperSQLite.ExecuteSql(sqlUpdateWorkingPallet); + int row2 = LeadDbHelperSQLite.ExecuteSql(sqlUpdateWorkingPalletDtl); + string sql2 = $@"SELECT WORKING_PALLET_CODE from CM_WORKING_PALLET_DTL GROUP BY WORKING_PALLET_CODE HAVING SUM(CURRENT_NUMBER) = 0"; + DataTable dt2 = LeadDbHelperSQLite.Query(sql2).Tables[0]; + if (dt2 != null && dt2.Rows.Count > 0) + { + foreach (DataRow item in dt2.Rows) + { + string sqlTmp = $@"delete from CM_WORKING_PALLET where WORKING_PALLET_CODE = '{item["WORKING_PALLET_CODE"].ToString()}'"; + string sqlTmp1 = $@"delete from CM_WORKING_PALLET_DTL where WORKING_PALLET_CODE = '{item["WORKING_PALLET_CODE"].ToString()}'"; + LeadDbHelperSQLite.ExecuteSql(sqlTmp); + LeadDbHelperSQLite.ExecuteSql(sqlTmp1); + } + } + PrintWorkedIrMsg(ktb_IR.Text); + //保存打印数据 + string sqlInsertZbkWorkingPallet = $@"INSERT INTO ZBK_WORKING_PALLET SELECT * FROM CM_WORKING_PALLET WHERE WORKING_PALLET_CODE in (select WORKING_PALLET_CODE from CM_WORKING_PALLET_DTL where IR_CODE = '{ktb_IR.Text}' and WORKING_DTL_STATUS = 1)"; + string sqlInsertZbkWorkingPalletDtl = $@"INSERT INTO ZBK_WORKING_PALLET_DTL SELECT * FROM CM_WORKING_PALLET_DTL WHERE WORKING_DTL_STATUS = 1 and IR_CODE = '{ktb_IR.Text}';"; + string sqlDeleteWorkingPallet = $@"delete from CM_WORKING_PALLET where WORKING_PALLET_CODE in (select WORKING_PALLET_CODE from CM_WORKING_PALLET_DTL where IR_CODE = '{ktb_IR.Text}' and WORKING_DTL_STATUS = 1);"; + string sqlDeleteWorkingPalletDtl = $@"delete from CM_WORKING_PALLET_DTL where WORKING_DTL_STATUS = 1 and IR_CODE = '{ktb_IR.Text}';"; + + LeadDbHelperSQLite.ExecuteSql(sqlInsertZbkWorkingPalletDtl); + LeadDbHelperSQLite.ExecuteSql(sqlInsertZbkWorkingPallet); + LeadDbHelperSQLite.ExecuteSql(sqlDeleteWorkingPallet); + LeadDbHelperSQLite.ExecuteSql(sqlDeleteWorkingPalletDtl); + + + LogHelper.WriteLog($"作业IR:【{ktb_IR.Text}】已经结束,数据库信息重置完成。", LogTypeEum.Run); + + Invoke(new Action(() => + { + //批次信息按钮可操作 + ktb_SaveIR.Enabled = true; + kcmb_SheetType.Enabled = true; + ktb_IR.Enabled = true; + kdtp_RecordDate.Enabled = true; + kbtn_forceFinish.Enabled = true; + + //污染类型操作禁用 + //kryptonGroupBox10.Enabled = false; + kryptonGroupBox2.Enabled = false; + kryptonGroupBox3.Enabled = false; + kryptonGroupBox4.Enabled = false; + kryptonGroupBox5.Enabled = false; + kbtn_Scrap.Enabled = false; + kbtn_Scrap_1.Enabled = false; + + //清空历史批次信息 + kcmb_SheetType.SelectedIndex = 0; + ktb_IR.Text = ""; + kdtp_RecordDate.Text = ""; + kdtp_RecordDate.Checked = false; + + ktb_CompleteNum.Text = "0"; + ktb_ScrapNum.Text = "0"; + ktb_CurrPalletCode.Text = ""; + ktb_CurrentPalletNum.Text = "0"; + ktb_FinishedPalletNum.Text = "0"; + + })); + + //清空当前内存污染计数 + foreach (BasCleanTypeMsg item in basCleanTypeMsgList) + { + if (string.IsNullOrEmpty(item.ContaminationDtlCode)) + {//常规清洗 清零(其他污染) + Invoke(new Action(() => + { + if (this.Controls.Find("knud_" + item.CleanModeCode, true).Length > 0) + { + KryptonNumericUpDown knudmd = this.Controls.Find("knud_" + item.CleanModeCode, true)[0] as KryptonNumericUpDown; + knudmd.Value = 0; + } + })); + } + else + {//特殊清洗 清零 + Invoke(new Action(() => + { + if (this.Controls.Find("knud_" + item.ContaminationDtlCode, true).Length > 0) + { + KryptonNumericUpDown knudmd = this.Controls.Find("knud_" + item.ContaminationDtlCode, true)[0] as KryptonNumericUpDown; + knudmd.Value = 0; + } + })); + } + } + + KryptonMessageBox.Show("Completed IR job successfully!"); + } + else + { + KryptonMessageBox.Show("Completed IR job failed!"); + } + } } - kryptonGroupBox1.Focus(); } + kryptonGroupBox1.Focus(); +#if !DEBUG + } catch (Exception ex) { KryptonMessageBox.Show(ex.Message); } +#endif kbtn_forceFinish.Enabled = true; } diff --git a/NX_LogUtility/LogHelper.cs b/NX_LogUtility/LogHelper.cs index a4c6024..75a1391 100644 --- a/NX_LogUtility/LogHelper.cs +++ b/NX_LogUtility/LogHelper.cs @@ -130,35 +130,34 @@ namespace NX_LogUtility private static void RunLogTask() { - bool createNew; - string threadName = "LogQueue"; - using (System.Threading.Mutex mtx = new System.Threading.Mutex(true, threadName, out createNew)) + //bool createNew; + //string threadName = "LogQueue"; + //using (System.Threading.Mutex mtx = new System.Threading.Mutex(true, threadName, out createNew)) + //{ + // if (createNew) + // { + Task.Factory.StartNew(() => { - if (createNew) + //从队列中取元素。 + while (!QueueBlock.IsComleted()) { - Task.Factory.StartNew(() => + try { - //从队列中取元素。 - while (!QueueBlock.IsComleted()) - { - try - { - var m = QueueBlock.Take(); - SaveLog(m.Content, m.LogType); - - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - }); + var m = QueueBlock.Take(); + SaveLog(m.Content, m.LogType); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } } - else - { - Console.WriteLine("日志线程已经运行"); - } - } + }); + // } + // else + // { + // Console.WriteLine("日志线程已经运行"); + // } + //} } /// @@ -167,7 +166,7 @@ namespace NX_LogUtility /// public class QueueBlock where T : class { - private static BlockingCollection Colls; + private static BlockingCollection Colls = new BlockingCollection(); public QueueBlock() {