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 OutputSet : Form { private string strsql; private ClsDBConn_sql db = new ClsDBConn_sql(); private DataSet ds = new DataSet(); public OutputSet() { InitializeComponent(); } private void comboBox4_TextChanged(object sender, EventArgs e) { if (comboBox4.SelectedIndex == 0) label7.Text = ""; else if (comboBox4.SelectedIndex == 1) label7.Text = "低电平输出"; else if (comboBox4.SelectedIndex == 2) label7.Text = "高电平输出"; } private void toolStripButton1_Click(object sender, EventArgs e) { groupBox1.Enabled = true; numericUpDown1.Value = 0; comboBox1.SelectedIndex = 1; comboBox2.SelectedIndex = 1; comboBox3.SelectedIndex = 1; comboBox4.SelectedIndex = 1; textBox1.Text = ""; } private void OutputSet_Load(object sender, EventArgs e) { strsql = "SELECT [Loc_ID] as 位置编号,[Card_ID] as 板卡编号,[Port] as 端口号,[Bit] as 端口位,[Value] as 输出值,[Remark] as 备注 FROM [IO_Set]"; if (ds.Tables.Count > 0) ds.Tables.Clear(); ds = db.connDt(strsql); dataGridView1.DataSource = ds.Tables[0]; } private void toolStripButton3_Click(object sender, EventArgs e) { if (Cls.Param.UserName_temp == "") { MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (numericUpDown1.Value == 0 || comboBox1.Text == "" || comboBox2.Text == "" || comboBox3.Text == "" || comboBox4.Text == "") return; strsql = "INSERT INTO [IO_Set] ([Loc_ID],[Card_ID],[Port] ,[Bit] ,[Value] ,[Remark]) " + " VALUES (" + numericUpDown1.Value + "," + comboBox1.SelectedIndex + "," + comboBox2.SelectedIndex + "," + comboBox3.SelectedIndex + "," + comboBox4.Text + ",'" + textBox1.Text + "')"; if (db.Command(strsql) == "1") { MessageBox.Show("添加成功!"); OutputSet_Load(null,null); groupBox1.Enabled = false; } } private void dataGridView1_DoubleClick(object sender, EventArgs e) { if (dataGridView1.Rows.Count > 0) { numericUpDown1.Value = Convert.ToDecimal(dataGridView1.CurrentRow.Cells[0].Value.ToString()); numericUpDown2.Value = Convert.ToDecimal(dataGridView1.CurrentRow.Cells[0].Value.ToString()); comboBox1.SelectedIndex = Convert.ToInt16(dataGridView1.CurrentRow.Cells[1].Value.ToString()); comboBox5.SelectedIndex = Convert.ToInt16(dataGridView1.CurrentRow.Cells[1].Value.ToString()); comboBox2.SelectedIndex = Convert.ToInt16(dataGridView1.CurrentRow.Cells[2].Value.ToString()); comboBox6.SelectedIndex = Convert.ToInt16(dataGridView1.CurrentRow.Cells[2].Value.ToString()); comboBox3.SelectedIndex = Convert.ToInt16(dataGridView1.CurrentRow.Cells[3].Value.ToString()); comboBox7.SelectedIndex = Convert.ToInt16(dataGridView1.CurrentRow.Cells[3].Value.ToString()); comboBox4.SelectedIndex = Convert.ToInt16(dataGridView1.CurrentRow.Cells[4].Value.ToString()); textBox1.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString(); groupBox1.Enabled = false; } } private void toolStripButton5_Click(object sender, EventArgs e) { groupBox1.Enabled = true; } private void toolStripButton4_Click(object sender, EventArgs e) { if (Cls.Param.UserName_temp == "") { MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (numericUpDown1.Value == 0 || comboBox1.Text == "" || comboBox2.Text == "" || comboBox3.Text == "" || comboBox4.Text == "") return; strsql = "DELETE FROM io_set where [Loc_ID] =" + numericUpDown1.Value + " and [Card_ID] = " + comboBox1.SelectedIndex + " and [Port] =" + comboBox2.SelectedIndex + " and [Bit] =" + comboBox3.SelectedIndex; if (db.Command(strsql) == "1") { MessageBox.Show("删除成功!"); OutputSet_Load(null, null); groupBox1.Enabled = false; } } private void toolStripButton6_Click(object sender, EventArgs e) { if (Cls.Param.UserName_temp == "") { MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (numericUpDown1.Value == 0 || comboBox1.Text == "" || comboBox2.Text == "" || comboBox3.Text == "") return; strsql = "update io_set set [Loc_ID] = " + numericUpDown1.Value + ",[Card_ID] = " + comboBox1.SelectedIndex + ",[Port] = " + comboBox2.SelectedIndex + ",[Bit] = " + comboBox3.SelectedIndex + ",[Value] =" + comboBox4.SelectedIndex + ",[Remark] = '" + textBox1.Text + "'"+ " where [Loc_ID] =" + numericUpDown2.Value + " and [Card_ID] = " + comboBox5.SelectedIndex + " and [Port] =" + comboBox6.SelectedIndex + " and [Bit] =" + comboBox7.SelectedIndex; if (db.Command(strsql) == "1") { MessageBox.Show("更新成功!"); OutputSet_Load(null, null); groupBox1.Enabled = false; } } } }