977 lines
45 KiB
C#
977 lines
45 KiB
C#
using CleanMachine.Model;
|
||
using CleanMachine.Model.BAS;
|
||
using CleanMachine.Model.CM;
|
||
using CleanMachineHMI.Domain.Enums;
|
||
using CleanMachineHMI.frmChild;
|
||
using CleanMachineHMI.FrmUserControl;
|
||
using CleanMachineHMI.Utils;
|
||
using Krypton.Navigator;
|
||
using Krypton.Toolkit;
|
||
using LeadDataBaseUtility;
|
||
using NX_LogUtility;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace CleanMachineHMI
|
||
{
|
||
[FormType(EnumFormType.Main)]
|
||
public partial class frmMainNew : KryptonForm
|
||
{
|
||
public frmMainNew()
|
||
{
|
||
InitializeComponent();
|
||
//清理过期任务
|
||
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.Execute(sqlZbkWorkingPallet);
|
||
LeadDbHelperSQLite.Execute(sqlZbkWorkingPalletDtl);
|
||
|
||
|
||
}
|
||
|
||
#region 全局变量
|
||
private bool isPlcConnStatus = false;
|
||
/// <summary>
|
||
/// 页面信息语言文本列表
|
||
/// </summary>
|
||
private readonly DataTable _InfoLanguageTextList;
|
||
public delegate void dlgRefreshFrmHost(string Msg);
|
||
public static dlgRefreshFrmHost RefreshFrmHost;
|
||
private bool sysAlarmFrmShowFlag = false;
|
||
public delegate void dlgShowMessage();
|
||
public static dlgShowMessage MothedShowMessage;
|
||
private int timerRunNUm = 1;
|
||
public delegate void dlgShow_ptb_Alarm(bool isShowFlag);
|
||
public static dlgShow_ptb_Alarm Show_ptb_Alarm;
|
||
public delegate void dlgShow_Plc_Alarm(string msg);
|
||
public static dlgShow_Plc_Alarm Show_Plc_Alarm;
|
||
public delegate void dlgRemoveMaintainingFlag();
|
||
public static dlgShowMessage RemoveMaintainingFlag;
|
||
#endregion
|
||
|
||
#region 主页面菜单切换
|
||
|
||
public delegate void dlgSwitchFrmMenu(EnumFormType enumFormType, bool isDefaultPage);
|
||
public static dlgSwitchFrmMenu SwitchFrmMenu;
|
||
private void AddFrmMenuPage(EnumFormType enumFormType, bool isDefaultPage)
|
||
{
|
||
//Invoke(new Action(() =>
|
||
//{
|
||
//UserControl objFrm = GlobalHelper.FrmModelList.Where(s => s.FormType == enumFormType).FirstOrDefault().Form;
|
||
Type frmType = Global.FrmModelList.Where(s => s.FormType == enumFormType).FirstOrDefault().Form;
|
||
if (isDefaultPage)
|
||
{
|
||
|
||
kryptonNavigator1.Pages[0].Controls.Clear();
|
||
|
||
//kryptonNavigator1.Pages[0].Text = enumFormType.ToString();
|
||
kryptonNavigator1.Pages[0].Name = enumFormType.ToString();
|
||
this.SetSingleControlText(kryptonNavigator1.Pages[0]);
|
||
kryptonNavigator1.SelectedPage = kryptonNavigator1.Pages[0];
|
||
if (frmType.BaseType.Name == "UserControl")
|
||
{
|
||
UserControl objFrm = (UserControl)Activator.CreateInstance(frmType);
|
||
objFrm.Dock = DockStyle.Fill;
|
||
objFrm.Parent = kryptonNavigator1.Pages[0];
|
||
objFrm.Show();
|
||
|
||
}
|
||
else
|
||
{
|
||
KryptonForm objFrm = (KryptonForm)Activator.CreateInstance(frmType);
|
||
objFrm.TopLevel = false;
|
||
objFrm.FormBorderStyle = FormBorderStyle.None;
|
||
objFrm.Dock = DockStyle.Fill;
|
||
objFrm.MinimizeBox = false;
|
||
objFrm.Parent = kryptonNavigator1.Pages[0];
|
||
objFrm.Show();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
KryptonPage tmpPage = kryptonNavigator1.Pages.FirstOrDefault(x => x.Name == enumFormType.ToString());
|
||
if (tmpPage != null)
|
||
{
|
||
kryptonNavigator1.SelectedPage = tmpPage;
|
||
}
|
||
else
|
||
{
|
||
KryptonPage tmpPage1 = new KryptonPage { Text = enumFormType.ToString(), Name = enumFormType.ToString() };
|
||
this.SetSingleControlText(tmpPage1);
|
||
|
||
ButtonSpecAny bsa = new ButtonSpecAny();
|
||
bsa.Style = PaletteButtonStyle.FormClose;
|
||
bsa.Type = PaletteButtonSpecStyle.FormClose;
|
||
bsa.Tag = tmpPage1;
|
||
bsa.Click += btnClose_Click;
|
||
kryptonNavigator1.Pages.Add(tmpPage1);
|
||
|
||
//if (enumFormType.ToString() != "IoMonitor")
|
||
//{
|
||
kryptonNavigator1.SelectedPage = tmpPage1;
|
||
kryptonNavigator1.SelectedPage.ButtonSpecs.Add(bsa);
|
||
//}
|
||
if (frmType.BaseType.Name == "UserControl")
|
||
{
|
||
UserControl objFrm = (UserControl)Activator.CreateInstance(frmType);
|
||
objFrm.Dock = DockStyle.Fill;
|
||
tmpPage1.Tag = objFrm;
|
||
objFrm.Parent = tmpPage1;
|
||
objFrm.Show();
|
||
}
|
||
else
|
||
{
|
||
KryptonForm objFrm = (KryptonForm)Activator.CreateInstance(frmType);
|
||
objFrm.TopLevel = false;
|
||
objFrm.FormBorderStyle = FormBorderStyle.None;
|
||
objFrm.Dock = DockStyle.Fill;
|
||
objFrm.MinimizeBox = false;
|
||
objFrm.Parent = tmpPage1;
|
||
tmpPage1.Tag = objFrm;
|
||
objFrm.Show();
|
||
}
|
||
}
|
||
}
|
||
//}));
|
||
}
|
||
private void btnClose_Click(object sender, EventArgs e)
|
||
{
|
||
ButtonSpecAny bsa = sender as ButtonSpecAny;
|
||
var page = bsa.Tag as KryptonPage;
|
||
|
||
foreach (var ctrl in page.Controls)
|
||
{
|
||
if (ctrl is Control)
|
||
{
|
||
(ctrl as Control).Visible = false;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
kryptonNavigator1.Pages.Remove(bsa.Tag);
|
||
kryptonNavigator1.SelectedPage = kryptonNavigator1.Pages[kryptonNavigator1.Pages.Count - 1];
|
||
if (Equals(((KryptonPage)bsa.Tag).Text, EnumFormType.Manual.ToString()))
|
||
{
|
||
//机器属于停止状态时才可进入自动模式
|
||
if (Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("ManualOrAuto", PlcItemTypeDesc.M)))
|
||
{
|
||
PlcOperationHelper.Instance.WritePlcItem("ManualOrAuto", "False", PlcItemTypeDesc.M);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
private void frmMainNew_Load(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.SetFormControlText();
|
||
SwitchFrmMenu = new dlgSwitchFrmMenu(AddFrmMenuPage);
|
||
|
||
var plcitems = new CleanMachine.BLL.BAS.PlcItemBLL().GetList("");
|
||
//foreach (var plcitem in plcitems)
|
||
//{
|
||
// switch (plcitem.PlcItemDataType)
|
||
// {
|
||
// case 0:
|
||
// Global.PlcItemMd_M_List.Add(plcitem);
|
||
// break;
|
||
|
||
// case 1:
|
||
// Global.PlcItemMd_D_List.Add(plcitem);
|
||
// break;
|
||
// case 2:
|
||
// Global.PlcItemMd_X_List.Add(plcitem);
|
||
// break;
|
||
// case 3:
|
||
// Global.PlcItemMd_Y_List.Add(plcitem);
|
||
// break;
|
||
// }
|
||
// Global.PlcItemMdList.Add(plcitem);
|
||
//}
|
||
|
||
|
||
|
||
|
||
//string sql1 = $@" SELECT * FROM BAS_PLC_ITEM ";
|
||
//DataTable dt1 = LeadDbHelperSQLite.Query(sql1).Tables[0];
|
||
//if (dt1 != null && dt1.Rows.Count > 0)
|
||
//{
|
||
//GlobalHelper.PlcItemMd_M_List = new List<PlcItem>();
|
||
//GlobalHelper.PlcItemMd_D_List = new List<PlcItem>();
|
||
//GlobalHelper.PlcItemMd_X_List = new List<PlcItem>();
|
||
//GlobalHelper.PlcItemMd_Y_List = new List<PlcItem>();
|
||
|
||
//foreach (DataRow item in dt1.Rows)
|
||
//{
|
||
// if (item["PLC_ITEM_DATA_TYPE"].ToString() == "0")
|
||
// {
|
||
// SetPlcItem(GlobalHelper.PlcItemMd_M_List, item);
|
||
// }
|
||
// else if (item["PLC_ITEM_DATA_TYPE"].ToString() == "1")
|
||
// {
|
||
// SetPlcItem(GlobalHelper.PlcItemMd_D_List, item);
|
||
// }
|
||
// else if (item["PLC_ITEM_DATA_TYPE"].ToString() == "2")
|
||
// {
|
||
// SetPlcItem(GlobalHelper.PlcItemMd_X_List, item);
|
||
// }
|
||
// else if (item["PLC_ITEM_DATA_TYPE"].ToString() == "3")
|
||
// {
|
||
// SetPlcItem(GlobalHelper.PlcItemMd_Y_List, item);
|
||
// }
|
||
//}
|
||
//GlobalHelper.PlcItemMdList = new List<PlcItem>();
|
||
//GlobalHelper.PlcItemMdList.AddRange(GlobalHelper.PlcItemMd_M_List);
|
||
//GlobalHelper.PlcItemMdList.AddRange(GlobalHelper.PlcItemMd_D_List);
|
||
//GlobalHelper.PlcItemMdList.AddRange(GlobalHelper.PlcItemMd_X_List);
|
||
//GlobalHelper.PlcItemMdList.AddRange(GlobalHelper.PlcItemMd_Y_List);
|
||
//}
|
||
InitWarningMsg();
|
||
bool isInitStatus = PlcOperationHelper.Instance.PlcInit(plcitems);
|
||
|
||
|
||
|
||
if (isInitStatus)
|
||
{
|
||
label3Professional.Text = this.T("串口打开成功,PLC连接成功!", "label3Professional_Success");
|
||
label3Professional.BackColor = Color.Lime;
|
||
isPlcConnStatus = true;
|
||
|
||
Global.SysThIsRunFlag = true;
|
||
|
||
PlcOperationHelper.Instance.StartRead();
|
||
|
||
|
||
//Thread th = new Thread(RefreshPlcItem)
|
||
//{
|
||
// IsBackground = true
|
||
//};
|
||
//th.Start();
|
||
|
||
|
||
//Thread th = new Thread(RefreshPlcItem_M)
|
||
//{
|
||
// IsBackground = true
|
||
//};
|
||
//th.Start();
|
||
|
||
//Thread th1 = new Thread(RefreshPlcItem_D)
|
||
//{
|
||
// IsBackground = true
|
||
//};
|
||
//th1.Start();
|
||
|
||
//Thread th2 = new Thread(RefreshPlcItem_X)
|
||
//{
|
||
// IsBackground = true
|
||
//};
|
||
//th2.Start();
|
||
|
||
//Thread th3 = new Thread(RefreshPlcItem_Y)
|
||
//{
|
||
// IsBackground = true
|
||
//};
|
||
//th3.Start();
|
||
|
||
Thread th4 = new Thread(MainThRunFunc)
|
||
{
|
||
IsBackground = true
|
||
};
|
||
th4.Start();
|
||
|
||
LogHelper.WriteLog($"串口打开成功,PLC连接成功!", LogTypeEum.Run);
|
||
}
|
||
else
|
||
{
|
||
//label3Professional.Text = "串口打开失败,PLC连接失败!";
|
||
label3Professional.Text = this.T("串口打开失败,PLC连接失败!", "label3Professional_Failed");
|
||
label3Professional.BackColor = Color.Red;
|
||
isPlcConnStatus = false;
|
||
|
||
LogHelper.WriteLog($"串口打开失败,PLC连接失败!", LogTypeEum.Run);
|
||
}
|
||
|
||
MothedShowMessage = new dlgShowMessage(Test);
|
||
RefreshFrmHost = new dlgRefreshFrmHost(ShowWorkingPalletFullNumAlarm);
|
||
//Show_ptb_Alarm = new dlgShow_ptb_Alarm(ShowPicAlarm);
|
||
PlcOperationHelper.Instance.OnShowMainFrmAlarmMsg += ShowPicAlarm;
|
||
Show_Plc_Alarm = new dlgShow_Plc_Alarm(ShowPlcAlarm);
|
||
RemoveMaintainingFlag = new dlgShowMessage(ClearMaintainingFlag);
|
||
timer.Enabled = true;
|
||
InitControl();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
KryptonMessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
private void ClearMaintainingFlag()
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
pictureBox1.Visible = false;
|
||
}));
|
||
}
|
||
|
||
private void ShowWarningMsg()
|
||
{
|
||
PlcItem item = PlcOperationHelper.Instance.PlcItemMd_D_List.FirstOrDefault(x => x.PlcItemCode == "AlarmPopUpMsg");
|
||
char[] tmpCharArr = Convert.ToString(Convert.ToInt32(item.PlcItemValue), 2).PadLeft(16, '0').Reverse().ToArray();
|
||
if (tmpCharArr.Contains('1'))
|
||
{
|
||
List<Warning> warnLst = new List<Warning>();
|
||
for (int j = 0; j < tmpCharArr.Length; j++)
|
||
{
|
||
if (tmpCharArr[j] == '1')
|
||
{
|
||
string priWarnCode = "bit";
|
||
Warning tmpMd = Global.BasWarningMd_List.Find(x => x.PlcItemCode == $"D12" && x.WarningCode == $"{priWarnCode + j}" && x.WarningType == "1");
|
||
if (tmpMd != null)
|
||
{
|
||
warnLst.Add(tmpMd);
|
||
}
|
||
}
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (Global.PopupWarningMsgForm == null)
|
||
{
|
||
frmPopupWarningMsg frm = new frmPopupWarningMsg();
|
||
frmPopupWarningMsg.warnLst = warnLst;
|
||
frm.TopMost = true;
|
||
frm.Show();
|
||
frmPopupWarningMsg.RefreshFrmHost();
|
||
Global.PopupWarningMsgForm = frm;
|
||
}
|
||
else
|
||
{
|
||
frmPopupWarningMsg.warnLst = warnLst;
|
||
frmPopupWarningMsg.RefreshFrmHost();
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
private void ShowPlcAlarm(string msg)
|
||
{
|
||
this.BeginInvoke(new Action(() =>
|
||
{
|
||
label3Professional.Text = msg;
|
||
}));
|
||
}
|
||
private void ShowPicAlarm()
|
||
{
|
||
|
||
ptb_Alarm.Visible = Global.CmWarningLogMd_List.Count > 0;
|
||
|
||
//Invoke(new Action(() =>
|
||
//{
|
||
// ptb_Alarm.Visible = (bool)isShowFlag;
|
||
// KryptonPage tmpPage = kryptonNavigator1.Pages.FirstOrDefault(x => x.Name == EnumFormType.PlcAlarmLog.ToString());
|
||
// if (tmpPage != null && (bool)isShowFlag)
|
||
// {
|
||
// frmPlcAlarmLog.RefreshFrmHost(false);
|
||
// }
|
||
//}));
|
||
}
|
||
private void InitWarningMsg()
|
||
{
|
||
//string sql = $@"SELECT * FROM BAS_WARNING";
|
||
//DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
|
||
//if (dt != null && dt.Rows.Count > 0)
|
||
//{
|
||
// GlobalHelper.BasWarningMd_List = new List<Warning>();
|
||
|
||
// foreach (DataRow item in dt.Rows)
|
||
// {
|
||
// GlobalHelper.BasWarningMd_List.Add(new Warning
|
||
// {
|
||
// WarningCode = item["WARNING_CODE"].ToString(),
|
||
// WarningName = item["WARNING_NAME"].ToString(),
|
||
// PlcItemCode = item["PLC_ITEM_CODE"] == null ? null : item["PLC_ITEM_CODE"].ToString(),
|
||
// WarningType = item["WARNING_TYPE"].ToString(),
|
||
// WarningMessage = item["WARNING_MESSAGE"].ToString(),
|
||
// });
|
||
// }
|
||
//}
|
||
Global.BasWarningMd_List = new CleanMachine.BLL.BAS.WarningBLL().GetList("").ToList();
|
||
Global.CmWarningLogMd_List = new List<WarningLog>();
|
||
string sql1 = $@"SELECT * FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 AND WARNING_HANDLE_RESULT =0";
|
||
DataTable dt1 = LeadDbHelperSQLite.Query(sql1).Tables[0];
|
||
if (dt1 != null && dt1.Rows.Count > 0)
|
||
{
|
||
|
||
foreach (DataRow item in dt1.Rows)
|
||
{
|
||
Global.CmWarningLogMd_List.Add(new WarningLog
|
||
{
|
||
WarningCode = item["WARNING_CODE"].ToString(),
|
||
WarningName = item["WARNING_NAME"].ToString(),
|
||
WarningType = item["WARNING_TYPE"].ToString(),
|
||
WarningMessage = item["WARNING_MESSAGE"].ToString(),
|
||
WarningTime = Convert.ToDateTime(item["WARNING_TIME"]),
|
||
PlcItemCode = item["PLC_ITEM_CODE"].ToString(),
|
||
WaringStatus = 0,
|
||
WarningHandleResult = 0,
|
||
CreateBy = Convert.ToInt32(item["CREATE_BY"]),
|
||
CreateTime = Convert.ToDateTime(item["CREATE_TIME"]),
|
||
UpdateBy = Convert.ToInt32(item["UPDATE_BY"]),
|
||
UpdateTime = Convert.ToDateTime(item["UPDATE_TIME"]),
|
||
DataVersion = Convert.ToInt32(item["DATA_VERSION"]),
|
||
});
|
||
}
|
||
string sql2 = $@"DELETE FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 AND WARNING_HANDLE_RESULT =0";
|
||
LeadDbHelperSQLite.Execute(sql2);
|
||
}
|
||
}
|
||
//private void SetPlcItem(List<PlcItem> PlcItemMdList, DataRow item)
|
||
//{
|
||
// if (PlcItemMdList != null)
|
||
// {
|
||
// PlcItem md = PlcItemMdList.Find(x => x.PlcItemCode == item["PLC_ITEM_CODE"].ToString());
|
||
// if (md != null)
|
||
// {
|
||
// md.PlcItemId = int.Parse(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());
|
||
// md.PlcItemDataType = Convert.ToInt32(item["PLC_ITEM_DATA_TYPE"].ToString());
|
||
// md.PlcItemPriAddress = item["PLC_ITEM_PRI_ADDRESS"].ToString();
|
||
// md.PlcItemModbusAddress = item["PLC_ITEM_MODBUS_ADDRESS"].ToString();
|
||
// md.PlcItemDeviationAddress = item["PLC_ITEM_DEVIATION_ADDRESS"] == null ? "" : item["PLC_ITEM_DEVIATION_ADDRESS"].ToString();
|
||
// md.PlcItemDataLength = Convert.ToInt32(item["PLC_ITEM_DATA_LENGTH"]);
|
||
// }
|
||
// else
|
||
// {
|
||
// PlcItemMdList.Add(new PlcItem
|
||
// {
|
||
// PlcItemId = int.Parse(item["PLC_ITEM_ID"].ToString()),
|
||
// PlcItemCode = item["PLC_ITEM_CODE"].ToString(),
|
||
// PlcItemName = item["PLC_ITEM_NAME"].ToString(),
|
||
// PlcItemType = Convert.ToInt32(item["PLC_ITEM_TYPE"].ToString()),
|
||
// PlcItemDataType = Convert.ToInt32(item["PLC_ITEM_DATA_TYPE"].ToString()),
|
||
// PlcItemPriAddress = item["PLC_ITEM_PRI_ADDRESS"].ToString(),
|
||
// PlcItemModbusAddress = item["PLC_ITEM_MODBUS_ADDRESS"].ToString(),
|
||
// PlcItemDeviationAddress = item["PLC_ITEM_DEVIATION_ADDRESS"] == null ? "" : item["PLC_ITEM_DEVIATION_ADDRESS"].ToString(),
|
||
// PlcItemDataLength = Convert.ToInt32(item["PLC_ITEM_DATA_LENGTH"]),
|
||
// });
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// PlcItemMdList = new List<PlcItem>();
|
||
// PlcItemMdList.Add(new PlcItem
|
||
// {
|
||
// PlcItemId = int.Parse(item["PLC_ITEM_ID"].ToString()),
|
||
// PlcItemCode = item["PLC_ITEM_CODE"].ToString(),
|
||
// PlcItemName = item["PLC_ITEM_NAME"].ToString(),
|
||
// PlcItemType = Convert.ToInt32(item["PLC_ITEM_TYPE"].ToString()),
|
||
// PlcItemDataType = Convert.ToInt32(item["PLC_ITEM_DATA_TYPE"].ToString()),
|
||
// PlcItemPriAddress = item["PLC_ITEM_PRI_ADDRESS"].ToString(),
|
||
// PlcItemModbusAddress = item["PLC_ITEM_MODBUS_ADDRESS"].ToString(),
|
||
// PlcItemDeviationAddress = item["PLC_ITEM_DEVIATION_ADDRESS"] == null ? "" : item["PLC_ITEM_DEVIATION_ADDRESS"].ToString(),
|
||
// PlcItemDataLength = Convert.ToInt32(item["PLC_ITEM_DATA_LENGTH"]),
|
||
// });
|
||
// }
|
||
//}
|
||
private void timer_Tick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
lbNow.Text = DateTime.Now.ToString();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
private void RefreshPlcItem()
|
||
{
|
||
while (Global.SysThIsRunFlag)
|
||
{
|
||
bool hashchange = false;
|
||
PlcOperationHelper.Instance.RefreshPlcItem_M(ref hashchange);
|
||
PlcOperationHelper.Instance.RefreshPlcItem_D(ref hashchange);
|
||
PlcOperationHelper.Instance.RefreshPlcItem_X(ref hashchange);
|
||
PlcOperationHelper.Instance.RefreshPlcItem_Y(ref hashchange);
|
||
ShowWarningMsg();
|
||
Thread.Sleep(100);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
#region 线程执行函数
|
||
private void RefreshPlcItem_M()
|
||
{
|
||
while (Global.SysThIsRunFlag)
|
||
{
|
||
var hashchange = false;
|
||
PlcOperationHelper.Instance.RefreshPlcItem_M(ref hashchange);
|
||
Thread.Sleep(100);
|
||
}
|
||
}
|
||
private void RefreshPlcItem_D()
|
||
{
|
||
while (Global.SysThIsRunFlag)
|
||
{
|
||
var hashchange = false;
|
||
PlcOperationHelper.Instance.RefreshPlcItem_D(ref hashchange);
|
||
ShowWarningMsg();
|
||
Thread.Sleep(100);
|
||
}
|
||
}
|
||
private void RefreshPlcItem_X()
|
||
{
|
||
while (Global.SysThIsRunFlag)
|
||
{
|
||
var hashchange = false;
|
||
PlcOperationHelper.Instance.RefreshPlcItem_X(ref hashchange);
|
||
Thread.Sleep(100);
|
||
}
|
||
}
|
||
private void RefreshPlcItem_Y()
|
||
{
|
||
while (Global.SysThIsRunFlag)
|
||
{
|
||
var hashchange = false;
|
||
PlcOperationHelper.Instance.RefreshPlcItem_Y(ref hashchange);
|
||
Thread.Sleep(100);
|
||
}
|
||
}
|
||
private void MainThRunFunc()
|
||
{
|
||
|
||
|
||
long lastTick = DateTime.Now.Ticks;
|
||
//var sysParameters = new CleanMachine.BLL.SYS.ParameterBLL().GetList("");
|
||
//int maintainAlarmTime = int.Parse(sysParameters.FirstOrDefault(m => m.ParameterCode == "MaintainAlarmTime").ParameterValue);
|
||
//int maintainTime = int.Parse(sysParameters.FirstOrDefault(m => m.ParameterCode == "MaintainTime").ParameterValue);
|
||
bool lastShowscrapRate = false;
|
||
int showdMinit = 0;
|
||
while (Global.SysThIsRunFlag)
|
||
{
|
||
#if !DEBUG
|
||
try
|
||
{
|
||
#endif
|
||
#region 定时器运行函数
|
||
//当前托报废率超过10%,则提示
|
||
string sql_CurrPalletmsg = $@"SELECT * FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
|
||
DataTable dt_CurrPalletmsg = LeadDbHelperSQLite.Query(sql_CurrPalletmsg).Tables[0];
|
||
bool showscrapRate = false;
|
||
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)
|
||
{
|
||
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
|
||
{
|
||
BeginInvoke(new Action(() => { label1.Visible = false; }));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
BeginInvoke(new Action(() => { label1.Visible = false; }));
|
||
}
|
||
}
|
||
|
||
int Minutes = 0;
|
||
if (Global.UserInfo != null)
|
||
{
|
||
|
||
int SysRunTime = (int)PlcOperationHelper.Instance.ReadPlcItem("SysRuningTime", PlcItemTypeDesc.D);
|
||
|
||
if (SysRunTime != 0)
|
||
{
|
||
new CleanMachine.BLL.CM.DayWorkTimeBLL().UpdateTime(DateTime.Today, SysRunTime, Global.UserInfo.UserName);
|
||
|
||
|
||
Minutes = (SysRunTime - CleanMachineHMI.Global.MaintainTime) / 60;
|
||
|
||
|
||
if (showdMinit != Minutes)
|
||
{
|
||
showdMinit = Minutes;
|
||
BeginInvoke(new Action(() =>
|
||
{
|
||
|
||
kryptonLabel1.Text = Minutes + " Minutes";
|
||
pictureBox1.Visible = Minutes >= Global.MaintainAlarmTime;
|
||
|
||
}));
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
//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)
|
||
// {
|
||
|
||
// if (timerRunNUm == 60)
|
||
// {
|
||
// 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 = 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)
|
||
// // {
|
||
// // 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";
|
||
// }));
|
||
// timerRunNUm = 1;
|
||
// }
|
||
// else
|
||
// {
|
||
// 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.Execute(sqlZbkWorkingPallet);
|
||
//LeadDbHelperSQLite.Execute(sqlZbkWorkingPalletDtl);
|
||
#endregion
|
||
|
||
// PlcOperationHelper.Instance.HeartbeatDetection();
|
||
ShowWarningMsg();
|
||
#endregion
|
||
#if RELEASE
|
||
}
|
||
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteLog($"定时器运行函数发生异常:【{ex.Message}】", LogTypeEum.Err);
|
||
}
|
||
#endif
|
||
Thread.Sleep(500);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
private void Test()
|
||
{
|
||
sysAlarmFrmShowFlag = false;
|
||
}
|
||
private void ShowWorkingPalletFullNumAlarm(string Msg)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (string.IsNullOrEmpty(Msg))
|
||
{
|
||
label2.Visible = false;
|
||
lbSysAlreadyRunning.Visible = true;
|
||
kryptonLabel1.Visible = true;
|
||
}
|
||
else
|
||
{
|
||
label2.Text = Msg;
|
||
label2.Visible = true;
|
||
lbSysAlreadyRunning.Visible = false;
|
||
kryptonLabel1.Visible = false;
|
||
}
|
||
}));
|
||
}
|
||
|
||
private void frmMainNew_FormClosing(object sender, FormClosingEventArgs e)
|
||
{
|
||
DialogResult dr = KryptonMessageBox.Show("Are you sure you want to close the software? If click is will close the software, please carefully operation!!!", "Prompt", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||
if (dr == DialogResult.Yes)
|
||
{
|
||
Task.Run(async delegate
|
||
{
|
||
|
||
if (Global.UserInfo != null)
|
||
|
||
{
|
||
int SysRunTime = (int)PlcOperationHelper.Instance.ReadPlcItem("SysRuningTime", PlcItemTypeDesc.D);
|
||
|
||
if (SysRunTime != 0)
|
||
{
|
||
new CleanMachine.BLL.CM.DayWorkTimeBLL().UpdateTime(DateTime.Today, SysRunTime, Global.UserInfo.UserName);
|
||
}
|
||
}
|
||
|
||
timer.Enabled = false;
|
||
Global.SysThIsRunFlag = false;
|
||
PlcOperationHelper.Instance.eventAlarmLock = true;
|
||
if (Global.CmWarningLogMd_List.Count > 0)
|
||
{
|
||
foreach (WarningLog item in Global.CmWarningLogMd_List)
|
||
{
|
||
if (item.WaringStatus == 0 && item.WarningHandleResult == 0)
|
||
{
|
||
string sql1 = $@"
|
||
INSERT INTO CM_WARNING_LOG (
|
||
WARNING_CODE,
|
||
WARNING_NAME,
|
||
WARNING_TYPE,
|
||
WARNING_MESSAGE,
|
||
WARNING_TIME,
|
||
PLC_ITEM_CODE,
|
||
WARING_STATUS,
|
||
WARNING_HANDLE_RESULT,
|
||
CREATE_BY,
|
||
CREATE_TIME,
|
||
UPDATE_BY,
|
||
UPDATE_TIME,
|
||
DATA_VERSION
|
||
)
|
||
VALUES (
|
||
'{item.WarningCode}',
|
||
'{item.WarningName}',
|
||
'{item.WarningType}',
|
||
'{item.WarningMessage}',
|
||
'{item.WarningTime.ToString("yyyy-MM-dd HH:mm:ss")}',
|
||
'{item.PlcItemCode}',
|
||
'{item.WaringStatus}',
|
||
'{item.WarningHandleResult}',
|
||
'{item.CreateBy}',
|
||
'{item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")}',
|
||
'{item.UpdateBy}',
|
||
'{item.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss")}',
|
||
'{item.DataVersion}'
|
||
);
|
||
";
|
||
LeadDbHelperSQLite.Execute(sql1);
|
||
}
|
||
else
|
||
{
|
||
string sql1 = $@"
|
||
INSERT INTO CM_WARNING_LOG (
|
||
WARNING_CODE,
|
||
WARNING_NAME,
|
||
WARNING_TYPE,
|
||
WARNING_MESSAGE,
|
||
WARNING_TIME,
|
||
PLC_ITEM_CODE,
|
||
WARING_STATUS,
|
||
WARNING_HANDLE_RESULT,
|
||
WARNING_HANDLE_TIME,
|
||
CREATE_BY,
|
||
CREATE_TIME,
|
||
UPDATE_BY,
|
||
UPDATE_TIME,
|
||
DATA_VERSION
|
||
)
|
||
VALUES (
|
||
'{item.WarningCode}',
|
||
'{item.WarningName}',
|
||
'{item.WarningType}',
|
||
'{item.WarningMessage}',
|
||
'{item.WarningTime.ToString("yyyy-MM-dd HH:mm:ss")}',
|
||
'{item.PlcItemCode}',
|
||
'{item.WaringStatus}',
|
||
'{item.WarningHandleResult}',
|
||
'{item.WarningHandleTime.ToString("yyyy-MM-dd HH:mm:ss")}',
|
||
'{item.CreateBy}',
|
||
'{item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")}',
|
||
'{item.UpdateBy}',
|
||
'{item.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss")}',
|
||
'{item.DataVersion}'
|
||
);
|
||
";
|
||
LeadDbHelperSQLite.Execute(sql1);
|
||
}
|
||
}
|
||
}
|
||
await Task.Delay(300);
|
||
|
||
if (isPlcConnStatus)
|
||
{
|
||
// 断开PLC连接
|
||
PlcOperationHelper.Instance.ClosePlcConn();
|
||
isPlcConnStatus = false;
|
||
}
|
||
if (Global.PopupWarningMsgForm != null)
|
||
Global.PopupWarningMsgForm.Close();
|
||
Environment.Exit(0);
|
||
});
|
||
}
|
||
else
|
||
{
|
||
e.Cancel = true;
|
||
}
|
||
}
|
||
|
||
private void frmMainNew_Shown(object sender, EventArgs e)
|
||
{
|
||
// InitControl();
|
||
}
|
||
private void InitControl()
|
||
{
|
||
string sqlParam = $@"SELECT * FROM SYS_PARAMETER";
|
||
DataTable dtParam = LeadDbHelperSQLite.Query(sqlParam).Tables[0];
|
||
if (dtParam != null && dtParam.Rows.Count > 0)
|
||
{
|
||
int maintainFlag = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainFlag'")[0]["PARAMETER_VALUE"]);
|
||
if (maintainFlag == 0)
|
||
{
|
||
bool canOperate = Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("SelfCheckPassFlag", PlcItemTypeDesc.M));
|
||
//自检通过则切换至主界面,否则进入自检画面
|
||
if (canOperate)
|
||
{
|
||
AddFrmMenuPage(EnumFormType.MainDetail, true);
|
||
}
|
||
else
|
||
{
|
||
AddFrmMenuPage(EnumFormType.MechineCheck, true);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AddFrmMenuPage(EnumFormType.Maintenance, true);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnExit_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
AddFrmMenuPage(EnumFormType.MainDetail, false);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
KryptonMessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
|
||
private void kryptonNavigator1_Selected(object sender, KryptonPageEventArgs e)
|
||
{
|
||
if (kryptonNavigator1.SelectedPage.Name != EnumFormType.MainDetail.ToString())
|
||
{
|
||
btnExit.Visible = true;
|
||
}
|
||
else
|
||
{
|
||
btnExit.Visible = false;
|
||
}
|
||
}
|
||
|
||
private void ptb_Alarm_Click(object sender, EventArgs e)
|
||
{
|
||
AddFrmMenuPage(EnumFormType.PlcAlarmLog, false);
|
||
frmPlcAlarmLog.RefreshFrmHost(false);
|
||
}
|
||
}
|
||
}
|