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.

2876 lines
133 KiB

using System;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using System.Net;
using CommonLib;
using System.Speech.Synthesis;
namespace wcfControlMonitorClient
{
public partial class FrmClient : Form, WcfControlMonitor.IControlMonitorCallback
{
//protected override CreateParams CreateParams
//{
// get
// {
// CreateParams cp = base.CreateParams;
// cp.ExStyle |= 0x02000000;//WS_CLIPCHILDREN 两个窗体叠加时,重叠部分不重绘
// return cp;
// }
//}
int timersum = 0;//20150103增加断网恢复
Model.MDevice devinfo;
FrmDeviceStatus _deviceStatus = new FrmDeviceStatus();
FrmWorkstationStatus _worstation = new FrmWorkstationStatus();
StringBuilder sql = new StringBuilder();
DBFactory.DBOperator dbo = CStaticClass.dbo;
DBFactory.DBOperator dbo1 = new DBFactory.DBOperator();
//SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
//public SpVoice Voice = new SpVoice();
private static SpeechSynthesizer speak = new SpeechSynthesizer();
public Model.MDevice[] devlist;
public int devsn = 0;
private static FrmClient _formInstance;
public static FrmClient FormInstance
{
get
{
if (_formInstance == null)
{
_formInstance = new FrmClient();
}
return _formInstance;
}
set { _formInstance = value; }
}
public FrmClient()
{
CommonClassLib.CCarryConvert.WriteDarkCasket("Login", "操作日志", "FrmClient()", "", "");
InitializeComponent();
try
{
//初始化管理和调度交互状态
Model.CGetInfo.AddIOControlStatus();
Model.CGetInfo.AddDeviceKindInfo();
Model.CGetInfo.AddDeviceInfo();
Model.CGetInfo.AddDeviceErrors();
devlist = Model.CGetInfo.DeviceInfo.Values.ToArray<Model.MDevice>();
DataView dv0 = dbo.ExceSQL("SELECT distinct F_S7Connection,F_DBWGetLength FROM T_Base_Device WHERE (F_DeviceKindIndex = 28)").Tables[0].DefaultView;
if (dv0.Count > 0)
{
for (int i = 0; i < dv0.Count; i++)
{
if (CStaticClass.MutiS7ConnReturns.ContainsKey(dv0[i]["F_S7Connection"].ToString()) == false)
{
CStaticClass.MutiS7ConnReturns.Add(dv0[i]["F_S7Connection"].ToString(), new int[Convert.ToInt32(dv0[i]["F_DBWGetLength"])]);
}
}
}
CStaticClass.SystemName = CommonClassLib.AppSettings.GetValue("SystemName");
this.notifyIcon1.Text = CStaticClass.SystemName;
this.Text = CStaticClass.SystemName;
#region 客户端订阅初始化20120428
DataView dvx;
DataView dv = dbo.ExceSQL("SELECT F_ReadSubscription, F_DeviceIndex, F_DBW2Address, F_DBWGetLength, F_S7Connection, F_SplitByte FROM T_Base_Device WHERE (F_ReadSubscription IS NOT NULL) AND (F_ReadSubscription =F_DeviceIndex) ORDER BY F_ReadSubscription").Tables[0].DefaultView;
for (int i = 0; i < dv.Count; i++)
{
dvx = dbo.ExceSQL(string.Format("SELECT (MAX(F_DBW2Address) + F_DBWGetLength) AS maxdbw2 FROM T_Base_Device WHERE (F_ReadSubscription = '{0}') AND (F_DeviceKindIndex <> 33) GROUP BY F_DBWGetLength ORDER BY maxdbw2 DESC", dv[i]["F_ReadSubscription"])).Tables[0].DefaultView;
if (dvx.Count > 0)
{
if (CStaticClass.MutiReadSubscriptionDeviceStateReturns.ContainsKey(dv[i]["F_ReadSubscription"].ToString()) == false)
{
CStaticClass.MutiReadSubscriptionDeviceStateReturns.Add(dv[i]["F_ReadSubscription"].ToString(), new int[Convert.ToInt32(dvx[0]["maxdbw2"]) - Convert.ToInt32(dv[i]["F_DBW2Address"])]);
}
}
}
dv = dbo.ExceSQL("SELECT F_ReadSubscription, F_DeviceIndex, F_DBW2Address, F_DBWGetLength, F_S7Connection, F_SplitByte FROM T_Base_Device WHERE (F_ReadSubscription IS NOT NULL) AND (F_DeviceKindIndex=33) ORDER BY F_ReadSubscription").Tables[0].DefaultView;
for (int i = 0; i < dv.Count; i++)
{
if (CStaticClass.MutiReadSubscriptionDeviceSplitReturns.ContainsKey(dv[i]["F_ReadSubscription"].ToString()) == false)
{
CStaticClass.MutiReadSubscriptionDeviceSplitReturns.Add(dv[i]["F_ReadSubscription"].ToString(), new int[Convert.ToInt32(dv[i]["F_DBWGetLength"])]);
}
}
CommonClassLib.CCarryConvert.WriteDarkCasket("Login", "操作日志", "FrmClient()-准备CreateSubscriptionGroup", "", "");
OPCClient.CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");
OPCClient.CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
OPCClient.CCommonOPCClient.CreateSubscriptionGroup();
CommonClassLib.CCarryConvert.WriteDarkCasket("Login", "操作日志", "FrmClient()-CreateSubscriptionGroup", "", "");
OPCClient.CCommonOPCClient.UpdateDB += new CUpdateDBEventHandler(CCommon_UpdateDB);
if (OPCClient.CCommonOPCClient.OpcError != null)
{
MessageBox.Show(OPCClient.CCommonOPCClient.OpcError);
}
}
catch (Exception ex)
{
CommonClassLib.CCarryConvert.WriteDarkCasket("Login", "操作日志", "FrmClient()-catch", ex.StackTrace, ex.Message);
throw ex;
}
#endregion
}
/// <summary>
/// 客户端事件响应20120428
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void CCommon_UpdateDB(object sender, CUpdateDBChangeEventArgs e)
{
if (CStaticClass.WCFOK == true && !CStaticClass.client.IsDisposed)
{
string errtext = string.Empty;
this.BeginInvoke(new MethodInvoker(delegate()
{ DealWithDeviceState(out errtext, e.Deviceindex, e.SplitbyteValue, e.Devicestates); }));
}
}
/// <summary>
/// 客户端事件响应处理函数20120428
/// </summary>
/// <param name="errtext"></param>
/// <param name="deviceindex"></param>
/// <param name="splitbyteValue"></param>
/// <param name="devicestates"></param>
/// <returns></returns>
bool DealWithDeviceState(out string errtext, int deviceindex, byte[] splitbyteValue, byte[] devicestates)
{//deviceindex设备组代表的订阅,首先把设备组按照F_DBW2Address由小到大排序,拆分到具体每个设备
if ((devicestates == null))//(splitbyteValue == null) &&
{//20120420
errtext = OPCClient.CCommonOPCClient.OpcError;
SendMessage(string.Format("tsStatus@FrmClient.DealWithDeviceState时,订阅组:{0}发生异常,{1}!", deviceindex, errtext));
return false;
}
errtext = string.Empty; DataView dv = new DataView(); DataView dvsp = new DataView(); DataView dvbc = new DataView();
//int devicebegin = 0; int DBW2Addressbegin = 0; string S7Connection = string.Empty;
//int SplitByteLength = 0;
try
{
//StringBuilder sql = new StringBuilder(string.Format("SELECT F_DeviceIndex, F_DBW2Address, F_DBWGetLength, F_SplitByte,F_S7Connection FROM T_Base_Device WHERE (F_DeviceKindIndex <>33) AND (F_ReadSubscription = '{0}') AND (F_DBW2Address IS NOT NULL) ORDER BY F_DBW2Address", deviceindex));
//dv = dbo1.ExceSQL(sql.ToString()).Tables[0].DefaultView;
//if (dv.Count > 0)
//{
// devicebegin = Convert.ToInt32(dv[0]["F_DeviceIndex"]);
// DBW2Addressbegin = Convert.ToInt32(dv[0]["F_DBW2Address"]);
// //SplitBytebegin = Convert.ToInt32(dv[0]["F_SplitByte"]);
// S7Connection = dv[0]["F_S7Connection"].ToString();
// sql = new StringBuilder(string.Format("SELECT F_DeviceIndex, F_DBW2Address, F_DBWGetLength, F_SplitByte,F_S7Connection FROM T_Base_Device WHERE (F_DeviceKindIndex =33) AND (F_ReadSubscription = '{0}') ORDER BY F_DBW2Address", deviceindex));
// dvsp = dbo1.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dvsp.Count > 0)
// {
// SplitByteLength = Convert.ToInt32(dvsp[0]["F_DBWGetLength"]);
// }
//}
//else
//{
// sql = new StringBuilder(string.Format("SELECT F_DeviceIndex, F_DBW2Address, F_DBWGetLength, F_SplitByte,F_S7Connection FROM T_Base_Device WHERE (F_DeviceIndex = '{0}') AND (F_DBW2Address IS NOT NULL) ORDER BY F_DBW2Address", deviceindex));
// dv = dbo1.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// devicebegin = Convert.ToInt32(dv[0]["F_DeviceIndex"]);
// DBW2Addressbegin = Convert.ToInt32(dv[0]["F_DBW2Address"]);
// //SplitBytebegin = Convert.ToInt32(dv[0]["F_SplitByte"]);
// S7Connection = dv[0]["F_S7Connection"].ToString();
// sql = new StringBuilder(string.Format("SELECT F_DeviceIndex, F_DBW2Address, F_DBWGetLength, F_SplitByte,F_S7Connection FROM T_Base_Device WHERE (F_DeviceKindIndex =33) AND (F_ReadSubscription = '{0}') ORDER BY F_DBW2Address", deviceindex));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// SplitByteLength = Convert.ToInt32(dv[0]["F_DBWGetLength"]);
// }
// }
// else
// {//20120420
// errtext = string.Format("FrmClient.DealWithDeviceState时,订阅组:{0}对应的设备索引不存在!", deviceindex);
// SendMessage(string.Format("tsStatus@FrmClient.DealWithDeviceState时,订阅组:{0}对应的设备索引不存在!", deviceindex));
// return false;
// }
//}
//int tempdb2addr = 0; StringBuilder sss = new StringBuilder(); StringBuilder barcode = new StringBuilder();
if (devicestates != null)
{
Array.Copy(devicestates, CStaticClass.MutiReadSubscriptionDeviceStateReturns[deviceindex.ToString()], devicestates.Length);
//for (int di = 0; di < dv.Count; di++)
//{
// int devidx = Convert.ToInt32(dv[di]["F_DeviceIndex"]);
// devinfo = Model.CGetInfo.GetDeviceInfo(devidx);
// int taskindex = 0;
// int state = 0;
// //以下代码重新开发CStaticClass.MutiS7ConnReturns改为按照F_ReadSubscription
// if (devinfo.Dbw2Getlength > 3)
// {
// tempdb2addr = Convert.ToInt32(dv[di]["F_DBW2Address"]) - DBW2Addressbegin;
// taskindex = (devicestates[tempdb2addr + 2] << 8) + devicestates[tempdb2addr + 3];
// if (devinfo.Dbw2Getlength > 1)
// {
// state = devicestates[tempdb2addr + 1];
// }
// }
// int devkind = devinfo.DeviceKind;
// if (state >= 30)
// {
// devinfo.ErrorCode = state;
// devinfo.RunState = 2;
// }
// else
// {//0,1,2
// if (state == 2)
// {
// devinfo.RunState = 5;
// }
// else
// {
// devinfo.RunState = state;
// }
// devinfo.ErrorCode = state;
// }
// if (devkind == 13 && devinfo.UnControl != "1")
// {//richard.liu20230718鸿安环穿0-1是心跳单独订阅;2是可下任务状态0:不可下命令,1:可下命令
// state = devicestates[tempdb2addr + 1] == 0 ? 1 : 0;//可下任务状态
// taskindex = (devicestates[tempdb2addr + 2] << 8) + devicestates[tempdb2addr + 3];
// }
// devinfo.TaskNo = taskindex;
// int sn = 4;//输送机光电开关位移
// if ((devinfo.DeviceKind == 1) || (devinfo.DeviceKind == 4) || (devinfo.DeviceKind == 14))
// {
// devinfo.XCoor = devicestates[tempdb2addr + 7] + (devicestates[tempdb2addr + 6] << 8) + (devicestates[tempdb2addr + 5] << 16) + (devicestates[tempdb2addr + 4] << 32);//X坐标
// if (devinfo.DeviceKind == 1)
// {
// sn = 13;//堆垛机光电开关位移
// devinfo.YCoor = devicestates[tempdb2addr + 11] + (devicestates[tempdb2addr + 10] << 8) + (devicestates[tempdb2addr + 9] << 16) + (devicestates[tempdb2addr + 8] << 32);//Y坐标
// devinfo.ZCoor = devicestates[tempdb2addr + 12];//Z相对坐标(1或2\3)
// }
// else
// {
// sn = 8;//直穿和环穿光电开关位移
// }
// }
// //设备开关状态
// if (devinfo.Dbw2Getlength >= 3)
// {
// devinfo.SplitByte_0 = (devicestates[tempdb2addr + sn] & 1) == 1 ? 1 : 0;
// devinfo.SplitByte_1 = (devicestates[tempdb2addr + sn] & 2) == 2 ? 1 : 0;
// devinfo.SplitByte_2 = (devicestates[tempdb2addr + sn] & 4) == 4 ? 1 : 0;
// devinfo.SplitByte_3 = (devicestates[tempdb2addr + sn] & 8) == 8 ? 1 : 0;
// devinfo.SplitByte_4 = (devicestates[tempdb2addr + sn] & 16) == 16 ? 1 : 0;
// devinfo.SplitByte_5 = (devicestates[tempdb2addr + sn] & 32) == 32 ? 1 : 0;
// devinfo.SplitByte_6 = (devicestates[tempdb2addr + sn] & 64) == 64 ? 1 : 0;
// devinfo.SplitByte_7 = (devicestates[tempdb2addr + sn] & 128) == 128 ? 1 : 0;
// }
// Model.CGetInfo.SetDeviceInfo(devinfo);
//}
int devidx =deviceindex;
devinfo = Model.CGetInfo.GetDeviceInfo(devidx);
int taskindex = 0;
int state = 0;
//以下代码重新开发CStaticClass.MutiS7ConnReturns改为按照F_ReadSubscription
if (devinfo.Dbw2Getlength > 3)
{
//tempdb2addr = Convert.ToInt32(dv[di]["F_DBW2Address"]) - DBW2Addressbegin;
taskindex = (devicestates[ 2] << 8) + devicestates[ 3];
if (devinfo.Dbw2Getlength > 1)
{
state = devicestates[ 1];
}
}
if (devinfo.Dbw2Getlength == 1)
{
state = devicestates[0];
}
int devkind = devinfo.DeviceKind;
if (state >= 30)
{
devinfo.ErrorCode = state;
devinfo.RunState = 2;
}
else
{//0,1,2
if (state == 2)
{
devinfo.RunState = 5;
}
else
{
devinfo.RunState = state;
}
devinfo.ErrorCode = state;
}
if (devkind == 13 && devinfo.UnControl != "1")
{//richard.liu20230718鸿安环穿0-1是心跳单独订阅;2是可下任务状态0:不可下命令,1:可下命令
state = devicestates[1] == 0 ? 1 : 0;//可下任务状态
taskindex = (devicestates[ 2] << 8) + devicestates[ 3];
}
devinfo.TaskNo = taskindex;
int sn = 4;//输送机光电开关位移
if ((devinfo.DeviceKind == 1) || (devinfo.DeviceKind == 4) || (devinfo.DeviceKind == 14))
{
devinfo.XCoor = devicestates[ 7] + (devicestates[ 6] << 8) + (devicestates[5] << 16) + (devicestates[4] << 32);//X坐标
if (devinfo.DeviceKind == 1)
{
sn = 13;//堆垛机光电开关位移
devinfo.YCoor = devicestates[11] + (devicestates[10] << 8) + (devicestates[9] << 16) + (devicestates[8] << 32);//Y坐标
devinfo.ZCoor = devicestates[12];//Z相对坐标(1或2\3)
}
else
{
sn = 8;//直穿和环穿光电开关位移
}
}
if (devinfo.DeviceKind == 5)
{
sn = 2;
}
//设备开关状态
if (devinfo.Dbw2Getlength >= 3)
{
devinfo.SplitByte_0 = (devicestates[sn] & 1) == 1 ? 1 : 0;
devinfo.SplitByte_1 = (devicestates[sn] & 2) == 2 ? 1 : 0;
devinfo.SplitByte_2 = (devicestates[sn] & 4) == 4 ? 1 : 0;
devinfo.SplitByte_3 = (devicestates[sn] & 8) == 8 ? 1 : 0;
devinfo.SplitByte_4 = (devicestates[sn] & 16) == 16 ? 1 : 0;
devinfo.SplitByte_5 = (devicestates[sn] & 32) == 32 ? 1 : 0;
devinfo.SplitByte_6 = (devicestates[sn] & 64) == 64 ? 1 : 0;
devinfo.SplitByte_7 = (devicestates[sn] & 128) == 128 ? 1 : 0;
}
Model.CGetInfo.SetDeviceInfo(devinfo);
}
return true;
}
catch (Exception ex)
{
SendMessage(string.Format("tsStatus@FrmClient.DealWithDeviceState时{0}", ex.StackTrace + ex.Message));
errtext = string.Format("tsStatus@FrmClient.DealWithDeviceState时{0}", ex.StackTrace + ex.Message);
return false;
}
finally
{
dv.Dispose();
dvbc.Dispose();
dvsp.Dispose();
}
}
#region wcf回调
public void SendDeviceInfo(Model.MDevice devinfo)
{
try
{
if (CStaticClass.WCFOK == false) return;
if (this.IsDisposed) return;
Model.CGetInfo.SetDeviceInfo(devinfo);
}
catch (Exception ex)
{
throw ex;
}
}
public IAsyncResult BeginSendDeviceInfo(Model.MDevice devinfo, AsyncCallback acb, object state)
{
return state as IAsyncResult;
}
public void EndSendDeviceInfo(IAsyncResult ar)
{
}
public IAsyncResult BeginSendMessage(string message, AsyncCallback acb, object state)
{
return state as IAsyncResult;
}
public void EndSendMessage(IAsyncResult ar)
{
}
public void SendMessage(string message)
{
char[] cc = new char[1] { '@' };
string[] strsplit = message.Split(cc);
if (strsplit.GetLength(0) > 1)
{//更新指定控件
if (strsplit[0] == "tsStatus")
{
tsStatus.Text = strsplit[1];
}
else if (strsplit[0] == "notifyIcon1")
{
this.BeginInvoke(new MethodInvoker(delegate()
{
notifyIcon1.BalloonTipText = strsplit[1];
notifyIcon1.ShowBalloonTip(10000, "警告:", strsplit[1],ToolTipIcon.Warning);
}));
}
}
//else
//{//刷新数据显示
// this.dgvManager.BeginInvoke(new MethodInvoker(delegate()
// {
// sql.Remove(0, sql.Length);
// sql.Append("select * from V_Manage_Task where ").Append(CStaticClass.Manstatus);
// this.dgvManager.DataSource = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// }));
// this.dgvMonitor.BeginInvoke(new MethodInvoker(delegate()
// {
// sql.Remove(0, sql.Length);
// sql.Append("select * from V_Monitor_Task where ").Append(CStaticClass.Monstatus).Append(" order by 设备指令索引 asc ");
// this.dgvMonitor.DataSource = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// }));
//}
}
//20140824richard
public void SendOrderMessage(Model.MonitorInfo mi)
{
this.BeginInvoke(new MethodInvoker(delegate()
{
try
{
if (CStaticClass.UserID.ToUpper() == "SA")
{
CStaticClass.Order = mi.Orderturnon;
CStaticClass.ObtainManageTask = mi.Obtaintask;
if (CStaticClass.Order == true)
{
ClickOrderTurnOn();
}
else
{
ClickOrderTurnOff();
}
if (CStaticClass.ObtainManageTask == true)
{
ClickObtainTask();
}
else
{
ClickStopObtainTask();
}
}
}
catch (Exception ex)
{
if (tsStatus.Text.IndexOf("接收【获取任务和命令开关】广播时:" + ex.Message) < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += "接收【获取任务和命令开关】广播时:" + ex.Message;
}
}
}));
}
public IAsyncResult BeginSendOrderMessage(Model.MonitorInfo mi, AsyncCallback callBack, object state)
{
return state as IAsyncResult;
}
public void EndSendOrderMessage(IAsyncResult ar)
{
}
//20140824richard
#endregion
private void Client_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("您确认要关闭"+CStaticClass.SystemName+"吗?", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
{
e.Cancel = true;
return;
}
ClientLogout();
OPCClient.CCommonOPCClient.DisConnectOPCServer();//20120428
CommonClassLib.AppSettings.dbo.Close();//richard20181022
CommonClassLib.AppSettings.dboM.Close();//richard20181022
FrmLogin.FormInstance.Close();
}
void LogCallBack(IAsyncResult ar)
{
try
{
string strErr = string.Empty;
if (CStaticClass.WcfControl.EndLogoutClient(out strErr, ar) == true)
{
//if (ar.AsyncState.ToString() == "RegisterClientCallBack")
//{
// CStaticClass.WcfControl.BeginRegisterClient(CStaticClass.UserID, "客户端:" + CStaticClass.ClientID + ",用户名:" + CStaticClass.UserID, new AsyncCallback(RegisterClientCallBack), null);
// return;
//}
}
CStaticClass.WCFOK = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public void ClientLogout()
{
try
{
string errtext = string.Empty;
CStaticClass.WcfControl.BeginLogoutClient("客户端:" + CStaticClass.ClientID + ",用户名:" + CStaticClass.UserID,new AsyncCallback(LogCallBack),"" );
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
FrmHandCommand.FormInstance.Show();
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
FrmHandAssociateCommand.FormInstance.Show();
}
private void MIManageShow_Click(object sender, EventArgs e)
{
FrmAutoCommand.FormInstance.Show();
}
private void MIAltMonitor_Click(object sender, EventArgs e)
{
FrmModifyMonitor.FormInstance.Show();
}
private void MIAltManange_Click(object sender, EventArgs e)
{
FrmModifyManage.FormInstance.Show();
}
private void notifyIcon1_BalloonTipShown(object sender, EventArgs e)
{
try
{
speak.Volume = 100;//设置音量
speak.Rate = 0;//设置语速
speak.SetOutputToDefaultAudioDevice();
speak.SpeakAsync(notifyIcon1.BalloonTipText);//播放内容
//Voice.Speak(notifyIcon1.BalloonTipText, SpFlags);
}
catch
{
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (CStaticClass.WCFOK == true)
{
this.TopMost = true;
this.Visible = true;
this.TopMost = false;
this.WindowState = FormWindowState.Maximized;
}
}
private void tsStatus_TextChanged(object sender, EventArgs e)
{
}
private void TSMrefresh_Click(object sender, EventArgs e)
{
sql.Remove(0, sql.Length);
sql.Append("select * from V_Manage_Task where ").Append(CStaticClass.Manstatus);
//this.dgvManager.DataSource = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
}
private void TSMMonitorRefresh_Click(object sender, EventArgs e)
{
sql.Remove(0, sql.Length);
sql.Append("select * from V_Monitor_Task where ").Append(CStaticClass.Monstatus).Append(" order by 设备指令索引 asc ");
//this.dgvMonitor.DataSource = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
}
private void rbmanAll_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
if (rb.Checked == true)
{
CStaticClass.Manstatus = " F_Status>=-1 ";
}
TSMrefresh_Click(sender, e);
}
private void rbmanRun_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
if (rb.Checked == true)
{
CStaticClass.Manstatus = " F_Status=1 ";
}
TSMrefresh_Click(sender, e);
}
private void rbmanWait_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
if (rb.Checked == true)
{
CStaticClass.Manstatus = " F_Status=0 ";
}
TSMrefresh_Click(sender, e);
}
//private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
//{
// try
// {
// string df = "";
// switch (this.comboBox1.Text)
// {
// case "条码":
// df = "条码";
// break;
// case "调度任务索引":
// df = "调度任务索引";
// break;
// case "设备指令索引":
// df = "设备指令索引";
// break;
// default:
// return;
// }
// //20100208
// sql.Remove(0, sql.Length);
// sql.Append("select distinct " + df + " from V_Monitor_Task ");
// DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// this.textBox1.DataSource = null;
// this.textBox1.DisplayMember = df;
// this.textBox1.ValueMember = df;
// this.textBox1.DataSource = dv;
// }
// }
// catch (Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
//}
//private void button1_Click(object sender, EventArgs e)
//{
// try
// {
// if (this.textBox1.Text.Trim().Length == 0) return;
// if (this.comboBox1.Text == "条码")
// {
// CStaticClass.Monstatus = " 条码='" + this.textBox1.Text.Trim() + "' ";
// }
// if (this.comboBox1.Text == "调度任务索引")
// {
// CStaticClass.Monstatus = " 调度任务索引='" + this.textBox1.Text.Trim() + "' ";
// }
// if (this.comboBox1.Text == "设备指令索引")
// {
// CStaticClass.Monstatus = " 设备指令索引='" + this.textBox1.Text.Trim() + "' ";
// }
// TSMMonitorRefresh_Click(sender, e);
// }
// catch (Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
//}
private void button2_Click(object sender, EventArgs e)
{
CStaticClass.Monstatus = " F_Status>=-1 ";
TSMMonitorRefresh_Click(sender, e);
}
public void MonitorRefresh()
{//20110222
sql.Remove(0, sql.Length);
sql.Append("select * from V_Monitor_Task where ").Append(CStaticClass.Monstatus).Append(" order by 设备指令索引 asc ");
//this.dgvMonitor.DataSource = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
}
public void ManagerRefresh()
{//20110222
sql.Remove(0, sql.Length);
sql.Append("select * from V_Manage_Task where ").Append(CStaticClass.Manstatus);
//this.dgvManager.DataSource = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
}
private void Btn_MouseEnter_Stop(object sender, EventArgs e)
{
string deviceindex = (sender as Control).Tag.ToString();
devinfo = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(deviceindex));
if (devinfo != null)
{
if (devinfo.SplitByte_6 == 1)//未停车
{
deviceindex = string.Format("{0}-未联机停车", devinfo.DeviceIndex);
}
if (devinfo.SplitByte_6 == 0)//停车
{
deviceindex = string.Format("{0}-联机停车", devinfo.DeviceIndex);
}
}
toolTip1.SetToolTip(sender as Control, deviceindex);
}
void BuildHandTaskCallBack(IAsyncResult ar)
{
string errtext = string.Empty;
if (CStaticClass.WcfControl.EndBuildHandTask(out errtext, ar) == false)
{
//MessageBox.Show(errtext, "操作提示:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Client_Load(object sender, EventArgs e)
{
try
{
//for (int i = 0; i <= 1000; i++)
//{
// Model.HandTask ht = new Model.HandTask(11001, 1, 0, "0", "00-00-00", "-", 0, 0);
// CStaticClass.WcfControl.BeginBuildHandTask(ht, new AsyncCallback(BuildHandTaskCallBack), ht);
//}
#region 添加输送机、穿梭车和堆垛机的单击事件
foreach (Control ctrl in this.plAccessorial1.Controls)
{
if (ctrl.GetType().ToString() == "System.Windows.Forms.Button")
{
ctrl.Click += new EventHandler(ctrl_Click);
toolTip1.SetToolTip(ctrl, ctrl.Tag.ToString());
}
if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Enabled == true))
{
if (ctrl.Name.ToString().Contains("stop"))
{
ctrl.Click += new EventHandler(ctrl_ClickPicStop);
ctrl.MouseEnter += new EventHandler(Btn_MouseEnter_Stop);
}
else
{
ctrl.Click += new EventHandler(ctrl_ClickPic);
}
toolTip1.SetToolTip(ctrl, ctrl.Tag.ToString());
}
}
foreach (Control ctrl in this.plAccessorial2.Controls)
{
if (ctrl.GetType().ToString() == "System.Windows.Forms.Button")
{
ctrl.Click += new EventHandler(ctrl_Click);
toolTip1.SetToolTip(ctrl, ctrl.Tag.ToString());
}
if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Enabled == true))
{
if (ctrl.Name.ToString().Contains("stop"))
{
ctrl.Click += new EventHandler(ctrl_ClickPicStop);
ctrl.MouseEnter += new EventHandler(Btn_MouseEnter_Stop);
}
else
{
ctrl.Click += new EventHandler(ctrl_ClickPic);
}
toolTip1.SetToolTip(ctrl, ctrl.Tag.ToString());
}
}
foreach (Control ctrl in this.plAccessorial3.Controls)
{
if (ctrl.GetType().ToString() == "System.Windows.Forms.Button")
{
ctrl.Click += new EventHandler(ctrl_Click);
toolTip1.SetToolTip(ctrl, ctrl.Tag.ToString());
}
if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Enabled == true))
{
if (ctrl.Name.ToString().Contains("stop"))
{
ctrl.Click += new EventHandler(ctrl_ClickPicStop);
ctrl.MouseEnter += new EventHandler(Btn_MouseEnter_Stop);
}
else
{
ctrl.Click += new EventHandler(ctrl_ClickPic);
}
toolTip1.SetToolTip(ctrl, ctrl.Tag.ToString());
}
}
//foreach (Control ctrl in this.plAccessorial4.Controls)
//{
// if (ctrl.GetType().ToString() == "System.Windows.Forms.Button")
// {
// ctrl.Click += new EventHandler(ctrl_Click);
// }
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Enabled == true))
// {
// if (ctrl.Name.ToString().Contains("stop"))
// {
// ctrl.Click += new EventHandler(ctrl_ClickPicStop);
// }
// else
// {
// ctrl.Click += new EventHandler(ctrl_ClickPic);
// }
// }
//}
//foreach (Control ctrl in this.plAccessorial5.Controls)
//{
// if (ctrl.GetType().ToString() == "System.Windows.Forms.Button")
// {
// ctrl.Click += new EventHandler(ctrl_Click);
// }
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Enabled == true))
// {
// if (ctrl.Name.ToString().Contains("stop"))
// {
// ctrl.Click += new EventHandler(ctrl_ClickPicStop);
// }
// else
// {
// ctrl.Click += new EventHandler(ctrl_ClickPic);
// }
// }
//}
//foreach (Control ctrl in this.plAccessorial6.Controls)
//{
// if (ctrl.GetType().ToString() == "System.Windows.Forms.Button")
// {
// ctrl.Click += new EventHandler(ctrl_Click);
// }
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Enabled == true))
// {
// if (ctrl.Name.ToString().Contains("stop"))
// {
// ctrl.Click += new EventHandler(ctrl_ClickPicStop);
// }
// else
// {
// ctrl.Click += new EventHandler(ctrl_ClickPic);
// }
// }
//}
//foreach (Control ctrl in this.plAccessorial7.Controls)
//{
// if (ctrl.GetType().ToString() == "System.Windows.Forms.Button")
// {
// ctrl.Click += new EventHandler(ctrl_Click);
// }
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Enabled == true))
// {
// if (ctrl.Name.ToString().Contains("stop"))
// {
// ctrl.Click += new EventHandler(ctrl_ClickPicStop);
// }
// else
// {
// ctrl.Click += new EventHandler(ctrl_ClickPic);
// }
// }
//}
#endregion
TSMrefresh_Click(sender, e);
TSMMonitorRefresh_Click(sender, e);
if (CStaticClass.UserID.ToUpper() == "SA")
{
this.MMmasterAdmin.Visible = true;
}
else
{
this.MMmasterAdmin.Visible = false;
}
}
catch (Exception ex)
{
throw (ex);
}
}
private void MIDeviceState_Click(object sender, EventArgs e)
{
FrmDeviceInfoEdit.FormInstance.Show();
}
private void MIRouteInfo_Click(object sender, EventArgs e)
{
FrmRouteEdit.FormInstance.Show();
}
private void MIWaitTime_Click(object sender, EventArgs e)
{
FrmWaitTime.FormInstance.Show();
}
private void MIMonitorConnectInfo_Click(object sender, EventArgs e)
{
FrmConnectDB.FormInstance.ConnectType = "Monitor";
FrmConnectDB.FormInstance.Show();
}
private void MIIOStation_Click(object sender, EventArgs e)
{
FrmIOStation.FormInstance.Show();
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
//for (int i = 0; i < 100; i++)
//{
// OPCClient.CCommonOPCClient.DisConnectOPCServer();
// OPCClient.CCommonOPCClient.CreateSubscriptionGroup();
//}
if (CStaticClass.WcfControl != null)
{
if (CStaticClass.WcfControl.State == CommunicationState.Faulted)
{
CStaticClass.WCFOK = false;
ReConnectAndRegisterClient();//20160115添加断线重连功能
}
else
{
CStaticClass.WcfControl.BeginHeartbeat(new AsyncCallback(CallBackHeartbeat), null);
//if (OPCClient.CCommonOPCClient.dtt != null)
//{
// if (OPCClient.CCommonOPCClient.dtt.AddMinutes(2) < DateTime.Now)
// {
// OPCClient.CCommonOPCClient.DisConnectOPCServer();
// OPCClient.CCommonOPCClient.CreateSubscriptionGroup();
// }
//}
}
}
}
catch (Exception ex)
{
ReConnectAndRegisterClient();//20160115添加断线重连功能
}
if (CStaticClass.WCFOK == false) return;
try
{
CStaticClass.WcfControl.BeginHeartbeat(new AsyncCallback(CallBackHeartbeat), null);
}
catch (Exception ex)
{
if (tsStatus.Text.IndexOf("BeginHeartbeat时:" + ex.Message) < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += "BeginHeartbeat时:" + DateTime.Now.ToString("u") + ex.Message;
}
ReRegisterClient();
}
}
void ReConnectAndRegisterClient()
{
try
{
CStaticClass.ClientID = Dns.GetHostName();
var ctx = new InstanceContext(CStaticClass.client);
CStaticClass.WcfControl = new WcfControlMonitor.ControlMonitorClient(ctx);
string errtext = string.Empty;
CommonClassLib.CCarryConvert.WriteDarkCasket("Login", "UserID:" + CStaticClass.UserID + "的操作日志", "尝试重新连接", "", "");
CStaticClass.WcfControl.BeginRegisterClient(CStaticClass.UserID, "客户端:" + CStaticClass.ClientID + ",用户名:" + CStaticClass.UserID, new AsyncCallback(ReConnectAndRegisterClientCallBack), null);
}
catch (Exception ex)
{
throw ex;
}
}
void ReConnectAndRegisterClientCallBack(IAsyncResult ar)
{
try
{
string ErrText = string.Empty;
if (false == CStaticClass.WcfControl.EndRegisterClient(out ErrText, ar))
{
//MessageBox.Show(ErrText, "登陆错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
CStaticClass.WCFOK = false;
return;
}
CommonClassLib.CCarryConvert.WriteDarkCasket("Login", "UserID:" + CStaticClass.UserID + "的操作日志", "重连**成功登录系统", "", "");
tsStatus.Text = "";
//CStaticClass.WcfControl.BeginSendAllDeviceStates(CStaticClass.client.devlist[0].DeviceIndex, new AsyncCallback(CStaticClass.client.SendAllDeviceStatesCallback), null);
CStaticClass.WCFOK = true;
//OPCClient.CCommonOPCClient.kkk();
//OPCClient.CCommonOPCClient.CreateSubscriptionGroup();
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message, "登陆错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
CStaticClass.WCFOK = false;
return;
}
//try
//{
// string ErrText = string.Empty;
// if (false == CStaticClass.WcfControl.EndRegisterClient(out ErrText, ar))
// {
// //MessageBox.Show(ErrText, "登陆错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
// //CStaticClass.WCFOK = false;
// return;
// }
// OPCClient.CCommonOPCClient.DisConnectOPCServer();
// OPCClient.CCommonOPCClient.UpdateDB += new CUpdateDBEventHandler(CCommon_UpdateDB);
// OPCClient.CCommonOPCClient.CreateSubscriptionGroup();
// CommonClassLib.CCarryConvert.WriteDarkCasket("Login", "UserID:" + CStaticClass.UserID + "的操作日志", "重连**成功登录系统", "", "");
// //CStaticClass.WcfControl.BeginSendAllDeviceStates(CStaticClass.client.devlist[0].DeviceIndex, new AsyncCallback(CStaticClass.client.SendAllDeviceStatesCallback), null);
// CStaticClass.WCFOK = true;
//}
//catch (Exception ex)
//{
// //MessageBox.Show(ex.Message, "登陆错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
// CStaticClass.WCFOK = false;
// return;
//}
}
public void SendAllDeviceStatesCallback(IAsyncResult ar)
{
try
{
Model.MDevice dev;
dev = CStaticClass.WcfControl.EndSendAllDeviceStates(ar);
if (dev != null)
{
Model.CGetInfo.SetDeviceInfo(dev);
}
devsn++;
if (devsn < devlist.Count())
{
CStaticClass.WcfControl.BeginSendAllDeviceStates(devlist[devsn].DeviceIndex, new AsyncCallback(SendAllDeviceStatesCallback), null);
}
else
{
//devsn=0;
//CStaticClass.WcfControl.BeginSendAllDeviceStates(devlist[devsn].DeviceIndex, new AsyncCallback(SendAllDeviceStatesCallback), null);
}
}
catch (Exception ex)
{
this.BeginInvoke(new MethodInvoker(delegate()
{
if (tsStatus.Text.IndexOf("SendAllDeviceStatesCallback时:" + ex.Message) < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += "SendAllDeviceStatesCallback时:" + ex.Message;
}
}));
ReRegisterClient();
}
}
private void MITransportTimeout_Click(object sender, EventArgs e)
{
FrmTransportTimeout.FormInstance.Show();
}
private void MISeeDarket_Click(object sender, EventArgs e)
{
FrmBrowseDarkCasket.FormInstance.Show();
}
private void MIDarketFileSet_Click(object sender, EventArgs e)
{
FrmDarkCasket.FormInstance.Show();
}
private void MIAutoTaskHistory_Click(object sender, EventArgs e)
{
FrmBrowseAotoTaskLog.FormInstance.Show();
}
private void MIUserInfoManage_Click(object sender, EventArgs e)
{
FrmUsers.FormInstance.Show();
}
private void MIAltPassword_Click(object sender, EventArgs e)
{
FrmPassword.FormInstance.Show();
}
private void MMExitSystem_Click(object sender, EventArgs e)
{
this.Close();
}
private void toolStripMenuItem10_Click(object sender, EventArgs e)
{
this.Visible = false;
}
private void toolStripMenuItem8_Click(object sender, EventArgs e)
{
this.Visible = true;
this.WindowState = FormWindowState.Maximized;
}
private void toolStripMenuItem9_Click(object sender, EventArgs e)
{
this.Close();
}
private void tabPage1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.TranslateTransform(this.tabPage1.AutoScrollPosition.X, this.tabPage1.AutoScrollPosition.Y);
g.Dispose();
}
private void ctrl_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
_deviceStatus.DeviceIndex = Convert.ToInt32(btn.Tag);
_deviceStatus.ShowDialog();
}
private void ctrl_ClickTxt(object sender, EventArgs e)
{
TextBox txt = (TextBox)sender;
_worstation.DeviceIndex = Convert.ToInt32(txt.Tag);
_worstation.ShowDialog();
}
private void ctrl_ClickPic(object sender, EventArgs e)
{
PictureBox btn = (PictureBox)sender;
_deviceStatus.DeviceIndex = Convert.ToInt32(btn.Tag);
_deviceStatus.ShowDialog();
}
private void ctrl_ClickPicStop(object sender, EventArgs e)
{
PictureBox btn = (PictureBox)sender;
int DeviceIndexForRunButton = Convert.ToInt32(btn.Tag);
Model.MDevice deviceRun = Model.CGetInfo.GetDeviceInfo(DeviceIndexForRunButton);
int iValue = 0;
iValue = (deviceRun.SplitByte_6 == 1) ? 0 : 1;
//if (iValue == 0)
//{
// if (MessageBox.Show("您确认要向设备:" + DeviceIndexForRunButton + "发送【设备急停】吗?", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
// {
// return;
// }
//}
//else
//{
// if (MessageBox.Show("您确认要向设备:" + DeviceIndexForRunButton + "发送【急停复位】吗?", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
// {
// return;
// }
//}
CStaticClass.WcfControl.BeginSendDeviceReset(DeviceIndexForRunButton, 10 + iValue, new AsyncCallback(SendDeviceResetCallBack), iValue);
// CStaticClass.WcfControl.BeginSendDeviceReset(DeviceIndexForRunButton, iValue, new AsyncCallback(SendDeviceResetCallBack), iValue);
}
void SendDeviceResetCallBack(IAsyncResult ar)
{
string errtext = string.Empty;
if (CStaticClass.WcfControl.EndSendDeviceReset(out errtext, ar) == false)
{
MessageBox.Show(errtext, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void timerFlash_Tick(object sender, EventArgs e)
{
string[] DS;char[] dd=new char [1]{'.'};
Model.MDevice device;
TimeSpan ts = DateTime.Now.TimeOfDay;
DataView dv; DataView dvJY;
this.SuspendLayout(); //richard.liu20140806
try
{
if (CStaticClass.WCFOK == true)
{
//timersum++;//20150103增加断网恢复//20151120取消断网恢复
//if (timersum >= 120)//1分钟刷新订阅一次
//{//20150103增加断网恢复
// OPCClient.CCommonOPCClient.RefreshMonitoringMode();
// timersum = 0;
//}
sql.Remove(0, sql.Length);//richard.liu20140806
sql.Append("SELECT F_DeviceIndex FROM T_Base_Device WHERE (F_LockedState = - 1) ");
dvJY = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;//richard.liu20140806
dvJY.Sort = "F_DeviceIndex";
//PictureBox stack1 = bt11001;
PictureBox pbdevice = pictureBoxShelfB1_1;
TextBox tw0 = t31101;
Panel pp = plAccessorial1;
if (this.tabControl1.SelectedIndex == 0)
{
pp = plAccessorial1;
}
if (this.tabControl1.SelectedIndex == 1)
{
pp = plAccessorial2;
}
if (this.tabControl1.SelectedIndex == 2)
{
pp = plAccessorial3;
}
#region 每层楼监视画面
#region 堆垛机、RGV
foreach (PictureBox ctrl in pp.Controls.OfType<PictureBox>())
{
if (ctrl.Enabled == false) continue;
device = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(ctrl.Tag));
if (device == null)
{//20100108
if (tsStatus.Text.IndexOf(ctrl.Name + "控件对应的设备索引:" + ctrl.Tag + "在数据库没有记录!") < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += ctrl.Name + "控件对应的设备索引:" + ctrl.Tag + "在数据库没有记录!";
}
continue;
}
#region 紧急停车按钮
if (ctrl.Name.ToString().Contains("stop"))
{
//紧急停车按钮
if (device.SplitByte_6 == 1)
{
ctrl.Image = global::wcfControlMonitorClient.Properties.Resources.stop0;
}
else
{
ctrl.Image = global::wcfControlMonitorClient.Properties.Resources.stop1;
}
continue;
}
#endregion
#region 动画
//if ((device.DeviceKind == 1) && ((device.XCoor != 0) && (device.YCoor != 0) || (device.DeviceIndex == 15011)))//&& (device.ZCoor != 0)
// {//堆垛机
// switch (device.DeviceIndex)//770/37 = 20.81 770/38 = 20.26
// {
// case 11001:
// stack1.Location = new Point((int)(500 + 20.35 * (device.XCoor - 1)), stack1.Location.Y);
// tw1.Location = new Point(stack1.Location.X + 7, tw1.Location.Y);
// break;
// case 11002:
// switch (device.ZCoor)
// {
// case 2:
// stack2.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 103);
// tw2.Location = new Point(stack2.Location.X + 7, stack2.Location.Y + 5);
// break;
// case 3:
// stack2.Location = new Point(1269, 82);
// tw2.Location = new Point(stack2.Location.X + 7, stack2.Location.Y + 5);
// break;
// case 1:
// stack2.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 62);
// tw2.Location = new Point(stack2.Location.X + 7, stack2.Location.Y + 5);
// break;
// default:
// stack2.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 62);
// tw2.Location = new Point(stack2.Location.X + 7, stack2.Location.Y + 5);
// break;
// }
// break;
// case 11003:
// switch (device.ZCoor)
// {
// case 2:
// stack3.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 185);
// tw3.Location = new Point(stack3.Location.X + 7, stack3.Location.Y + 5);
// break;
// case 3:
// stack3.Location = new Point(1269, 164);
// tw3.Location = new Point(stack3.Location.X + 7, stack3.Location.Y + 5);
// break;
// case 1:
// stack3.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 144);
// tw3.Location = new Point(stack3.Location.X + 7, stack3.Location.Y + 5);
// break;
// default:
// stack3.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 144);
// tw3.Location = new Point(stack3.Location.X + 7, stack3.Location.Y + 5);
// break;
// }
// break;
// case 11004:
// switch (device.ZCoor)
// {
// case 2:
// stack4.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 273);
// tw4.Location = new Point(stack4.Location.X + 7, stack4.Location.Y + 5);
// break;
// case 3:
// stack4.Location = new Point(1269, 252);
// tw4.Location = new Point(stack4.Location.X + 7, stack4.Location.Y + 5);
// break;
// case 1:
// stack4.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 232);
// tw4.Location = new Point(stack4.Location.X + 7, stack4.Location.Y + 5);
// break;
// default:
// stack4.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 232);
// tw4.Location = new Point(stack4.Location.X + 7, stack4.Location.Y + 5);
// break;
// }
// break;
// case 11005:
// stack5.Location = new Point((int)(500 + 20.35 * (device.XCoor - 1)), stack5.Location.Y);
// tw5.Location = new Point(stack5.Location.X + 7, tw5.Location.Y);
// break;
// case 11006:
// switch (device.ZCoor)
// {
// case 2:
// stack6.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 396);
// tw6.Location = new Point(stack6.Location.X + 7, stack6.Location.Y + 5);
// break;
// case 3:
// stack6.Location = new Point(1269, 375);
// tw6.Location = new Point(stack6.Location.X + 7, stack6.Location.Y + 5);
// break;
// case 1:
// stack6.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 355);
// tw6.Location = new Point(stack6.Location.X + 7, stack6.Location.Y + 5);
// break;
// default:
// stack6.Location = new Point((int)(500 + 20.9 * (device.XCoor - 1)), 355);
// tw6.Location = new Point(stack6.Location.X + 7, stack6.Location.Y + 5);
// break;
// }
// break;
// case 11007:
// stack7.Location = new Point((int)(500 + 20.35 * (device.XCoor - 1)), stack7.Location.Y);
// tw7.Location = new Point(stack7.Location.X + 7, tw7.Location.Y);
// break;
// case 11008://850/40=21.25 850/39=21.80
// switch (device.ZCoor)
// {
// case 2:
// stack8.Location = new Point((int)(421 + 20.7 * (device.XCoor - 1)), 529);
// tw8.Location = new Point(stack8.Location.X + 7, stack8.Location.Y + 5);
// break;
// case 3:
// stack8.Location = new Point(1269, 508);
// tw8.Location = new Point(stack8.Location.X + 7, stack8.Location.Y + 5);
// break;
// case 1:
// stack8.Location = new Point((int)(421 + 20.7 * (device.XCoor - 1)), 488);
// tw8.Location = new Point(stack8.Location.X + 7, stack8.Location.Y + 5);
// break;
// default:
// stack8.Location = new Point((int)(421 + 20.7 * (device.XCoor - 1)), 488);
// tw8.Location = new Point(stack8.Location.X + 7, stack8.Location.Y + 5);
// break;
// }
// break;
// case 11009:
// stack9.Location = new Point((int)(421 + 20.2 * (device.XCoor - 1)), stack9.Location.Y);
// tw9.Location = new Point(stack9.Location.X + 7, tw9.Location.Y);
// break;
// case 11010:
// switch (device.ZCoor)
// {
// case 2:
// stack10.Location = new Point((int)(421 + 20.7 * (device.XCoor - 1)), 653);
// tw10.Location = new Point(stack10.Location.X + 7, stack10.Location.Y + 5);
// break;
// case 3:
// stack10.Location = new Point(1269, 632);
// tw10.Location = new Point(stack10.Location.X + 7, stack10.Location.Y + 5);
// break;
// case 1:
// stack10.Location = new Point((int)(421 + 20.7 * (device.XCoor - 1)), 611);
// tw10.Location = new Point(stack10.Location.X + 7, stack10.Location.Y + 5);
// break;
// default:
// stack10.Location = new Point((int)(421 + 20.7 * (device.XCoor - 1)), 611);
// tw10.Location = new Point(stack10.Location.X + 7, stack10.Location.Y + 5);
// break;
// }
// break;
// case 15011:
// switch (device.XCoor)
// {
// case 1:
// stack11.Location = new Point(stack11.Location.X, 384);
// tw11.Location = new Point(stack11.Location.X + 5, 396);
// tw12.Location = new Point(stack11.Location.X + 5, 389);
// break;
// case 2:
// stack11.Location = new Point(stack11.Location.X, 384);
// tw11.Location = new Point(stack11.Location.X + 5, 396);
// tw12.Location = new Point(stack11.Location.X + 5, 389);
// break;
// case 3:
// stack11.Location = new Point(stack11.Location.X, 362);
// tw11.Location = new Point(stack11.Location.X + 5, 374);
// tw12.Location = new Point(stack11.Location.X + 5, 367);
// break;
// case 4:
// stack11.Location = new Point(stack11.Location.X, 325);
// tw11.Location = new Point(stack11.Location.X + 5, 337);
// tw12.Location = new Point(stack11.Location.X + 5, 330);
// break;
// default:
// stack11.Location = new Point(stack11.Location.X, 277);
// tw11.Location = new Point(stack11.Location.X + 5, 289);
// tw12.Location = new Point(stack11.Location.X + 5, 282);
// break;
// }
// break;
// }
// }
// else if (device.DeviceKind == 4)
// {//RGV
// switch (device.DeviceIndex)
// {
// case 15012:
// switch (device.XCoor)
// {
// case 13:
// stack12.Location = new Point(stack12.Location.X, 439);
// tw121.Location = new Point(stack12.Location.X + 5, 445);
// break;
// case 11:
// case 12:
// stack12.Location = new Point(stack12.Location.X, 454);
// tw121.Location = new Point(stack12.Location.X + 5, 460);
// break;
// case 10:
// stack12.Location = new Point(stack12.Location.X, 473);
// tw121.Location = new Point(stack12.Location.X + 5, 479);
// break;
// case 9:
// stack12.Location = new Point(stack12.Location.X, 499);
// tw121.Location = new Point(stack12.Location.X + 5, 505);
// break;
// case 8:
// stack12.Location = new Point(stack12.Location.X, 513);
// tw121.Location = new Point(stack12.Location.X + 5, 519);
// break;
// case 7:
// stack12.Location = new Point(stack12.Location.X, 539);
// tw121.Location = new Point(stack12.Location.X + 5, 545);
// break;
// case 6:
// stack12.Location = new Point(stack12.Location.X, 555);
// tw121.Location = new Point(stack12.Location.X + 5, 561);
// break;
// case 5:
// stack12.Location = new Point(stack12.Location.X, 581);
// tw121.Location = new Point(stack12.Location.X + 5, 587);
// break;
// case 4:
// stack12.Location = new Point(stack12.Location.X, 596);
// tw121.Location = new Point(stack12.Location.X + 5, 602);
// break;
// case 3:
// stack12.Location = new Point(stack12.Location.X, 622);
// tw121.Location = new Point(stack12.Location.X + 5, 628);
// break;
// case 2:
// stack12.Location = new Point(stack12.Location.X, 637);
// tw121.Location = new Point(stack12.Location.X + 5, 643);
// break;
// case 1:
// stack12.Location = new Point(stack12.Location.X, 663);
// tw121.Location = new Point(stack12.Location.X + 5, 669);
// break;
// default:
// stack12.Location = new Point(stack12.Location.X, 403);
// tw121.Location = new Point(stack12.Location.X + 5, 409);
// break;
// }
// break;
// }
// }
#endregion
#region 设备被禁用
//richar.liu20140806
if (dvJY.Count > 0)
{
if (dvJY.Find(device.DeviceIndex) >= 0)
{
ctrl.BackColor = Color.Maroon;
}
}
#endregion
}
#endregion
#region 类输送机
foreach (Button ctrl in pp.Controls.OfType<Button>())
{
//ctrl.FlatStyle = FlatStyle.Flat;
//ctrl.FlatAppearance.BorderColor = Color.BlueViolet;
//ctrl.FlatAppearance.BorderSize = 1;
device = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(ctrl.Tag));
if (device == null)
{//20100108
if (tsStatus.Text.IndexOf(ctrl.Name + "控件对应的设备索引:" + ctrl.Tag + "在数据库没有记录!") < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += ctrl.Name + "控件对应的设备索引:" + ctrl.Tag + "在数据库没有记录!";
}
continue;
}
#region 设置设备状态
if (device.DeviceKind == 2)
{
switch (device.RunState)
{
//空闲
case 0:
ctrl.BackColor = Color.LightSkyBlue;
break;
//运行
case 1:
ctrl.BackColor = Color.Lime;
break;
//故障
case 2:
ctrl.BackColor = Color.Red;
break;
//离线
case 3:
ctrl.BackColor = Color.LightYellow;
break;
//停用
case 4:
ctrl.BackColor = Color.Maroon;
break;
//20090920动作完成
case 5:
ctrl.BackColor = Color.Gray;
break;
}
}
else
{
switch (device.RunState)
{
//空闲
case 0:
ctrl.BackColor = Color.Orange;
break;
//运行
case 1:
ctrl.BackColor = Color.Lime;
break;
//故障
case 2:
ctrl.BackColor = Color.Red;
break;
//离线
case 3:
ctrl.BackColor = Color.LightYellow;
break;
//停用
case 4:
ctrl.BackColor = Color.Maroon;
break;
//20090920动作完成
case 5:
ctrl.BackColor = Color.SeaGreen;//MediumOrchid;
break;
}
}
#endregion
#region 设备被禁用
//richar.liu20140806
if (dvJY.Count > 0)
{
if (dvJY.Find(device.DeviceIndex) >= 0)
{
ctrl.BackColor = Color.Maroon;
}
}
#endregion
//动画显示【堆垛机】
if (device.DeviceKind == 1)
{
//缓存库
if (pp == plAccessorial2)
{
//暂存库界面中只有暂存库堆垛机动态显示【成品大库不做动态显示】
int deviceNumber = Convert.ToInt32(ctrl.Tag.ToString());
if (deviceNumber == 31101 || deviceNumber == 31102 || deviceNumber == 31103 || deviceNumber == 31104)
{
const int Widthoffset = 0;
const int Heightoffset = 0;
const int section1 = 5;
double SizePerCell = -32;
double CellLength = 0;
#region 动画测试
bool test = false;
if (test)
{
if (device.XCoor < 8)
{
device.XCoor++;
}
else
{
device.XCoor = 0;
}
}
//Console.WriteLine(device.XCoor);
#endregion
if (device.XCoor <= section1)
{
SizePerCell = -32;
CellLength = SizePerCell * device.XCoor;
}
else
{
SizePerCell = -32;
CellLength = SizePerCell * section1;
SizePerCell = -38.5;
CellLength += SizePerCell * (device.XCoor - section1);
}
//显示基准为左侧货架图片【此处命名如:pictureBoxShelfB1_1;pictureBoxShelfB2_1等】
pbdevice = (PictureBox)pp.Controls[string.Format("pictureBoxShelfB{0}_1", ctrl.Tag.ToString().Substring(4))];
ctrl.Location = new Point((int)(ctrl.Location.X + Widthoffset), (int)(pbdevice.Location.Y + pbdevice.Size.Height + Heightoffset + CellLength));
//堆垛机是否有货
const int twWidthoffset = 0;
const int twHeightoffset = 6;
tw0 = (TextBox)pp.Controls[string.Format("t{0}", ctrl.Tag)];
tw0.Location = new Point(tw0.Location.X + twWidthoffset, ctrl.Location.Y + twHeightoffset);
#region 动画测试
if (test)
{
tw0.Visible = true;
}
#endregion
}
}
//成品大库
else if (pp == plAccessorial3)
{
const int Widthoffset = 0;
const int Heightoffset = -25;
const int section1 = 2;
const int section2 = 60;
double SizePerCell = 35;
double CellLength = 0;
#region 动画测试
bool test = false;
if (test)
{
if (device.XCoor < 61)
{
device.XCoor++;
}
else
{
device.XCoor = 0;
}
}
#endregion
if (device.XCoor <= section1)
{
SizePerCell = 35;
CellLength = SizePerCell * device.XCoor;
}
else if (device.XCoor <= section2)
{
SizePerCell = 35;
CellLength = SizePerCell * section1;
SizePerCell = 5;
CellLength += SizePerCell * (device.XCoor - section1);
}
else
{
SizePerCell = 35;
CellLength = SizePerCell * section1;
SizePerCell = 5;
CellLength += SizePerCell * (section2 - section1);
SizePerCell = 35;
CellLength += SizePerCell * (device.XCoor - section2);
}
//显示基准为左侧货架图片
pbdevice = (PictureBox)pp.Controls["pictureBoxShelf22_3B"];
ctrl.Location = new Point((int)(ctrl.Location.X + Widthoffset), (int)(pbdevice.Location.Y + Heightoffset + CellLength));
//堆垛机是否有货
const int twWidthoffset = 0;
const int twHeightoffset = 6;
tw0 = (TextBox)pp.Controls[string.Format("t{0}", ctrl.Tag)];
tw0.Location = new Point(tw0.Location.X + twWidthoffset, ctrl.Location.Y + twHeightoffset);
#region 动画测试
if (test)
{
tw0.Visible = true;
}
#endregion
}
}
//动画显示【直穿】
if (device.DeviceKind == 4)
{
// //缓存库
if (pp == plAccessorial2)
{
//只显示车【不显示总控】
int deviceNumber = Convert.ToInt32(ctrl.Tag.ToString());
if (deviceNumber == 35401 || deviceNumber == 35402 || deviceNumber == 35403)
{
ctrl.Location = new Point((int)(1813 - 0.01161 * (device.XCoor - 3277)), ctrl.Location.Y);
tw0 = (TextBox)pp.Controls[string.Format("t{0}F", ctrl.Tag)];
tw0.Location = new Point(ctrl.Location.X + 6, ctrl.Location.Y + 9);
//const int Widthoffset = 0;
//const int Heightoffset = 0;
////填写标定位置【需要对准的站台位置码与显示坐标X】
////标定点:左边界;反工口(左1)32144;异常口32146;反向口32153;右边界
//int[] sectionCode = { 100000, 130000, 140000, 160000, 200000 };
//int[] sectionPosition = { 18, 650, 772, 1280, 1854 };
////比例尺
//double scale = (double)(sectionPosition[sectionPosition.Length - 1] - sectionPosition[0]) / (double)(sectionCode[sectionCode.Length - 1] - sectionCode[0]);
//double distance = 0;
//#region 动画测试
//bool test = false;
//if (test)
//{
// if (device.XCoor < sectionCode[0])
// {
// device.XCoor = sectionCode[0];
// if (deviceNumber == 35401) device.XCoor = sectionCode[0] + 2000;
// if (deviceNumber == 35402) device.XCoor = sectionCode[0] + 1000;
// if (deviceNumber == 35403) device.XCoor = sectionCode[0];
// }
// if (device.XCoor < sectionCode[sectionCode.Length - 1])
// {
// device.XCoor += 1000;
// }
// else
// {
// device.XCoor = sectionCode[0];
// }
//}
//#endregion
////计算距离
//if (device.XCoor <= sectionCode[0])
//{
// distance = sectionPosition[0];
//}
//else if (device.XCoor >= sectionCode[sectionCode.Length - 1])
//{
// distance = sectionPosition[sectionPosition.Length - 1];
//}
//else
//{
// //distance包括两部分【1为整段,直接从sectionPosition取;2为半段,需要按此段比例尺计算】
// //整段部分获取
// int sectionIndex = 0;
// for (int i = 0; i < sectionCode.Length; i++)
// {
// if (device.XCoor > sectionCode[i])
// {
// sectionIndex = i;
// }
// else
// {
// break;
// }
// }
// distance = sectionPosition[sectionIndex];
// //半段部分计算
// scale = (double)(sectionPosition[sectionIndex + 1] - sectionPosition[sectionIndex]) / (double)(sectionCode[sectionIndex + 1] - sectionCode[sectionIndex]);
// distance += scale * (device.XCoor - sectionCode[sectionIndex]);
//}
////车体定位
//ctrl.Location = new Point((int)(Widthoffset + distance), ctrl.Location.Y + Heightoffset);
////堆垛机是否有货定位
//const int twWidthoffset = 6;
//const int twHeightoffset = 0;
//tw0 = (TextBox)pp.Controls[string.Format("t{0}F", ctrl.Tag)];
//tw0.Location = new Point(ctrl.Location.X + twWidthoffset, tw0.Location.Y + twHeightoffset);
//#region 动画测试
//if (test)
//{
// tw0.Visible = true;
//}
//#endregion
}
}
//成品大库
else if (pp == plAccessorial3)
{
// //只显示车【不显示总控】
int deviceNumber = Convert.ToInt32(ctrl.Tag.ToString());
if (deviceNumber == 35401 || deviceNumber == 35402 || deviceNumber == 35403)
{
ctrl.Location = new Point((int)(1813 - 0.01161 * (device.XCoor - 3277)), ctrl.Location.Y);
tw0 = (TextBox)pp.Controls[string.Format("t{0}", ctrl.Tag)];
tw0.Location = new Point(ctrl.Location.X + 6, ctrl.Location.Y + 9);
// const int Widthoffset = 0;
// const int Heightoffset = 0;
// //填写标定位置【需要对准的站台位置码与显示坐标X】
// //标定点:左边界;站台32219;站台32231;站台32247;右边界
// int[] sectionCode = { 100000, 130000, 155000, 180000, 200000 };
// int[] sectionPosition = { 18, 660, 1124, 1613, 1854 };
// //比例尺
// double scale = (double)(sectionPosition[sectionPosition.Length - 1] - sectionPosition[0]) / (double)(sectionCode[sectionCode.Length - 1] - sectionCode[0]);
// double distance = 0;
// #region 动画测试
// bool test = false;
// if (test)
// {
// if (device.XCoor < sectionCode[0])
// {
// device.XCoor = sectionCode[0];
// if (deviceNumber == 35401) device.XCoor = sectionCode[0] + 2000;
// if (deviceNumber == 35402) device.XCoor = sectionCode[0] + 1000;
// if (deviceNumber == 35403) device.XCoor = sectionCode[0];
// }
// if (device.XCoor < sectionCode[sectionCode.Length - 1])
// {
// device.XCoor += 1000;
// }
// else
// {
// device.XCoor = sectionCode[0];
// }
// }
// #endregion
// //计算距离
// if (device.XCoor <= sectionCode[0])
// {
// distance = sectionPosition[0];
// }
// else if (device.XCoor >= sectionCode[sectionCode.Length - 1])
// {
// distance = sectionPosition[sectionPosition.Length - 1];
// }
// else
// {
// //distance包括两部分【1为整段,直接从sectionPosition取;2为半段,需要按此段比例尺计算】
// //整段部分获取
// int sectionIndex = 0;
// for (int i = 0; i < sectionCode.Length; i++)
// {
// if (device.XCoor > sectionCode[i])
// {
// sectionIndex = i;
// }
// else
// {
// break;
// }
// }
// distance = sectionPosition[sectionIndex];
// //半段部分计算
// scale = (double)(sectionPosition[sectionIndex + 1] - sectionPosition[sectionIndex]) / (double)(sectionCode[sectionIndex + 1] - sectionCode[sectionIndex]);
// distance += scale * (device.XCoor - sectionCode[sectionIndex]);
// }
// //车体定位
// ctrl.Location = new Point((int)(Widthoffset + distance), ctrl.Location.Y + Heightoffset);
// //堆垛机是否有货定位
// const int twWidthoffset = 6;
// const int twHeightoffset = 0;
// tw0 = (TextBox)pp.Controls[string.Format("t{0}", ctrl.Tag)];
// tw0.Location = new Point(ctrl.Location.X + twWidthoffset, tw0.Location.Y + twHeightoffset);
// #region 动画测试
// if (test)
// {
// tw0.Visible = true;
// }
// #endregion
}
}
}
if (device.DeviceKind == 14)
{
//成品大库
if (pp == plAccessorial3)
{
// //只显示车【不显示总控】
int deviceNumber = Convert.ToInt32(ctrl.Tag.ToString());
if (device.XCoor >= 167445 && device.XCoor <= 315252)
{
ctrl.Location = new Point((int)(1814 - 0.01187 * (device.XCoor - 167445)), 647);
}
else if (device.XCoor > 315252 || (device.XCoor >= 0 && device.XCoor <= 393))
{
ctrl.Location = new Point(19, 679);
}
else if (device.XCoor > 393 && device.XCoor <= 138458)
{
ctrl.Location = new Point((int)(56 + 0.01187 * (device.XCoor - 393)), 714);
}
else if (device.XCoor > 138458 && device.XCoor < 167445)
{
ctrl.Location = new Point(1843, 679);
}
else
{
ctrl.Location = new Point(19, 679);
}
tw0 = (TextBox)pp.Controls[string.Format("t{0}", ctrl.Tag)];
tw0.Location = new Point(ctrl.Location.X + 6, ctrl.Location.Y + 9);
}
}
}
#endregion
#region 货物探测
foreach (TextBox ctrl in pp.Controls.OfType<TextBox>())
{
DS = ctrl.Tag.ToString().Split(dd);
int devicebyte = 0; int devbit = 0;
int.TryParse(DS[0], out devicebyte);
int.TryParse(DS[1], out devbit);
device = Model.CGetInfo.GetDeviceInfo(devicebyte);
if (device == null)
{//20100108
if (tsStatus.Text.IndexOf(ctrl.Name + "控件对应的设备索引:" + ctrl.Tag + "在数据库没有记录!") < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += ctrl.Name + "控件对应的设备索引:" + ctrl.Tag + "在数据库没有记录!";
}
continue;
}
switch (devbit)
{
case 0:
ctrl.Visible = device.SplitByte_0 == 1 ? true : false;
break;
case 1:
ctrl.Visible = device.SplitByte_1 == 1 ? true : false;
break;
case 2:
ctrl.Visible = device.SplitByte_2 == 1 ? true : false;
break;
case 3:
ctrl.Visible = device.SplitByte_3 == 1 ? true : false;
break;
case 4:
ctrl.Visible = device.SplitByte_4 == 1 ? true : false;
break;
case 5:
ctrl.Visible = device.SplitByte_5 == 1 ? true : false;
break;
case 6:
ctrl.Visible = device.SplitByte_6 == 1 ? true : false;
ctrl.BackColor = Color.Goldenrod;
break;
case 7:
ctrl.Visible = device.SplitByte_7 == 1 ? true : false;
break;
}
}
#endregion
#region 逻辑有物显示
foreach (RadioButton ctrl in pp.Controls.OfType<RadioButton>())
{
//20100108DataView dvh;
dv = dbo.ExceSQL("SELECT F_DeviceIndex FROM T_Base_Device WHERE (F_DeviceIndex = " + ctrl.Tag + ") AND (F_HaveGoods >0)").Tables[0].DefaultView;
if (dv.Count > 0)
{
ctrl.Visible = true;
ctrl.BackColor = Color.Blue;
}
else
{
ctrl.Visible = false;
}
}
#endregion
#region 联机紧急停车状态
foreach (PictureBox ctrl in pp.Controls.OfType<PictureBox>())
{
if (pp == plAccessorial2|| pp == plAccessorial3)
{
if (ctrl.Tag != null)
{
//如果是紧急停车按钮的时候
if (!ctrl.Tag.ToString().Contains("."))
{
string test = "4"+ctrl.Name.ToString().Substring(ctrl.Name.Length - 4, 4);
device = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32("4"+ctrl.Name.ToString().Substring(ctrl.Name.Length -4, 4)));
if (device.DeviceKind == 40)
{
//取堆垛机13.6状态来显示颜色
device = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(ctrl.Tag));
if (device == null)
{
if (tsStatus.Text.IndexOf(ctrl.Name + "控件对应的设备索引:" + ctrl.Name.ToString() + "在数据库没有记录!") < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += ctrl.Name + "控件对应的设备索引:" + ctrl.Name.ToString()+ "在数据库没有记录!";
}
continue;
}
DataView dwRunDevice = dbo.ExceSQL("SELECT F_DeviceIndex FROM T_Base_Device WHERE F_DeviceKindIndex = 1 or F_DeviceKindIndex = 4").Tables[0].DefaultView;
for (int i = 0; i < dwRunDevice.Count; i++)
{
if (ctrl.Tag.ToString() == dwRunDevice[i]["F_Deviceindex"].ToString())
{
Model.MDevice deviceRun = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(ctrl.Tag.ToString()));
if (deviceRun.SplitByte_6 == 1)
{
//ctrl.Image = wcfControlMonitorClient.Properties.Resources.stop0;
ctrl.Image = wcfControlMonitorClient.Properties.Resources.stop0;
}
if (deviceRun.SplitByte_6 == 0)
{
//ctrl.Image = wcfControlMonitorClient.Properties.Resources.stop1;
ctrl.Image = wcfControlMonitorClient.Properties.Resources.stop1;
}
}
}
}
}
}
}
}
#endregion
#endregion
}
}
catch (Exception ex)
{//20100108
if (tsStatus.Text.IndexOf("刷新界面动画时:" + ex.Message) < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += "刷新界面动画时:" + ex.Message;
}
}
finally
{//20100108
TimeSpan ts1 = DateTime.Now.TimeOfDay;
device = null;
this.ResumeLayout();//richard.liu20140806
}
}
//private void dgvMonitor_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
//{
// int mfid = 0;
// Color BackColor = Color.YellowGreen;
// foreach (DataGridViewRow DGVRow in this.dgvMonitor.Rows)
// {
// if (DGVRow != null)
// {
// if (Convert.ToInt32(DGVRow.Cells["调度任务索引"].Value) != mfid)
// {
// mfid = Convert.ToInt32(DGVRow.Cells["调度任务索引"].Value);
// if (BackColor == Color.YellowGreen)
// {
// BackColor = Color.LightBlue;
// }
// else
// {
// BackColor = Color.YellowGreen;
// }
// DGVRow.DefaultCellStyle.BackColor = BackColor;
// }
// else
// {
// DGVRow.DefaultCellStyle.BackColor = BackColor;
// }
// if (Convert.ToInt32(DGVRow.Cells["f_status"].Value) >= 30)
// {
// DGVRow.DefaultCellStyle.BackColor = Color.Red;
// }
// if (Convert.ToInt32(DGVRow.Cells["f_status"].Value) == 2 || Convert.ToInt32(DGVRow.Cells["f_status"].Value) == 1)
// {
// DGVRow.DefaultCellStyle.BackColor = Color.Lime;
// }
// }
// }
//}
void ReRegisterClient()
{
//CStaticClass.ClientID = Dns.GetHostName();
//var ctx = new InstanceContext(CStaticClass.client);
//CStaticClass.WcfControl = new WcfControlMonitor.ControlMonitorClient(ctx);
//string errtext = string.Empty;
//CStaticClass.WcfControl.BeginRegisterClient(CStaticClass.UserID, "客户端:" + CStaticClass.ClientID + ",用户名:" + CStaticClass.UserID, new AsyncCallback(RegisterClientCallBack), null);
}
void RegisterClientCallBack(IAsyncResult ar)
{
try
{
string ErrText;
if (CStaticClass.WcfControl.EndRegisterClient(out ErrText, ar) == true)
{
CStaticClass.WCFOK = true;
devsn++;
if (devsn < devlist.Count())
{
CStaticClass.WcfControl.BeginSendAllDeviceStates(devlist[devsn].DeviceIndex, new AsyncCallback(SendAllDeviceStatesCallback), null);
}
else
{
devsn = 0;
CStaticClass.WcfControl.BeginSendAllDeviceStates(devlist[devsn].DeviceIndex, new AsyncCallback(SendAllDeviceStatesCallback), null);
}
}
else
{
CStaticClass.WcfControl.BeginLogoutClient("客户端:" + CStaticClass.ClientID + ",用户名:" + CStaticClass.UserID, new AsyncCallback(LogCallBack), "RegisterClientCallBack");
this.BeginInvoke(new MethodInvoker(delegate()
{
if (tsStatus.Text.IndexOf("EndRegisterClient时:" + ErrText) < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += "EndRegisterClient时:" + ErrText;
}
}));
}
}
catch (Exception ex)
{
this.BeginInvoke(new MethodInvoker(delegate()
{
if (tsStatus.Text.IndexOf("EndRegisterClient时:" + ex.Message) < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += "EndRegisterClient时:" + ex.Message;
}
}));
}
}
private void btClearStatus_Click(object sender, EventArgs e)
{
this.tsStatus.Text = "";
}
private void MIStartRetrieveTask_Click(object sender, EventArgs e)
{
ClickObtainTask();
CStaticClass.WcfControl.BeginObtainTask("", "UPDATE", new AsyncCallback(CallbackObtainTask), null);
}
private void MIStopRetrieveTask_Click(object sender, EventArgs e)
{
ClickStopObtainTask();
CStaticClass.WcfControl.BeginStopObtainTask(new AsyncCallback(CallbackStopObtainTask),null );
}
private void MITurnOn_Click(object sender, EventArgs e)
{
ClickOrderTurnOn();
CStaticClass.WcfControl.BeginOrderTurnOn(new AsyncCallback(CallbackTurnOn),null );
}
private void MITurnOff_Click(object sender, EventArgs e)
{
if (MessageBox.Show("您确认要“关闭命令开关”吗?如果“关闭命令开关”将导致调度计算机与所有设备通讯中断!", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
{
return;
}
ClickOrderTurnOff();
CStaticClass.WcfControl.BeginOrderTurnOff(new AsyncCallback(CallbackTurnOff),null );
}
private void MISystemInit_Click(object sender, EventArgs e)
{
FrmSystemInit.FormInstance.Show();
}
void CallbackObtainTask(IAsyncResult ar)
{
CStaticClass.WcfControl.EndObtainTask(ar);
}
void CallbackStopObtainTask(IAsyncResult ar)
{
CStaticClass.WcfControl.EndStopObtainTask(ar);
}
void CallbackTurnOn(IAsyncResult ar)
{
CStaticClass.WcfControl.EndOrderTurnOn(ar);
}
void CallbackTurnOff(IAsyncResult ar)
{
CStaticClass.WcfControl.EndOrderTurnOff(ar);
}
void CallBackHeartbeat(IAsyncResult ar)
{this.BeginInvoke(new MethodInvoker(delegate()
{
try
{
string errtext = string.Empty;
Model.MonitorInfo mi;
CStaticClass.WcfControl.EndHeartbeat(out mi, ar);
if (CStaticClass.UserID.ToUpper() == "SA")
{
CStaticClass.Order =mi.Orderturnon ;
CStaticClass.ObtainManageTask = mi.Obtaintask;
if (mi.Orderturnon == true)
{
ClickOrderTurnOn();
}
else
{
ClickOrderTurnOff();
}
if (mi.Obtaintask == true)
{
ClickObtainTask();
}
else
{
ClickStopObtainTask();
}
}
if (mi.S7connectOnline.Count > 0)
{
foreach (PictureBox ctrl in pS7conn.Controls.OfType<PictureBox>())
{
if (mi.S7connectOnline.ContainsKey(ctrl.Name.Substring(2)) && (mi.S7connectOnline[ctrl.Name.Substring(2)] == 0))
{
ctrl.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
}
else
{
ctrl.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
}
}
//if (mi.S7connectOnline["@localserver"] == 0)
//if (mi.S7connectOnline.ContainsKey("S7 connection_1") && (mi.S7connectOnline["S7 connection_1"] == 0))
//{
// pbF1S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
//}
//else
//{
// pbF1S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
//}
//if (mi.S7connectOnline.ContainsKey("S7 connection_2") && (mi.S7connectOnline["S7 connection_2"] == 0))
//{
// pbF2S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
//}
//else
//{
// pbF2S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
//}
//if (mi.S7connectOnline.ContainsKey("S7 connection_5") && (mi.S7connectOnline["S7 connection_5"] == 0))
//{
// pbF5S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
//}
//else
//{
// pbF5S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
//}
//if (mi.S7connectOnline.ContainsKey("S7 connection_6") && (mi.S7connectOnline["S7 connection_6"] == 0))
//{
// pbF6S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
//}
//else
//{
// pbF6S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
//}
//if (mi.S7connectOnline.ContainsKey("S7 connection_8") && (mi.S7connectOnline["S7 connection_8"] == 0))
//{
// pbF8S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
//}
//else
//{
// pbF8S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
//}
//if (mi.S7connectOnline.ContainsKey("S7 connection_9") && (mi.S7connectOnline["S7 connection_9"] == 0))
//{
// pbF9S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
//}
//else
//{
// pbF9S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
//}
//if (mi.S7connectOnline.ContainsKey("S7 connection_3") && (mi.S7connectOnline["S7 connection_3"] == 0)
// && mi.S7connectOnline.ContainsKey("S7 connection_4") && (mi.S7connectOnline["S7 connection_4"] == 0)
// && mi.S7connectOnline.ContainsKey("S7 connection_7") && (mi.S7connectOnline["S7 connection_7"] == 0))
//{
// pbF3S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
//}
//else
//{
// pbF3S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
//}
//if (mi.S7connectOnline.ContainsKey("S7 connection_10") && (mi.S7connectOnline["S7 connection_10"] == 0))
//{
// pbF10S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
//}
//else
//{
// pbF10S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
//}
//if (mi.S7connectOnline["@localserver"] == 0)
//if (mi.S7connectOnline.ContainsKey("S7 connection_2") && (mi.S7connectOnline["S7 connection_2"] == 0))
//{
// pbF2S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
//}
//else
//{
// pbF2S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
//}
}
}
catch (Exception ex)
{
if (tsStatus.Text.IndexOf("CallBackHeartbeat时:" + ex.Message) < 0)
{
tsStatus.ForeColor = Color.Red;
this.tsStatus.Text += "CallBackHeartbeat时:" + ex.Message;
}
ReRegisterClient();
}
}));
}
void ClickObtainTask()
{
if (MITurnOn.Checked == true)
{
if (this.Text != CStaticClass.SystemName + "【开始获取任务!】" + "【正在执行自动命令!】")
{
this.Text = CStaticClass.SystemName + "【开始获取任务!】" + "【正在执行自动命令!】";
}
}
else
{
if (this.Text != CStaticClass.SystemName + "【开始获取任务!】")
{
this.Text = CStaticClass.SystemName + "【开始获取任务!】";
}
}
MIStartRetrieveTask.Checked = true;
MIStartRetrieveTask.Enabled = false;
MIStopRetrieveTask.Checked = false;
MIStopRetrieveTask.Enabled = true;
}
void ClickStopObtainTask()
{
if (MITurnOn.Checked == true)
{
if (this.Text != CStaticClass.SystemName + "【正在执行自动命令!】")
{
this.Text = CStaticClass.SystemName + "【正在执行自动命令!】";
}
}
else
{
if (this.Text != CStaticClass.SystemName)
{
this.Text = CStaticClass.SystemName;
}
}
MIStartRetrieveTask.Checked = false;
MIStartRetrieveTask.Enabled = true;
MIStopRetrieveTask.Enabled = false;
MIStopRetrieveTask.Checked = true;
}
void ClickOrderTurnOn()
{
if (MIStartRetrieveTask.Checked == true)
{
if (this.Text != CStaticClass.SystemName + "【开始获取任务!】" + "【正在执行自动命令!】")
{
this.Text = CStaticClass.SystemName + "【开始获取任务!】" + "【正在执行自动命令!】";
}
}
else
{
if (this.Text != CStaticClass.SystemName + "【正在执行自动命令!】")
{
this.Text = CStaticClass.SystemName + "【正在执行自动命令!】";
}
}
MITurnOff.Enabled = true;
MITurnOn.Enabled = false;
MITurnOff.Checked = false;
MITurnOn.Checked = true;
}
void ClickOrderTurnOff()
{
if (MIStartRetrieveTask.Checked == true)
{
if (this.Text != CStaticClass.SystemName + "【开始获取任务!】")
{
this.Text = CStaticClass.SystemName + "【开始获取任务!】";
}
}
else
{
if (this.Text != CStaticClass.SystemName)
{
this.Text = CStaticClass.SystemName;
}
}
MITurnOff.Enabled = false;
MITurnOn.Enabled = true;
MITurnOn.Checked = false;
MITurnOff.Checked = true;
}
private void timer2_Tick(object sender, EventArgs e)
{
//OPCClient.CCommonOPCClient.DisConnectOPCServer();
//try
//{
// TSMMonitorRefresh_Click(sender, e);
// TSMrefresh_Click(sender, e);
//}
//catch
//{
// //if (tsStatus.Text.IndexOf("读取数据库时:" + ex.Message) < 0)
// //{
// // tsStatus.ForeColor = Color.Red;
// // this.tsStatus.Text += "读取数据库时时:" + ex.Message;
// //}
//}
}
private void MISystemInit2_Click(object sender, EventArgs e)
{
FrmSystemInit.FormInstance.Show();
}
private void MIManageConnectInfo_Click(object sender, EventArgs e)
{
FrmConnectDB.FormInstance.ConnectType = "Manage";
FrmConnectDB.FormInstance.Show();
}
public bool IsEquals(Array array1, Array array2, int arraylength)
{//20090902新增加arraylength
//比较类型是否一样
if ((array1 == null) || (array2 == null)) return false;
if (!Object.ReferenceEquals(array1.GetType(), array2.GetType()))
{
return false;
}
//比较长度是否一样
if (array1.GetLength(0) != array2.GetLength(0))
{
return false;
}
//比较成员是否对应相等
ValueType v1, v2;
for (int i = 0; i < arraylength; i++)
{
v1 = (ValueType)array1.GetValue(i);
v2 = (ValueType)array2.GetValue(i);
if (!v1.Equals(v2))
{
return false;
}
}
return true;
}
string GetBarcodeFromMonitorIndex(int taskindex)
{
DataView dvb = new DataView(); StringBuilder sss = new StringBuilder("");
try
{
sss.Append("SELECT F_TxtParam FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(taskindex).Append(")");
dvb = dbo.ExceSQL(sss.ToString()).Tables[0].DefaultView;
if (dvb.Count > 0)
{
return dvb[0]["F_TxtParam"].ToString();
}
else
{
return "-";
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dvb.Dispose();
}
}
int GetMonitorRunTaskIndexFromBarCode(StringBuilder BarCode)
{//20110216
DataView dv = new DataView();
try
{
string bc = BarCode.ToString();
dv = dbo1.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;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
int GetMonitorAskTaskIndexFromBarCode(StringBuilder BarCode)
{//20110216
DataView dv = new DataView();
try
{
string bc = BarCode.ToString();
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) or (F_SendFlag=2 and F_Status=0)) and F_DeviceCommandIndex=6 order by F_MonitorIndex asc", bc)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return Convert.ToInt32(dv[0]["F_MonitorIndex"]);
}
else
{
return -1;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
int GetMonitorTaskIndexFromBarCode(StringBuilder BarCode, Model.MDevice devinf)
{//20110216
DataView dv = new DataView();
try
{
string bc = BarCode.ToString();
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_NumParam4 = {1} or F_NumParam4 = {2}) and F_Status>0 order by F_MonitorIndex asc", bc, devinf.DeviceIndex, devinf.DeviceVisual)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return Convert.ToInt32(dv[0]["F_MonitorIndex"]);
}
else
{
//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;
//}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
string GetMonitorTaskStartTime(int taskindex, out int order)
{//20110216
DataView dv = new DataView();
try
{
dv = dbo.ExceSQL(string.Format("SELECT F_StartTime,F_DeviceCommandIndex FROM T_Monitor_Task WHERE F_MonitorIndex={0}", taskindex)).Tables[0].DefaultView;
if (dv.Count > 0)
{
order = Convert.ToInt32(dv[0]["F_DeviceCommandIndex"]);
return dv[0]["F_StartTime"].ToString();
}
else
{
order = -1;
return "-";
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
private void MIZCKSetIO_Click(object sender, EventArgs e)
{
FrmZCKSetIOStation.FormInstance.Show();
}
private void MIErrorSolutions_Click(object sender, EventArgs e)
{//20151120
FrmDeviceErrorSolutions.FormInstance.Show();
}
private void MITaskCount_Click(object sender, EventArgs e)
{//20151120
FrmTaskManage.FormInstance.Show();
}
private void MIStorageCheck_Click(object sender, EventArgs e)
{
FrmStorageCheck.FormInstance.Show();
}
private void MILanePile_Click(object sender, EventArgs e)
{
FrmLanePile.FormInstance.Show();
}
private void MIPalletCode_Click(object sender, EventArgs e)
{
FrmWMSOutTask.FormInstance.Show();
}
private void MIErrorLog_Click(object sender, EventArgs e)
{
FrmDeviceErrorLog.FormInstance.Show();
}
private void MIDeskStatus_Click(object sender, EventArgs e)
{
FrmDeskStatus.FormInstance.Show();
}
private void MIWmsRecall_Click(object sender, EventArgs e)
{
FrmWmsRecall.FormInstance.Show();
}
private void MIMutiOutTask_Click(object sender, EventArgs e)
{
FrmAutoOutTasks.FormInstance.Show();
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
private void MI14005OUT_Click(object sender, EventArgs e)
{
FrmOutCountandHave14005.FormInstance.Show();
}
private void MIRGVAreaSet_Click(object sender, EventArgs e)
{
FrmRGVAreaSet.FormInstance.Show();
}
private void timer3_Tick(object sender, EventArgs e)
{
if (CommonClassLib.CCarryConvert.dark.Count > 0)
{
timer3.Enabled = false;
for (int i = 0; i < CommonClassLib.CCarryConvert.dark.Count; i++)
{
try
{
if (CommonClassLib.CCarryConvert.dark[i] == null) break; //dark中数量近万时,偶尔会出现 dark[0] 值为null
string[] aaa = CommonClassLib.CCarryConvert.dark[i].ToString().Split('|');
CommonClassLib.CCarryConvert.kkk(aaa[0], aaa[1], aaa[2], aaa[3], aaa[4]); //将 dark[i] 的记录写入文件中
//dbo1.ExecuteSql("insert into test(T1) values('" + sql[i].ToString() + "')");
}
catch (Exception exa)
{
}
finally
{
CommonClassLib.CCarryConvert.dark.RemoveAt(i);//移除 dark[i]
i--;
timer3.Enabled = true;
}
}
}
}
}
}