修改线程UI错误

This commit is contained in:
gongxh
2022-01-19 13:27:34 +08:00
parent e1731268c0
commit f802acfd18
2 changed files with 340 additions and 324 deletions

View File

@@ -483,103 +483,108 @@ namespace CleanMachineHMI.FrmUserControl
/// </summary> /// </summary>
private void FinishWorkingPallet() private void FinishWorkingPallet()
{ {
#if !DEBUG
try try
{ {
//满料标识 #endif
bool isFinishWorkingPallet = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("FinishWorkingPallet", PlcItemTypeDesc.M)); //满料标识
//ToDo: 根据满料的方式,增加相应的满料判断代码 bool isFinishWorkingPallet = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("FinishWorkingPallet", PlcItemTypeDesc.M));
bool fullPalletMode = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("FullPalletMode", PlcItemTypeDesc.M)); //ToDo: 根据满料的方式,增加相应的满料判断代码
bool fullPalletMode = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("FullPalletMode", PlcItemTypeDesc.M));
int countFullNum = Convert.ToInt32(PlcOperationHelper.Instance.ReadPlcItem("WorkedFullPalletNum", PlcItemTypeDesc.D)); int countFullNum = Convert.ToInt32(PlcOperationHelper.Instance.ReadPlcItem("WorkedFullPalletNum", PlcItemTypeDesc.D));
//是否强制满料 //是否强制满料
bool isForceFullPallet = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("ForceFullPallet", PlcItemTypeDesc.M)); bool isForceFullPallet = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("ForceFullPallet", PlcItemTypeDesc.M));
string sql_CurrPalletmsg = $@"SELECT * FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0"; string sql_CurrPalletmsg = $@"SELECT * FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
DataTable dt_CurrPalletmsg = LeadDbHelperSQLite.Query(sql_CurrPalletmsg).Tables[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();
//{ string sqlCurrNumMsg = $@"SELECT ifnull(SUM(CURRENT_NUMBER),0) FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}' and CLEAN_MODE_CODE = 'SortedCleaned'";
// string palletCodeMsg = dt_CurrPalletmsg.Rows[0]["WORKING_PALLET_CODE"].ToString(); DataTable dt_CurrNumMsg = LeadDbHelperSQLite.Query(sqlCurrNumMsg).Tables[0];
// LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,开始处理延时满料业务。", LogTypeEum.Run); if (dt_CurrNumMsg != null && dt_CurrNumMsg.Rows.Count > 0)
// 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(); //这个值只包含托盘在这个IR下个数量
string sqlCurrNumMsg = $@"SELECT SUM(CURRENT_NUMBER) FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}' and CLEAN_MODE_CODE = 'SortedCleaned'"; int currentNum = Convert.ToInt32(dt_CurrNumMsg.Rows[0][0]);
DataTable dt_CurrNumMsg = LeadDbHelperSQLite.Query(sqlCurrNumMsg).Tables[0];
if (dt_CurrNumMsg != null && dt_CurrNumMsg.Rows.Count > 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下个数量 LogHelper.WriteLog($"作业托盘:【{palletCodeMsg}】,开始处理计数满料业务。满料方式:【正常满料】", LogTypeEum.Run);
int currentNum = Convert.ToInt32(dt_CurrNumMsg.Rows[0][0]); 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 sql1 = $@"Update CM_WORKING_PALLET set WORKING_STATUS = 0 where WORKING_STATUS = '-1'";
string sql = $@"select * from CM_WORKING_PALLET where WORKING_STATUS = '-1'"; string sql2 = $@"Update CM_WORKING_PALLET_DTL set WORKING_DTL_STATUS = 0 where WORKING_DTL_STATUS = '-1'";
DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; LeadDbHelperSQLite.ExecuteSql(sql1);
if (dt != null && dt.Rows.Count > 0) 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'"; //kryptonGroupBox10.Enabled = false;
LeadDbHelperSQLite.ExecuteSql(sql1); kryptonGroupBox2.Enabled = true;
LeadDbHelperSQLite.ExecuteSql(sql2); kryptonGroupBox3.Enabled = true;
BeginInvoke(new Action(() => kryptonGroupBox4.Enabled = true;
{ kryptonGroupBox5.Enabled = true;
//污染类型操作禁用 kbtn_Scrap.Enabled = true;
//kryptonGroupBox10.Enabled = false; kbtn_Scrap_1.Enabled = true;
kryptonGroupBox2.Enabled = true; kbtn_forceFinish.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) catch (Exception ex)
{ {
LogHelper.WriteLog($"~~~~~~~~~~~~~~托盘结束发生异常!【{ex.Message}】。~~~~~~~~~~~~~~", LogTypeEum.Run); LogHelper.WriteLog($"~~~~~~~~~~~~~~托盘结束发生异常!【{ex.Message}】。~~~~~~~~~~~~~~", LogTypeEum.Run);
} }
#endif
} }
/// <summary> /// <summary>
@@ -803,8 +808,7 @@ namespace CleanMachineHMI.FrmUserControl
{ {
#region 生成的新的组盘信息,等待计数作业。 #region 生成的新的组盘信息,等待计数作业。
string trayCode = GlobalHelper.GetPalletCode(); string trayCode = GlobalHelper.GetPalletCode();
string sqlInsertWorkPallet = $@" string sqlInsertWorkPallet = $@" INSERT INTO [CM_WORKING_PALLET] (
INSERT INTO [CM_WORKING_PALLET] (
[WORKING_PALLET_CODE], [WORKING_PALLET_CODE],
[WORKING_PALLET_DESC], [WORKING_PALLET_DESC],
[WORKING_STATUS], [WORKING_STATUS],
@@ -820,10 +824,18 @@ namespace CleanMachineHMI.FrmUserControl
'{GlobalHelper.UserInfo.UserId}', '{GlobalHelper.UserInfo.UserId}',
'{GlobalHelper.UserInfo.UserId}', '{GlobalHelper.UserInfo.UserId}',
'{0}' '{0}'
); );";
";
LeadDbHelperSQLite.ExecuteSql(sqlInsertWorkPallet); LeadDbHelperSQLite.ExecuteSql(sqlInsertWorkPallet);
string SheetTypeCode = "";
this.Invoke(new Action(() =>
{
SheetTypeCode = ((ListItem)kcmb_SheetType.SelectedItem).Value;
}));
foreach (BasCleanTypeMsg item in basCleanTypeMsgList) foreach (BasCleanTypeMsg item in basCleanTypeMsgList)
{ {
string sqlInsertWorkPalletDtl = $@" string sqlInsertWorkPalletDtl = $@"
@@ -853,8 +865,8 @@ namespace CleanMachineHMI.FrmUserControl
VALUES VALUES
( (
'{trayCode}', '{trayCode}',
'{ktb_IR.Text.Trim()}', '{workingIrMsg}',
'{((ListItem)kcmb_SheetType.SelectedItem).Value}', '{SheetTypeCode}',
(datetime('now','localtime')), (datetime('now','localtime')),
'{item.CleanModeCode}', '{item.CleanModeCode}',
'{item.ContaminationTypeCode}', '{item.ContaminationTypeCode}',
@@ -873,15 +885,14 @@ namespace CleanMachineHMI.FrmUserControl
NULL, NULL,
NULL, NULL,
NULL NULL
); );";
";
LeadDbHelperSQLite.ExecuteSql(sqlInsertWorkPalletDtl); LeadDbHelperSQLite.ExecuteSql(sqlInsertWorkPalletDtl);
} }
Invoke(new Action(() => Invoke(new Action(() =>
{ {
ktb_CurrPalletCode.Text = trayCode; 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 #endregion
Invoke(new Action(() => Invoke(new Action(() =>
@@ -3134,248 +3145,254 @@ namespace CleanMachineHMI.FrmUserControl
private void kbtn_forceFinish_Click_1(object sender, EventArgs e) private void kbtn_forceFinish_Click_1(object sender, EventArgs e)
{ {
kbtn_forceFinish.Enabled = false; kbtn_forceFinish.Enabled = false;
#if !DEBUG
try 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."); int num = Convert.ToInt32(dt.Rows[0][0]);
return; if (num == 0)
}
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)
{ {
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);
int num = Convert.ToInt32(dt.Rows[0][0]); if (dr == DialogResult.Yes)
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); 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}')";
if (dr == DialogResult.Yes) 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}'"; ktb_SaveIR.Enabled = true;
LeadDbHelperSQLite.ExecuteSql(sql1); kcmb_SheetType.Enabled = true;
LeadDbHelperSQLite.ExecuteSql(sql2); ktb_IR.Enabled = true;
KryptonMessageBox.Show("Delete IR information success!"); kdtp_RecordDate.Enabled = true;
kbtn_forceFinish.Enabled = true;
Invoke(new Action(() => //污染类型操作禁用
{ //kryptonGroupBox10.Enabled = false;
//批次信息按钮可操作 kryptonGroupBox2.Enabled = false;
ktb_SaveIR.Enabled = true; kryptonGroupBox3.Enabled = false;
kcmb_SheetType.Enabled = true; kryptonGroupBox4.Enabled = false;
ktb_IR.Enabled = true; kryptonGroupBox5.Enabled = false;
kdtp_RecordDate.Enabled = true; kbtn_Scrap.Enabled = false;
kbtn_forceFinish.Enabled = true; kbtn_Scrap_1.Enabled = false;
//污染类型操作禁用 //清空历史批次信息
//kryptonGroupBox10.Enabled = false; kcmb_SheetType.SelectedIndex = 0;
kryptonGroupBox2.Enabled = false; ktb_IR.Text = "";
kryptonGroupBox3.Enabled = false; kdtp_RecordDate.Text = "";
kryptonGroupBox4.Enabled = false; kdtp_RecordDate.Checked = false;
kryptonGroupBox5.Enabled = false;
kbtn_Scrap.Enabled = false;
kbtn_Scrap_1.Enabled = false;
//清空历史批次信息 ktb_CompleteNum.Text = "0";
kcmb_SheetType.SelectedIndex = 0; ktb_ScrapNum.Text = "0";
ktb_IR.Text = ""; }));
kdtp_RecordDate.Text = "";
kdtp_RecordDate.Checked = false;
ktb_CompleteNum.Text = "0"; //清空当前内存污染计数
ktb_ScrapNum.Text = "0"; foreach (BasCleanTypeMsg item in basCleanTypeMsgList)
}));
//清空当前内存污染计数
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)
{ {
//当前托盘在本IR中的数量 if (string.IsNullOrEmpty(item.ContaminationDtlCode))
int cleanMacNum = Convert.ToInt32(dt1.Rows[0][0]); {//常规清洗 清零(其他污染)
//当前托盘在之前IR的数量之和 Invoke(new Action(() =>
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)) 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) catch (Exception ex)
{ {
KryptonMessageBox.Show(ex.Message); KryptonMessageBox.Show(ex.Message);
} }
#endif
kbtn_forceFinish.Enabled = true; kbtn_forceFinish.Enabled = true;
} }

View File

@@ -130,35 +130,34 @@ namespace NX_LogUtility
private static void RunLogTask() private static void RunLogTask()
{ {
bool createNew; //bool createNew;
string threadName = "LogQueue"; //string threadName = "LogQueue";
using (System.Threading.Mutex mtx = new System.Threading.Mutex(true, threadName, out createNew)) //using (System.Threading.Mutex mtx = new System.Threading.Mutex(true, threadName, out createNew))
//{
// if (createNew)
// {
Task.Factory.StartNew(() =>
{ {
if (createNew) //从队列中取元素。
while (!QueueBlock<QueueMessage>.IsComleted())
{ {
Task.Factory.StartNew(() => try
{ {
//从队列中取元素。 var m = QueueBlock<QueueMessage>.Take();
while (!QueueBlock<QueueMessage>.IsComleted()) SaveLog(m.Content, m.LogType);
{ }
try catch (Exception ex)
{ {
var m = QueueBlock<QueueMessage>.Take(); Console.WriteLine(ex.Message);
SaveLog(m.Content, m.LogType); }
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
});
} }
else });
{ // }
Console.WriteLine("日志线程已经运行"); // else
} // {
} // Console.WriteLine("日志线程已经运行");
// }
//}
} }
/// <summary> /// <summary>
@@ -167,7 +166,7 @@ namespace NX_LogUtility
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
public class QueueBlock<T> where T : class public class QueueBlock<T> where T : class
{ {
private static BlockingCollection<T> Colls; private static BlockingCollection<T> Colls = new BlockingCollection<T>();
public QueueBlock() public QueueBlock()
{ {