添加编译指令

This commit is contained in:
gongxh
2022-01-18 20:20:10 +08:00
parent a7ef9c7b54
commit 89f1bb0536
5 changed files with 707 additions and 640 deletions

View File

@@ -1319,7 +1319,7 @@ namespace CleanMachineHMI.FrmUserControl
}
else
{
BeginInvoke(new Action(() =>
{
cbt_Brush3StatusTran.BackColor = Color.Gray;
@@ -2832,7 +2832,12 @@ namespace CleanMachineHMI.FrmUserControl
}
//自动模式下,打印结束操控 M231 交替 别名: PrintFinish
/// <summary>
/// 自动模式下,打印结束操控 M231 交替 别名: PrintFinish
/// 打印不成功时候按这个重新向PLC发这个指令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void kryptonButton7_Click(object sender, EventArgs e)
{
if (isManualStatus())
@@ -3133,7 +3138,7 @@ namespace CleanMachineHMI.FrmUserControl
{
if (isManualStatus())
{
KryptonMessageBox.Show("The manual operation interface has been opened and is currently in manual mode.");
return;
}

File diff suppressed because it is too large Load Diff

View File

@@ -372,7 +372,7 @@ namespace CleanMachineHMI
PlcItem md = PlcItemMdList.Find(x => x.PlcItemCode == item["PLC_ITEM_CODE"].ToString());
if (md != null)
{
md.PlcItemId =item["PLC_ITEM_ID"].ToString();
md.PlcItemId = item["PLC_ITEM_ID"].ToString();
md.PlcItemCode = item["PLC_ITEM_CODE"].ToString();
md.PlcItemName = item["PLC_ITEM_NAME"].ToString();
md.PlcItemType = Convert.ToInt32(item["PLC_ITEM_TYPE"].ToString());
@@ -484,169 +484,174 @@ namespace CleanMachineHMI
long lastTick = DateTime.Now.Ticks;
while (GlobalHelper.SysThIsRunFlag)
{
#if !DEBUG
try
{
#region 定时器运行函数
//当前托报废率超过10%,则提示
string sql_CurrPalletmsg = $@"SELECT * FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
DataTable dt_CurrPalletmsg = LeadDbHelperSQLite.Query(sql_CurrPalletmsg).Tables[0];
if (dt_CurrPalletmsg != null && dt_CurrPalletmsg.Rows.Count > 0)
#endif
#region 定时器运行函数
//当前托报废率超过10%,则提示
string sql_CurrPalletmsg = $@"SELECT * FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
DataTable dt_CurrPalletmsg = LeadDbHelperSQLite.Query(sql_CurrPalletmsg).Tables[0];
if (dt_CurrPalletmsg != null && dt_CurrPalletmsg.Rows.Count > 0)
{
string palletCodeMsg = dt_CurrPalletmsg.Rows[0]["WORKING_PALLET_CODE"].ToString();
string sqlCurrPalletScrapNumMsg = $@"SELECT CURRENT_NUMBER FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}' AND CONTAMINATION_DTL_CODE = 'MoistureOrWet'";
string sqlCurrPalletCountNumMsg = $@"SELECT SUM(CURRENT_NUMBER) FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}'";
DataTable dt_CurrPalletScrapNumMsg = LeadDbHelperSQLite.Query(sqlCurrPalletScrapNumMsg).Tables[0];
DataTable dt_CurrPalletCountNumMsg = LeadDbHelperSQLite.Query(sqlCurrPalletCountNumMsg).Tables[0];
if (dt_CurrPalletScrapNumMsg != null && dt_CurrPalletScrapNumMsg.Rows.Count > 0 && dt_CurrPalletCountNumMsg != null && dt_CurrPalletCountNumMsg.Rows.Count > 0)
{
string palletCodeMsg = dt_CurrPalletmsg.Rows[0]["WORKING_PALLET_CODE"].ToString();
string sqlCurrPalletScrapNumMsg = $@"SELECT CURRENT_NUMBER FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}' AND CONTAMINATION_DTL_CODE = 'MoistureOrWet'";
string sqlCurrPalletCountNumMsg = $@"SELECT SUM(CURRENT_NUMBER) FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}'";
DataTable dt_CurrPalletScrapNumMsg = LeadDbHelperSQLite.Query(sqlCurrPalletScrapNumMsg).Tables[0];
DataTable dt_CurrPalletCountNumMsg = LeadDbHelperSQLite.Query(sqlCurrPalletCountNumMsg).Tables[0];
if (dt_CurrPalletScrapNumMsg != null && dt_CurrPalletScrapNumMsg.Rows.Count > 0 && dt_CurrPalletCountNumMsg != null && dt_CurrPalletCountNumMsg.Rows.Count > 0)
int ScrapNumMsg = Convert.ToInt32(dt_CurrPalletScrapNumMsg.Rows[0][0]);
int CountNumMsg = Convert.ToInt32(dt_CurrPalletCountNumMsg.Rows[0][0]);
if (CountNumMsg == 0 || ScrapNumMsg == 0)
{
int ScrapNumMsg = Convert.ToInt32(dt_CurrPalletScrapNumMsg.Rows[0][0]);
int CountNumMsg = Convert.ToInt32(dt_CurrPalletCountNumMsg.Rows[0][0]);
if (CountNumMsg == 0 || ScrapNumMsg == 0)
BeginInvoke(new Action(() => { label1.Visible = false; }));
}
else
{
int scrapRate = Convert.ToInt32(Math.Round(decimal.Parse(((decimal)ScrapNumMsg / (decimal)CountNumMsg).ToString("0.000")), 2) * 100);
if (scrapRate >= 10)
{
BeginInvoke(new Action(() => { label1.Visible = false; }));
}
else
{
int scrapRate = Convert.ToInt32(Math.Round(decimal.Parse(((decimal)ScrapNumMsg / (decimal)CountNumMsg).ToString("0.000")), 2) * 100);
if (scrapRate >= 10)
{
BeginInvoke(new Action(() => { label1.Visible = false; }));
}
else
{
BeginInvoke(new Action(() => { label1.Visible = false; }));
}
BeginInvoke(new Action(() => { label1.Visible = false; }));
}
}
else
{
BeginInvoke(new Action(() => { label1.Visible = false; }));
}
}
string sqlParam = $@"SELECT * FROM SYS_PARAMETER";
DataTable dtParam = LeadDbHelperSQLite.Query(sqlParam).Tables[0];
if (dtParam != null && dtParam.Rows.Count > 0)
else
{
int sysRuningTimeLen = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'SysRuningTimeLen'")[0]["PARAMETER_VALUE"]);
int scrapRate = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'ScrapRate'")[0]["PARAMETER_VALUE"]);
int maintainItemTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainItemTime'")[0]["PARAMETER_VALUE"]);
int maintainAlarmTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainAlarmTime'")[0]["PARAMETER_VALUE"]);
int maintainQuitTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainQuitTime'")[0]["PARAMETER_VALUE"]);
int maintainFlag = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainFlag'")[0]["PARAMETER_VALUE"]);
string maintainRelieveCode = dtParam.Select("PARAMETER_CODE = 'MaintainRelieveCode'")[0]["PARAMETER_VALUE"].ToString();
if (maintainFlag == 0)
BeginInvoke(new Action(() => { label1.Visible = false; }));
}
}
string sqlParam = $@"SELECT * FROM SYS_PARAMETER";
DataTable dtParam = LeadDbHelperSQLite.Query(sqlParam).Tables[0];
if (dtParam != null && dtParam.Rows.Count > 0)
{
int sysRuningTimeLen = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'SysRuningTimeLen'")[0]["PARAMETER_VALUE"]);
int scrapRate = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'ScrapRate'")[0]["PARAMETER_VALUE"]);
int maintainItemTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainItemTime'")[0]["PARAMETER_VALUE"]);
int maintainAlarmTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainAlarmTime'")[0]["PARAMETER_VALUE"]);
int maintainQuitTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainQuitTime'")[0]["PARAMETER_VALUE"]);
int maintainFlag = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainFlag'")[0]["PARAMETER_VALUE"]);
string maintainRelieveCode = dtParam.Select("PARAMETER_CODE = 'MaintainRelieveCode'")[0]["PARAMETER_VALUE"].ToString();
if (maintainFlag == 0)
{
bool isRun = (bool)PlcOperationHelper.Instance.ReadPlcItem("CleanMacRunStatusNew", PlcItemTypeDesc.M);
if (isRun)
{
bool isRun = (bool)PlcOperationHelper.Instance.ReadPlcItem("CleanMacRunStatusNew", PlcItemTypeDesc.M);
if (isRun)
if (timerRunNUm == 60)
{
if (timerRunNUm == 60)
sysRuningTimeLen++;
if (sysRuningTimeLen < maintainItemTime)
{
sysRuningTimeLen++;
if (sysRuningTimeLen < maintainItemTime)
//pictureBox1.Visible = false;
BeginInvoke(new Action(() => { pictureBox1.Visible = false; }));
}
else if (sysRuningTimeLen >= maintainItemTime && sysRuningTimeLen < maintainAlarmTime)
{
//pictureBox1.Visible = true;
BeginInvoke(new Action(() => { pictureBox1.Visible = true; }));
}
else if (sysRuningTimeLen >= maintainAlarmTime && sysRuningTimeLen < maintainQuitTime)
{
BeginInvoke(new Action(() =>
{
//pictureBox1.Visible = false;
BeginInvoke(new Action(() => { pictureBox1.Visible = false; }));
}
else if (sysRuningTimeLen >= maintainItemTime && sysRuningTimeLen < maintainAlarmTime)
{
//pictureBox1.Visible = true;
BeginInvoke(new Action(() => { pictureBox1.Visible = true; }));
}
else if (sysRuningTimeLen >= maintainAlarmTime && sysRuningTimeLen < maintainQuitTime)
{
BeginInvoke(new Action(() =>
pictureBox1.Visible = true;
if (!sysAlarmFrmShowFlag)
{
sysAlarmFrmShowFlag = true;
frmSysExitAlarm frm = new frmSysExitAlarm();
//frm.showMsg = "机器即将于" + (maintainQuitTime - sysRuningTimeLen) + "分钟后退出。";
frm.showMsg = $"The machine will exit in {(maintainQuitTime - sysRuningTimeLen)} minutes.";
frm.TopLevel = true;
frm.ShowDialog();
}
}));
}
else if (sysRuningTimeLen >= maintainQuitTime)
{
BeginInvoke(new Action(() =>
{
pictureBox1.Visible = true;
string sql = "SELECT 1 FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
pictureBox1.Visible = true;
if (!sysAlarmFrmShowFlag)
{
sysAlarmFrmShowFlag = true;
frmSysExitAlarm frm = new frmSysExitAlarm();
//frm.showMsg = "机器即将于" + (maintainQuitTime - sysRuningTimeLen) + "分钟后退出。";
frm.showMsg = $"The machine will exit in {(maintainQuitTime - sysRuningTimeLen)} minutes.";
frm.showMsg = $"The machine maintenance time has exceeded: [{(maintainQuitTime - sysRuningTimeLen)}] minutes, please complete the current operation tray as soon as possible, and carry out equipment maintenance !!!!!!";
frm.TopLevel = true;
frm.ShowDialog();
}
}));
}
else if (sysRuningTimeLen >= maintainQuitTime)
{
BeginInvoke(new Action(() =>
}
else
{
pictureBox1.Visible = true;
string sql = "SELECT 1 FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
if (!sysAlarmFrmShowFlag)
{
sysAlarmFrmShowFlag = true;
frmSysExitAlarm frm = new frmSysExitAlarm();
frm.showMsg = $"The machine maintenance time has exceeded: [{(maintainQuitTime - sysRuningTimeLen)}] minutes, please complete the current operation tray as soon as possible, and carry out equipment maintenance !!!!!!";
frm.TopLevel = true;
frm.ShowDialog();
}
}
else
{
string sqlUpdateParam = $@"update SYS_PARAMETER set PARAMETER_VALUE = '1' WHERE PARAMETER_CODE = 'MaintainFlag'";
LeadDbHelperSQLite.ExecuteSql(sqlUpdateParam);
PlcOperationHelper.Instance.WritePlcItem("StopSys", "True", PlcItemTypeDesc.M);
PlcOperationHelper.Instance.WritePlcItem("StopSys", "False", PlcItemTypeDesc.M);
PlcOperationHelper.Instance.WritePlcItem("ResetSys", "True", PlcItemTypeDesc.M);
PlcOperationHelper.Instance.WritePlcItem("ResetSys", "False", PlcItemTypeDesc.M);
Environment.Exit(0);
}
}));
}
string sqlUpdateRunTimeLen = $@"UPDATE SYS_PARAMETER set PARAMETER_VALUE = '{sysRuningTimeLen}' WHERE PARAMETER_CODE = 'SysRuningTimeLen'";
LeadDbHelperSQLite.ExecuteSql(sqlUpdateRunTimeLen);
BeginInvoke(new Action(() =>
{
kryptonLabel1.Text = sysRuningTimeLen + " Minutes";
string sqlUpdateParam = $@"update SYS_PARAMETER set PARAMETER_VALUE = '1' WHERE PARAMETER_CODE = 'MaintainFlag'";
LeadDbHelperSQLite.ExecuteSql(sqlUpdateParam);
PlcOperationHelper.Instance.WritePlcItem("StopSys", "True", PlcItemTypeDesc.M);
PlcOperationHelper.Instance.WritePlcItem("StopSys", "False", PlcItemTypeDesc.M);
PlcOperationHelper.Instance.WritePlcItem("ResetSys", "True", PlcItemTypeDesc.M);
PlcOperationHelper.Instance.WritePlcItem("ResetSys", "False", PlcItemTypeDesc.M);
Environment.Exit(0);
}
}));
timerRunNUm = 1;
}
else
string sqlUpdateRunTimeLen = $@"UPDATE SYS_PARAMETER set PARAMETER_VALUE = '{sysRuningTimeLen}' WHERE PARAMETER_CODE = 'SysRuningTimeLen'";
LeadDbHelperSQLite.ExecuteSql(sqlUpdateRunTimeLen);
BeginInvoke(new Action(() =>
{
timerRunNUm++;
BeginInvoke(new Action(() =>
{
kryptonLabel1.Text = sysRuningTimeLen + " Minutes";
}));
}
kryptonLabel1.Text = sysRuningTimeLen + " Minutes";
}));
timerRunNUm = 1;
}
}
else
{
BeginInvoke(new Action(() =>
else
{
pictureBox1.Visible = true;
}));
timerRunNUm++;
BeginInvoke(new Action(() =>
{
kryptonLabel1.Text = sysRuningTimeLen + " Minutes";
}));
}
}
}
else
{
BeginInvoke(new Action(() =>
{
pictureBox1.Visible = true;
}));
}
#region 定期清理历史业务数据 -- 数据保存2个月
string sqlZbkWorkingPallet = $@"DELETE FROM ZBK_WORKING_PALLET WHERE julianday('now') - julianday(UPDATE_TIME) > 30";
string sqlZbkWorkingPalletDtl = $@"DELETE FROM ZBK_WORKING_PALLET_DTL WHERE julianday('now') - julianday(UPDATE_TIME) > 30";
LeadDbHelperSQLite.ExecuteSql(sqlZbkWorkingPallet);
LeadDbHelperSQLite.ExecuteSql(sqlZbkWorkingPalletDtl);
#endregion
PlcOperationHelper.Instance.HeartbeatDetection();
#endregion
}
#region 定期清理历史业务数据 -- 数据保存2个月
string sqlZbkWorkingPallet = $@"DELETE FROM ZBK_WORKING_PALLET WHERE julianday('now') - julianday(UPDATE_TIME) > 30";
string sqlZbkWorkingPalletDtl = $@"DELETE FROM ZBK_WORKING_PALLET_DTL WHERE julianday('now') - julianday(UPDATE_TIME) > 30";
LeadDbHelperSQLite.ExecuteSql(sqlZbkWorkingPallet);
LeadDbHelperSQLite.ExecuteSql(sqlZbkWorkingPalletDtl);
#endregion
PlcOperationHelper.Instance.HeartbeatDetection();
#endregion
#if !DEBUG
}
catch (Exception ex)
{
LogHelper.WriteLog($"定时器运行函数发生异常:【{ex.Message}】", LogTypeEum.Err);
}
#endif
Thread.Sleep(1000);
}
}
@@ -770,8 +775,8 @@ namespace CleanMachineHMI
if (isPlcConnStatus)
{
// 断开PLC连接
PlcOperationHelper.Instance.ClosePlcConn();
// 断开PLC连接
PlcOperationHelper.Instance.ClosePlcConn();
isPlcConnStatus = false;
}
if (GlobalHelper.PopupWarningMsgForm != null)

View File

@@ -28,25 +28,28 @@ namespace LeadDataBaseUtility
public static int ExecuteSql(string sql)
{
int affectedRows = 0;
#if !DEBUG
try
{
using (SQLiteConnection conn = new SQLiteConnection(connectionString))
#endif
using (SQLiteConnection conn = new SQLiteConnection(connectionString))
{
conn.Open();
using (SQLiteCommand cmd = new SQLiteCommand(conn))
{
conn.Open();
using (SQLiteCommand cmd = new SQLiteCommand(conn))
{
cmd.CommandText = sql;
affectedRows = cmd.ExecuteNonQuery();
}
conn.Close();
cmd.CommandText = sql;
affectedRows = cmd.ExecuteNonQuery();
}
conn.Close();
}
#if !DEBUG
}
catch (Exception e)
{
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{sql}】。", LogTypeEum.DbErr);
}
#endif
return affectedRows;
}
/// <summary>
@@ -59,17 +62,21 @@ namespace LeadDataBaseUtility
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
DataSet ds = new DataSet();
#if !DEBUG
try
{
connection.Open();
SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
connection.Close();
}
#endif
connection.Open();
SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
connection.Close();
#if !DEBUG
}
catch (Exception e)
{
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{SQLString}】。", LogTypeEum.DbErr);
}
{
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{SQLString}】。", LogTypeEum.DbErr);
}
#endif
return ds;
}
}
@@ -84,27 +91,31 @@ namespace LeadDataBaseUtility
{
using (SQLiteCommand cmd = new SQLiteCommand(SQLString, connection))
{
#if !DEBUG
try
{
connection.Open();
object obj = cmd.ExecuteScalar();
if ((Equals(obj, null)) || (Equals(obj, System.DBNull.Value)))
{
connection.Close();
return null;
}
else
{
connection.Close();
return obj;
}
}
catch (System.Data.SQLite.SQLiteException e)
#endif
connection.Open();
object obj = cmd.ExecuteScalar();
if ((Equals(obj, null)) || (Equals(obj, System.DBNull.Value)))
{
connection.Close();
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{SQLString}】。", LogTypeEum.DbErr);
return null;
}
else
{
connection.Close();
return obj;
}
#if !DEBUG
}
catch (System.Data.SQLite.SQLiteException e)
{
connection.Close();
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{SQLString}】。", LogTypeEum.DbErr);
return null;
}
#endif
}
}
}

View File

@@ -36,6 +36,14 @@ namespace NX_LogUtility
}
public static class LogHelper
{
private readonly static System.Collections.Concurrent.BlockingCollection<string> messages = new System.Collections.Concurrent.BlockingCollection<string>();
#region 记录日志为文本文档形式
/// <summary>
/// 记录日志类
@@ -75,47 +83,54 @@ namespace NX_LogUtility
Task.Run(() =>
{
#if !DEBUG
try
{
lock (lockobj)
#endif
lock (lockobj)
{
if (!Directory.Exists(strDir))//如果日志文件存放的文件夹不存在,就新建一个文件夹。
{
if (!Directory.Exists(strDir))//如果日志文件存放的文件夹不存在,就新建一个文件夹。
{
Directory.CreateDirectory(strDir);
}
if (File.Exists(filePath))//日志文件存放路径存在,向日志文件追加记录。
{
fs = new FileStream(filePath, FileMode.Append);
}
else//日志文件存放路径不存在,创建日志文件。
{
fs = new FileStream(filePath, FileMode.Create);
}
sw = new StreamWriter(fs);
//开始写入
sw.Write(txt);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
Directory.CreateDirectory(strDir);
}
if (File.Exists(filePath))//日志文件存放路径存在,向日志文件追加记录。
{
fs = new FileStream(filePath, FileMode.Append);
}
else//日志文件存放路径不存在,创建日志文件。
{
fs = new FileStream(filePath, FileMode.Create);
}
sw = new StreamWriter(fs);
//开始写入
sw.Write(txt);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
}
#if !DEBUG
}
catch (Exception)
{
;
}
finally
{
if (sw != null)
sw.Close();
if (fs != null)
fs.Close();
#endif
if (sw != null)
sw.Close();
if (fs != null)
fs.Close();
#if !DEBUG
}
#endif
});