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.
1330 lines
57 KiB
1330 lines
57 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.ServiceModel;
|
|
using WcfControlMonitorLib;
|
|
using CommonLib;
|
|
using System.Globalization;
|
|
using CommonLib;
|
|
using OPCClient;
|
|
namespace wcfControlMonitorClient
|
|
{
|
|
public partial class FrmHost : Form
|
|
{
|
|
Model.MonitorInfo mi;//20140824richard
|
|
//20130122
|
|
private static FrmHost _formInstance;
|
|
//20130122
|
|
public static FrmHost FormInstance
|
|
{
|
|
get
|
|
{
|
|
if (_formInstance == null)
|
|
{
|
|
_formInstance = new FrmHost();
|
|
}
|
|
return _formInstance;
|
|
}
|
|
set { _formInstance = value; }
|
|
}
|
|
int timersum = 0;//20120513
|
|
DBFactory.DBOperator dbo;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public FrmHost()
|
|
{
|
|
try
|
|
{
|
|
dbo = CStaticClass.dbo;
|
|
InitializeComponent();
|
|
CStaticClass.SystemName = CommonClassLib.AppSettings.GetValue("SystemName");
|
|
this.notifyIcon1.Text = CStaticClass.SystemName;
|
|
this.Text = CStaticClass.SystemName;
|
|
_host = new ServiceHost(typeof(WcfControlMonitorLib.SControlMonitor));
|
|
_host.Open();
|
|
//Silverlight跨域访问服务
|
|
policyHost = ClientCrossDomainAccessPolicy.GetHost(_host.BaseAddresses[0].Host);
|
|
policyHost.Open();
|
|
SControlMonitor.ChannelOpen += new ClientLogEventHandler(SControlMonitor_ChannelOpen);
|
|
SControlMonitor.ClientLogout += new ClientLogEventHandler(SControlMonitor_ClientLogout);
|
|
SControlMonitor.RefreshMonitor += new RefreshMonitorEventHandler(SControlMonitor_RefreshMonitor);
|
|
SControlMonitor.PLCCommonUpdateDB += new CUpdateDBEventHandler(SControlMonitor_PLCCommonUpdateDB);//PLC//20121108
|
|
SControlMonitor.AGVUpdateDB += new CUpdateDBEventHandler(SControlMonitor_AGVUpdateDB);//AGV//20121108
|
|
SControlMonitor.SendBarcode += new CStringInfoEventHandler(SControlMonitor_SendBarcode);
|
|
SControlMonitor.WriteDarkCasket += new CWriteDarkCasketEventHandler(SControlMonitor_WriteDarkCasket);//20121108
|
|
SControlMonitor.SendDeviceOrder += new CSendDeviceOrderEventHandler(SControlMonitor_SendDeviceOrder); ;//20121108
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message + ex.InnerException, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
this.Close();
|
|
}
|
|
}
|
|
|
|
void SControlMonitor_AGVUpdateDB(object sender, CUpdateDBChangeEventArgs e)
|
|
{//20120616
|
|
this.BeginInvoke(new MethodInvoker(delegate ()
|
|
{ CStaticClass.WcfControl.DealWithListenAGVState_UpdateDB(sender, e); }));
|
|
|
|
}
|
|
|
|
void SControlMonitor_PLCCommonUpdateDB(object sender, CUpdateDBChangeEventArgs e)
|
|
{
|
|
|
|
string errtext = string.Empty;
|
|
this.BeginInvoke(new MethodInvoker(delegate ()
|
|
{ CStaticClass.WcfControl.DealWithDeviceState(out errtext, e.Deviceindex, e.SplitbyteValue, e.Devicestates); }));
|
|
|
|
}
|
|
void SControlMonitor_SendBarcode(object sender, CStringInfoEventArgs e)
|
|
{
|
|
string errtext = string.Empty;
|
|
this.BeginInvoke(new MethodInvoker(delegate ()
|
|
{
|
|
CStaticClass.WcfControl.WriteDBData(e.Deviceindex, "DB1", e.Barcode + "," + e.Confirm.ToString(), out errtext);
|
|
dbo.ExceSQL(string.Format(" update T_Base_PLC_Ask set F_TaskIndex={0} WHERE (F_DeviceIndex = {1})", e.Deviceindex, Convert.ToInt32(sender)));
|
|
}));
|
|
|
|
}
|
|
void SControlMonitor_SendDeviceOrder(object sender, CSendDeviceOrderEventArgs e)
|
|
{//20121108
|
|
this.BeginInvoke(new MethodInvoker(delegate ()
|
|
{ CStaticClass.WcfControl.DealWithSendDeviceOrder(sender, e); }));
|
|
}
|
|
void SControlMonitor_WriteDarkCasket(object sender, CWriteDarkCasketEventArgs e)
|
|
{//20121108
|
|
this.BeginInvoke(new MethodInvoker(delegate ()
|
|
{ CStaticClass.WcfControl.DealWithWriteDarkCasket(sender, e); }));
|
|
}
|
|
|
|
void SControlMonitor_CDeviceState(object sender, CDeviceStateChangeEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
SendDeviceInfosToClient(e.Devinfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf("SControlMonitor_CDeviceState:" + ex.StackTrace + ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += "SControlMonitor_CDeviceState:" + ex.StackTrace + ex.Message;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SControlMonitor_RefreshMonitor(RefreshMonitorEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.BeginInvoke(new MethodInvoker(delegate ()
|
|
{
|
|
SendMessageToClient(e.RefreshObjectName + "@" + e.RefreshObjectInfo);
|
|
}));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf("SControlMonitor_RefreshMonitor:" + ex.StackTrace + ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += "SControlMonitor_RefreshMonitor:" + ex.StackTrace + ex.Message;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SControlMonitor_DataChange(object sender, CDataChangeEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
SendMessageToClient(sender.ToString());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf("SControlMonitor_DataChange:" + ex.StackTrace + ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += "SControlMonitor_DataChange:" + ex.StackTrace + ex.Message;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SControlMonitor_ClientLogout(ClientLogEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
AddList1Info(e.clientInfo);//20120503
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf("SControlMonitor_ClientLogout:" + ex.StackTrace + ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += "SControlMonitor_ClientLogout:" + ex.StackTrace + ex.Message;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SControlMonitor_ChannelOpen(ClientLogEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
AddList1Info(e.clientInfo);//20120503
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf("SControlMonitor_ChannelOpen:" + ex.StackTrace + ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += "SControlMonitor_ChannelOpen:" + ex.StackTrace + ex.Message;
|
|
}
|
|
}
|
|
}
|
|
private ServiceHost _host = null;
|
|
private ServiceHost policyHost = null;
|
|
private void FrmHost_Load(object sender, EventArgs e)
|
|
{
|
|
if (WcfControlMonitorLib.CStaticClass.Automatic == "1")
|
|
{
|
|
MIStartRetrieveTask_Click(sender, e);
|
|
MITurnOn_Click(sender, e);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void MIDataClear_Click(object sender, EventArgs e)
|
|
{
|
|
if (MessageBox.Show("您确认清空调度系统的调度队列和设备指令队列数据吗?这个操作将导致调度系统丢失当前记录的所有数据,并且使系统恢复到初始状态!", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
|
|
{
|
|
return;
|
|
}
|
|
string errtext = string.Empty;
|
|
if (CStaticClass.WcfControl.DataClear(out errtext) == false)
|
|
{
|
|
MessageBox.Show(errtext, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
void SendMessageToClient(string strmessage)
|
|
{
|
|
|
|
IClient cl = null;
|
|
try
|
|
{
|
|
if (AddList1Info(strmessage) == false) return;//20130510
|
|
var list = WcfControlMonitorLib.SControlMonitor.ClientCallbackLists;
|
|
if (list == null || list.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
lock (list)
|
|
{
|
|
foreach (System.Collections.DictionaryEntry client in list)
|
|
{
|
|
// Broadcast
|
|
cl = (IClient)client.Key;
|
|
//string aa = client.Value.ToString();
|
|
//this.BeginInvoke(new MethodInvoker(delegate()
|
|
//{
|
|
//20140824richard
|
|
if (strmessage == "巡检客户端")
|
|
{
|
|
cl.BeginSendOrderMessage(mi, new AsyncCallback(SendOrderMessageCallback), mi);
|
|
}
|
|
else
|
|
{
|
|
cl.BeginSendMessage(strmessage, new AsyncCallback(sendMessageCallback), strmessage);
|
|
|
|
}
|
|
//20140824richard
|
|
//}));
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (cl != null)
|
|
{
|
|
WcfControlMonitorLib.SControlMonitor.ClientCallbackLists.Remove(cl);
|
|
WcfControlMonitorLib.SControlMonitor.ClientShowLists.Remove(cl);
|
|
}
|
|
AddList1Info(string.Format("SendMessageToClient时异常:{0}", ex.Message));//20120503
|
|
//if (listBox1.Items.Count >= 100) listBox1.Items.Clear();
|
|
//this.listBox1.Items.Add(string.Format("SendMessageToClient时异常:{0},{1}" , ex.Message,DateTime.Now.ToString("u")));
|
|
}
|
|
}
|
|
void SendOrderMessageCallback(IAsyncResult ar)
|
|
{
|
|
|
|
}
|
|
void sendMessageCallback(IAsyncResult ar)
|
|
{
|
|
try
|
|
{
|
|
this.BeginInvoke(new MethodInvoker(delegate ()
|
|
{
|
|
|
|
string sem = (string)ar.AsyncState;
|
|
AddList1Info(sem);//20120503
|
|
//if (listBox1.Items.Count >= 100) listBox1.Items.Clear();
|
|
//if (listBox1.Items.Count >= 1)
|
|
//{
|
|
// if (this.listBox1.Items[listBox1.Items.Count - 1].ToString().IndexOf(sem) >= 0) return;
|
|
//}
|
|
//if (sem == "巡检客户端") return;
|
|
//listBox1.Items.Add(DateTime.Now.ToLongTimeString()+sem);
|
|
|
|
}));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.BeginInvoke(new MethodInvoker(delegate ()
|
|
{
|
|
if (tsStatus.Text.IndexOf("巡检客户端sendMessageCallback:" + ex.StackTrace + ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += "巡检客户端sendMessageCallback:" + ex.StackTrace + ex.Message;
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
void SendDeviceInfosToClient(Model.MDevice devinfo)
|
|
{
|
|
IClient cl = null;
|
|
try
|
|
{
|
|
var list = WcfControlMonitorLib.SControlMonitor.ClientCallbackLists;
|
|
if (list == null || list.Count == 0)
|
|
return;
|
|
lock (list)
|
|
{
|
|
foreach (System.Collections.DictionaryEntry client in list)
|
|
{
|
|
// Broadcast
|
|
cl = (IClient)client.Key;
|
|
cl.BeginSendDeviceInfo(devinfo, new AsyncCallback(sendDeviceInfosCallback), null);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (cl != null)
|
|
{
|
|
WcfControlMonitorLib.SControlMonitor.ClientCallbackLists.Remove(cl);
|
|
WcfControlMonitorLib.SControlMonitor.ClientShowLists.Remove(cl);
|
|
}
|
|
AddList1Info(string.Format("SendDeviceInfosToClient时异常:{0}", ex.Message));//20120503
|
|
//if (listBox1.Items.Count >= 100) listBox1.Items.Clear();
|
|
//this.listBox1.Items.Add(string.Format("SendDeviceInfosToClient时异常:{0},{1}" , ex.Message , DateTime.Now.ToString("u")));
|
|
}
|
|
}
|
|
|
|
void sendDeviceInfosCallback(IAsyncResult ar)
|
|
{
|
|
|
|
}
|
|
private void FrmHost_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (MessageBox.Show("您确认要关闭" + CStaticClass.SystemName + "吗?", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
|
|
{
|
|
e.Cancel = true;
|
|
return;
|
|
}
|
|
if (_host != null)
|
|
{
|
|
SControlMonitor.ChannelOpen -= new ClientLogEventHandler(SControlMonitor_ChannelOpen);
|
|
SControlMonitor.ClientLogout -= new ClientLogEventHandler(SControlMonitor_ClientLogout);
|
|
SControlMonitor.DataChange -= new CDataSourceChangeEventHandler(SControlMonitor_DataChange);
|
|
SControlMonitor.RefreshMonitor -= new RefreshMonitorEventHandler(SControlMonitor_RefreshMonitor);
|
|
SControlMonitor.CDeviceState -= new CDeviceStateChangeEventHandler(SControlMonitor_CDeviceState);
|
|
SControlMonitor.PLCCommonUpdateDB -= new CUpdateDBEventHandler(SControlMonitor_PLCCommonUpdateDB);
|
|
SControlMonitor.SendBarcode -= new CStringInfoEventHandler(SControlMonitor_SendBarcode);
|
|
CStaticClass.WcfControl.OrderTurnOff("关闭服务端");
|
|
_host.Close();
|
|
IDisposable host = _host as IDisposable;
|
|
host.Dispose();
|
|
}
|
|
CommonClassLib.AppSettings.dbo.Close();
|
|
CommonClassLib.AppSettings.dboM.Close();
|
|
}
|
|
|
|
private void MIStartRetrieveTask_Click(object sender, EventArgs e)
|
|
{
|
|
if (MITurnOn.Checked == true)
|
|
{
|
|
this.Text = CStaticClass.SystemName + "【开始获取任务!】" + "【正在执行自动命令!】";//20120510
|
|
}
|
|
else
|
|
{
|
|
this.Text = CStaticClass.SystemName + "【开始获取任务!】";//20120510
|
|
}
|
|
CStaticClass.WcfControl.ObtainTask("服务端", "", "UPDATE");
|
|
MIStopRetrieveTask.Enabled = true;
|
|
//CStaticClass.ObtainManageTask = true;
|
|
MIStartRetrieveTask.Checked = true;
|
|
MIStopRetrieveTask.Checked = false;
|
|
}
|
|
|
|
private void MIStopRetrieveTask_Click(object sender, EventArgs e)
|
|
{
|
|
if (MITurnOn.Checked == true)
|
|
{
|
|
this.Text = CStaticClass.SystemName + "【正在执行自动命令!】";//20120510
|
|
}
|
|
else
|
|
{
|
|
this.Text = CStaticClass.SystemName;//20120510
|
|
}
|
|
CStaticClass.WcfControl.StopObtainTask("服务端");
|
|
//CStaticClass.ObtainManageTask = false;
|
|
//20120510CStaticClass.WcfControl.StopObtainTask();
|
|
ToolStripMenuItem tsm;
|
|
for (int i = 0; i < MIStartRetrieveTask.DropDown.Items.Count; i++)
|
|
{
|
|
tsm = (ToolStripMenuItem)MIStartRetrieveTask.DropDown.Items[i];
|
|
tsm.Checked = false;
|
|
}
|
|
MIStartRetrieveTask.Checked = false;
|
|
MIStartRetrieveTask.Enabled = true;
|
|
|
|
MIStopRetrieveTask.Enabled = false;
|
|
MIStopRetrieveTask.Checked = true;
|
|
}
|
|
void ToolStripMenu_Click(object sender, EventArgs e)
|
|
{
|
|
ToolStripMenuItem tsm; bool ifget = false;
|
|
|
|
DataView dv;
|
|
char[] cc = new char[1] { ':' };
|
|
int laneway = 0; StringBuilder minz = new StringBuilder(); StringBuilder maxz = new StringBuilder();
|
|
StringBuilder wherez = new StringBuilder();
|
|
ToolStripMenuItem aa = (ToolStripMenuItem)sender;
|
|
|
|
if (aa.Name == "MCAll")
|
|
{
|
|
if (aa.Checked == true)
|
|
{
|
|
aa.Checked = false;
|
|
CStaticClass.WcfControl.ObtainTask("服务端", "", "UPDATE");
|
|
|
|
}
|
|
else
|
|
{
|
|
aa.Checked = true;
|
|
CStaticClass.WcfControl.ObtainTask("服务端", " or (1=1) ", "UPDATE");
|
|
|
|
}
|
|
//20100625修正不能获取站台到站台的任务
|
|
|
|
for (int i = 0; i < MIStartRetrieveTask.DropDown.Items.Count; i++)
|
|
{
|
|
|
|
tsm = (ToolStripMenuItem)MIStartRetrieveTask.DropDown.Items[i];
|
|
if (tsm.Name != "MCAll")
|
|
{
|
|
|
|
tsm.Checked = aa.Checked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//20100625修正不能获取站台到站台的任务
|
|
|
|
}
|
|
else
|
|
{
|
|
laneway = Convert.ToInt32(aa.Text.Split(cc)[1]);
|
|
dv = dbo.ExceSQL("select min(f_z) as minZ from st_cell where flaneway=" + laneway + "").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["minZ"].ToString().Length == 1)
|
|
{
|
|
minz = minz.Append("'0").Append(dv[0]["minZ"].ToString()).Append("-00-00'");
|
|
}
|
|
else
|
|
{
|
|
minz = minz.Append("'" + dv[0]["minZ"].ToString()).Append("-00-00'");
|
|
}
|
|
|
|
}
|
|
dv = dbo.ExceSQL("select max(f_z) as maxZ from st_cell where flaneway=" + laneway + "").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["maxZ"].ToString().Length == 1)
|
|
{
|
|
maxz = maxz.Append("'0").Append(dv[0]["maxZ"].ToString()).Append("-99-99'");
|
|
}
|
|
else
|
|
{
|
|
maxz = maxz.Append("'" + dv[0]["maxZ"].ToString()).Append("-99-99'");
|
|
}
|
|
}
|
|
wherez.Append(" or ((START_DEVICE_CODE between ").Append(minz).Append(" and ").Append(maxz).Append(" ) or (END_DEVICE_CODE between ").Append(minz).Append(" and ").Append(maxz).Append("))");
|
|
if (aa.Checked == true)
|
|
{
|
|
aa.Checked = false;
|
|
//20100625修正不能获取站台到站台的任务
|
|
CStaticClass.WcfControl.ObtainTask("服务端", wherez.ToString(), "REPLACE");
|
|
|
|
|
|
ToolStripMenuItem cm = new ToolStripMenuItem();
|
|
ToolStripMenuItem all = (ToolStripMenuItem)MIStartRetrieveTask.DropDown.Items["MCAll"];
|
|
CStaticClass.WcfControl.ObtainTask("服务端", " or (1=1) ", "REPLACE");
|
|
all.Checked = false;
|
|
StringBuilder wherez1 = new StringBuilder();
|
|
|
|
for (int ii = 0; ii < MIStartRetrieveTask.DropDown.Items.Count; ii++)
|
|
{
|
|
//20101208
|
|
minz.Remove(0, minz.Length);
|
|
maxz.Remove(0, maxz.Length);
|
|
|
|
cm = (ToolStripMenuItem)MIStartRetrieveTask.DropDown.Items[ii];
|
|
if ((cm.Checked == true) && (cm.Name != aa.Name) && (cm.Name != "MCAll"))
|
|
{
|
|
laneway = Convert.ToInt32(cm.Text.Split(cc)[1]);
|
|
dv = dbo.ExceSQL("select min(f_z) as minZ from st_cell where flaneway=" + laneway + "").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["minZ"].ToString().Length == 1)
|
|
{
|
|
minz = minz.Append("'0").Append(dv[0]["minZ"].ToString()).Append("-00-00'");
|
|
}
|
|
else
|
|
{
|
|
minz = minz.Append("'" + dv[0]["minZ"].ToString()).Append("-00-00'");
|
|
}
|
|
|
|
}
|
|
dv = dbo.ExceSQL("select max(f_z) as maxZ from st_cell where flaneway=" + laneway + "").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["maxZ"].ToString().Length == 1)
|
|
{
|
|
maxz = maxz.Append("'0").Append(dv[0]["maxZ"].ToString()).Append("-99-99'");
|
|
}
|
|
else
|
|
{
|
|
maxz = maxz.Append("'" + dv[0]["maxZ"].ToString()).Append("-99-99'");
|
|
}
|
|
}
|
|
wherez1.Append(" or ((START_DEVICE_CODE between ").Append(minz).Append(" and ").Append(maxz).Append(" ) or (END_DEVICE_CODE between ").Append(minz).Append(" and ").Append(maxz).Append("))");
|
|
|
|
}
|
|
|
|
}
|
|
CStaticClass.WcfControl.ObtainTask("服务端", wherez1.ToString(), "APPEND");
|
|
|
|
//20100625修正不能获取站台到站台的任务
|
|
}
|
|
else
|
|
{
|
|
aa.Checked = true;
|
|
|
|
CStaticClass.WcfControl.ObtainTask("服务端", wherez.ToString(), "APPEND");
|
|
}
|
|
}
|
|
|
|
MIStartRetrieveTask_Click(sender, e);
|
|
|
|
for (int i = 0; i < MIStartRetrieveTask.DropDown.Items.Count; i++)
|
|
{
|
|
tsm = (ToolStripMenuItem)MIStartRetrieveTask.DropDown.Items[i];
|
|
if (tsm.Checked == true)
|
|
{
|
|
ifget = true;
|
|
}
|
|
}
|
|
if (ifget == false)
|
|
{
|
|
MIStopRetrieveTask_Click(sender, e);
|
|
|
|
}
|
|
}
|
|
|
|
private void MITurnOn_Click(object sender, EventArgs e)
|
|
{
|
|
MITurnOff.Enabled = true;
|
|
MITurnOn.Enabled = false;
|
|
tsmTurnOff.Enabled = true;
|
|
tsmTurnOn.Enabled = false;
|
|
//timerrunmodel.Enabled = true;
|
|
tsmTurnOff.Checked = false;
|
|
tsmTurnOn.Checked = true;
|
|
MITurnOff.Checked = false;
|
|
MITurnOn.Checked = true;
|
|
//CStaticClass.Order = true;
|
|
CStaticClass.WcfControl.OrderTurnOn("服务端");
|
|
if (MIStartRetrieveTask.Checked == true)
|
|
{
|
|
this.Text = CStaticClass.SystemName + "【开始获取任务!】" + "【正在执行自动命令!】";
|
|
}
|
|
else
|
|
{
|
|
this.Text = CStaticClass.SystemName + "【正在执行自动命令!】";
|
|
}
|
|
//20120510CStaticClass.WcfControl.OrderTurnOn();
|
|
}
|
|
|
|
private void MITurnOff_Click(object sender, EventArgs e)
|
|
{
|
|
if (MessageBox.Show("您确认要“关闭命令开关”吗?如果“关闭命令开关”将导致调度计算机与所有设备通讯中断!", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
|
|
{
|
|
return;
|
|
}
|
|
CStaticClass.WcfControl.OrderTurnOff("服务端");
|
|
//CStaticClass.Order = false;
|
|
MITurnOff.Enabled = false;
|
|
MITurnOn.Enabled = true;
|
|
tsmTurnOff.Enabled = false;
|
|
tsmTurnOn.Enabled = true;
|
|
|
|
tsmTurnOn.Checked = false;
|
|
tsmTurnOff.Checked = true;
|
|
MITurnOn.Checked = false;
|
|
MITurnOff.Checked = true;
|
|
|
|
if (MIStartRetrieveTask.Checked == true)
|
|
{
|
|
this.Text = CStaticClass.SystemName + "【开始获取任务!】";
|
|
}
|
|
else
|
|
{
|
|
this.Text = CStaticClass.SystemName;
|
|
}
|
|
//20120510CStaticClass.WcfControl.OrderTurnOff();
|
|
}
|
|
|
|
private void timerObtainTask_Tick(object sender, EventArgs e)
|
|
{
|
|
timerObtainTask.Enabled = false;
|
|
try
|
|
//if (CStaticClass.ObtainManageTask == true)
|
|
{
|
|
string errtext = string.Empty;
|
|
|
|
if (CStaticClass.WcfControl.GetAllManageTask(out errtext) == false)
|
|
{
|
|
if (tsStatus.Text.IndexOf(errtext) < 0)
|
|
{
|
|
tsStatus.Text += errtext;
|
|
}
|
|
}
|
|
#region AGV任务没响应,任务重发
|
|
|
|
//int DeviceIdx;
|
|
//int TaskIdx = 0;
|
|
//StringBuilder sql = new StringBuilder();
|
|
//DataView dvmo =new DataView();
|
|
//sql.Remove(0, sql.Length);
|
|
//sql.Append("SELECT F_DeviceIndex,F_DeviceKindIndex,F_MaxSendCount,F_SendInterval FROM T_Base_Device WHERE F_DeviceKindIndex = 6");
|
|
//DataView dd = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
//for (int j = 0; j < dd.Count; j++)
|
|
//{
|
|
// DeviceIdx = Convert.ToInt32(dd[j]["F_DeviceIndex"]);
|
|
// #region 发送后规定时间内没报开始或者读取数据成功需要进行超时重发,重发超限时报错
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("select F_MonitorIndex,F_DeviceIndex,F_SendCount,F_StartTime,F_Status,F_AgvNo from T_Monitor_Task where F_DeviceIndex=").Append(DeviceIdx).Append(" and f_status=1 and F_SendFlag='1'");
|
|
// dvmo= dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;//20100905只重发主任务
|
|
// if (dvmo.Count > 0)
|
|
// {//20110510
|
|
// TaskIdx = Convert.ToInt32(dvmo[0]["F_MonitorIndex"]);
|
|
// int scount = Convert.ToInt32(dvmo[0]["F_SendCount"]);
|
|
// scount++;
|
|
// if (scount > Convert.ToInt32(dd[j]["F_MaxSendCount"]))
|
|
// {
|
|
// //发送次数超限报警
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("update T_Monitor_Task set F_Status=999 where F_Status<>999 and F_MonitorIndex=").Append(TaskIdx);//20110505
|
|
// dbo.ExceSQL(sql.ToString());
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// //DateTime.Now.AddMilliseconds
|
|
// if (dvmo[0]["F_StartTime"].ToString() != "-")
|
|
// {
|
|
// if (Convert.ToDateTime(dvmo[0]["F_StartTime"].ToString().Substring(0, 19), CultureInfo.CurrentCulture).AddMilliseconds(Convert.ToDouble(dd[j]["F_SendInterval"])) <= DateTime.Now)
|
|
// {
|
|
|
|
// if (dvmo[0]["F_AgvNo"] == DBNull.Value)
|
|
// {
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("update T_Base_Device set F_LockedState=0 where F_DeviceIndex=").Append(DeviceIdx);
|
|
// dbo.ExceSQL(sql.ToString());
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("update T_Monitor_Task set F_SendCount=").Append(scount).Append(",F_Status=0 where F_MonitorIndex=").Append(TaskIdx);
|
|
// dbo.ExceSQL(sql.ToString());
|
|
// }
|
|
// CommonClassLib.CCarryConvert.WriteDarkCasket("GetDeviceState", "超时重发", DeviceIdx.ToString(), "设备指令索引:" + TaskIdx.ToString() + "发送后,一直没有报告执行或者完成,重新发送命令!");
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// #endregion
|
|
//}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf(ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += ex.Message;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
timerObtainTask.Enabled = true;
|
|
}
|
|
}
|
|
|
|
private void timerDisassembleTask_Tick(object sender, EventArgs e)
|
|
{
|
|
timerDisassembleTask.Enabled = false;
|
|
try
|
|
//if (CStaticClass.Order == true)
|
|
{
|
|
string errtext = string.Empty;
|
|
if (CStaticClass.WcfControl.DisassembleTask(out errtext) == false)
|
|
{
|
|
if (tsStatus.Text.IndexOf(errtext) < 0)
|
|
{
|
|
tsStatus.Text += errtext;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf(ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += ex.Message;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
timerDisassembleTask.Enabled = true;
|
|
}
|
|
}
|
|
|
|
private void timerSendOrder_Tick(object sender, EventArgs e)
|
|
{
|
|
timerSendOrder.Enabled = false;
|
|
try
|
|
//if (CStaticClass.Order == true)
|
|
{
|
|
string errtext = string.Empty;
|
|
if (CStaticClass.WcfControl.StartSendDeviceOrder(out errtext) == false)
|
|
{
|
|
if (tsStatus.Text.IndexOf(errtext) < 0)
|
|
{
|
|
tsStatus.Text += errtext;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf(ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += ex.Message;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
timerSendOrder.Enabled = true;
|
|
}
|
|
}
|
|
|
|
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 MMExitSystem_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void MISystemInit_Click(object sender, EventArgs e)
|
|
{
|
|
FrmSystemInit.FormInstance.Show();
|
|
}
|
|
|
|
private void toolStripMenuItem13_Click(object sender, EventArgs e)
|
|
{
|
|
MITurnOn_Click(sender, e);
|
|
}
|
|
|
|
private void toolStripMenuItem14_Click(object sender, EventArgs e)
|
|
{
|
|
MITurnOff_Click(sender, e);
|
|
}
|
|
|
|
private void toolStripMenuItem9_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void toolStripMenuItem8_Click(object sender, EventArgs e)
|
|
{
|
|
this.Visible = true;
|
|
this.WindowState = FormWindowState.Maximized;
|
|
}
|
|
|
|
private void toolStripMenuItem10_Click(object sender, EventArgs e)
|
|
{
|
|
this.Visible = false;
|
|
}
|
|
|
|
|
|
|
|
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
|
|
this.TopMost = true;
|
|
this.Visible = true;
|
|
this.TopMost = false;
|
|
this.WindowState = FormWindowState.Maximized;
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
listBox1.Items.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 20120503向列表框增加显示内容
|
|
/// </summary>
|
|
/// <param name="txtinfo"></param>
|
|
/// <returns></returns>
|
|
bool AddList1Info(string txtinfo)
|
|
{
|
|
try
|
|
{
|
|
if (txtinfo.IndexOf("巡检客户端") >= 0) return true;
|
|
if (listBox1.Items.Count >= 70) listBox1.Items.Clear();
|
|
foreach (object li in listBox1.Items)
|
|
{
|
|
if (li.ToString().IndexOf(txtinfo) >= 0)
|
|
{
|
|
//listBox1.Items.Remove(li);
|
|
//listBox1.Items.Add(DateTime.Now.ToLongTimeString() + txtinfo);
|
|
return false;
|
|
}
|
|
}
|
|
listBox1.Items.Add(DateTime.Now.ToLongTimeString() + txtinfo);
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf("巡检客户端AddList1Info:" + ex.StackTrace + ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += "巡检客户端AddList1Info:" + ex.StackTrace + ex.Message;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
#region 修正32064前面只有32056
|
|
////F_RouteID:170---187 的32064插入32057
|
|
//object[] arr = new object[7];
|
|
//DataView dv = dbo.ExceSQL("SELECT F_RouteDeviceIndex,F_RouteID, F_RouteIDSub, F_DeviceIndex, F_SerialNumber,F_DeviceOrder, F_UseAwayFork FROM T_Base_Route_Device WHERE (F_RouteID >=170) and (F_RouteID<=187) and F_DeviceIndex=32064").Tables[0].DefaultView;
|
|
//for (int i = 0; i < dv.Count; i++)
|
|
//{
|
|
// dbo.ExecuteSql(string.Format("update T_Base_Route_Device set F_SerialNumber=F_SerialNumber+1 where F_RouteIDSub={0} and F_SerialNumber>={1}", dv[i]["F_RouteIDSub"], dv[i]["F_SerialNumber"]));
|
|
|
|
// arr[0] =Convert.ToInt32( dv[i]["F_RouteDeviceIndex"])-1;
|
|
// arr[1] = Convert.ToInt32(dv[i]["F_RouteID"]);
|
|
// arr[2] = Convert.ToInt32(dv[i]["F_RouteIDSub"]);
|
|
// arr[3] = 32057;
|
|
// arr[4] = Convert.ToInt32(dv[i]["F_SerialNumber"])-1;
|
|
// arr[5] = Convert.ToInt32(dv[i]["F_DeviceOrder"]);
|
|
// arr[6] =dv[i]["F_UseAwayFork"].ToString();
|
|
// dbo.ExecuteSql(string.Format("INSERT INTO T_Base_Route_Device (F_RouteDeviceIndex, F_RouteID, F_RouteIDSub, F_DeviceIndex, F_SerialNumber, F_DeviceOrder, F_UseAwayFork)VALUES ({0},{1},{2},{3},{4},{5},'{6}')", arr));
|
|
|
|
//}
|
|
#endregion
|
|
|
|
#region 导出类似数据至T_Base_Route_DeviceBAK
|
|
|
|
//int fstartdev = 0, fenddev = 0; DataView dv0;
|
|
//DataView dv = dbo.ExceSQL("SELECT * FROM T_Base_Route WHERE (F_RouteID =227)").Tables[0].DefaultView;
|
|
//for (int i = 0; i < dv.Count; i++)
|
|
//{
|
|
// if (dv[i]["F_StartDevice"].ToString() == "32070")
|
|
// {
|
|
|
|
// fstartdev =30200;
|
|
|
|
// fenddev = 32025;
|
|
// //if ((Convert.ToInt32(dv[i]["F_EndDevice"]) >= 42031) && (Convert.ToInt32(dv[i]["F_EndDevice"]) <= 42037))
|
|
// //{
|
|
// // fenddev = 40100;
|
|
// //}
|
|
// //else
|
|
// //{
|
|
// // fenddev = Convert.ToInt32(dv[i]["F_EndDevice"]);
|
|
// //}
|
|
// }
|
|
// //else if ((Convert.ToInt32(dv[i]["F_StartDevice"]) >= 42031) && (Convert.ToInt32(dv[i]["F_StartDevice"]) <= 42037))
|
|
// //{
|
|
// // fstartdev = 40100;
|
|
// // if (dv[i]["F_EndDevice"].ToString() == "32070")
|
|
// // {
|
|
// // fenddev = 30200;
|
|
// // }
|
|
// // else
|
|
// // {
|
|
// // fenddev = Convert.ToInt32(dv[i]["F_EndDevice"]);
|
|
// // }
|
|
// //}
|
|
// dv0 = dbo.ExceSQL(string.Format("SELECT F_RouteDeviceIndex, T_Base_Route_Device.F_RouteID, F_RouteIDSub, F_DeviceIndex, F_SerialNumber,F_DeviceOrder, F_UseAwayFork FROM T_Base_Route,T_Base_Route_Device WHERE T_Base_Route.F_RouteID=T_Base_Route_Device.F_RouteID and (T_Base_Route.F_RouteID <228) and F_StartDevice={0} and F_EndDevice={1} and F_InsideAltDevice={2}", fstartdev, fenddev, Convert.ToInt32(dv[i]["F_InsideAltDevice"]))).Tables[0].DefaultView;
|
|
// if (dv0.Count > 0)
|
|
// {
|
|
// StringBuilder sql = new StringBuilder();
|
|
// sql.Append("INSERT INTO T_Base_Route_DeviceBAK SELECT F_RouteID, F_RouteIDSub, F_DeviceIndex, F_SerialNumber,F_DeviceOrder, F_UseAwayFork FROM T_Base_Route_Device where F_RouteID=").Append(dv0[0]["F_RouteID"]);
|
|
// dbo.ExecuteSql(sql.ToString());
|
|
|
|
// sql.Clear();//replace F_RouteID,F_RouteIDSub
|
|
// sql.Append(string.Format("update T_Base_Route_DeviceBAK set F_RouteID=replace(F_RouteID,{0},{1}),F_RouteIDSub=replace(F_RouteIDSub,{0},{1}) where F_RouteID={0}", dv0[0]["F_RouteID"], dv[i]["F_RouteID"]));
|
|
// dbo.ExecuteSql(sql.ToString());
|
|
// sql.Clear();//replace F_DeviceIndex dv[i]["F_StartDevice"]
|
|
// sql.Append(string.Format("update T_Base_Route_DeviceBAK set F_DeviceIndex={1} where F_RouteID={0} and F_DeviceIndex={2}", dv[i]["F_RouteID"], dv[i]["F_StartDevice"], fstartdev));
|
|
// dbo.ExecuteSql(sql.ToString());
|
|
// sql.Clear();//replace F_DeviceIndex dv[i]["F_EndDevice"].ToString()
|
|
// sql.Append(string.Format("update T_Base_Route_DeviceBAK set F_DeviceIndex={1} where F_RouteID={0} and F_DeviceIndex={2}", dv[i]["F_RouteID"], dv[i]["F_EndDevice"], fenddev));
|
|
// dbo.ExecuteSql(sql.ToString());
|
|
|
|
// //sql.Clear();//delete 30101--30107;30201--30207;40101--40110
|
|
// //sql.Append("delete T_Base_Route_DeviceBAK where ((F_DeviceIndex>=30101 and F_DeviceIndex<=30107) or (F_DeviceIndex>=30201 and F_DeviceIndex<=30207) or (F_DeviceIndex>=40101 and F_DeviceIndex<=40110)) and F_RouteID=").Append(dv[i]["F_RouteID"]);
|
|
// //dbo.ExecuteSql(sql.ToString());
|
|
// }
|
|
//}
|
|
|
|
#endregion
|
|
|
|
#region 插入虚拟设备
|
|
|
|
//DataView ob = null; string sql = string.Empty; object obb = null; object[] arr = new object[6];
|
|
//DataView dv = dbo.ExceSQL("SELECT DISTINCT F_RouteIDSub FROM T_Base_Route_Device WHERE (F_RouteID >= 228) and (F_RouteID <= 251) GROUP BY F_RouteIDSub").Tables[0].DefaultView;
|
|
//for (int i = 0; i < dv.Count; i++)
|
|
//{
|
|
|
|
// obb = dbo.GetSingle("select (max(F_RouteDeviceIndex )+1) as maxfdi from T_Base_Route_Device");
|
|
// ob = dbo.ExceSQL("SELECT top 1 F_RouteID, F_RouteIDSub, (max(F_SerialNumber)+1) as maxsn FROM T_Base_Route_Device WHERE (F_RouteIDSub = " + dv[i][0] + ") GROUP BY F_RouteID, F_RouteIDSub order by maxsn desc").Tables[0].DefaultView;
|
|
// arr[0] = Convert.ToInt32(obb);
|
|
// arr[1] = ob[0][0];
|
|
// arr[2] = ob[0][1];
|
|
// arr[3] = 46005;
|
|
// arr[4] = ob[0][2];
|
|
// arr[5] = -1;
|
|
// dbo.ExecuteSql(string.Format("INSERT INTO T_Base_Route_Device (F_RouteDeviceIndex, F_RouteID, F_RouteIDSub, F_DeviceIndex, F_SerialNumber, F_DeviceOrder)VALUES ({0},{1},{2},{3},{4},{5})", arr));
|
|
// ////obb = dbo.GetSingle("select (max(F_RouteDeviceIndex )+1) as maxfdi from T_Base_Route_Device");
|
|
// ////ob = dbo.ExceSQL("SELECT top 1 F_RouteID, F_RouteIDSub, (max(F_SerialNumber)+1) as maxsn FROM T_Base_Route_Device WHERE (F_RouteIDSub = " + dv[i][0] + ") GROUP BY F_RouteID, F_RouteIDSub order by maxsn desc").Tables[0].DefaultView;
|
|
// ////arr[0] = Convert.ToInt32(obb);
|
|
// ////arr[1] = ob[0][0];
|
|
// ////arr[2] = ob[0][1];
|
|
// ////arr[3] = 35002;
|
|
// ////arr[4] = ob[0][2];
|
|
// ////arr[5] = -1;
|
|
// ////dbo.ExecuteSql(string.Format("INSERT INTO T_Base_Route_Device (F_RouteDeviceIndex, F_RouteID, F_RouteIDSub, F_DeviceIndex, F_SerialNumber, F_DeviceOrder)VALUES ({0},{1},{2},{3},{4},{5})", arr));
|
|
// //for (int j = 30201; j <= 30207; j++)
|
|
// //{
|
|
// // obb = dbo.GetSingle("select (max(F_RouteDeviceIndex )+1) as maxfdi from T_Base_Route_Device");
|
|
// // ob = dbo.ExceSQL("SELECT top 1 F_RouteID, F_RouteIDSub, (max(F_SerialNumber)+1) as maxsn FROM T_Base_Route_Device WHERE (F_RouteIDSub = " + dv[i][0] + ") GROUP BY F_RouteID, F_RouteIDSub order by maxsn desc").Tables[0].DefaultView;
|
|
// // arr[0] = Convert.ToInt32(obb);
|
|
// // arr[1] = ob[0][0];
|
|
// // arr[2] = ob[0][1];
|
|
// // arr[3] = j;
|
|
// // arr[4] = ob[0][2];
|
|
// // arr[5] = -1;
|
|
// // dbo.ExecuteSql(string.Format("INSERT INTO T_Base_Route_Device (F_RouteDeviceIndex, F_RouteID, F_RouteIDSub, F_DeviceIndex, F_SerialNumber, F_DeviceOrder)VALUES ({0},{1},{2},{3},{4},{5})", arr));
|
|
|
|
// //}
|
|
//}
|
|
|
|
#endregion
|
|
|
|
#region 修正46005
|
|
//DataView dv1; DataView dv0;
|
|
//DataView dv = dbo.ExceSQL("SELECT DISTINCT F_RouteIDSub FROM T_Base_Route_Device WHERE (F_RouteID >= 191) AND (F_RouteID <= 202)").Tables[0].DefaultView;
|
|
//for (int i = 0; i < dv.Count; i++)
|
|
//{
|
|
// dv0 = dbo.ExceSQL(string.Format("SELECT F_RouteDeviceIndex,f_deviceindex,F_RouteIDsub FROM T_Base_Route_Device WHERE (F_RouteIDSub={0}) and (F_DeviceOrder = - 1) ORDER BY F_SerialNumber asc", dv[i]["F_RouteIDSub"])).Tables[0].DefaultView;
|
|
// if (dv0.Count > 0)
|
|
// {
|
|
// dv1 = dbo.ExceSQL(string.Format("SELECT * FROM T_Base_Route_Device WHERE (F_RouteIDsub = {0}) and f_deviceindex=46005", dv0[0]["F_RouteIDsub"])).Tables[0].DefaultView;
|
|
// if (dv1.Count > 0)
|
|
// {
|
|
// dbo.ExecuteSql(string.Format("update T_Base_Route_Device set f_deviceindex=46005 where (F_RouteDeviceIndex = {0}) ", dv0[0]["F_RouteDeviceIndex"]));
|
|
// dbo.ExecuteSql(string.Format("update T_Base_Route_Device set f_deviceindex={1} where (F_RouteDeviceIndex = {0}) ", dv1[0]["F_RouteDeviceIndex"], dv0[0]["f_deviceindex"]));
|
|
// }
|
|
// }
|
|
//}
|
|
#endregion
|
|
//int appid = CommonClassLib.AppSettings.dboM.GetManageTableIndex("IO_CONTROL_APPLY", true);
|
|
object[] ob = new object[9] { 1, 12001, "S10086", 0, "15:37:46", "", "1", 1, 1 };
|
|
//CommonClassLib.AppSettings.dboM.ExceSQL("set identity_insert IO_CONTROL_APPLY on");
|
|
CommonClassLib.AppSettings.dboM.ExceSQL(string.Format("INSERT INTO IO_CONTROL_APPLY(CONTROL_APPLY_TYPE,DEVICE_CODE, STOCK_BARCODE, APPLY_TASK_STATUS, CREATE_TIME,CONTROL_APPLY_REMARK,WAREHOUSE_CODE)VALUES ({0},'{1}','{2}',{3},'{4}','{5}','{6}')", ob));
|
|
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.listBox2.Items.Clear();
|
|
var list = WcfControlMonitorLib.SControlMonitor.ClientCallbackLists;
|
|
if (list == null || list.Count == 0)
|
|
return;
|
|
lock (list)
|
|
{
|
|
foreach (System.Collections.DictionaryEntry client in list)
|
|
{
|
|
listBox2.Items.Add(client.Value.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf("刷新客户端时:" + ex.StackTrace + ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += "刷新客户端时:" + ex.StackTrace + ex.Message;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (listBox2.SelectedItem == null) return;
|
|
var list = WcfControlMonitorLib.SControlMonitor.ClientCallbackLists;
|
|
foreach (System.Collections.DictionaryEntry client in list)
|
|
{
|
|
if (client.Value.ToString() == listBox2.SelectedItem.ToString())
|
|
{
|
|
WcfControlMonitorLib.SControlMonitor.ClientShowLists.Remove(client.Key);
|
|
WcfControlMonitorLib.SControlMonitor.ClientCallbackLists.Remove(client.Key);
|
|
button4_Click(sender, e);
|
|
return;
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf("注销客户端时:" + ex.StackTrace + ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += "注销客户端时:" + ex.StackTrace + ex.Message;
|
|
}
|
|
}
|
|
}
|
|
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 timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{//20121203
|
|
//20130817richard
|
|
|
|
CStaticClass.WcfControl.Heartbeat(out mi);
|
|
if (mi.S7connectOnline.Count > 0)
|
|
{
|
|
if (mi.S7connectOnline.ContainsKey("S7 connection_1"))
|
|
{
|
|
if (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"))
|
|
{
|
|
if (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_3"))
|
|
{
|
|
if (mi.S7connectOnline["S7 connection_3"] == 0)
|
|
{
|
|
pbF3S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
|
|
}
|
|
else
|
|
{
|
|
pbF3S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
|
|
}
|
|
}
|
|
if (mi.S7connectOnline.ContainsKey("S7 connection_4"))
|
|
{
|
|
if (mi.S7connectOnline["S7 connection_4"] == 0)
|
|
{
|
|
pbF4S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
|
|
}
|
|
else
|
|
{
|
|
pbF4S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
|
|
}
|
|
}
|
|
if (mi.S7connectOnline.ContainsKey("S7 connection_5"))
|
|
{
|
|
if (mi.S7connectOnline["S7 connection_5"] == 0)
|
|
{
|
|
pbF5S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressSuccess;
|
|
}
|
|
else
|
|
{
|
|
pbF5S7.Image = wcfControlMonitorClient.Properties.Resources.ProgressError;
|
|
}
|
|
}
|
|
}
|
|
if (mi.Orderturnon == true)
|
|
{
|
|
ClickOrderTurnOn();
|
|
}
|
|
else
|
|
{
|
|
ClickOrderTurnOff();
|
|
}
|
|
if (mi.Obtaintask == true)
|
|
{
|
|
ClickObtainTask();
|
|
}
|
|
else
|
|
{
|
|
ClickStopObtainTask();
|
|
}
|
|
timersum++;//20120513
|
|
if (timersum > 60)//20120513
|
|
{
|
|
listBox1.Items.Clear();
|
|
timersum = 0;
|
|
dv = dbo.ExceSQL("SELECT T_Monitor_Task.F_MonitorIndex,T_Base_Device.F_DeviceIndex FROM T_Base_Device,T_Monitor_Task where T_Base_Device.F_DeviceIndex = T_Monitor_Task.F_DeviceIndex and (T_Base_Device.F_DeviceKindIndex = 1 OR T_Base_Device.F_DeviceKindIndex = 4) and F_Status>0 and F_StartTime<>'-' and (datediff(MINUTE,CONVERT(datetime,SUBSTRING( F_StartTime,1,19),120),GETDATE()) >5)").Tables[0].DefaultView;
|
|
for (int i = 0; i < dv.Count; i++)
|
|
{
|
|
CStaticClass.WcfControl.ActionError(Convert.ToInt32(dv[i][1]), Convert.ToInt32(dv[i][0]), 999);
|
|
CStaticClass.dbo.ExecuteSql(string.Format("update T_Base_Device set F_ErrorTaskNo=0 where F_ErrorTaskNo={0}", Convert.ToInt32(dv[i][0])));
|
|
}
|
|
}
|
|
SendMessageToClient("巡检客户端");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tsStatus.Text.IndexOf("巡检客户端时:" + ex.StackTrace + ex.Message) < 0)
|
|
{
|
|
tsStatus.Text += "巡检客户端时:" + ex.StackTrace + ex.Message;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 指示灯点亮和熄灭
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void Timer2_Tick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//TODO 控制灯塔亮灭
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.Clear();
|
|
sql.AppendFormat("SELECT * FROM T_Base_Device WHERE F_DeviceKindIndex = 16 ");
|
|
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
sql.Clear();
|
|
sql.AppendFormat($"SELECT DEVICE_CODE FROM IO_CONTROL_APPLY WHERE APPLY_TASK_STATUS = 2 ");
|
|
int[] arr = dbo.ExceSQL(sql.ToString()).Tables[0].AsEnumerable().Select(c => Convert.ToInt32(c.Field<string>("DEVICE_CODE"))).ToArray();
|
|
if (dv.Count > 0)
|
|
{
|
|
int[] state = new int[] { 0, 0 };
|
|
for (int i = 0; i < dv.Count; i++)
|
|
{
|
|
int DeviceIndex = Convert.ToInt32(dv[i]["F_DeviceIndex"]);
|
|
int tempDevice = 0;
|
|
switch (DeviceIndex)
|
|
{
|
|
case 17001: tempDevice = 19001; break;
|
|
case 17002: tempDevice = 19002; break;
|
|
case 17003: tempDevice = 19003; break;
|
|
case 27002: tempDevice = 29002; break;
|
|
case 27003: tempDevice = 29003; break;
|
|
case 27004: tempDevice = 29004; break;
|
|
case 27005: tempDevice = 29005; break;
|
|
case 27006: tempDevice = 29006; break;
|
|
case 37003:
|
|
tempDevice = 39003;
|
|
break;
|
|
}
|
|
Model.MDevice tempDevinfo = Model.CGetInfo.GetDeviceInfo(tempDevice);//AGV站台
|
|
Model.MDevice lampDevinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);//AGV站台 塔灯
|
|
|
|
sql.Clear();
|
|
sql.Append($"SELECT * FROM T_Manage_Task WHERE FENDDEVICE = {tempDevice} ");
|
|
int task = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count;
|
|
int[] lampState = lampDevinfo.ReturnMessage;
|
|
//无货无任务,亮绿灯
|
|
if (tempDevinfo.SplitByte_0 == 0 && arr.Contains(tempDevice) == false && task <= 0)
|
|
{
|
|
state = new int[] { 1, 0 };
|
|
}
|
|
//无货有任务,亮红灯
|
|
else if (tempDevinfo.SplitByte_0 == 0 && arr.Contains(tempDevice) == true)
|
|
{
|
|
state = new int[] { 0, 1 };
|
|
}
|
|
//有任务,不亮灯
|
|
else if (task > 0)
|
|
{
|
|
state = new int[] { 0, 0 };
|
|
}
|
|
//有货,不亮灯
|
|
else
|
|
{
|
|
state = new int[] { 0, 0 };
|
|
}
|
|
if (lampState != null && lampState.Length > 1)
|
|
{
|
|
if (lampState[0] != state[0] || lampState[1] != state[1])
|
|
{
|
|
CStaticClass.WcfControl.WriteDBData1(DeviceIndex, "DB2", string.Join(",", state), out string errtext);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|