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 APInfo : Form { private ClsDBConn_sql db = new ClsDBConn_sql(); private System.Data.DataSet ds = new System.Data.DataSet(); public APInfo( ) { InitializeComponent(); ds.Tables.Clear(); ds = db.connDt("SELECT [Name] FROM [AP_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 = db.connDt("select id from ipaddress where id not in (select ipaddress from agvinfo) and id not in (select ipaddress from ap_site) order by seq"); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { cmb_ip.Items.Add(dr[0].ToString()); } } } } private void APInfo_Load(object sender, EventArgs e) { ds.Tables.Clear(); ds = db.connDt("select id as 编号, type as 型号,ipaddress as ip地址,[信道] , ssid ,[位置] ,[Status] ,[Remark] from AP_Site"); if (ds.Tables.Count > 0) { dataGridView1.DataSource = ds.Tables[0]; } groupBox2.Enabled = false; this.WindowState = FormWindowState.Maximized; } private void dataGridView1_DoubleClick(object sender, EventArgs e) { if (dataGridView1.RowCount > 0) { try { groupBox2.Enabled = false; num_id.Value = Convert.ToDecimal(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["编号"].Value); cmb_ip.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["IP地址"].Value.ToString(); txt_ssid.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["SSID"].Value.ToString(); num_xd.Value = Convert.ToDecimal(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["xd"].Value); ; txt_location.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["location"].Value.ToString(); ; txt_remark.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["remark"].Value.ToString(); cmb_type.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["型号"].Value.ToString(); cmb_status.Text = (dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["设备状态"].Value.ToString() == "True") ? "启用" : "禁用"; } catch { } } } private void btn_Click(object sender, EventArgs e) { } private int add_ap(string id , string ip , string ssid,string xd,string location,string remark,string type) { int rowcount = 0; try { rowcount = Convert.ToInt16(db.Command("insert into ap_site (id , ipaddress , ssid,[信道] ,[位置] ,[Remark],type) values (" + id + ",'" + ip + "','" + ssid + "','" + xd + "','" + location + "','" +remark +"','"+type+"')")); } catch { } return rowcount; } private int update_ap(string id, string ip, string ssid, string xd, string location, string remark,string type) { int rowcount = 0; try { rowcount = Convert.ToInt16(db.Command("update ap_site set ipaddress='" + ip + "',ssid='" + ssid + "',信道='" + xd + "',位置='" + location + "',remark='" + remark + "',type='"+ type +"' where id=" + id)); } catch { } return rowcount; } private int delete_ap(string id, string ip, string ssid) { int rowcount = 0; try { rowcount = Convert.ToInt16(db.Command("delete from ap_site where id=" + id)); } catch { } return rowcount; } private void toolStripButton1_Click(object sender, EventArgs e) { num_id.Value = 0; num_xd.Value = 0; txt_location.Text = ""; txt_remark.Text = ""; txt_ssid.Text = ""; cmb_ip.Text = ""; groupBox2.Enabled = true; } private void toolStripButton3_Click(object sender, EventArgs e) { if (Cls.Param.UserName_temp == "") { MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (num_id.Value == 0 || cmb_ip.Text == "") { return; } if (add_ap(num_id.Value.ToString(), cmb_ip.Text, txt_ssid.Text, num_xd.Value.ToString(), txt_location.Text.Trim(), txt_remark.Text.Trim(),cmb_type.Text) > 0) { MessageBox.Show("添加成功!"); } else return; ds.Tables.Clear(); ds = db.connDt("select id as 编号, ipaddress as ip地址,[信道] , ssid ,[位置] ,[Status] ,[Remark] from AP_Site"); if (ds.Tables.Count > 0) { dataGridView1.DataSource = ds.Tables[0]; } } private void toolStripButton4_Click(object sender, EventArgs e) { if (Cls.Param.UserName_temp == "") { MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (num_id.Value == 0 || cmb_ip.Text == "") { return; } if (delete_ap(num_id.Value.ToString(), cmb_ip.Text, txt_ssid.Text) > 0) { MessageBox.Show("删除成功!"); } else return; ds.Tables.Clear(); ds = db.connDt("select id as 编号, ipaddress as ip地址,[信道] , ssid ,[位置] ,[Status] ,[Remark] from AP_Site"); if (ds.Tables.Count > 0) { dataGridView1.DataSource = ds.Tables[0]; } } private void toolStripButton6_Click(object sender, EventArgs e) { if (groupBox2.Enabled) { if (Cls.Param.UserName_temp == "") { MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (num_id.Value == 0 || cmb_ip.Text == "") { return; } if (update_ap(num_id.Value.ToString(), cmb_ip.Text, txt_ssid.Text.Trim(), num_xd.Value.ToString(), txt_location.Text.Trim(), txt_remark.Text.Trim(), cmb_type.Text) > 0) { MessageBox.Show("修改成功!"); } else return; APInfo_Load(null,null); } } private void textBox1_TextChanged(object sender, EventArgs e) { if (textBox1.Text == "") textBox1.Visible = false; else textBox1.Visible = true; } private void cmb_type_SelectedIndexChanged(object sender, EventArgs e) { ds.Tables.Clear(); ds = db.connDt("SELECT description FROM [AP_Type] where name ='"+cmb_type.Text+"'"); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { textBox1.Text = ds.Tables[0].Rows[0][0].ToString(); } } } private void toolStripButton5_Click(object sender, EventArgs e) { groupBox2.Enabled = true; } } }