天津康师傅调度系统
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.
 
 

1548 lines
65 KiB

using Opc.Ua;
using OPCClient;
using Snap7;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace wcfControlMonitorClient
{
/// <summary>
/// Creator:Richard.liu
/// 调度程序主窗口
/// </summary>
public partial class FrmControlMonitor : WeifenLuo.WinFormsUI.Docking.DockContent
{
StringBuilder sql = new StringBuilder();
Model.MDevice devinfo;
Model.MDevice devinfostop;
FrmDeviceStatus _deviceStatus = new FrmDeviceStatus();
DBFactory.DBOperator dbo = CStaticClass.dbo;
DBFactory.DBOperator dboM = CStaticClass.dboM;
DBFactory.DBOperator dbo1 = new DBFactory.DBOperator();
private static FrmControlMonitor _formInstance;
public static FrmControlMonitor FormInstance
{
get
{
if (_formInstance == null)
{
_formInstance = new FrmControlMonitor();
}
return _formInstance;
}
set { _formInstance = value; }
}
#region 货物探测重写-1 zcy
//第一步和第二步,是为了减少了第三步中的时间
TextBox[] myTextBox = new System.Windows.Forms.TextBox[800]; //海湾输送线500左右,此处定义数组数量要大于输送线数量
int initNum = 0;
#endregion
public FrmControlMonitor()
{
InitializeComponent();
#region 货物探测重写-2 zcy 只定义最基本的属性
for (int i =0; i< myTextBox.Length; i++)
{
myTextBox[i] = new System.Windows.Forms.TextBox();
myTextBox[i].BackColor = System.Drawing.Color.Blue;
myTextBox[i].BorderStyle = System.Windows.Forms.BorderStyle.None;
myTextBox[i].Enabled = false;
myTextBox[i].Multiline = true;
myTextBox[i].Visible = false;
}
#endregion
//this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
////设定字体大小为12px
//this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
_formInstance = this;
}
#region 方法
public void FlashPanit(string obj, bool visible)
{
this.Controls[obj].Visible = visible;
}
public void FlashPanit(string obj, Image backgroundImage)
{
this.Controls[obj].BackgroundImage = backgroundImage;
}
public void FlashPanit(string obj, ImageLayout backgroundImageLayout)
{
this.Controls[obj].BackgroundImageLayout = backgroundImageLayout;
}
public void FlashPanit(string obj, int top, int left)
{
this.Controls[obj].Top = top;
this.Controls[obj].Left = left;
}
public void FlashPanit(string obj, string text, bool append)
{
if (append == true)
{
this.Controls[obj].Text += text;
}
else
{
this.Controls[obj].Text = text;
}
}
public string GetObjectText(string obj)
{
return this.Controls[obj].Text;
}
public void MonitorRefresh(object dataSource)
{
#region Added by DingXiaoxu for Dock TaskList on 20101219
FrmTaskList.FormInstance.MonitorRefresh(dataSource);
#endregion
//this.dgvMonitor.DataSource = dataSource;
////20100108
//dataSource = null;
}
public void ManagerRefresh(object dataSource)
{
#region Added by DingXiaoxu for Dock TaskList on 20101219
FrmTaskList.FormInstance.ManagerRefresh(dataSource);
#endregion
//this.dgvManager.DataSource = dataSource;
////20100108
//dataSource = null;
}
#endregion
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;//WS_CLIPCHILDREN 两个窗体叠加时,重叠部分不重绘
return cp;
}
}
#region 每个项目需要重新填的
double laneStartlocation = 400;
double laneEndlocation = 1160;
int lastCellY = 62; //最大货位列
#endregion
private void timerFlash_Tick(object sender, EventArgs e)
{
string[] DS; char[] dd = new char[1] { '.' };
Model.MDevice device;
DataView dv; DataView dvJY;
this.SuspendLayout(); //richard.liu20140806
try
{
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";
#region 堆垛机绑定
Button stack1 = bStack11;
Button stack2 = bStack12;
Button stack3 = bStack13;
Button stack4 = bStack14;
Button stack5 = bStack15;
Button stack6 = bStack16;
Button stack7 = bStack17;
Button stack8 = bStack18;
Button stack9 = bStack19;
TextBox tw1n = tb11;
TextBox tw2n = tb12;
TextBox tw3n = tb13;
TextBox tw4n = tb14;
TextBox tw5n = tb15;
TextBox tw6n = tb16;
TextBox tw7n = tb17;
TextBox tw8n = tb18;
TextBox tw9n = tb19;
//step 堆垛机之间的距离长度,areastep立库两跨之间的额外长度
int step = 105; int areastep = 65;
Panel pp = plAccessorial1;
if (this.tabControl1.SelectedTab.Name == "tabPage2")
{
pp = plAccessorial2;
stack1 = bStack21;
stack2 = bStack22;
stack3 = bStack23;
stack4 = bStack24;
stack5 = bStack25;
stack6 = bStack26;
stack7 = bStack27;
stack8 = bStack28;
stack9 = bStack29;
tw1n = tb21;
tw2n = tb22;
tw3n = tb23;
tw4n = tb24;
tw5n = tb25;
tw6n = tb26;
tw7n = tb27;
tw8n = tb28;
tw9n = tb29;
laneStartlocation = 423;//第一、二跨的列起点
laneEndlocation = 154;//第一、二跨的列终点
}
else if (this.tabControl1.SelectedTab.Name == "tabPage3")
{
pp = plAccessorial3;
stack1 = bStack31;
stack2 = bStack32;
stack3 = bStack33;
stack4 = bStack34;
stack5 = bStack35;
stack6 = bStack36;
stack7 = bStack37;
stack8 = bStack38;
stack9 = bStack39;
tw1n = tb31;
tw2n = tb32;
tw3n = tb33;
tw4n = tb34;
tw5n = tb35;
tw6n = tb36;
tw7n = tb37;
tw8n = tb38;
tw9n = tb39;
laneStartlocation = 398;//第三、四跨的列起点
laneEndlocation = 398+760;//第三、四跨的列终点
}
#endregion 堆垛机绑定
#region 每层楼监视画面
foreach (Button ctrl in pp.Controls.OfType<Button>())
{
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 (device.DeviceKind == 1)
{
#region 托盘
{
double k = (double)(760 - bStack11.Size.Width) / (double)62; //图上货架长度/货架列数,
////double k = (double)(1070) / (double)13100;//图上货架长度/货架实际长度
////double k = (double)(panel_Length.Size.Height - 40) / (double)11947;//1067/40560
////double k = 0.0263067;//1067/40560
////double startcode = 901;//第一列对应的实际坐标
double a = 0;
int xcoor = device.XCoor;
int zcoor = device.ZCoor;
//locationY 堆垛机的列坐标=>动画位置 Y方向
int locationX = (int)laneStartlocation;
if (xcoor == 1)
{
//locationX += stack1.Size.Width; //原点在货架右侧
//locationX -= stack1.Size.Width; //原点在货架左侧
locationX += bStack11.Size.Height;
}
else if (xcoor == 63)
{
locationX = (int)laneEndlocation - bStack11.Size.Height;
}
else
{
//locationX = (int)(startadd + a - k * (xcoor - 2)); //原点在货架右侧
locationX = (int)(laneStartlocation + a + k * (xcoor - 2)); //原点在货架左侧
//locationY = (int)(startadd + a + k * (xcoor - 1)); //原点在货架上侧
//locationY = (int)(laneStartlocation + a - k * (xcoor - 1)); //原点在货架下侧
}
//int locationX = (int)(startadd + a + k * (xcoor - 2)); //堆垛机在站台位置的X坐标
int locationY = 132;
int twx = 8, twy = 7;
switch (device.DeviceIndex)
{
case 11001:
//if (stack1.Location.X != locationX || stack1.Location.Y != locationY)
//{
// stack1.Location = new Point(locationX, locationY);
// tw1n.Location = new Point(locationX + twx, locationY + twy);
//}
//break;
case 11002:
//locationX += step;
//if (stack2.Location.X != locationX || stack2.Location.Y != locationY)
//{
// stack2.Location = new Point(locationX, locationY);
// tw2n.Location = new Point(locationX + twx, locationY + twy);
//}
break;
case 11003:
//locationX += step * 2;
//if (stack3.Location.X != locationX || stack3.Location.Y != locationY)
//{
// stack3.Location = new Point(locationX, locationY);
// tw3n.Location = new Point(locationX + twx, locationY + twy);
//}
break;
}
}
#endregion
}
else if (device.DeviceKind == 4)
{
//穿梭车和提升机
}
else if (device.DeviceKind == 2)
{
//台车
}
#endregion
#region 设置设备状态
switch (device.RunState)
{
//空闲
case 0:
if (device.DeviceKind == 1 || device.DeviceKind == 4 || device.DeviceKind == 17)
{
if (device.ControlMode > 0)
{
ctrl.BackColor = Color.DarkViolet;
}
else
{
ctrl.BackColor = Color.Orange;
}
}
else
{
//if (device.DeviceIndex >= 13014 && device.DeviceIndex <= 13015)
//{
// ctrl.BackColor = Color.LightPink;
//}
//else if (device.DeviceIndex == 12014 || device.DeviceIndex == 12018 || device.DeviceIndex == 12022)
//{
// ctrl.BackColor = Color.LightPink;
//}
//else if (device.DeviceIndex >= 19001 && device.DeviceIndex <= 19003)
//{
// ctrl.BackColor = Color.Khaki;
//}
//else if (device.DeviceIndex >= 13007 && device.DeviceIndex <= 13008)
//{
// ctrl.BackColor = Color.Khaki;
//}
//else
{
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.SeaGreen;//MediumOrchid;
break;
}
#endregion
#region 设备被禁用
//richar.liu20140806
int index = dvJY.Find(device.DeviceIndex);
if (index >= 0)
{
ctrl.BackColor = Color.Maroon;
}
if (device.VirtualStack > 0 && index >= 0)//互斥堆垛机被禁用
{
ctrl.Visible = false;
}
else
{
ctrl.Visible = true;
}
#endregion
}
//foreach (TextBox ctrl in pp.Controls.OfType<TextBox>())
//{
// if (ctrl.Tag.ToString() == "11001.0" || ctrl.Tag.ToString() == "11002.0" || ctrl.Tag.ToString() == "11003.0")
// {
// int bbb = 3;
// bbb = bbb + 1;
// }else
// {
// continue;
// }
//}
#region 货物探测 TextBox
foreach (TextBox ctrl in pp.Controls.OfType<TextBox>())
{
if (ctrl.Tag == null || ctrl.Tag.ToString() == "") continue; //2019.10.28 zcy
DS = ctrl.Tag.ToString().Split(dd);
if (DS.Length != 2) continue;
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;
}
int index = dvJY.Find(device.DeviceIndex);
switch (devbit)
{
case 0:
if (device.VirtualStack > 0 && index >= 0)//互斥堆垛机被禁用
{
ctrl.Visible = false;
}
else
{
//if (ctrl.Location.X == 0 && ctrl.Location.Y == 0)
ctrl.Visible = device.SplitByte_0 == 1 ? true : false;
}
break;
case 1:
if (device.VirtualStack > 0 && index >= 0)//互斥堆垛机被禁用
{
ctrl.Visible = false;
}
else
{
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 高位开关探测 Label
foreach (Label ctrl in pp.Controls.OfType<Label>())
{
if (ctrl.Tag != null && ctrl.Tag.ToString() != "" && ctrl.ForeColor != Color.Red)
{
DS = ctrl.Tag.ToString().Split(dd);
if (DS.Length <= 1) continue; //WXSS
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;
}
if (devbit < 8)
{
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;
}
}
else
{
devbit = devbit % 8;
switch (devbit)
{
case 0:
ctrl.Visible = (device.SplitByte_5 & 1) == 1 ? true : false;
break;
case 1:
ctrl.Visible = (device.SplitByte_5 & 2) == 2 ? true : false;
break;
case 2:
ctrl.Visible = (device.SplitByte_5 & 4) == 4 ? true : false;
break;
case 3:
ctrl.Visible = (device.SplitByte_5 & 8) == 8 ? true : false;
break;
case 4:
ctrl.Visible = (device.SplitByte_5 & 16) == 16 ? true : false;
break;
case 5:
ctrl.Visible = (device.SplitByte_5 & 32) == 32 ? true : false;
break;
case 6:
ctrl.Visible = (device.SplitByte_5 & 64) == 64 ? true : false;
break;
case 7:
ctrl.Visible = (device.SplitByte_5 & 128) == 128 ? true : false;
break;
}
}
}
}
#endregion
#region 逻辑有物显示 RadioButton
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 ( ctrl.Tag.ToString()!="")
// {
// DS = ctrl.Tag.ToString().Split(dd);
// if(DS.Length>1)
// {
// 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;
// break;
// case 7:
// ctrl.Visible = device.SplitByte_7 == 1 ? true : false;
// break;
// }
// }
// }
//}
#endregion
//20200303
#region WCS急停、入库灯、安全门 PictureBox
foreach (PictureBox ctrl in pp.Controls.OfType<PictureBox>())
{
if (ctrl.Enabled == false) continue;
if (ctrl.Tag == null || ctrl.Tag.ToString() == "") continue;
if (ctrl.Tag.ToString().IndexOf(".") <= 0)
{
#region 急停按钮
string devicestops = Convert.ToString(ctrl.Tag);
if (devicestops.Length == 7 )
{
int devicestop = Convert.ToInt32(devicestops.Substring(0, 5));//取道堆垛机的设备编号
device = Model.CGetInfo.GetDeviceInfo(devicestop);
if (device != null)
{
Label labelname = new Label();
foreach (Label ll in pp.Controls.OfType<Label>())
{
if (ll.Tag == ctrl.Tag)
{
labelname = ll;
break;
}
}
if (device.SplitByte_6 == 0)//0为急停
{
ctrl.Image = wcfControlMonitorClient.Properties.Resources.stop000;
//labelname.Text = "取消联机停车";
}
else
{
ctrl.Image = wcfControlMonitorClient.Properties.Resources.stop111;
//labelname.Text = " 联机停车";
}
}
ctrl.Visible = true;
//ctrl.Visible = false;
}
#endregion
#region 入库灯
string light = Convert.ToString(ctrl.Tag);
if (light.Length == 5 && (light.IndexOf('.') <= 0))
{
int devicelight = Convert.ToInt32(ctrl.Tag);//入库灯设备编号
device = Model.CGetInfo.GetDeviceInfo(devicelight);
if (device != null)
{
ctrl.Visible = device.RunState == 1 ? true : false;
}
}
#endregion
continue;
}
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;
break;
case 7:
ctrl.Visible = device.SplitByte_7 == 1 ? true : false;
break;
}
}
#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 Button Stack_Location_(Model.MDevice device)
{
Button stack = new Button();
#region 托盘
{
double k = (double)(760 - bStack11.Size.Width) / (double)62; //图上货架长度/货架列数,
double a = 0;
int xcoor = device.XCoor;
int zcoor = device.ZCoor;
//locationY 堆垛机的列坐标=>动画位置 Y方向
int locationX = (int)laneStartlocation;
if (xcoor == 1)
{
//locationX += bStack1.Size.Width; //原点在货架右侧
locationX -= bStack11.Size.Width; //原点在货架左侧
//locationX += bStack1.Size.Height;
}
else if (xcoor == 63)
{
locationX = (int)laneEndlocation - bStack11.Size.Height;
}
else
{
//locationX = (int)(startadd + a - k * (xcoor - 2)); //原点在货架右侧
locationX = (int)(laneStartlocation + a + k * (xcoor - 2)); //原点在货架左侧
//locationY = (int)(startadd + a + k * (xcoor - 1)); //原点在货架上侧
//locationY = (int)(laneStartlocation + a - k * (xcoor - 1)); //原点在货架下侧
}
//int locationX = (int)(startadd + a + k * (xcoor - 2)); //堆垛机在站台位置的X坐标
int locationY = 132;
int twx = 8, twy = 7;
switch (device.DeviceIndex)
{
case 11001:
if (stack.Location.X != locationX || stack.Location.Y != locationY)
{
stack.Location = new Point(locationX, locationY);
//tw1n.Location = new Point(locationX + twx, locationY + twy);
}
break;
//case 11002:
// locationX += step;
// if (stack2.Location.X != locationX || stack2.Location.Y != locationY)
// {
// stack2.Location = new Point(locationX, locationY);
// //tw2n.Location = new Point(locationX + twx, locationY + twy);
// }
// break;
//case 11003:
// locationX += step * 2;
// if (stack3.Location.X != locationX || stack3.Location.Y != locationY)
// {
// stack3.Location = new Point(locationX, locationY);
// //tw3n.Location = new Point(locationX + twx, locationY + twy);
// }
// break;
}
}
#endregion
return stack;
}
private void ctrl_Click(object sender, EventArgs e) //控件的单击事件,运行时单击触发
{
Button btn = (Button)sender;
_deviceStatus.DeviceIndex = Convert.ToInt32(btn.Tag);
_deviceStatus.ShowDialog();
}
private void Btn_MouseEnter(object sender, EventArgs e) //控件的鼠标进入事件,运行鼠标移动到控件上即可触发
{
int deviceindex;
string[] DS; char[] dd = new char[1] { '.' };
string msg = (sender as Control).Tag.ToString();
string name = (sender as Control).Name.ToString();
DS = msg.Split(dd);
if (DS.Length > 0)
{
if (int.TryParse(DS[0], out deviceindex))
{
devinfo = Model.CGetInfo.GetDeviceInfo(deviceindex);
if (devinfo != null)
{
//msg = string.Format("{0},位置X,Y:({1},{2})", devinfo.DeviceName, (sender as Control).Location.X,(sender as Control).Location.Y+83);
msg = string.Format("{0}", devinfo.DeviceName);
if (DS.Length > 1)
{
if (DS[1] == "5")
{
msg = "安全门打开";
}
}
//msg = string.Format("{0}", devinfo.DeviceName);
}
}
}
if(name.IndexOf("lift")>0)
{
msg = "请立即搬离托盘!";
}
toolTip_DeviceIndex.SetToolTip(sender as Control, msg);
}
private void ctrl_ClickPicStop(object sender, EventArgs e)
{
PictureBox btn = (PictureBox)sender;
int devicestop = Convert.ToInt32(btn.Tag);
int device = Convert.ToInt32(devicestop.ToString().Substring(0, 5));
//int device = Convert.ToInt32(devicestop.ToString().Substring(0, 4)); //WXSS
devinfostop = Model.CGetInfo.GetDeviceInfo(device);
if (devinfostop != null)
{
//int iValue = 0;
//iValue = devinfostop.SplitByte_6 == 1 ? 0 : 1;
//CStaticClass.WcfControl.BeginSendDeviceReset(devicestop, iValue, new AsyncCallback(SendDeviceResetCallBack), iValue);
int iValue = 1;
iValue = devinfostop.SplitByte_6 == 0 ? 1 : 0;
//if (iValue == 1)
//{
CStaticClass.WcfControl.BeginSendDeviceReset(devicestop, 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);
}
else
{
if (ar.AsyncState != null)
{
}
}
}
private void ctrl_ClickLabel(object sender, EventArgs e)
{
Label label = (Label)sender;
_deviceStatus.DeviceIndex = Convert.ToInt32(label.Tag);
_deviceStatus.ShowDialog();
}
/// <summary>
/// 滚动方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void FormSample_MouseWheel(object sender, MouseEventArgs e)
{
////获取光标位置
//Point mousePoint = new Point(e.X, e.Y);
////换算成相对本窗体的位置
//mousePoint.Offset(this.Location.X, this.Location.Y);
////判断是否在panel内
//if (panelWareHouse.RectangleToScreen(panelWareHouse.DisplayRectangle).Contains(mousePoint))
//{
// //滚动
// panelWareHouse.AutoScrollPosition = new Point(0, panelWareHouse.VerticalScroll.Value - e.Delta);
//}
}
private void FrmControlMonitor_Load(object sender, EventArgs e)
{
try
{
//this.panelWareHouse.MouseWheel += new MouseEventHandler(FormSample_MouseWheel);
//this.panelWareHouse.Focus();
#region 添加输送机、穿梭车和堆垛机的单击事件 (注册事件)
//foreach (Control ctrl in this.plAccessorial1.Controls)
//{
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.Button") && (ctrl.Tag != null))
// {
// ctrl.Click += new EventHandler(ctrl_Click);
// ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// }
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.Label") && (ctrl.Tag != null) && (ctrl.ForeColor == Color.Red))
// {
// ctrl.Click += new EventHandler(ctrl_ClickLabel);
// ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// }
// //if ((ctrl.GetType().ToString() == "System.Windows.Forms.Label") && (ctrl.Tag != null) && (ctrl.BackColor == Color.LightSteelBlue))
// //{
// // ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// //}
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Tag != null) && (ctrl.Enabled == true))
// {
// //ctrl.Click += new EventHandler(ctrl_ClickPic);
// ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// }
//}
//foreach (Control ctrl in this.panelWareHouse.Controls)
//{
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.Button") && (ctrl.Tag != null))
// {
// ctrl.Click += new EventHandler(ctrl_Click);
// ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// }
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.Label") && (ctrl.Tag != null) && (ctrl.ForeColor == Color.Red))
// {
// ctrl.Click += new EventHandler(ctrl_ClickLabel);
// ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// }
// //if ((ctrl.GetType().ToString() == "System.Windows.Forms.Label") && (ctrl.Tag != null) && (ctrl.ForeColor == Color.Blue))
// //{
// // ctrl.Visible = true;
// // ctrl.Visible = false;
// //}
// //if ((ctrl.GetType().ToString() == "System.Windows.Forms.Label") && (ctrl.Tag != null) && (ctrl.BackColor == Color.LightSteelBlue))
// //{
// // ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// //}
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Tag != null) && (ctrl.Enabled == true))
// {
// //ctrl.Click += new EventHandler(ctrl_ClickPic);
// ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// }
//}
//foreach (Control ctrl in this.InOutAreaPanel.Controls)
//{
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.Button") && (ctrl.Tag != null))
// {
// ctrl.Click += new EventHandler(ctrl_Click);
// ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// }
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.Label") && (ctrl.Tag != null) && (ctrl.ForeColor == Color.Red))
// {
// ctrl.Click += new EventHandler(ctrl_ClickLabel);
// ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// }
// //if ((ctrl.GetType().ToString() == "System.Windows.Forms.Label") && (ctrl.Tag != null) && (ctrl.ForeColor == Color.Blue))
// //{
// // ctrl.Visible = true;
// // ctrl.Visible = false;
// //}
// //if ((ctrl.GetType().ToString() == "System.Windows.Forms.Label") && (ctrl.Tag != null) && (ctrl.BackColor == Color.LightSteelBlue))
// //{
// // ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// //}
// if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Tag != null) && (ctrl.Enabled == true))
// {
// //ctrl.Click += new EventHandler(ctrl_ClickPic);
// ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
// }
//}
#endregion
foreach (TabPage tabPage in tabControl1.TabPages)
{
if (tabPage.Tag.ToString() == CStaticClass.UserArea || CStaticClass.UserArea == "")
{
foreach (Control ctrls in tabPage.Controls)
{
if (ctrls.GetType().ToString() == "System.Windows.Forms.Panel")
{
foreach (Control ctrl in ctrls.Controls)
{
if ((ctrl.GetType().ToString() == "System.Windows.Forms.Button") && (ctrl.Tag != null))
{
ctrl.Click += new EventHandler(ctrl_Click);
ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
}
if ((ctrl.GetType().ToString() == "System.Windows.Forms.Label") && (ctrl.Tag != null) && (ctrl.ForeColor == Color.Red))
{
ctrl.Click += new EventHandler(ctrl_ClickLabel);
ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
}
//if ((ctrl.GetType().ToString() == "System.Windows.Forms.Label") && (ctrl.Tag != null) && (ctrl.BackColor == Color.LightSteelBlue))
//{
// ctrl.MouseEnter += new EventHandler(Btn_MouseEnter);
//}
if ((ctrl.GetType().ToString() == "System.Windows.Forms.PictureBox") && (ctrl.Tag != null) && (ctrl.Enabled == true))
{
if ((Convert.ToString(ctrl.Tag).Length == 7) && (ctrl.Tag.ToString().IndexOf(".")<=0))
{
ctrl.Click += new EventHandler(ctrl_ClickPicStop);
}
else
{
//ctrl.Click += new EventHandler(ctrl_ClickPic);
ctrl.Click += new EventHandler(Btn_MouseEnter);
}
}
}
}
}
}
else
{
tabPage.Parent = null;
}
}
String noAutoPaintSplit1 = "12110;12115;12125;12130;12140;12145;12153;12158;12168;12173;12183;12188;22103;22106;22109";
string noAutoPaintSplit2 = "12049;12052;1205512058;12061;12064;12067;12070;12009;12012;12015;12018;12029;12032;12035;12038;";
string noAutoPaintSplit3 = "42026;42018;42005;32037;32024;32016;32003;32001";
#region 货物探测重写-3 zcy
/*foreach (Panel p in this.tabControl1.TabPages)
{
Panel pp = p;
if (p == tabPage1)
{
pp = plAccessorial1;
}
if (p == tabPage2)
{
pp = plAccessorial2;
}
if (p == tabPage3)
{
pp = plAccessorial3;
}
//foreach里不要改变元素总数,对循环有影响,先放进list,再统一添加
List<TextBox> addTB = new List<TextBox>();
foreach (Button ctrl in pp.Controls.OfType<Button>())
{
int dev = 0;
if (ctrl.Tag == null || ctrl.Tag.ToString() == "") continue;
if (int.TryParse(ctrl.Tag.ToString(), out dev) == false)
{
continue;
}
//如果有顶升站台或有多个光电点位,在这里不自动生成
//string noAutoGate = "";
//if (noAutoGate.Contains(ctrl.Tag.ToString()) )
//{
// continue;
//}
devinfo = Model.CGetInfo.GetDeviceInfo(dev);
if (devinfo != null && devinfo.DeviceKind == 2)
{
if ( (noAutoPaintSplit1.Contains(dev.ToString()) == false) &&
(noAutoPaintSplit2.Contains(dev.ToString()) == false) &&
(noAutoPaintSplit3.Contains(dev.ToString()) == false) )
{
//TextBox temp = new System.Windows.Forms.TextBox(); //感觉此处new用的时间要长一些
TextBox temp = myTextBox[initNum];
initNum++;
addTB.Add(temp);
//temp.Location = new System.Drawing.Point(0, 0); //经过测试,计算坐标也需要一定时间,但没想到更好的方法
temp.Location = new System.Drawing.Point(ctrl.Location.X + ctrl.Width / 4, ctrl.Location.Y + ctrl.Height / 4);
temp.Name = ctrl.Tag.ToString() + "_0";
temp.Size = new System.Drawing.Size(ctrl.Width / 2, ctrl.Height / 2);
temp.Tag = ctrl.Tag.ToString() + ".0";
temp.Visible = true;
}
}
}
foreach (TextBox tb in addTB)
{
pp.Controls.Add(tb);
tb.BringToFront();
}
}*/
#endregion
}
catch (Exception ex)
{
throw (ex);
}
}
private void tsStatus_ForeColorChanged(object sender, EventArgs e)
{
FrmErrorMessage.FormInstance.NewForeColor((sender as TextBox).ForeColor);
}
private void tsStatus_TextChanged(object sender, EventArgs e)
{
//throw new System.Exception("The method or operation is not implemented.");
string msg = (sender as TextBox).Text;
if (msg != "")
{
//msg = string.Format("{0}\r\n", msg);
//msg=msg+"\r\n";
CommonClassLib.CCarryConvert.WriteDarkCasket("Error", msg, "", "", "");
FrmErrorMessage.FormInstance.NewMessage(msg);
}
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
int index = ((TabControl)sender).SelectedIndex;
if (index == 1)
{
//button242.Focus();
}
}
private void button1_Click(object sender, EventArgs e)
{
StringBuilder endcode = new StringBuilder();
StringBuilder startcode = new StringBuilder();
//if (textBox_in.Text != null && textBox_in.Text != "")
{
for (int i=1; i<9; i++)
{
string index = "1100" + i.ToString();
sql.Clear();
sql.Append("select * from T_Manage_Task where FControlTASKType = 4 and FSTARTDEVICE = ").Append(index);
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count == 0 )
{
//int devindex = Convert.ToInt32(dv[i]["FSTARTDEVICE"].ToString());
Model.MDevice device = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(index));
if (device.YCoor > 50 && device.RunState == 0)
{
endcode.Clear();
startcode.Clear();
endcode.Append(i.ToString().PadLeft(2,'0')).Append("-01-09");
startcode.Append(i.ToString().PadLeft(2, '0')).Append("-54-17");
}
if (device.YCoor < 10 && device.RunState == 0)
{
endcode.Clear();
startcode.Clear();
endcode.Append(i.ToString().PadLeft(2, '0')).Append("-54-17");
startcode.Append(i.ToString().PadLeft(2, '0')).Append("-01-09");
}
string arrloc = "1800" + i.ToString();
Model.HandTask ht = new Model.HandTask(device.DeviceIndex, 4, 0, arrloc, startcode.ToString(), "", 0, "");
CStaticClass.WcfControl.BeginBuildHandTask(ht, new AsyncCallback(BuildHandTaskCallBack), ht);
ht = new Model.HandTask(device.DeviceIndex, 5, 0, arrloc, "", endcode.ToString(), 0, "");
CStaticClass.WcfControl.BeginBuildHandTask(ht, new AsyncCallback(BuildHandTaskCallBack), ht);
}
}
}
}
void BuildHandTaskCallBack(IAsyncResult ar)
{
string errtext = string.Empty;
if (CStaticClass.WcfControl.EndBuildHandTask(out errtext, ar) == false)
{
MessageBox.Show(errtext, "操作提示:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
void BuildAutoTaskCallBack(IAsyncResult ar)
{
string errtext = string.Empty;
if (CStaticClass.WcfControl.EndBuildAutoTask(out errtext, ar) == false)
{
MessageBox.Show(errtext, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cb_SelectedIndexChanged(object sender, EventArgs e)
{
//DataSet ds = dbo.ExceSQL("select FLaneWay from ST_CELL where FLaneWay=" + Convert.ToInt32(cbstartposition.SelectedValue) + "");
////DataSet ds = dbo.ExceSQL("select F_DeviceIndex,F_DeviceKindIndex from T_Base_Device where F_DeviceKindIndex=10 and F_DeviceIndex=" + Convert.ToInt32(cbstartposition.SelectedValue) + "");
//if (ds.Tables[0].DefaultView.Count > 0)
//{
//}
}
#region 堆垛机方向和坐标自动计算
private void LR_Right() //货架方向左右,1列在货架右侧
{
}
private void LR_Left()//货架方向左右,1列在货架左侧
{
}
private int[] UD_Up(int xcoor, int ycoor, int k, int a) //货架方向上下,1列在货架上侧
{
//int startlocation = 0;
//int endlocation = 0;
//locationY 堆垛机的列坐标=>动画位置 Y方向
int locationY = (int)laneStartlocation;
if (xcoor == 1)
{
locationY += bStack11.Size.Height;
}
else if (xcoor == lastCellY + 1)
{
locationY = (int)laneEndlocation - bStack11.Size.Height;
}
else
{
locationY = (int)(laneStartlocation + a - k * (xcoor - 1));
}
int locationX = 40;
int[] locat = new int[2];
locat[0] = locationX;
locat[1] = locationY;
return locat;
}
private void UD_Down() //货架方向上下,1列在货架下侧
{
}
#endregion
string remoteIP = "192.168.2.50";
static DateTime d1, d2, d3;
static TimeSpan span1, span2, span3, span4, span5, span6;
static byte[] data1 = new byte[10];
static byte[] data2 = new byte[100];
static byte[] data3 = new byte[1000];
DataValueCollection dvc;
static S7Client myClient = new S7Client();
static S7Client myClient2 = new S7Client();
static S7Client myClient3 = new S7Client();
static byte[] res = new byte[1];
private static S7Client.S7CliCompletion CallBack = new S7Client.S7CliCompletion(CompletionProc);
private void timer1_Tick(object sender, EventArgs e)
{
{
int result = 0;
//myClient.SetAsCallBack(CallBack, new IntPtr(Convert.ToInt32(10)));
//result = myClient.ConnectTo(remoteIP, 0, 2);
//d1 = DateTime.Now;
//result = myClient.AsDBRead(2, 0, 10, data1);
//myClient2.SetAsCallBack(CallBack, new IntPtr(Convert.ToInt32(100)));
//int result2 = myClient2.ConnectTo(remoteIP, 0, 2);
//d2 = DateTime.Now;
//result = myClient2.AsDBRead(2, 0, 100, data2);
myClient3.SetAsCallBack(CallBack, new IntPtr(Convert.ToInt32(1000)));
int result3 = myClient3.ConnectTo(remoteIP, 0, 2);
d3 = DateTime.Now;
result = myClient3.AsDBRead(2, 0, 1000, data3);
return;
StringBuilder[] itemnames = new StringBuilder[1] { new StringBuilder("") };
StringBuilder[] resopc = new StringBuilder[1] { new StringBuilder("") };
StringBuilder[] resopc2 = new StringBuilder[1] { new StringBuilder("") };
resopc[0].Append('2');
resopc2[0].Append(Model.CGeneralFunction.DBGet).Append(".").Append(0).Append(",b");
itemnames[0].Append(Model.CGeneralFunction.DBGet).Append(".").Append(0).Append(",b,10");
d1 = DateTime.Now;
dvc = CCommonOPCClient.SyncReadAllItemValue(itemnames);
if (dvc.Count > 0)
{
//span4 = DateTime.Now - d1;
//CommonClassLib.CCarryConvert.WriteDarkCasket("Error", "READ10-1", "span4", span4.ToString(), "");
CCommonOPCClient.SyncWriteAllItemValue(resopc2, resopc);
span4 = DateTime.Now - d1;
CommonClassLib.CCarryConvert.WriteDarkCasket("Error", "READ10-WRITE1", "span4", span4.ToString(), "");
}
itemnames[0].Clear();
itemnames[0].Append(Model.CGeneralFunction.DBGet).Append(".").Append(0).Append(",b,100");
d2 = DateTime.Now;
dvc = CCommonOPCClient.SyncReadAllItemValue(itemnames);
if (dvc.Count > 0)
{
//span5 = DateTime.Now - d2;
//CommonClassLib.CCarryConvert.WriteDarkCasket("Error", "READ100-1", "span5", span5.ToString(), "");
CCommonOPCClient.SyncWriteAllItemValue(resopc2, resopc);
span5 = DateTime.Now - d2;
CommonClassLib.CCarryConvert.WriteDarkCasket("Error", "READ100-WRITE1", "span5", span5.ToString(), "");
}
itemnames[0].Clear();
itemnames[0].Append(Model.CGeneralFunction.DBGet).Append(".").Append(0).Append(",b,1000");
d3 = DateTime.Now;
dvc = CCommonOPCClient.SyncReadAllItemValue(itemnames);
if (dvc.Count > 0)
{
//span6 = DateTime.Now - d3;
//CommonClassLib.CCarryConvert.WriteDarkCasket("Error", "READ1000-1", "span6", span6.ToString(), "");
CCommonOPCClient.SyncWriteAllItemValue(resopc2, resopc);
span6 = DateTime.Now - d3;
CommonClassLib.CCarryConvert.WriteDarkCasket("Error", "READ1000-WRITE1", "span6", span6.ToString(), "");
}
}
}
static void CompletionProc(IntPtr usrPtr, int opCode, int opResult)
{
if (opResult == 0) //异步读写成功
{
int length = Convert.ToInt32(usrPtr.ToString());
#region 异步读回调处理
if (opCode == 1 )
{
if (length == 10)
{
//byte[] buff = new Byte[length];
//Array.Copy(data1, 0, buff, 0, length);
//span1 = DateTime.Now - d1;
//CommonClassLib.CCarryConvert.WriteDarkCasket("Error","READ-10", "span1", span1.ToString(), "");
int result = myClient.AsDBWrite(2, 0, 1, res);
}
if (length == 100)
{
//byte[] buff = new Byte[length];
//Array.Copy(data2, 0, buff, 0, length);
//span2 = DateTime.Now - d2;
//CommonClassLib.CCarryConvert.WriteDarkCasket("Error","READ-100", "span2", span2.ToString(), "");
int result = myClient2.AsDBWrite(2, 0, 1, res);
}
if (length == 1000)
{
//byte[] buff = new Byte[length];
//Array.Copy(data3, 0, buff, 0, length);
//span3 = DateTime.Now - d3;
//CommonClassLib.CCarryConvert.WriteDarkCasket("Error","READ-1000", "span3", span3.ToString(), "");
int result = myClient3.AsDBWrite(2, 0, 1, res);
}
}
#endregion
if (opCode == 2)
{
if (length == 10)
{
span1 = DateTime.Now - d1;
CommonClassLib.CCarryConvert.WriteDarkCasket("Error","READ10-WRITE1", "span1", span1.ToString(), "");
}
if (length == 100)
{
span2 = DateTime.Now - d2;
CommonClassLib.CCarryConvert.WriteDarkCasket("Error", "READ100-WRITE1", "span2", span2.ToString(),"");
}
if (length == 1000)
{
span3 = DateTime.Now - d3;
CommonClassLib.CCarryConvert.WriteDarkCasket("Error", "READ1000-WRITE1", "span3", span3.ToString(), "");
}
}
}
else
{
// 异步读取失败
#region 写入黑匣子
#endregion
}
}
}
}