You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
946 lines
34 KiB
946 lines
34 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
using MESClassLibrary;
|
|
using MESClassLibrary.BLL.BasicInfo;
|
|
using MESClassLibrary.BLL.Log;
|
|
using MESClassLibrary.BLL.TruckBox;
|
|
using MESClassLibrary.DAL;
|
|
using MESClassLibrary.EFModel;
|
|
using OPCAutomation;
|
|
|
|
namespace InjectionPC
|
|
{
|
|
public partial class FrmTighten : Form
|
|
{
|
|
public FrmTighten()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#region 变量
|
|
|
|
private string strHostIP;
|
|
private string strHostName;
|
|
private OPCServer opcServer;
|
|
private OPCGroups opcGroups;
|
|
private OPCGroup opcGroup1;
|
|
private OPCItems opcItems1;
|
|
private OPCItem[] opcItemm1;
|
|
private OPCGroup opcGroup2;
|
|
private OPCItems opcItems2;
|
|
private OPCItem[] opcItemm2;
|
|
private OPCGroup opcGroup3;
|
|
private OPCItems opcItems3;
|
|
private OPCItem[] opcItemm3;
|
|
private OPCGroup opcGroup4;
|
|
private OPCItems opcItems4;
|
|
private OPCItem[] opcItemm4;
|
|
|
|
private OPCGroup opcGroup5;
|
|
private OPCItems opcItems5;
|
|
private OPCItem[] opcItemm5;
|
|
private OPCGroup opcGroup6;
|
|
private OPCItems opcItems6;
|
|
private OPCItem[] opcItemm6;
|
|
private OPCGroup opcGroup7;
|
|
private OPCItems opcItems7;
|
|
private OPCItem[] opcItemm7;
|
|
|
|
private string[] ItemIDs;
|
|
object ItemValues;
|
|
object Qualities;
|
|
object TimeStamps;
|
|
public bool Connected = false;
|
|
|
|
#endregion
|
|
|
|
string barCode = "";
|
|
private long times = 0;
|
|
|
|
private void FrmTighten_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Control.CheckForIllegalCrossThreadCalls = false;
|
|
|
|
|
|
InitList();
|
|
GetClass();
|
|
GetOpenCount();
|
|
|
|
#region 连接PLC
|
|
|
|
if (CreateServer())
|
|
{
|
|
if (ConnectServer(strHostIP, "Kepware.KEPServerEX.V6"))
|
|
{
|
|
Connected = true;
|
|
|
|
#region 创建组
|
|
|
|
opcGroups = opcServer.OPCGroups;
|
|
opcGroup1 = opcGroups.Add("Read2"); //打螺钉
|
|
SetGroupProperty(opcGroup1, 100);
|
|
opcGroup2 = opcGroups.Add("Write2");
|
|
SetGroupProperty(opcGroup2, 100);
|
|
opcGroup3 = opcGroups.Add("Write3"); //开门
|
|
SetGroupProperty(opcGroup3, 100);
|
|
|
|
opcGroup4 = opcGroups.Add("Read4"); //底涂
|
|
SetGroupProperty(opcGroup4, 100);
|
|
opcGroup5 = opcGroups.Add("Write4");
|
|
SetGroupProperty(opcGroup5, 100);
|
|
|
|
opcGroup6 = opcGroups.Add("Read5"); //视觉
|
|
SetGroupProperty(opcGroup6, 100);
|
|
opcGroup7 = opcGroups.Add("Write5");
|
|
SetGroupProperty(opcGroup6, 100);
|
|
|
|
#endregion
|
|
|
|
#region 创建项
|
|
|
|
opcItems1 = opcGroup1.OPCItems;
|
|
opcItems1.DefaultIsActive = true;
|
|
|
|
AddressBLL bll = new AddressBLL();
|
|
|
|
DataTable dt1 = CommonTools.ListToDataTable(bll.SearchInfo("2", 0));
|
|
if (dt1 != null && dt1.Rows.Count > 0)
|
|
{
|
|
opcItemm1 = new OPCItem[dt1.Rows.Count];
|
|
for (int i = 0; i < dt1.Rows.Count; i++)
|
|
{
|
|
opcItemm1[i] = opcItems1.AddItem(dt1.Rows[i]["Address"].ToString(), i);
|
|
}
|
|
}
|
|
|
|
Thread.Sleep(200);
|
|
|
|
opcItems2 = opcGroup2.OPCItems;
|
|
opcItems2.DefaultIsActive = true;
|
|
|
|
DataTable dt2 = CommonTools.ListToDataTable(bll.SearchInfo("2", 1));
|
|
if (dt2 != null && dt2.Rows.Count > 0)
|
|
{
|
|
opcItemm2 = new OPCItem[dt2.Rows.Count];
|
|
for (int i = 0; i < dt2.Rows.Count; i++)
|
|
{
|
|
opcItemm2[i] = opcItems2.AddItem(dt2.Rows[i]["Address"].ToString(), i);
|
|
}
|
|
}
|
|
|
|
opcItems3 = opcGroup3.OPCItems;
|
|
opcItems3.DefaultIsActive = true;
|
|
|
|
DataTable dt3 = CommonTools.ListToDataTable(bll.SearchInfo("3", 1));
|
|
if (dt3 != null && dt3.Rows.Count > 0)
|
|
{
|
|
opcItemm3 = new OPCItem[dt3.Rows.Count];
|
|
for (int i = 0; i < dt3.Rows.Count; i++)
|
|
{
|
|
opcItemm3[i] = opcItems3.AddItem(dt3.Rows[i]["Address"].ToString(), i);
|
|
}
|
|
}
|
|
|
|
opcItems4 = opcGroup4.OPCItems;
|
|
opcItems4.DefaultIsActive = true;
|
|
|
|
DataTable dt4 = CommonTools.ListToDataTable(bll.SearchInfo("4", 0));
|
|
if (dt4 != null && dt4.Rows.Count > 0)
|
|
{
|
|
opcItemm4 = new OPCItem[dt4.Rows.Count];
|
|
for (int i = 0; i < dt4.Rows.Count; i++)
|
|
{
|
|
opcItemm4[i] = opcItems4.AddItem(dt4.Rows[i]["Address"].ToString(), i);
|
|
}
|
|
}
|
|
|
|
opcItems5 = opcGroup5.OPCItems;
|
|
opcItems5.DefaultIsActive = true;
|
|
|
|
DataTable dt5 = CommonTools.ListToDataTable(bll.SearchInfo("4", 1));
|
|
if (dt5 != null && dt5.Rows.Count > 0)
|
|
{
|
|
opcItemm5 = new OPCItem[dt5.Rows.Count];
|
|
for (int i = 0; i < dt5.Rows.Count; i++)
|
|
{
|
|
opcItemm5[i] = opcItems5.AddItem(dt5.Rows[i]["Address"].ToString(), i);
|
|
}
|
|
}
|
|
|
|
opcItems6 = opcGroup6.OPCItems;
|
|
opcItems6.DefaultIsActive = true;
|
|
|
|
DataTable dt6 = CommonTools.ListToDataTable(bll.SearchInfo("5", 0));
|
|
if (dt6 != null && dt6.Rows.Count > 0)
|
|
{
|
|
opcItemm6 = new OPCItem[dt6.Rows.Count];
|
|
for (int i = 0; i < dt6.Rows.Count; i++)
|
|
{
|
|
opcItemm6[i] = opcItems6.AddItem(dt6.Rows[i]["Address"].ToString(), i);
|
|
}
|
|
}
|
|
|
|
opcItems7 = opcGroup7.OPCItems;
|
|
opcItems7.DefaultIsActive = true;
|
|
|
|
DataTable dt7 = CommonTools.ListToDataTable(bll.SearchInfo("5", 1));
|
|
if (dt7 != null && dt7.Rows.Count > 0)
|
|
{
|
|
opcItemm7 = new OPCItem[dt7.Rows.Count];
|
|
for (int i = 0; i < dt7.Rows.Count; i++)
|
|
{
|
|
opcItemm7[i] = opcItems7.AddItem(dt7.Rows[i]["Address"].ToString(), i);
|
|
}
|
|
}
|
|
|
|
if (ReadSingleValueFromOPC(opcItemm4,0).ToString().ToLower()=="true" || ReadSingleValueFromOPC(opcItemm4,1).ToString().ToLower()=="true")
|
|
{
|
|
timer1.Start();
|
|
}
|
|
|
|
opcGroup1.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup1_DataChange);
|
|
opcGroup4.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup4_DataChange);
|
|
opcGroup5.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup5_DataChange);
|
|
opcGroup6.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup6_DataChange);
|
|
|
|
#endregion
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("连接到OPC服务器失败!", "提示", MessageBoxButtons.OK);
|
|
Connected = false;
|
|
LogHelper.WriteLog("连接到OPC服务器失败!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("创建OPC服务失败!", "提示", MessageBoxButtons.OK);
|
|
Connected = false;
|
|
LogHelper.WriteLog("创建OPC服务失败!");
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
times = 0;
|
|
|
|
Thread t = new Thread(new ThreadStart(TimeGo));
|
|
t.Start();
|
|
Thread t2 = new Thread(new ThreadStart(TimeGo2));
|
|
t2.Start();
|
|
|
|
//Thread t3 = new Thread(new ThreadStart(TimeGo3));
|
|
//t3.Start();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拧紧
|
|
/// </summary>
|
|
/// <param name="TransactionID"></param>
|
|
/// <param name="NumItems"></param>
|
|
/// <param name="ClientHandles"></param>
|
|
/// <param name="ItemValues"></param>
|
|
/// <param name="Qualities"></param>
|
|
/// <param name="TimeStamps"></param>
|
|
void opcGroup1_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps)
|
|
{
|
|
try
|
|
{
|
|
InspectionBLL bll = new InspectionBLL();
|
|
TightenBLL tbll = new TightenBLL();
|
|
tb_TightenInfo tmd=new tb_TightenInfo();
|
|
tb_Inspection_tx md = new tb_Inspection_tx();
|
|
|
|
int isOk = 0, isOk1 = 0, isOk2 = 0, isOk3 = 0, isOk4 = 0, isOk5 = 0, isOk6 = 0, isOk7 = 0;
|
|
double torque1 = 0, torque2 = 0, torque3 = 0, torque4 = 0, torque5 = 0, torque6 = 0, torque7 = 0;
|
|
double angle1 = 0, angle2 = 0, angle3 = 0, angle4 = 0, angle5 = 0, angle6 = 0, angle7 = 0;
|
|
|
|
for (int i = 1; i <= NumItems; i++)
|
|
{
|
|
int handle = Convert.ToInt32(ClientHandles.GetValue(i).ToString().Trim());
|
|
string value = ItemValues.GetValue(i).ToString();
|
|
string address = opcItemm1[(Convert.ToInt32(ClientHandles.GetValue(i)))].ItemID;
|
|
|
|
#region 拧紧工位条码信息
|
|
|
|
if (handle == 0)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(value))
|
|
{
|
|
var list = bll.SearchInfoByBarCode(value);
|
|
if (list.Count > 0)
|
|
{
|
|
foreach (var x in list)
|
|
{
|
|
if (x.IsOK == 1)
|
|
{
|
|
opcItemm2[0].Write(2); //合格
|
|
barCode = value;
|
|
}
|
|
else
|
|
{
|
|
opcItemm2[0].Write(3); //不合格
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 拧紧完成
|
|
|
|
if (handle == 1)
|
|
{
|
|
if (value == "1" || value.ToLower() == "true")
|
|
{
|
|
isOk = ReadSingleValueFromOPC(opcItemm1, 2).ToString()== "1" ? 1 : 0;
|
|
isOk1 = ReadSingleValueFromOPC(opcItemm1, 3).ToString() == "1" ? 1 : 0;
|
|
isOk2 = ReadSingleValueFromOPC(opcItemm1, 4).ToString() == "1" ? 1 : 0;
|
|
isOk3 = ReadSingleValueFromOPC(opcItemm1, 5).ToString() == "1" ? 1 : 0;
|
|
isOk4 = ReadSingleValueFromOPC(opcItemm1, 6).ToString() == "1" ? 1 : 0;
|
|
isOk5 = ReadSingleValueFromOPC(opcItemm1, 7).ToString() == "1" ? 1 : 0;
|
|
isOk6 = ReadSingleValueFromOPC(opcItemm1, 8).ToString() == "1" ? 1 : 0;
|
|
isOk7 = ReadSingleValueFromOPC(opcItemm1, 9).ToString() == "1" ? 1 : 0;
|
|
|
|
torque1 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 10));
|
|
torque2 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 11));
|
|
torque3 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 12));
|
|
torque4 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 13));
|
|
torque5 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 14));
|
|
torque6 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 15));
|
|
torque7 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 16));
|
|
|
|
angle1 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 17));
|
|
angle2 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 18));
|
|
angle3 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 19));
|
|
angle4 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 20));
|
|
angle5 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 21));
|
|
angle6 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 22));
|
|
angle7 = Convert.ToDouble(ReadSingleValueFromOPC(opcItemm1, 23));
|
|
|
|
Thread.Sleep(1000);
|
|
opcItemm2[1].Write(2); //=2是MES读取完成
|
|
|
|
//Thread.Sleep(2000);
|
|
//string x = "1";
|
|
//if (Convert.ToBoolean(ReadSingleValueFromOPC(opcItemm2, 1)).ToString().ToLower() == x.ToLower())
|
|
//{
|
|
//MessageBox.Show(ReadSingleValueFromOPC(opcItemm2, 1).ToString());
|
|
//}
|
|
//else
|
|
//{
|
|
// MessageBox.Show("写入失败");
|
|
//}
|
|
|
|
#region 存储数据
|
|
|
|
tmd.BarCode = barCode;
|
|
tmd.IsOK = isOk;
|
|
tmd.IsOK1 = isOk1;
|
|
tmd.IsOK2 = isOk2;
|
|
tmd.IsOK3 = isOk3;
|
|
tmd.IsOK4 = isOk4;
|
|
tmd.IsOK5 = isOk5;
|
|
tmd.IsOK6 = isOk6;
|
|
tmd.IsOK7 = isOk7;
|
|
tmd.Torque1 = torque1;
|
|
tmd.Torque2 = torque2;
|
|
tmd.Torque3 = torque3;
|
|
tmd.Torque4 = torque4;
|
|
tmd.Torque5 = torque5;
|
|
tmd.Torque6 = torque6;
|
|
tmd.Torque7 = torque7;
|
|
tmd.Angle1 = angle1;
|
|
tmd.Angle2 = angle2;
|
|
tmd.Angle3 = angle3;
|
|
tmd.Angle4 = angle4;
|
|
tmd.Angle5 = angle5;
|
|
tmd.Angle6 = angle6;
|
|
tmd.Angle7 = angle7;
|
|
tbll.AddInfo(tmd);
|
|
|
|
md.BarCode = barCode;
|
|
md.IsOK = isOk;
|
|
md.Station = 3;
|
|
bll.AddInfo(md);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 底涂读
|
|
/// </summary>
|
|
/// <param name="TransactionID"></param>
|
|
/// <param name="NumItems"></param>
|
|
/// <param name="ClientHandles"></param>
|
|
/// <param name="ItemValues"></param>
|
|
/// <param name="Qualities"></param>
|
|
/// <param name="TimeStamps"></param>
|
|
void opcGroup4_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues,
|
|
ref Array Qualities, ref Array TimeStamps)
|
|
{
|
|
try
|
|
{
|
|
for (int i = 1; i <= NumItems; i++)
|
|
{
|
|
int handle = Convert.ToInt32(ClientHandles.GetValue(i).ToString().Trim());
|
|
string value = ItemValues.GetValue(i).ToString();
|
|
string address = opcItemm4[(Convert.ToInt32(ClientHandles.GetValue(i)))].ItemID;
|
|
|
|
AddressBLL bll=new AddressBLL();
|
|
|
|
bll.UpdateValue(address, value);
|
|
if (handle == 0 || handle == 1)
|
|
{
|
|
if (value.ToLower() == "true")
|
|
{
|
|
timer1.Start();
|
|
}
|
|
else
|
|
{
|
|
timer1.Stop();
|
|
}
|
|
}
|
|
|
|
|
|
if (handle == 2 || handle == 3)
|
|
{
|
|
if (value.ToLower() == "true")
|
|
{
|
|
|
|
if (handle == 2)
|
|
{
|
|
bll.UpdateValue("BBMPT1.ZP.WriteDone1", "False");
|
|
}
|
|
else
|
|
{
|
|
bll.UpdateValue("BBMPT1.ZP.WriteDone2", "False");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
|
}
|
|
}
|
|
|
|
void opcGroup5_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues,
|
|
ref Array Qualities, ref Array TimeStamps)
|
|
{
|
|
try
|
|
{
|
|
for (int i = 1; i <= NumItems; i++)
|
|
{
|
|
int handle = Convert.ToInt32(ClientHandles.GetValue(i).ToString().Trim());
|
|
string value = ItemValues.GetValue(i).ToString();
|
|
//string address = opcItemm1[(Convert.ToInt32(ClientHandles.GetValue(i)))].ItemID;
|
|
|
|
if (handle == 4 || handle == 5)
|
|
{
|
|
if (value.ToLower() == "true")
|
|
{
|
|
timer1.Start();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 视觉检测
|
|
/// </summary>
|
|
/// <param name="TransactionID"></param>
|
|
/// <param name="NumItems"></param>
|
|
/// <param name="ClientHandles"></param>
|
|
/// <param name="ItemValues"></param>
|
|
/// <param name="Qualities"></param>
|
|
/// <param name="TimeStamps"></param>
|
|
void opcGroup6_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps)
|
|
{
|
|
InspectionBLL bll = new InspectionBLL();
|
|
tb_Inspection_tx md = new tb_Inspection_tx();
|
|
|
|
string code = "";
|
|
int isOk = 0;
|
|
|
|
for (int i = 1; i <= NumItems; i++)
|
|
{
|
|
int handle = Convert.ToInt32(ClientHandles.GetValue(i).ToString().Trim());
|
|
string value = ItemValues.GetValue(i).ToString();
|
|
|
|
#region 视觉检测结果
|
|
|
|
if (handle == 1)
|
|
{
|
|
if (value == "1") //OK
|
|
{
|
|
code = ReadSingleValueFromOPC(opcItemm6, 0).ToString();
|
|
isOk = 1;
|
|
Thread.Sleep(1000);
|
|
opcItemm7[0].Write(1);
|
|
}
|
|
if (value == "2") //NG
|
|
{
|
|
code = ReadSingleValueFromOPC(opcItemm6, 0).ToString();
|
|
isOk = 0;
|
|
Thread.Sleep(1000);
|
|
opcItemm7[0].Write(1);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(code))
|
|
{
|
|
#region 存质检结果
|
|
|
|
md.BarCode = code;
|
|
md.IsOK = isOk;
|
|
md.Station = 5;
|
|
|
|
bll.AddInfo(md);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建服务
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private bool CreateServer()
|
|
{
|
|
try
|
|
{
|
|
opcServer = new OPCServer();
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 连接到服务器
|
|
/// </summary>
|
|
/// <param name="strHostIP"></param>
|
|
/// <param name="strHostName"></param>
|
|
/// <returns></returns>
|
|
private bool ConnectServer(string strHostIP, string strHostName)
|
|
{
|
|
try
|
|
{
|
|
opcServer.Connect(strHostName, strHostIP);
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置组的属性
|
|
/// </summary>
|
|
/// <param name="opcGroup"></param>
|
|
/// <param name="updateRate"></param>
|
|
private void SetGroupProperty(OPCGroup opcGroup, int updateRate)
|
|
{
|
|
opcGroup.IsActive = true;
|
|
opcGroup.DeadBand = 0;
|
|
opcGroup.UpdateRate = updateRate;
|
|
opcGroup.IsSubscribed = true;
|
|
}
|
|
|
|
public object ReadSingleValueFromOPC(OPCItem[] item, int i)
|
|
{
|
|
object ItemValues;
|
|
object Qualities;
|
|
object TimeStamps;
|
|
|
|
item[i].Read(1, out ItemValues, out Qualities, out TimeStamps);
|
|
|
|
if ((ItemValues != null) && (Qualities.ToString() != "Good"))
|
|
{
|
|
return ItemValues.ToString();
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private void TimeGo()
|
|
{
|
|
System.Timers.Timer timer = new System.Timers.Timer();
|
|
timer.Interval = 1000;
|
|
timer.Enabled = true;
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Tick);
|
|
}
|
|
|
|
private void TimeGo2()
|
|
{
|
|
System.Timers.Timer timer = new System.Timers.Timer();
|
|
timer.Interval = 60000;
|
|
timer.Enabled = true;
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer2_Tick);
|
|
}
|
|
|
|
private void TimeGo3()
|
|
{
|
|
System.Timers.Timer timer = new System.Timers.Timer();
|
|
timer.Interval = 1000;
|
|
timer.Enabled = true;
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer3_Tick);
|
|
}
|
|
|
|
private void timer_Tick(object sender, EventArgs e)
|
|
{
|
|
label2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
try
|
|
{
|
|
times++;
|
|
if (times % 2 == 0)
|
|
{
|
|
opcItemm2[2].Write(0);
|
|
opcItemm7[1].Write(0);
|
|
}
|
|
else
|
|
{
|
|
opcItemm2[2].Write(1);
|
|
opcItemm7[1].Write(1);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
}
|
|
Thread.Sleep(500);
|
|
}
|
|
|
|
private void textBox1_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
BarCodeBLL bll=new BarCodeBLL();
|
|
InspectionBLL ibll = new InspectionBLL();
|
|
ScanRecordBLL sbll = new ScanRecordBLL();
|
|
|
|
tb_ScanRecord_OpenDoor md=new tb_ScanRecord_OpenDoor();
|
|
tb_Inspection_tx imd = new tb_Inspection_tx();
|
|
|
|
#region 校验有效性
|
|
|
|
if (string.IsNullOrWhiteSpace(textBox1.Text))
|
|
{
|
|
MessageBox.Show("条码不能为空!", "提示", MessageBoxButtons.OK);
|
|
textBox1.Focus();
|
|
textBox1.SelectAll();
|
|
return;
|
|
}
|
|
|
|
if (!bll.IsExist(textBox1.Text.Trim()))
|
|
{
|
|
MessageBox.Show("条码有误!", "提示", MessageBoxButtons.OK);
|
|
textBox1.Focus();
|
|
textBox1.SelectAll();
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
md.BarCode = textBox1.Text.Trim();
|
|
md.ScanTime=DateTime.Now;
|
|
|
|
#region 判断质检是否合格
|
|
|
|
var list=ibll.SearchInfoByBarCode(textBox1.Text.Trim());
|
|
if (list.Count > 0)
|
|
{
|
|
foreach (var x in list)
|
|
{
|
|
if (x.IsOK == 0)
|
|
{
|
|
opcItemm3[1].Write(1); //NG
|
|
md.IsOk = 0;
|
|
}
|
|
else
|
|
{
|
|
opcItemm3[0].Write(1); //OK
|
|
md.IsOk = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
sbll.AddInfo(md);
|
|
|
|
#region 存质检结果
|
|
|
|
imd.BarCode = textBox1.Text.Trim();
|
|
imd.IsOK = md.IsOk;
|
|
imd.Station = 4;
|
|
|
|
ibll.AddInfo(imd);
|
|
|
|
#endregion
|
|
|
|
InitList();
|
|
GetOpenCount();
|
|
|
|
textBox1.SelectAll();
|
|
textBox1.Focus();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
|
}
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
AddressBLL bll=new AddressBLL();
|
|
|
|
DataTable dt = CommonTools.ListToDataTable(bll.GetDoneValue());
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
if (i == 0 && dt.Rows[0]["RealValue"].ToString().ToLower()=="true")
|
|
{
|
|
#region 1#罐子
|
|
|
|
opcItemm5[0].Write(bll.GetTimeValue(54)); //失效时间
|
|
opcItemm5[1].Write(bll.GetTimeValue(55)); //保质期
|
|
opcItemm5[4].Write(1);
|
|
|
|
#endregion
|
|
}
|
|
if (i == 1 && dt.Rows[1]["RealValue"].ToString().ToLower() == "true")
|
|
{
|
|
#region 2#罐子
|
|
|
|
opcItemm5[2].Write(bll.GetTimeValue(56)); //失效时间
|
|
opcItemm5[3].Write(bll.GetTimeValue(57)); //保质期
|
|
opcItemm5[5].Write(1);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
}
|
|
}
|
|
|
|
private void label2_Click(object sender, EventArgs e)
|
|
{
|
|
Environment.Exit(0);
|
|
}
|
|
|
|
private void InitList()
|
|
{
|
|
try
|
|
{
|
|
ScanRecordBLL bll =new ScanRecordBLL();
|
|
|
|
string t1="", t2="";
|
|
if (DateTime.Now.Hour >= 8 && DateTime.Now.Hour <20)
|
|
{
|
|
t1 = DateTime.Now.ToString("yyyy-MM-dd") + " 08:00:00";
|
|
t2 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
else if (DateTime.Now.Hour >= 20 && DateTime.Now.Hour <= 23)
|
|
{
|
|
t1 = DateTime.Now.ToString("yyyy-MM-dd") + " 20:00:00";
|
|
t2 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
else
|
|
{
|
|
t1 = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + " 20:00:00";
|
|
t2 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
|
|
glacialList1.Items.Clear();
|
|
|
|
DataTable dt = bll.SearchInfo(t1, t2);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
glacialList1.Items.Add(i.ToString());
|
|
glacialList1.Items[i].SubItems[0].Text = dt.Rows[i]["BarCode"].ToString();
|
|
glacialList1.Items[i].SubItems[1].Text = dt.Rows[i]["ProductName"].ToString();
|
|
glacialList1.Items[i].SubItems[2].Text = dt.Rows[i]["IsOk"].ToString() == "1" ? "通过" : "未通过";
|
|
glacialList1.Items[i].SubItems[3].Text = dt.Rows[i]["ScanTime"].ToString();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
|
}
|
|
}
|
|
|
|
private DateTime GetDateTime()
|
|
{
|
|
string sql = "";
|
|
DateTime time;
|
|
DataTable dt;
|
|
try
|
|
{
|
|
sql = @"select convert(char(23),getdate(),121) as time";
|
|
|
|
dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
time = DateTime.ParseExact(dt.Rows[0]["time"].ToString(), "yyyy-MM-dd HH:mm:ss.fff",
|
|
System.Globalization.CultureInfo.CurrentCulture);
|
|
|
|
}
|
|
else
|
|
{
|
|
time = DateTime.Now;
|
|
}
|
|
return time;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return DateTime.Now;
|
|
}
|
|
}
|
|
|
|
private void GetClass()
|
|
{
|
|
try
|
|
{
|
|
DateTime aa = GetDateTime();
|
|
|
|
if (GetDateTime().Hour >= 8 && GetDateTime().Hour < 20)
|
|
{
|
|
Program.Shift = "白班";
|
|
|
|
}
|
|
else
|
|
{
|
|
Program.Shift = "夜班";
|
|
}
|
|
|
|
comboBox1.Text = Program.Shift;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
}
|
|
}
|
|
|
|
private void GetOpenCount()
|
|
{
|
|
try
|
|
{
|
|
ScanRecordBLL bll = new ScanRecordBLL();
|
|
string startTime = "", endTime = "";
|
|
if (comboBox1.Text == "白班")
|
|
{
|
|
startTime = DateTime.Now.ToString("yyyy-MM-dd") + " 08:00:00";
|
|
endTime = DateTime.Now.ToString("yyyy-MM-dd") + " 20:00:00";
|
|
|
|
}
|
|
else
|
|
{
|
|
if (DateTime.Now.Hour <= 7)
|
|
{
|
|
startTime = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + " 20:00:00";
|
|
endTime = DateTime.Now.ToString("yyyy-MM-dd") + " 08:00:00";
|
|
}
|
|
else
|
|
{
|
|
startTime = DateTime.Now.ToString("yyyy-MM-dd") + " 20:00:00";
|
|
endTime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + " 08:00:00";
|
|
}
|
|
}
|
|
|
|
label6.Text = bll.ScanCount(startTime, endTime);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
}
|
|
}
|
|
|
|
private void timer2_Tick(object sender, EventArgs e)
|
|
{
|
|
GetClass();
|
|
GetOpenCount();
|
|
}
|
|
|
|
private void timer3_Tick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
times++;
|
|
if (times % 2 == 0)
|
|
{
|
|
opcItemm2[2].Write(0);
|
|
opcItemm7[1].Write(0);
|
|
}
|
|
else
|
|
{
|
|
opcItemm2[2].Write(1);
|
|
opcItemm7[1].Write(1);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|