吉林安睿特调度
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.

381 lines
12 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using OPCClient;
using Opc.Ua;
using System.Net;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Reflection.Emit;
using System.Linq;
using System.Security.Cryptography;
namespace wcfControlMonitorClient
{
/// <summary>
/// Creator:Richard.liu and Jack.Ma
/// 设备实时状态显示
/// </summary>
public partial class FrmDeviceMS : Form
{
#region 变量定义
Model.MDevice _device = null;
int _deviceIndex;
DBFactory.DBOperator dboMan = CStaticClass.dboM;
DBFactory.DBOperator dbo = CStaticClass.dbo;
StringBuilder sql = new StringBuilder();
int count = 0;
/// <summary>
/// 设置要显示的设备索引
/// </summary>
public int DeviceIndex
{
set { _deviceIndex = value; }
}
private static FrmDeviceMS _formInstance;
public static FrmDeviceMS FormInstance
{
get
{
if (_formInstance == null)
{
_formInstance = new FrmDeviceMS();
}
return _formInstance;
}
set { _formInstance = value; }
}
#endregion
#region 构造函数/初始化
public FrmDeviceMS()
{
InitializeComponent();
_formInstance = this;
}
private void FrmDeviceStatus_Load(object sender, EventArgs e)
{
btnRefresh_Click(null, EventArgs.Empty);
}
#endregion
#region 更新设备状态
private void btnRefresh_Click(object sender, EventArgs e)
{
try
{
_device = Model.CGetInfo.GetDeviceInfo(_deviceIndex);
//20100108
if (_device == null)
{
MessageBox.Show("您选择的设备在数据库没有记录!", "操作提示:", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//设备索引
this.F_DeviceIndex.Text = _device.DeviceIndex.ToString();
sql = new StringBuilder();
sql.Append("SELECT * from T_Base_Device where F_DeviceIndex=").Append(_deviceIndex);
DataView dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
switch (Convert.ToInt32(dvlane[0]["F_STATE"].ToString()))
{
case 0:
this.F_STATE.Text = "空闲";
break;
case 1:
this.F_STATE.Text = "运行";
break;
case 2:
this.F_STATE.Text = "故障";
break;
case 5:
this.F_STATE.Text = "动作完成";
break;
default:
this.F_STATE.Text = "未知状态";
break;
}
//设备状态
//设备任务号
this.F_LockedState.Text = dvlane[0]["F_LockedState"].ToString();
}
int dev1;
int dev2;
switch (_deviceIndex)
{
case 13001:
dev1 = 12011;
dev2 = 12014;
this.F_DeviceIndex3.Text = "12014";
this.F_DeviceIndex2.Text = "12011";
break;
case 13002:
dev1 = 12007;
dev2 = 12008;
this.F_DeviceIndex3.Text = "12008";
this.F_DeviceIndex2.Text = "12007";
break;
default:
dev1 = 0;
dev2 = 0;
break;
}
sql.Clear();
sql.Append(string.Format("SELECT * from ZH_pallet where Device={0}", dev1));
DataView qty1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
sql.Clear();
sql.Append(string.Format("SELECT * from ZH_pallet where Device={0}", dev2));
DataView qty2 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
dataGridView1.Rows.Clear();
dataGridView2.Rows.Clear();
if (qty1.Count > 0)
{
this.Mqty1.Text = qty1[0]["qty"].ToString();
this.tray1.Text = qty1[0]["STOCK_BARCODE"].ToString();
string[] SNList = qty1[0]["SN"].ToString().Split(',');
for (int i = 0; i < SNList.Length; i++)
{
dataGridView1.Rows.Add(SNList[i]);
}
}
else
{
this.Mqty1.Text = "0";
this.tray1.Text = "";
}
if (qty2.Count > 0)
{
this.Mqty2.Text = qty2[0]["qty"].ToString();
this.tray2.Text = qty2[0]["STOCK_BARCODE"].ToString();
string[] SNList = qty2[0]["SN"].ToString().Split(',');
for (int i = 0; i < SNList.Length; i++)
{
dataGridView2.Rows.Add(SNList[i]);
}
}
else
{
this.Mqty2.Text = "0";
this.tray2.Text = "";
}
sql.Clear();
sql.Append("SELECT * from IO_INTERFACE_TASK_STATE_LOG");
DataView its = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (its.Count > 0)
{
this.testingRandomPointCode.Text = its[0]["testingRandomPointCode"].ToString();
this.productCode.Text = its[0]["productCode"].ToString();
}
else
{
this.testingRandomPointCode.Text = "";
this.productCode.Text = "无计划任务";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
#region 关闭窗体
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
private void button3_Click(object sender, EventArgs e)
{
if (MessageBox.Show("您确认要向设备:" + this._deviceIndex + "发送【完成应答】吗?", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
string errtext = string.Empty;
CStaticClass.WcfControl.BeginSendDeviceReset(this._deviceIndex, 2, new AsyncCallback(SendDeviceResetCallBack), 2);
}
void SendDeviceResetCallBack(IAsyncResult ar)
{
string errtext = string.Empty;
if (CStaticClass.WcfControl.EndSendDeviceReset(out errtext, ar) == false)
{
MessageBox.Show(errtext, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (ar.AsyncState != null)
{
//if ((((int)ar.AsyncState) == 4)&&(_device.DeviceKind==4))
//{
// CStaticClass.WcfControl.BeginSendDeviceReset(_deviceIndex, 2, new AsyncCallback(SendDeviceResetCallBack), null);
//}
if (((int)ar.AsyncState) == 2)
{
CStaticClass.WcfControl.BeginSendDeviceReset(_deviceIndex, 0, new AsyncCallback(SendDeviceResetCallBack), null);
}
}
}
}
private void FrmDeviceStatus_FormClosing(object sender, FormClosingEventArgs e)
{
_formInstance = null;
}
private void button4_Click(object sender, EventArgs e)
{
if (MessageBox.Show("您确认要向设备:" + this._deviceIndex + "发送【设备复位】吗?", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
string errtext = string.Empty;
CStaticClass.WcfControl.BeginSendDeviceReset(this._deviceIndex, 4, new AsyncCallback(SendDeviceResetCallBack), 4);
}
int GetMonitorTaskIndexFromBarCode(StringBuilder BarCode)
{//20110216
string bc = BarCode.ToString();
DataView dv = dbo.ExceSQL(string.Format("SELECT T_Monitor_Task.F_MonitorIndex FROM T_Base_Device,T_Monitor_Task WHERE T_Base_Device.F_DeviceIndex = T_Monitor_Task.F_DeviceIndex and ((T_Base_Device.F_DeviceKindIndex = 13) OR (T_Base_Device.F_DeviceKindIndex = 31)) and (F_TxtParam = '{0}') and F_Status>0 order by F_MonitorIndex asc", bc)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return Convert.ToInt32(dv[0]["F_MonitorIndex"]);
}
else
{
return -1;
}
}
void WriteDBDataCallback(IAsyncResult ar)
{
string errtext;
if (CStaticClass.WcfControl.EndWriteDBData(out errtext, ar) == false)
{
MessageBox.Show("操作提示", errtext, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
void WriteBarcodeCallback(IAsyncResult ar)
{
if (CStaticClass.WcfControl.EndWriteBarcode(ar) == false)
{
MessageBox.Show("操作提示", "补码失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("操作提示", "补码成功", MessageBoxButtons.OK, MessageBoxIcon.None);
}
}
void WriteGroupBarcodeCallback(IAsyncResult ar)
{
if (CStaticClass.WcfControl.EndWriteGroupBarcode(ar) == false)
{
MessageBox.Show("操作提示", "修改失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("操作提示", "修改成功", MessageBoxButtons.OK, MessageBoxIcon.None);
}
}
void ClearFireAlarmCallback(IAsyncResult ar)
{
if (CStaticClass.WcfControl.EndClearFireAlarm(ar) == false)
{
MessageBox.Show("操作提示", "火警暂停解除失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("操作提示", "火警暂停解除成功", MessageBoxButtons.OK, MessageBoxIcon.None);
}
}
void ClearPalletCallback(IAsyncResult ar)
{
if (CStaticClass.WcfControl.EndClearPallet(ar) == false)
{
MessageBox.Show("操作提示", "串盘锁定解除失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("操作提示", "串盘锁定解除成功", MessageBoxButtons.OK, MessageBoxIcon.None);
}
}
private void button6_Click(object sender, EventArgs e)
{
//强制满垛
string strSQL = string.Format("update ZH_pallet set GOODS_COUNT=1 where Device={0}", _deviceIndex);
int bl = dboMan.ExecuteSql(strSQL);
if (bl == 1)
{
MessageBox.Show("操作提示", "强制满垛一下发!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("没有码垛任务!!");
}
}
private void button4_Click_1(object sender, EventArgs e)
{
sql.Clear();
sql.Append(string.Format("delete from ZH_pallet where Device={0}", F_DeviceIndex2.Text.ToString()));
dbo.ExceSQL(sql.ToString());
}
private void button5_Click(object sender, EventArgs e)
{
sql.Clear();
sql.Append(string.Format("delete from ZH_pallet where Device={0}", F_DeviceIndex3.Text.ToString()));
dbo.ExceSQL(sql.ToString());
}
}
}