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; namespace AGVSystem { public partial class AGVManage : Form { private int flag = 0; private ClsDBConn_sql db = new ClsDBConn_sql(); private System.Data.DataSet ds = new System.Data.DataSet(); public AGVManage()//string caption, string btn_name { InitializeComponent(); //this.Text = caption; //btn.Text = btn_name; ds = db.connDt("select CONVERT( VARCHAR(10),id) +' . '+ line_name as info from Assembly_Line order by id"); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { cmb_linelist.Items.Add(dr[0].ToString()); } } } ds.Tables.Clear(); ds = db.connDt("select id from ipaddress where id not in (select ipaddress from agvinfo) order by seq"); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { cmb_iplist.Items.Add(dr[0].ToString()); cmb_switchip.Items.Add(dr[0].ToString()); } } } ds.Tables.Clear(); ds = db.connDt("SELECT [ID] FROM [Agv_Type]"); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { cmb_type.Items.Add(dr[0].ToString()); } } } ds.Tables.Clear(); ds = db.connDt("SELECT [Name] FROM [WorkLocationInfo]"); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { cmb_worktype.Items.Add(""); foreach (DataRow dr in ds.Tables[0].Rows) { cmb_worktype.Items.Add(dr[0].ToString()); } } } } private void AGVManage_Load(object sender, EventArgs e) { ds.Tables.Clear(); ds = db.connDt("SELECT AgvInfo.ID as 编号, AgvInfo.IPAddress as IP地址,SwitchIP as 交换机IP, port as 通讯端口, AgvInfo.WorkType as 物料名称 , AgvInfo.Internal_ID as 序号 ,[Status] as 设备状态,[Type] as 设备型号, " + " AgvInfo.Assembly_Line as 线体编号 , assembly_line.line_name as 线体名称 ,agvinfo.Mileage as 行驶里程 FROM AgvInfo ,assembly_line " + " where AgvInfo.Assembly_Line = assembly_line.id order by AgvInfo.ID"); dataGridView1.DataSource = ds.Tables[0]; groupBox2.Enabled = false; this.WindowState = FormWindowState.Maximized; } private void btn_Click(object sender, EventArgs e) { num_id.Value = 0; num_seq.Value = 0; cmb_iplist.Text = ""; cmb_linelist.Text = ""; lab_km.Text = "0"; } private int add_agv(string id, string seq, string ip, string line_id, int port, int type, string switchip, int WorkType) { int rowcount = 0; rowcount = Convert.ToInt16(db.Command("insert into agvinfo (id , ipaddress , internal_id , assembly_line, port,type,switchip,WorkType) values (" + id + ",'" + ip + "'," + seq + "," + line_id + "," + port + "," + type + ",'" + switchip + "'," + WorkType + ")")); return rowcount; } private int delete_agv(string id) { int rowcount = 0; rowcount = Convert.ToInt16(db.Command("delete from agvinfo where id =" + id)); return rowcount; } private int update_agv() { int rowcount = 0; string strsql; strsql = "UPDATE [AgvInfo] "+ "SET [IPAddress] = '"+cmb_iplist.Text+"'"+ " ,[Status] = "+cmb_status.SelectedIndex+ " ,[Internal_ID] = "+num_seq.Value+ " ,[Assembly_Line] = "+cmb_linelist.Text.Split('.')[0]+ " ,[Type] = "+cmb_type.Text+ " ,[Mileage] = "+lab_km.Text+ " ,port = "+numPort.Value+ " ,switchip = '" +cmb_switchip.Text+ "' ,[WorkType] = " + cmb_worktype.SelectedIndex + " WHERE [ID] = "+lab_id.Text; rowcount = Convert.ToInt16(db.Command(strsql)); return rowcount; } private void select_agv(string id, string line_id) { ds.Tables.Clear(); if (id != "0") { ds = db.connDt("SELECT AgvInfo.ID as 编号, AgvInfo.IPAddress as IP地址, port as 通讯端口, AgvInfo.WorkType as 物料名称, AgvInfo.Internal_ID as 序号 ,[Status] as 设备状态,[Type] as 设备型号, " + " AgvInfo.Assembly_Line as 线体编号 , assembly_line.line_name as 线体名称 ,agvinfo.Mileage as 行驶里程 FROM AgvInfo ,assembly_line " + " where AgvInfo.Assembly_Line = assembly_line.id and AgvInfo.ID= " + id + " order by AgvInfo.ID"); } //else if (seq != "0") //{ // ds = db.connDt("SELECT AgvInfo.ID as 编号, AgvInfo.IPAddress as IP地址, AgvInfo.Internal_ID as 序号 , " + // " AgvInfo.Assembly_Line as 线体编号 , assembly_line.line_name as 线体名称,agvinfo.Mileage as 行驶里程 FROM AgvInfo ,assembly_line " + // " where AgvInfo.Assembly_Line = assembly_line.id and AgvInfo.Internal_ID= " + seq + // " order by AgvInfo.ID"); //} //else if (ip != "") //{ // ds = db.connDt("SELECT AgvInfo.ID as 编号, AgvInfo.IPAddress as IP地址, AgvInfo.Internal_ID as 序号 , " + // " AgvInfo.Assembly_Line as 线体编号 , assembly_line.line_name as 线体名称,agvinfo.Mileage as 行驶里程 FROM AgvInfo ,assembly_line " + // " where AgvInfo.Assembly_Line = assembly_line.id and AgvInfo.IPAddress= '" + ip +"'"+ // " order by AgvInfo.ID"); //} else if (line_id.Trim() != "") { ds = db.connDt("SELECT AgvInfo.ID as 编号, AgvInfo.IPAddress as IP地址, port as 通讯端口, AgvInfo.WorkType as 物料名称, AgvInfo.Internal_ID as 序号 ,[Status] as 设备状态,[Type] as 设备型号, " + " AgvInfo.Assembly_Line as 线体编号 , assembly_line.line_name as 线体名称 ,agvinfo.Mileage as 行驶里程 FROM AgvInfo ,assembly_line " + " where AgvInfo.Assembly_Line = assembly_line.id and AgvInfo.Assembly_Line= " + line_id + " order by AgvInfo.ID"); } else { ds = db.connDt("SELECT AgvInfo.ID as 编号, AgvInfo.IPAddress as IP地址, port as 通讯端口, AgvInfo.WorkType as 物料名称, AgvInfo.Internal_ID as 序号 ,[Status] as 设备状态,[Type] as 设备型号, " + " AgvInfo.Assembly_Line as 线体编号 , assembly_line.line_name as 线体名称 ,agvinfo.Mileage as 行驶里程 FROM AgvInfo ,assembly_line " + " where AgvInfo.Assembly_Line = assembly_line.id order by AgvInfo.ID"); } dataGridView1.DataSource = ds.Tables[0]; } private void dataGridView1_DoubleClick(object sender, EventArgs e) { if (dataGridView1.RowCount > 0) { flag = 0; num_id.Value = Convert.ToDecimal( dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["编号"].Value); lab_id.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["编号"].Value.ToString(); num_seq.Value = Convert.ToDecimal( dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["序号"].Value); cmb_iplist.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["IP地址"].Value.ToString(); cmb_switchip.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["交换机IP"].Value.ToString(); cmb_linelist.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["线体编号"].Value.ToString()+" . "+ dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["线体名称"].Value.ToString(); lab_km.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["行驶里程"].Value.ToString(); cmb_status.Text= (dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["设备状态"].Value.ToString()=="True")?"启用":"禁用"; cmb_type.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["设备型号"].Value.ToString(); numPort.Value = Convert.ToDecimal(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["通讯端口"].Value.ToString()); cmb_worktype.SelectedIndex = Convert.ToInt16(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["物料名称"].Value); groupBox2.Enabled = false; } } private void button5_Click(object sender, EventArgs e) { lab_km.Text = "0"; } private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e) { e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1); } private void toolStripButton1_Click(object sender, EventArgs e) { flag = 1; num_seq.Value = 0; cmb_iplist.Text = ""; cmb_switchip.Text = ""; cmb_linelist.SelectedIndex = 0; lab_km.Text = "0"; lab_id.Text = ""; groupBox2.Enabled = true; DataSet ds1 = db.connDt("SELECT max([ID])+1 FROM [AgvInfo]"); if (ds1.Tables[0].Rows[0][0].ToString() != "") { num_id.Value = Convert.ToDecimal(ds1.Tables[0].Rows[0][0].ToString()); } else { num_id.Value = 1; } cmb_type.SelectedIndex = 0; numPort.Value = 0; } private void toolStripButton3_Click(object sender, EventArgs e) { flag = 0; if (Cls.Param.UserName_temp == "") { MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (num_id.Value == 0 || num_seq.Value == 0 || cmb_iplist.Text == "" || cmb_linelist.Text.Trim() == "") { return; } if (add_agv(num_id.Value.ToString(), num_seq.Value.ToString(), cmb_iplist.Text, cmb_linelist.Text.Split('.')[0], Convert.ToInt16(numPort.Value ),Convert.ToInt16( cmb_type.Text ),cmb_switchip.Text,cmb_worktype.SelectedIndex) > 0) { cmb_iplist.Items.Remove(cmb_iplist.Text); MessageBox.Show("添加成功!"); } else { return; } AGVManage_Load(null, null); toolStripButton1_Click(null, null); } private void toolStripButton4_Click(object sender, EventArgs e) { flag = 0; if (Cls.Param.UserName_temp == "") { MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (num_id.Value == 0 || num_seq.Value == 0 || cmb_iplist.Text == "" || cmb_linelist.Text == "") { return; } if (delete_agv(num_id.Value.ToString()) > 0) { cmb_iplist.Items.Add(cmb_iplist.Text); MessageBox.Show("删除成功!"); } else { return; } AGVManage_Load(null, null); toolStripButton1_Click(null, null); } private void toolStripButton6_Click(object sender, EventArgs e) { flag = 0; if (Cls.Param.UserName_temp == "") { MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (num_id.Value == 0 || num_seq.Value == 0 || cmb_iplist.Text == "" || cmb_linelist.Text == "") { return; } if (update_agv() > 0) { AGVManage_Load(null,null); MessageBox.Show("修改成功!"); } else { return; } } private void toolStripButton2_Click(object sender, EventArgs e) { flag = 0; select_agv(num_id.Value.ToString(), cmb_linelist.Text.Split('.')[0]); return; } private void toolStripButton5_Click(object sender, EventArgs e) { flag = 0; groupBox2.Enabled = true; } private void cmb_type_TextChanged(object sender, EventArgs e) { if (cmb_type.SelectedIndex == 0) { pictureBox1.BackgroundImage = null; label9.Text = ""; } else if (cmb_type.SelectedIndex > 0) { try { DataSet ds1 = db.connDt("SELECT [Remark] FROM [Agv_Type] where id =" + cmb_type.Text); if (ds1.Tables[0].Rows.Count > 0) label9.Text = ds1.Tables[0].Rows[0][0].ToString(); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\picture\" + cmb_type.Text + ".JPG"); } catch { } } } private void cmb_linelist_TextChanged(object sender, EventArgs e) { if (flag == 1 && cmb_linelist.Text.Trim()!="") { DataSet ds1 = db.connDt("SELECT max([Internal_ID])+1 FROM [AgvInfo] where Assembly_Line=" + cmb_linelist.Text.Split('.')[0]); if (ds1.Tables[0].Rows[0][0].ToString() !="") num_seq.Value = Convert.ToDecimal(ds1.Tables[0].Rows[0][0].ToString()); else num_seq.Value = 1; } } } }