Files
FG2608061/CODE/20230901/SA17168/AGVSystem Ver2.0/A17168/Frm_A17168.cs
T

1525 lines
59 KiB
C#
Raw Normal View History

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.Net.NetworkInformation;
using System.Threading;
using System.Collections;
using System.Runtime.InteropServices;
using System.Globalization;
using AGVSystem.Cls;
using Automation.BDaq;
using AGVSystem.A17168;
using HxBusiness;
namespace AGVSystem
{
public partial class Frm_A17168 : Form
{
public static int iJsState = 0;
public static ClsDBConn_sql newdb = new ClsDBConn_sql();
public static Cls_A17168 Agvcontrol = new Cls_A17168();
public static Frm_A17168 frm;
public static DataSet ds_Station_Info = new DataSet();
public static DataSet ds_Agv_Info_Interface = new DataSet();
public static ClsDBConn_sql db_station = new ClsDBConn_sql();
public static ClsDBConn_sql db_Agv_Info = new ClsDBConn_sql();
public static BusinessManage businessCtrl;
2026-08-19 17:02:08 +08:00
/// <summary>
/// 第三方交管自动归还秒数
/// </summary>
public static int TraffAutoTimet = 0;
/// <summary>
/// 第三方交管路口占用列表
/// </summary>
public static List<TrafficModel> autoLeavedDic = new List<TrafficModel>();
public static Dictionary<int, int> leavedDic = new Dictionary<int, int>();
/// <summary>
/// Array_Station_Info [17,12]
/// 17行 12列 数据库中去除前两列的数据
/// </summary>
public static int[,] Array_Station_Info = new int[17, 17];
/// <summary>
/// Btn_Filter [17,2]
/// 17条线 集配与线边的按钮
/// </summary>
public static int[,] Btn_Filter = new int[17, 3];
/// <summary>
/// 存储线边按钮放行信号
/// 为实现线边按钮放行后,集配区放行
/// </summary>
public static int[,] btn_line = new int[17, 2];
//保存机械手读取信息
public static int[,] Array_Robot_Status = new int[4, 8];
//保存机械手将要写入的信息
public static byte[,] Array_Robot_Set = new byte[4, 8];
public static byte[,] Array_Robot_Set_temp = new byte[4, 8];
/// <summary>
/// 线边AGV数量
/// </summary>
public static int[] nLine_Point_AGV_Num = new int[17];
//private LineShape lp = new LineShape();
/// <summary>
/// PB[17, 6]
/// </summary>
public static PictureBox[,] PB = new PictureBox[17, 9];
[DllImport("kernel32")]
public static extern uint GetTickCount();
public static Panel P1;
public static Panel P2;
public static Panel P3;
public static Panel P4;
public static Panel P5;
public static Panel P6;
public static Panel P7;
public static Panel P8;
public static Panel P9;
public static Panel P10;
public static Panel P11;
private PictureBox[] led = new PictureBox[16];
private Panel[] pnl = { P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11 };
/// <summary>
/// AGV智能管理启动状态
/// </summary>
public static bool AGV_Running = true;
/// <summary>
/// 保存所有AGV Socket客户端
/// </summary>
public static ArrayList al_AGVClientCls = new ArrayList();
private DataSet agv_list = new DataSet();
public Frm_A17168()
{
//byte[] a = new byte[8];
//a[6] = 99;
//int[,] n = new int[4, 8];
//n=Cls_Method.Array_Robot_Info(a);
//Cls_Method.HEX_To_BIN(34);
InitializeComponent();
frm = this;
mainfrm.Map1 = panel3;
mainfrm.Map2 = panel2;
mainfrm.Map3 = panel1;
businessCtrl = new BusinessManage();
2026-08-19 17:02:08 +08:00
//初始化第三方交管路口占用列表
if (businessCtrl != null && businessCtrl.apiModel != null)
{
TraffAutoTimet = businessCtrl.apiModel.AutoTime;
if (!string.IsNullOrEmpty(businessCtrl.apiModel.waitRfidList))
{
autoLeavedDic = new List<TrafficModel>();
foreach (string areaCode in businessCtrl.apiModel.waitRfidList.Split(','))
{
autoLeavedDic.Add(new TrafficModel
{
areaCode = areaCode
});
}
}
}
this.ControlBox = false;
this.Width = mainfrm.newmainfrm.ClientSize.Width - 5;
this.Height = mainfrm.newmainfrm.ClientSize.Height - 29 - 74 - 22 - 5;
Func.db_conn = new ClsDBConn_sql();
if (Cls.Param.Card1_Interval > 0)
{
try
{
instantDiCtrl1.SelectedDevice = mainfrm.myDevice_DI0;
instantDoCtrl1.SelectedDevice = mainfrm.myDevice_DO0;
tm_card.Interval = Cls.Param.Card1_Interval;
tm_card.Enabled = true;
instantDiCtrl1.SnapStart();
}
catch { }
}
if (Cls.Param.Card2_Interval > 0)
{
try
{
instantDiCtrl2.SelectedDevice = mainfrm.myDevice_DI1;
instantDoCtrl2.SelectedDevice = mainfrm.myDevice_DO1;
tm_card.Interval = Cls.Param.Card2_Interval;
tm_card.Enabled = true;
instantDiCtrl2.SnapStart();
}
catch { }
}
if (Cls.Param.Card3_Interval > 0)
{
try
{
instantDiCtrl3.SelectedDevice = mainfrm.myDevice_DI2;
instantDoCtrl3.SelectedDevice = mainfrm.myDevice_DO2;
tm_card.Interval = Cls.Param.Card3_Interval;
tm_card.Enabled = true;
instantDiCtrl3.SnapStart();
}
catch { }
}
pnl1.Height = Cls.Param.Icon_Size;
pnl2.Height = Cls.Param.Icon_Size;
pnl3.Height = Cls.Param.Icon_Size;
pnl4.Height = Cls.Param.Icon_Size;
pnl5.Height = Cls.Param.Icon_Size;
pnl6.Height = Cls.Param.Icon_Size;
pnl7.Height = Cls.Param.Icon_Size;
pnl8.Height = Cls.Param.Icon_Size;
pnl9.Height = Cls.Param.Icon_Size;
pnl10.Height = Cls.Param.Icon_Size;
pnl11.Height = Cls.Param.Icon_Size;
P1 = pnl1;
P2 = pnl2;
P3 = pnl3;
P4 = pnl4;
P5 = pnl5;
P6 = pnl6;
P7 = pnl7;
P8 = pnl8;
P9 = pnl9;
P10 = pnl10;
P11 = pnl11;
pnl[0] = P1;
pnl[1] = P2;
pnl[2] = P3;
pnl[3] = P4;
pnl[4] = P5;
pnl[5] = P6;
pnl[6] = P7;
pnl[7] = P8;
pnl[8] = P9;
pnl[9] = P10;
pnl[10] = P11;
//led[0] = pictureBox1;
//led[1] = pictureBox2;
//led[2] = pictureBox3;
//led[3] = pictureBox4;
//led[4] = pictureBox5;
//led[8] = pictureBox6;
//led[9] = pictureBox7;
//led[10] = pictureBox8;
//led[11] = pictureBox9;
//led[12] = pictureBox10;
agvLocation = new agvlocation(AgvLocation);
//dataset_Set = new dataset_set(Dataset_Set);
pictureboxSet = new pictureboxset(PictureboxSet);
string strsql = "";
Form.CheckForIllegalCrossThreadCalls = false;
ClsDBConn_sql db = new ClsDBConn_sql();
strsql = "SELECT [ID] as '设备编号' ,[Loc_ID] as '设备位置' ,'' as '状态' , '0' as '复位','' as '在线状态' FROM [AgvInfo] order by id";
agv_list = db.connDt(strsql).Copy();
dataGridView1.DataSource = agv_list.Tables[0];
//设置AGV列表信息
strsql = "SELECT Line_name FROM [Assembly_Line] order by ID";
mainfrm.ds_ProductLine.Tables.Clear();
mainfrm.ds_ProductLine = db.connDt(strsql);
vScrollBar1.Maximum = mainfrm.ds_ProductLine.Tables[0].Rows.Count;
for (int i = 0; i < mainfrm.ds_ProductLine.Tables[0].Rows.Count; i++)
{
if (i == 0)
{
lab1.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl1.Visible = true;
}
else if (i == 1)
{
lab2.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl2.Visible = true;
}
else if (i == 2)
{
lab3.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl3.Visible = true;
}
else if (i == 3)
{
lab4.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl4.Visible = true;
}
else if (i == 4)
{
lab5.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl5.Visible = true;
}
else if (i == 5)
{
lab6.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl6.Visible = true;
}
else if (i == 6)
{
lab7.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl7.Visible = true;
}
else if (i == 7)
{
lab8.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl8.Visible = true;
}
else if (i == 8)
{
lab9.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl9.Visible = true;
}
else if (i == 9)
{
//lab10.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl10.Visible = true;
}
else if (i == 10)
{
lab11.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl11.Visible = true;
}
else if (i == 12)
{
lab13.Text = mainfrm.ds_ProductLine.Tables[0].Rows[i][0].ToString();
pnl10.Visible = true;
}
}
if (mainfrm.ds_ProductLine.Tables[0].Rows.Count <= 3)
{
panel8.Height = Cls.Param.Icon_Size * mainfrm.ds_ProductLine.Tables[0].Rows.Count;
if (mainfrm.ds_ProductLine.Tables[0].Rows.Count == 1)
{
lab1.Text = "设备列表:";
}
}
else
panel8.Height = Cls.Param.Icon_Size * 3;
//AGV列表设置结束
//初始化小车btn 数量
Func.agvcar = new AgvCar.Agv[Cls.Param.AGV_Qty];
Thread dbThread = new Thread(UPDateDBList.UpDateDb);
dbThread.IsBackground = true;
dbThread.Start();
2026-08-19 17:02:08 +08:00
//第三方交管自动归还监听线程
Thread trafficThread = new Thread(TrafficCtrl.Listen);
trafficThread.IsBackground = true;
trafficThread.Start();
//初始化小车控制线程
Cls.Param.th_GetData = new Thread[Cls.Param.AGV_Qty];
strsql = "SELECT [ID] ,[LOC_ID] ,[Warn_ID] FROM [Agv_Info_Interface]";
//db_Agv_Info = new ClsDBConn_sql();
ds_Agv_Info_Interface = db_Agv_Info.connDt(strsql);
int COUNT = ds_Agv_Info_Interface.Tables[0].Rows.Count;
strsql = "select id , line_name from Assembly_Line";
mainfrm.ds_ProductLine.Clear();
mainfrm.ds_ProductLine = db.connDt(strsql).Copy();
strsql = "SELECT [Warn_ID] ,[Warn_Info] ,[Warn_Level] FROM [Warn_Info] order by Warn_ID";
ds_warn = db.connDt(strsql).Copy();
for (int row = 0; row < mainfrm.ds_Agvlist.Tables[0].Rows.Count; row++)
{
CreateBtnAgv(mainfrm.ds_Agvlist.Tables[0].Rows[row]["Internal_ID"].ToString(),
mainfrm.ds_Agvlist.Tables[0].Rows[row]["Assembly_Line"].ToString(),
mainfrm.ds_Agvlist.Tables[0].Rows[row]["ID"].ToString(),
mainfrm.ds_Agvlist.Tables[0].Rows[row]["IPAddress"].ToString(),
mainfrm.ds_Agvlist.Tables[0].Rows[row]["line_Name"].ToString());
//string STR = mainfrm.ds_Agvlist.Tables[0].Rows[row]["ID"].ToString();
//Func.AgvInfo[row] = new Agv_Info.AgvInfo(); ;
//Func.AgvInfo[row].Agv_ID = Convert.ToInt16(mainfrm.ds_Agvlist.Tables[0].Rows[row]["ID"].ToString());
//Func.AgvInfo[row].AssemblyLine = Convert.ToInt16(mainfrm.ds_Agvlist.Tables[0].Rows[row]["Assembly_Line"].ToString());
//Func.AgvInfo[row].AssemblyName = mainfrm.ds_Agvlist.Tables[0].Rows[row]["line_Name"].ToString();
//Func.AgvInfo[row].Enable = Convert.ToBoolean(mainfrm.ds_Agvlist.Tables[0].Rows[row]["Status"].ToString());
//Func.AgvInfo[row].Internal_ID = Convert.ToInt16(mainfrm.ds_Agvlist.Tables[0].Rows[row]["Internal_ID"].ToString());
//Func.AgvInfo[row].IP = mainfrm.ds_Agvlist.Tables[0].Rows[row]["IPAddress"].ToString();
//Func.AgvInfo[row].Area = Convert.ToInt16(mainfrm.ds_Agvlist.Tables[0].Rows[row]["area"].ToString());
//Func.AgvInfo[row].Cross_Location_Go = Convert.ToInt16(mainfrm.ds_Agvlist.Tables[0].Rows[row]["LOC_ID"].ToString());
//Func.AgvInfo[row].Cross_Path_Id = Convert.ToInt16(mainfrm.ds_Agvlist.Tables[0].Rows[row]["Warn_ID"].ToString());
//Func.AgvInfo[row].Mileage = Convert.ToDouble(mainfrm.ds_Agvlist.Tables[0].Rows[row]["Mileage"].ToString());
}
strsql = "SELECT distinct Loc_ID, Flag_Value, Loc_X, Loc_Y, Binding, Area, Assembly_ID ,Assembly_Line FROM LandMarkInfo order by Loc_ID";
DataSet ds_Location = db.connDt(strsql);
string loc_id = "";
int nWidth = Screen.PrimaryScreen.Bounds.Width;
int nHeight = Screen.PrimaryScreen.Bounds.Height;
foreach (DataRow dr in ds_Location.Tables[0].Rows)
{
if (loc_id == "")
{
Func.CreatePanelLocation(dr["Loc_ID"].ToString(),
Convert.ToInt16(dr["Binding"]),
Convert.ToInt16(dr["Loc_x"]),
Convert.ToInt16(dr["loc_y"]),
Convert.ToInt16(dr["Area"]), dr["Assembly_ID"].ToString());
loc_id = dr["Loc_ID"].ToString();
}
else if (dr["Loc_ID"].ToString() != loc_id)
{
Func.CreatePanelLocation(dr["Loc_ID"].ToString(),
Convert.ToInt16(dr["Binding"]),
Convert.ToInt16(dr["Loc_x"]),
Convert.ToInt16(dr["loc_y"]),
Convert.ToInt16(dr["Area"]), dr["Assembly_ID"].ToString());
}
}
strsql = "SELECT [Current_Line_ID] ,[Current_Landmark] ,[Reset_Line_ID] ,[Reset_Landmark] FROM [Reset_Relation]";
mainfrm.ds_Reset_Relation = newdb.connDt(strsql).Copy();
strsql = "SELECT [Start_Point] ,[End_Point] ,[Distance] FROM [Mileage]";
mainfrm.ds_Mileage = newdb.connDt(strsql).Copy();
agvcontrol_init();
for (int i = 0; i < Cls.Param.AGV_Qty; i++)
//for (int i = 0; i < 1; i++)
{
//if (Func.AgvInfo[i].Agv_ID == 45)
Agvcontrol.AGV_start(Func.AgvInfo[i]);
}
//Agvcontrol.Function();
//mainfrm.warnlist1.Show();
}
public delegate void pictureboxset(PictureBox pb, string str);
public pictureboxset pictureboxSet;
public static void PictureboxSet(PictureBox pb, string str)
{
if (str == "hui")
pb.BackgroundImage = Properties.Resources.hui;
else if (str == "ledlow")
pb.BackgroundImage = Properties.Resources.ledLow;
else if (str == "_0")
pb.BackgroundImage = Properties.Resources._0;
else if (str == "_1")
pb.BackgroundImage = Properties.Resources._1;
}
private void agvcontrol_init()
{
//Agvcontrol.AgvRecConnCount = new int[Cls.Param.AGV_Qty];
//Agvcontrol.ds_AGVGo = mainfrm.ds_AGVGo;
//Agvcontrol.ds_AGVWarn = mainfrm.ds_AgvWarn;
//Agvcontrol.ds_CrossInfo = mainfrm.ds_CrossInfo;
//Agvcontrol.ds_Warn = mainfrm.ds_WarnList;
Agvcontrol.StartFlag = Cls.Param.StartFlag;
Agvcontrol.th_GetData = Cls.Param.th_GetData;
Agvcontrol.ConnectStr = Cls.Param.connectStr;
//Agvcontrol.Agv_Qty = Cls.Param.AGV_Qty;
//Agvcontrol.ds_Reset_Relation = mainfrm.ds_Reset_Relation;
Agvcontrol.ds_Mileage = mainfrm.ds_Mileage;
//Agvcontrol.Plc_Type = Cls.Param.PLC_Type;
for (byte i = 0; i < 17; i++)
{
Btn_Filter[i, 0] = 0;
Btn_Filter[i, 1] = 0;
}
for (byte row = 0; row < Array_Robot_Status.Length / 8; row++)
{
for (byte col = 0; col < 8; col++)
{
Array_Robot_Status[row, col] = 0;
Array_Robot_Set[row, col] = 0;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
if (Cls.Param.map1_status)
{
panel3.Dock = DockStyle.Fill;
panel3.BackgroundImage = Image.FromFile(Application.StartupPath + "\\map\\" + Cls.Param.Pro_id + "_1");
}
if (Cls.Param.map2_status)
{
panel2.Dock = DockStyle.Fill;
panel2.BackgroundImage = Image.FromFile(Application.StartupPath + "\\map\\" + Cls.Param.Pro_id + "_2");
}
if (Cls.Param.map3_status)
{
panel1.Dock = DockStyle.Fill;
panel1.BackgroundImage = Image.FromFile(Application.StartupPath + "\\map\\" + Cls.Param.Pro_id + "_3");
}
panel3.Visible = true;
panel2.Visible = false;
panel1.Visible = false;
tm_AgvInfo.Enabled = true;
}
public static void label12_DoubleClick(object sender, EventArgs e)
{
if (((System.Windows.Forms.Label)sender).Tag.ToString() == "")
return;
if (MessageBox.Show("是否复位该路口?", "消息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) return;
int[] num = new int[2];
num[0] = Convert.ToInt16(((System.Windows.Forms.Label)sender).Tag.ToString().Split('-')[0]);
num[1] = Convert.ToInt16(((System.Windows.Forms.Label)sender).Tag.ToString().Split('-')[1]);
for (int i = 0; i < mainfrm.ds_CrossInfo.Tables[0].Rows.Count; i++)
{
string s = mainfrm.ds_CrossInfo.Tables[0].Rows[i]["当前地标编号"].ToString();
string a = mainfrm.ds_CrossInfo.Tables[0].Rows[i]["AGV编号"].ToString();
if (mainfrm.ds_CrossInfo.Tables[0].Rows[i]["当前产线编号"].ToString() == num[0].ToString() &&
mainfrm.ds_CrossInfo.Tables[0].Rows[i]["当前地标编号"].ToString() == num[1].ToString() &&
mainfrm.ds_CrossInfo.Tables[0].Rows[i]["AGV编号"].ToString() != "0")
{
MessageBox.Show("AGV-" + mainfrm.ds_CrossInfo.Tables[0].Rows[i]["AGV编号"].ToString() + "占用路口信息被清除!");
mainfrm.ds_CrossInfo.Tables[0].Rows[i]["AGV编号"] = 0;
}
}
}
/// <summary>
/// 设置Agv的实时位置
/// </summary>
/// <param name="ID">地标编号:地标(2位)</param>
/// <param name="agvnum">agv编号</param>
public delegate void agvlocation(string LandMarkID, int agvnum, int map_id);
public agvlocation agvLocation;
public static void AgvLocation(string LandMarkID, int agvnum, int map_id)
{
if (LandMarkID == "0") return;
Panel pl = new Panel();//xin panel
Panel pl_parent = new Panel();//jiu panel
bool flag = false;
Panel parent_pnl = new Panel();
if (map_id == 1)
{
parent_pnl = mainfrm.Map1;
}
else if (map_id == 2)
{
parent_pnl = mainfrm.Map2;
}
else
{
parent_pnl = mainfrm.Map3;
}
foreach (System.Windows.Forms.Control ctl in parent_pnl.Controls)
{
if (ctl.GetType().Name == "Panel")
{
if (ctl.Tag.ToString().Split('-')[0] == LandMarkID)
{
pl = (Panel)ctl;
if (pl == (Panel)Func.agvcar[agvnum - 1].Parent)
flag = false;
else
flag = true;
break;
}
}
}
if (!flag) return;
//以下设置agvbtn
pl_parent = (Panel)Func.agvcar[agvnum - 1].Parent;
Func.agvcar[agvnum - 1].Parent = pl;
if (pl.Tag.ToString().Trim() != "")
{
//1.左端(后退) 2.右端(前进) 3.顶部(向上) 4.底部(向下)
if (pl.Tag.ToString().Split('-')[1] == "1")
{
//Func.agvcar[agvnum - 1].Direction("backward");
Func.agvcar[agvnum - 1].Dock = DockStyle.Left;
Func.agvcar[agvnum - 1].Width = Func.agvcar[agvnum - 1].Height = 32;
Func.agvcar[agvnum - 1].BringToFront();
//Func.AgvBtn[agvnum - 1].SendToBack();
}
else if (pl.Tag.ToString().Split('-')[1] == "2")
{
//Func.agvcar[agvnum - 1].Direction("forward");
Func.agvcar[agvnum - 1].Dock = DockStyle.Left;
Func.agvcar[agvnum - 1].Width = Func.agvcar[agvnum - 1].Height = 32;
Func.agvcar[agvnum - 1].BringToFront();
}
else if (pl.Tag.ToString().Split('-')[1] == "3")
{
//Func.agvcar[agvnum - 1].Direction("upward");
Func.agvcar[agvnum - 1].Dock = DockStyle.Top;
Func.agvcar[agvnum - 1].Width = Func.agvcar[agvnum - 1].Height = 32;
Func.agvcar[agvnum - 1].BringToFront();
}
else if (pl.Tag.ToString().Split('-')[1] == "4")
{
//Func.agvcar[agvnum - 1].Direction("down");
Func.agvcar[agvnum - 1].Dock = DockStyle.Top;
Func.agvcar[agvnum - 1].Width = Func.agvcar[agvnum - 1].Height = 32;
Func.agvcar[agvnum - 1].BringToFront();
//Func.AgvBtn[agvnum - 1].SendToBack();
}
}
//以下设置新容器大小
int i = 0;
foreach (System.Windows.Forms.Control ctl in pl.Controls)
{
//1.左端(后退) 2.右端(前进) 3.顶部(向上) 4.底部(向下)
if (pl.Tag.ToString().Split('-')[1] == "3" || pl.Tag.ToString().Split('-')[1] == "4")
{
i = i + ctl.Height;
}
else
{
i = i + ctl.Width;
}
}
if (pl.Tag.ToString().Split('-')[1] == "3" || pl.Tag.ToString().Split('-')[1] == "4")
{
pl.Height = i;
}
else
{
pl.Width = i;
}
}
/// <summary>
/// 创建代表每个AGV的button
/// </summary>
/// <param name="agvID">agv内部编号</param>
/// <param name="assembly">所属流水线编号</param>
/// <param name="agvID_tot">agv总编号</param>
public void CreateBtnAgv(string agvID, string assembly, string agvID_tot, string ip, string linename)
{
AgvCar.Agv btn = new AgvCar.Agv();
//btn.Text = agvID;
btn.Tag = agvID_tot + "-" + assembly;
btn.Label = agvID;
btn.Width = Cls.Param.Icon_Size;
btn.Height = Cls.Param.Icon_Size;
//btn.Agv_seq = agvID;
//btn.Agv_IP = ip;
//btn.Agv_No = agvID+" / "+ agvID_tot;
//btn.LineName= linename;
//btn.SetToolTip();
btn.Font = new System.Drawing.Font("宋体", 9, FontStyle.Regular);
btn.ForeColor = Color.Blue;
if (assembly == "1")
btn.Parent = pnl1;
else if (assembly == "2")
btn.Parent = pnl2;
else if (assembly == "3")
btn.Parent = pnl3;
else if (assembly == "4")
btn.Parent = pnl4;
else if (assembly == "5")
btn.Parent = pnl5;
else if (assembly == "6")
btn.Parent = pnl6;
else if (assembly == "7")
btn.Parent = pnl7;
else if (assembly == "8")
btn.Parent = pnl8;
btn.Font = new System.Drawing.Font("宋体", 9);
//btn.MouseEnter += new System.EventHandler(this.button6_MouseEnter);
//btn.MouseLeave += new System.EventHandler(this.button6_MouseLeave);
//btn.FlatStyle = FlatStyle.Flat;
btn.Dock = DockStyle.Left;
btn.BringToFront();
Func.agvcar[Convert.ToInt16(agvID_tot) - 1] = btn;
}
public static void Map_Display(byte i)
{
if (i == 1)
{
mainfrm.Map1.Visible = true;
mainfrm.Map2.Visible = false;
mainfrm.Map3.Visible = false;
}
else if (i == 2)
{
mainfrm.Map1.Visible = false;
mainfrm.Map2.Visible = true;
mainfrm.Map3.Visible = false;
}
else if (i == 3)
{
mainfrm.Map1.Visible = false;
mainfrm.Map2.Visible = false;
mainfrm.Map3.Visible = true;
}
}
private void button6_MouseEnter(object sender, EventArgs e)
{
Label btn;
btn = (Label)sender;
btn.Font = new System.Drawing.Font("宋体", 16, FontStyle.Regular);
btn.TextAlign = ContentAlignment.MiddleCenter;
}
private void button6_MouseLeave(object sender, EventArgs e)
{
Label btn;
btn = (Label)sender;
btn.Font = new System.Drawing.Font("宋体", 9, FontStyle.Regular);
btn.TextAlign = ContentAlignment.BottomLeft;
}
//private void button6_Click(object sender, EventArgs e)
//{
// Form1.frm.Invoke(Form1.frm.btnset, Func.AgvBtn[1], (byte)2);
// Form1.frm.Invoke(Form1.frm.btnset, Func.AgvBtn[2], (byte)3);
// Form1.frm.Invoke(Form1.frm.btnset, Func.AgvBtn[3], (byte)1);
// Form1.frm.Invoke(Form1.frm.agvLocation, "5", 1, 1);
// Form1.frm.Invoke(Form1.frm.agvLocation, "6", 2, 1);
// Form1.frm.Invoke(Form1.frm.agvLocation, "7", 3, 1);
// Form1.frm.Invoke(Form1.frm.agvLocation, "8", 4, 1);
//}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
mainfrm.Lab_location.Text = "X " + e.X.ToString() + " ,Y " + e.Y.ToString();
if (e.Y > panel1.Height - 10)
{
if (!panel8.Visible)
{
panel8.Visible = true;
this.Location = new Point(0, 103);
}
}
else
{
if (panel8.Visible)
{
panel8.Visible = false;
this.Location = new Point(0, 29);
}
}
if (e.Y < 10)
{
if (!mainfrm.toolStrip.Visible)
mainfrm.toolStrip.Visible = true;
this.Height = mainfrm.newmainfrm.ClientSize.Height - 130;
}
else
{
if (mainfrm.toolStrip.Visible)
mainfrm.toolStrip.Visible = false;
this.Height = mainfrm.newmainfrm.ClientSize.Height - 56;
}
//if (e.X > ((Panel)sender).Width - 10)
//{
// if (!panel4.Visible)
// panel4.Visible = true;
//}
//else
//{
// if (panel4.Visible)
// panel4.Visible = false;
//}
}
private void panel2_MouseMove(object sender, MouseEventArgs e)
{
mainfrm.Lab_location.Text = "X " + e.X.ToString() + " ,Y " + e.Y.ToString();
if (e.Y > panel2.Height - 10)
{
if (!panel8.Visible)
panel8.Visible = true;
}
else
{
if (panel8.Visible)
panel8.Visible = false;
}
if (e.Y < 10)
{
if (!mainfrm.toolStrip.Visible)
mainfrm.toolStrip.Visible = true;
this.Height = mainfrm.newmainfrm.ClientSize.Height - 130;
}
else
{
if (mainfrm.toolStrip.Visible)
mainfrm.toolStrip.Visible = false;
this.Height = mainfrm.newmainfrm.ClientSize.Height - 56;
}
if (e.Y > ((Panel)sender).Width - 10)
{
if (!panel4.Visible)
panel4.Visible = true;
}
else
{
if (panel4.Visible)
panel4.Visible = false;
}
//if (e.X > ((Panel)sender).Width - 10)
//{
// if (!panel4.Visible)
// panel4.Visible = true;
//}
//else
//{
// if (panel4.Visible)
// panel4.Visible = false;
//}
}
private void panel3_MouseMove(object sender, MouseEventArgs e)
{
mainfrm.Lab_location.Text = "X " + e.X.ToString() + " ,Y: " + e.Y.ToString();
if (e.Y > panel3.Height - 10)
{
if (!panel8.Visible)
panel8.Visible = true;
}
else
{
if (panel8.Visible)
panel8.Visible = false;
}
if (e.Y < 10)
{
if (!mainfrm.toolStrip.Visible)
mainfrm.toolStrip.Visible = true;
this.Height = mainfrm.newmainfrm.ClientSize.Height - 130;
}
else
{
if (mainfrm.toolStrip.Visible)
mainfrm.toolStrip.Visible = false;
this.Height = mainfrm.newmainfrm.ClientSize.Height - 56;
}
if (e.X > ((Panel)sender).Width - 10)
{
if (!panel4.Visible)
panel4.Visible = true;
}
else
{
if (panel4.Visible)
panel4.Visible = false;
}
}
private bool b = false;
private void panel3_DoubleClick(object sender, EventArgs e)
{
b = !b;
if (b)
{
this.panel3.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.panel3_MouseMove);
this.panel1.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
this.panel2.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.panel2_MouseMove);
if (!mainfrm.toolStrip.Visible)
mainfrm.toolStrip.Visible = true;
this.Height = mainfrm.newmainfrm.ClientSize.Height - 130;
//if (!panel4.Visible)
// panel4.Visible = true;
mainfrm.toolStrip_info.Text = "Locked.";
}
else
{
this.panel3.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel3_MouseMove);
this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
this.panel2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel2_MouseMove);
mainfrm.toolStrip_info.Text = "";
}
mainfrm.Lab_location.Text = "W" + panel3.Width.ToString() + " , H" + panel3.Height.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
for (int i = 0; i < Cls.Param.AGV_Qty; i++)
{
Func.Agv_Car_Status(Func.AgvInfo[i].Agv_ID,
Func.AgvInfo[i].Run_Status == 1 ? true : false,
Func.AgvInfo[i].Warn_Level,
Func.AgvInfo[i].Location_Display,
Func.AgvInfo[i].Area,
Func.AgvInfo[i].Run_Direction);
}
}
System.Data.DataSet ds_warn = new System.Data.DataSet(); //报警信息
byte map_id = 1;
private void tm_Tick(object sender, EventArgs e)
{
if (Cls.Param.Map_ID != map_id)
{
map_id = Cls.Param.Map_ID;
if (map_id == 0)
{
panel3.Visible = true;
panel2.Visible = false;
panel1.Visible = false;
}
else if (map_id == 1)
{
panel2.Visible = true;
panel3.Visible = false;
panel1.Visible = false;
}
else if (map_id == 2)
{
panel1.Visible = true;
panel2.Visible = false;
panel3.Visible = false;
}
//panel4.BringToFront();
////panel4.SendToBack();
//panel4.Visible = true;
//panel4.Parent = this;
}
if (Agvcontrol.StartFlag != Cls.Param.StartFlag)
{
if (Cls.Param.Thread_Count == Cls.Param.AGV_Qty)
{
Agvcontrol.ClosedFlag = Cls.Param.AGV_Qty;
}
Agvcontrol.StartFlag = Cls.Param.StartFlag;
}
if (Cls.Param.StartFlag == true && Cls.Param.Thread_Count == 0)
{
for (int i = 0; i < Cls.Param.AGV_Qty; i++)
{
Agvcontrol.AGV_start(Func.AgvInfo[i]);
}
Cls.Param.Thread_Count = -1;
}
if (Cls.Param.Thread_Count != -1 && Agvcontrol.ClosedFlag != -1 && Cls.Param.Thread_Count != Agvcontrol.ClosedFlag)
{
Cls.Param.Thread_Count = Agvcontrol.ClosedFlag;
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Agvcontrol.ClosedFlag = Cls.Param.AGV_Qty;
int count = 15;
while (Agvcontrol.ClosedFlag > 0 && count > 0)
{
Thread.Sleep(80);
count--;
}
if (!Cls.Param.Load_Path_His)
{
//for (byte i = 0; i < mainfrm.ds_CrossInfo.Tables[0].Rows.Count; i++)
//{
//mainfrm.ds_CrossInfo.Tables[0].Rows[i][4] = 0;
//}
}
//newdb.dtCommit(mainfrm.ds_CrossInfo);
for (int i = 0; i < Cls.Param.AGV_Qty; i++)
{
newdb.Command("UPDATE [AgvInfo] SET [Loc_ID] = " + (Cls.Param.Load_Path_His == true ? Func.AgvInfo[i].Cross_Location_Go : 0) + " ,[Path_ID] = " + (Cls.Param.Load_Path_His == true ? Func.AgvInfo[i].Cross_Path_Id : 0) + ", [Mileage]=" + Func.AgvInfo[i].Mileage + " WHERE id=" + Func.AgvInfo[i].Agv_ID);
try
{
Func.AgvInfo[i].Soc.Close();
Func.AgvInfo[i].Soc = null;
}
catch
{ }
}
}
private void button3_Click(object sender, EventArgs e)
{
agv_alarm_insert(0, "NEISHIXIAN", "1", 1, "FZ", 4);
}
private static void agv_alarm_insert(int del_agv_no, string Assembly_Name, string Assembly_Id, int AGV_Internal_No, string AlarmInfo, int agv_no)
{
if (del_agv_no == 0)
{
bool update_flag = false;
if (mainfrm.ds_AgvWarn.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < mainfrm.ds_AgvWarn.Tables[0].Rows.Count; i++)
{
string ss = mainfrm.ds_AgvWarn.Tables[0].Rows[i][3].ToString();
if (Convert.ToInt16(mainfrm.ds_AgvWarn.Tables[0].Rows[i][3].ToString()) == agv_no)
{
mainfrm.ds_AgvWarn.Tables[0].Rows[i][0] = DateTime.Now.ToString();
mainfrm.ds_AgvWarn.Tables[0].Rows[i][1] = Assembly_Id;
mainfrm.ds_AgvWarn.Tables[0].Rows[i][2] = Assembly_Name;
mainfrm.ds_AgvWarn.Tables[0].Rows[i][3] = agv_no;
mainfrm.ds_AgvWarn.Tables[0].Rows[i][4] = AGV_Internal_No;
mainfrm.ds_AgvWarn.Tables[0].Rows[i][5] = AlarmInfo;
update_flag = true;
break;
}
}
}
if (!update_flag)
{
DataRow dr = mainfrm.ds_AgvWarn.Tables[0].NewRow();
dr[0] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");// 时间
dr[1] = Assembly_Id; // 线体编号
dr[2] = Assembly_Name; // 线体名称
dr[3] = agv_no; // 设备编号
dr[4] = AGV_Internal_No; // 内部编号
dr[5] = AlarmInfo; // 报警信息
mainfrm.ds_AgvWarn.Tables[0].Rows.Add(dr);
}
}
else
{
for (int i = 0; i < mainfrm.ds_AgvWarn.Tables[0].Rows.Count; i++)
{
if (Convert.ToInt16(mainfrm.ds_AgvWarn.Tables[0].Rows[i][3]) == del_agv_no)
{
newdb.Command("INSERT INTO [Warn_Log] ([Dt] ,[Agv_id] ,[Type] ,[Reset]) VALUES ('" +
mainfrm.ds_AgvWarn.Tables[0].Rows[i][0] + "'," + mainfrm.ds_AgvWarn.Tables[0].Rows[i][3] + ",'" + mainfrm.ds_AgvWarn.Tables[0].Rows[i][5] + "','" + DateTime.Now.ToString() + "')");
mainfrm.ds_AgvWarn.Tables[0].Rows.RemoveAt(i);
i--;
}
}
}
}
private void button4_Click(object sender, EventArgs e)
{
agv_alarm_insert(4, "NEISHIXIAN", "1", 1, "FZ", 4);
}
private void checkBox1_MouseEnter(object sender, EventArgs e)
{
((CheckBox)sender).ForeColor = Color.Red;
}
private void checkBox1_MouseLeave(object sender, EventArgs e)
{
((CheckBox)sender).ForeColor = Color.Black;
}
private void vScrollBar1_ValueChanged(object sender, EventArgs e)
{
for (byte i = 0; i < vScrollBar1.Maximum; i++)
{
if (i < vScrollBar1.Value)
pnl[i].Visible = false;
else
pnl[i].Visible = true;
}
}
private void panel3_MouseClick(object sender, MouseEventArgs e)
{
if (Cls.Param.UserName_temp == "")
{
return;
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
//Location_Set ls = new Location_Set(Func.loc_flag, e.X, e.Y, Convert.ToInt16(((Panel)sender).Tag));
//Func.loc_flag = 0;
//ls.ShowDialog();
Point_loc_Set loc_set = new Point_loc_Set(e.X, e.Y);
loc_set.Show();
}
}
private void button5_Click(object sender, EventArgs e)
{
Func.AgvInfo[1].Run_Status = 1;
Func.AgvInfo[1].Warn_Level = 1;
Func.AgvInfo[1].Location_Display = 1;
Func.AgvInfo[1].Area = 1;
Func.AgvInfo[1].Run_Direction = 1;
}
private void button6_Click(object sender, EventArgs e)
{
Func.AgvInfo[1].Run_Status = 1;
Func.AgvInfo[1].Warn_Level = 3;
Func.AgvInfo[1].Location_Display = 1;
Func.AgvInfo[1].Area = 1;
Func.AgvInfo[1].Run_Direction = 1;
}
private void button7_Click(object sender, EventArgs e)
{
Func.AgvInfo[1].Run_Status = 1;
Func.AgvInfo[1].Warn_Level = 1;
Func.AgvInfo[1].Location_Display = 2;
Func.AgvInfo[1].Area = 1;
Func.AgvInfo[1].Run_Direction = 1;
}
private void card1_Tick()
{
ErrorCode err = ErrorCode.Success;
byte out_value = 0;
for (byte i = 0; i < instantDiCtrl1.Features.PortCount; i++)
{
for (byte j = 0; j < 8; j++)
{
err = instantDiCtrl1.ReadBit(i, j, out out_value);
if (mainfrm.Card_DI1[i, j] == 0 && out_value == 1)
mainfrm.Card_DI1[i, j] = count;
if (err != ErrorCode.Success)
{
tm_card.Enabled = false;
HandleError(err, 1);
return;
}
}
}
for (byte i = 0; i < instantDoCtrl1.Features.PortCount; i++)
{
for (byte j = 0; j < 8; j++)
{
err = instantDoCtrl1.WriteBit(i, j, mainfrm.Card_DO1[i, j]);
if (err != ErrorCode.Success)
{
tm_card.Enabled = false;
HandleError(err, 1);
return;
}
}
}
}
private void HandleError(ErrorCode err, byte card_id)
{
if (err != ErrorCode.Success)
{
MessageBox.Show("Sorry ! Some errors happened, the error code is: " + err.ToString() + " , this card id = " + card_id.ToString(), "Static DI OR DO");
}
}
private void card2_Tick()
{
byte out_value = 0;
ErrorCode err = ErrorCode.Success;
for (byte i = 0; i < instantDiCtrl2.Features.PortCount; i++)
{
for (byte j = 0; j < 8; j++)
{
err = instantDiCtrl2.ReadBit(i, j, out out_value);
if (mainfrm.Card_DI2[i, j] == 0 && out_value == 1)
mainfrm.Card_DI2[i, j] = count;
if (err != ErrorCode.Success)
{
tm_card.Enabled = false;
HandleError(err, 2);
return;
}
}
}
for (byte i = 0; i < instantDoCtrl2.Features.PortCount; i++)
{
for (byte j = 0; j < 8; j++)
{
err = instantDoCtrl2.WriteBit(i, j, mainfrm.Card_DO2[i, j]);
if (err != ErrorCode.Success)
{
tm_card.Enabled = false;
HandleError(err, 2);
return;
}
}
}
}
private void card3_Tick()
{
byte out_value = 0;
ErrorCode err = ErrorCode.Success;
for (byte i = 0; i < instantDiCtrl3.Features.PortCount; i++)
{
for (byte j = 0; j < 8; ++j)
{
err = instantDiCtrl3.ReadBit(i, j, out out_value);
if (mainfrm.Card_DI3[i, j] == 0 && out_value == 1)
mainfrm.Card_DI3[i, j] = count;
if (err != ErrorCode.Success)
{
tm_card.Enabled = false;
HandleError(err, 3);
return;
}
}
}
for (byte i = 0; i < instantDoCtrl3.Features.PortCount; i++)
{
for (byte j = 0; j < 8; j++)
{
err = instantDoCtrl3.WriteBit(i, j, mainfrm.Card_DO3[i, j]);
if (err != ErrorCode.Success)
{
tm_card.Enabled = false;
HandleError(err, 3);
return;
}
}
}
}
private byte count = 10;
private void tm_card_Tick(object sender, EventArgs e)
{
for (byte i = 0; i < 4; ++i)
{
for (byte j = 0; j < 8; ++j)
{
mainfrm.Card_DO1[i, j] = 0;
mainfrm.Card_DO2[i, j] = 0;
mainfrm.Card_DO3[i, j] = 0;
if (mainfrm.Card_DI1[i, j] > 1)
{
mainfrm.Card_DI1[i, j]--;
}
else
{
if (mainfrm.ds_Card_DI_Call.Tables[0].Rows.Count > 0)
{
DataView rowfilter = new DataView(mainfrm.ds_Card_DI_Call.Tables[0]);
rowfilter.RowFilter = "Card_ID=1 and Port=" + i + " and bit= " + j + " and value=1 and class =0";
rowfilter.RowStateFilter = DataViewRowState.OriginalRows;
DataTable dt = rowfilter.ToTable();
if (dt.Rows.Count == 1)
{
}
else
{
mainfrm.Card_DI1[i, j] = 0;
}
}
}
if (mainfrm.Card_DI2[i, j] > 1)
{
mainfrm.Card_DI2[i, j]--;
}
else
{
DataView rowfilter = new DataView(mainfrm.ds_Card_DI_Call.Tables[0]);
if (mainfrm.ds_Card_DI_Call.Tables[0].Rows.Count > 0)
{
rowfilter.RowFilter = "Card_ID=2 and Port=" + i + " and bit= " + j + " and value=1 and class =0";
rowfilter.RowStateFilter = DataViewRowState.OriginalRows;
DataTable dt = rowfilter.ToTable();
if (dt.Rows.Count == 1)
{
}
else
{
mainfrm.Card_DI2[i, j] = 0;
}
}
}
if (mainfrm.Card_DI3[i, j] > 1)
{
mainfrm.Card_DI3[i, j]--;
}
else
{
DataView rowfilter = new DataView(mainfrm.ds_Card_DI_Call.Tables[0]);
rowfilter.RowFilter = "Card_ID=3 and Port=" + i + " and bit= " + j + " and value=1 and class =0";
rowfilter.RowStateFilter = DataViewRowState.OriginalRows;
DataTable dt = rowfilter.ToTable();
if (dt.Rows.Count == 1)
{
}
else
{
mainfrm.Card_DI3[i, j] = 0;
}
}
}
}
if (mainfrm.ds_Card_DO.Tables[0].Rows.Count > 0)
{
int[,] nCount = new int[3, 16];//计算数量--AGV 在红绿灯地标上的数量
for (int i = 0; i < mainfrm.ds_Card_DO.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < Cls.Param.AGV_Qty; j++)
{
if (Func.AgvInfo[j].Cross_Location_Go == Func.AgvInfo[j].Location_Display && Func.AgvInfo[j].Cross_Location_Go == Convert.ToInt16(mainfrm.ds_Card_DO.Tables[0].Rows[i]["Loc_ID"].ToString()))
{
if (mainfrm.ds_Card_DO.Tables[0].Rows[i]["Value"].ToString() == "1")
{
int nCardNum = Convert.ToInt16(mainfrm.ds_Card_DO.Tables[0].Rows[i]["Card_ID"].ToString());
int nBit = Convert.ToInt16(mainfrm.ds_Card_DO.Tables[0].Rows[i]["Bit"].ToString());
nCount[nCardNum - 1, nBit - 1]++;
}
}
}
}
for (int i = 0; i < 3; i++)
{
int nBit = 0, nPort = 0;
for (int j = 0; j < 16; j++)
{
if (j >= 0 && j < 8)
{
nPort = 0;
nBit = j;
}
else if (j >= 8 && j < 16)
{
nPort = 1;
nBit = j - 8;
}
if (nCount[i, j] != 0)
{
if (i == 0)
{
mainfrm.Card_DO1[nPort, nBit] = 1;
}
else if (i == 1)
{
mainfrm.Card_DO2[nPort, nBit] = 1;
}
else if (i == 2)
{
mainfrm.Card_DO3[nPort, nBit] = 1;
}
}
else
{
if (i == 0)
{
mainfrm.Card_DO1[nPort, nBit] = 0;
}
else if (i == 1)
{
mainfrm.Card_DO2[nPort, nBit] = 0;
}
else if (i == 2)
{
mainfrm.Card_DO3[nPort, nBit] = 0;
}
}
}
}
}
if (Cls.Param.Card1_Interval > 0)
{
card1_Tick();
}
if (Cls.Param.Card2_Interval > 0)
{
card2_Tick();
}
if (Cls.Param.Card3_Interval > 0)
{
card3_Tick();
}
}
private void pictureBox106_Click(object sender, EventArgs e)
{
int row = 0, col = 0;
PictureBox pb = (PictureBox)sender;
row = Convert.ToInt16(pb.Tag.ToString().Split(',')[0]) - 1;
col = Convert.ToInt16(pb.Tag.ToString().Split(',')[1]) - 1;
if ((col >= 0 && col < 4) || col == 6 || col == 7)
{
if (col >= 0 && col < 4)
{
if (MessageBox.Show("是否要重置 " + ds_Station_Info.Tables[0].Rows[row][1].ToString().Trim() + " 工位 " + (col + 1).ToString() + " 位置编号: " + ds_Station_Info.Tables[0].Rows[row][2 + col].ToString() + " 的状态?", "信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
{
if (ds_Station_Info.Tables[0].Rows[row][8 + col].ToString() == "0")
{
Array_Station_Info[row, 6 + col] = 1;
ds_Station_Info.Tables[0].Rows[row][8 + col] = 1;
PB[row, col].BackgroundImage = Properties.Resources._1;
}
else
{
Array_Station_Info[row, 6 + col] = 0;
ds_Station_Info.Tables[0].Rows[row][8 + col] = 0;
PB[row, col].BackgroundImage = Properties.Resources._0;
}
}
}
else if (col == 6 || col == 7)
{
if (MessageBox.Show("是否要重置 " + ds_Station_Info.Tables[0].Rows[row][1].ToString().Trim() + " 工位 " + (col - 3).ToString() + " 位置编号: " +
ds_Station_Info.Tables[0].Rows[row][(col == 6) ? "Station5_LandMark" : "Station6_LandMark"].ToString() + " 的状态?", "信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
{
if (ds_Station_Info.Tables[0].Rows[row][col == 6 ? "station5" : "station6"].ToString() == "0")
{
Array_Station_Info[row, col + 8] = 1;
ds_Station_Info.Tables[0].Rows[row][col == 6 ? "station5" : "station6"] = 1;
PB[row, col].BackgroundImage = Properties.Resources._1;
}
else
{
Array_Station_Info[row, 8 + col] = 0;
ds_Station_Info.Tables[0].Rows[row][col == 6 ? "station5" : "station6"] = 0;
PB[row, col].BackgroundImage = Properties.Resources._0;
}
}
}
db_station.dtCommit(ds_Station_Info);
}
}
public const byte Number = 10;
public static bool maplandmarkisEdit = false;
private static int Agv_Count_Area(int worktype, int[] landmark)
{
int count = 0;
for (int i = 0; i < Func.AgvInfo.Length; i++)
{
if (Func.AgvInfo[i].WorkType == worktype)
{
for (int j = 0; j < landmark.Length; j++)
{
if (Func.AgvInfo[i].Location_Display == landmark[j])
count++;
}
}
}
return count;
}
private void toolStripMenuItem_Save_Location_X_Y_Click(object sender, EventArgs e)
{
if (MessageBox.Show("是否保存坐标数据?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
ClsDBConn_sql sqlconn = new ClsDBConn_sql();
string sql = "";
foreach (System.Windows.Forms.Control ctl in panel3.Controls)
{
if (ctl.GetType().Name == "Panel")
{
if (ctl.Tag != null)
{
int locx = ctl.Location.X;
int locy = ctl.Location.Y;
int flag_value = Convert.ToInt16(ctl.Tag.ToString().Split('-')[0]);
sql = "update LandMarkInfo set Loc_X=" + locx + ",Loc_Y=" + locy + " where Loc_ID=" + flag_value;
if (sqlconn.Command(sql).Length > 6)
{
WriteTxt.SaveLog1("保存坐标数据失败,地标:" + flag_value.ToString(), "坐标数据保存日志", "Syslog");
}
}
}
}
}
maplandmarkisEdit = false;
}
private void toolStripMenuItem_Update_location_X_Y_Click(object sender, EventArgs e)
{
if (MessageBox.Show("是否更改坐标数据?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
maplandmarkisEdit = true;
}
else
{
maplandmarkisEdit = false;
}
}
private void timer3_Tick(object sender, EventArgs e)
{
if (dataGridView1.Rows.Count == 0) return;
for (int i = 0; i < Func.AgvInfo.Length; i++)
{
if (dataGridView1.Rows[i].Cells["设备位置"].Value.ToString() != Func.AgvInfo[i].Location_Display.ToString())
{
dataGridView1.Rows[i].Cells["设备位置"].Value = Func.AgvInfo[i].Location_Display;
}
if (dataGridView1.Rows[i].Cells["状态"].Value.ToString() != Func.AgvInfo[i].Warn_info)
{
dataGridView1.Rows[i].Cells["状态"].Value = Func.AgvInfo[i].Warn_info;
}
if (Func.AgvInfo[i].bPlcLinked)
{
if (dataGridView1.Rows[i].Cells["在线状态"].Value.ToString() != "Onine")
{
dataGridView1.Rows[i].Cells["在线状态"].Value = "Online";
}
}
else if (!Func.AgvInfo[i].bPlcLinked)
{
if (dataGridView1.Rows[i].Cells["在线状态"].Value.ToString() != "网络中断")
{
dataGridView1.Rows[i].Cells["在线状态"].Value = "网络中断";
}
}
}
}
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
}
}
}