private void button1_Click(object sender, EventArgs e) { MyMeans.SQLstr = "Insert into mlmoban values ('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + richTextBox1.Text.Trim() + "')"; MyMeans.ExecuteSql(MyMeans.SQLstr); MessageBox.Show("增加成功"); Form5 form5 = new Form5(); textBox2.Text = ""; richTextBox1.Text = ""; int Temple_BH = 1; MyMeans.SQLstr = "select* from mlmoban"; SqlDataReader Sdr = MyMeans.GgtDataReader(MyMeans.SQLstr); while (Sdr.Read()) { if (int.Parse(Sdr[0].ToString()) > Temple_BH) { Temple_BH = int.Parse(Sdr[0].ToString()); } } Temple_BH++; textBox1.Text = Temple_BH.ToString(); textBox2.Focus(); }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { string SC_ml = dataGridView1.SelectedCells[0].Value.ToString().Trim(); MyMeans.SQLstr = "Delete from daifaml where 命令编号=" + int.Parse(SC_ml); MyMeans.ExecuteSql(MyMeans.SQLstr); MyMeans.SQLstr = "Select*from daifaml"; DataSet ds = MyMeans.GetDataSet(MyMeans.SQLstr); dataGridView1.DataSource = ds.Tables[0]; }
private void button1_Click(object sender, EventArgs e) { mlbh = textBox6.Text.Trim(); mllx = comboBox1.Text.Trim(); slcz = comboBox2.Text.Trim(); xl = comboBox3.Text.Trim(); qsz = comboBox4.Text.Trim(); jsz = comboBox5.Text.Trim(); xsqd = textBox1.Text.Trim() + "km" + textBox2.Text.Trim() + "m"; xszd = textBox3.Text.Trim() + "km" + textBox4.Text.Trim() + "m"; xsyy = textBox5.Text.Trim(); if (checkBox1.CheckState == CheckState.Checked) { xsxt = "列控中心"; } if (checkBox2.CheckState == CheckState.Checked) { xsxt += " RBC"; } kssj = dateTimePicker1.Text; jssj = dateTimePicker2.Text; xsnr = comboBox7.Text; // 如果所有信息填写完整,则完成新建命令,将命令插入到数据库中 if (mlbh != "" && mllx != "" && slcz != "" && xl != "" && qsz != "" && jsz != "" && xsqd != "" && xszd != "" && xsyy != "" && xsxt != "" && kssj != "" && jssj != "" && xsnr != "") { MyMeans.SQLstr = "Insert Into 临时限速命令 Values('" + int.Parse(mlbh) + "','" + mllx + "','" + slcz + "','" + xl + "','" + qsz + "','" + jsz + "','" + xsqd + "','" + xszd + "','" + xsyy + "','" + xsxt + "','" + kssj + "','" + jssj + "','" + xsnr + "',null)"; MyMeans.ExecuteSql(MyMeans.SQLstr); MyMeans.SQLstr = "Select * from 临时限速命令"; DataSet ds = null; ds = MyMeans.GetDataSet(MyMeans.SQLstr); dataGridView1.DataSource = ds.Tables[0]; comboBox1.Text = ""; comboBox2.Text = ""; comboBox3.Text = ""; comboBox4.Text = ""; comboBox5.Text = ""; comboBox6.Text = ""; comboBox7.Text = ""; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; checkBox1.CheckState = CheckState.Unchecked; checkBox2.CheckState = CheckState.Unchecked; } else { MessageBox.Show("请补全命令内容"); } }
private void button3_Click(object sender, EventArgs e) { if (listBox1.SelectedItems.Count == 0) { MessageBox.Show("请选择要删除的数据"); } else { MyMeans.SQLstr = "delete from changyongch where 常用词汇='" + listBox1.SelectedItem + "'"; MyMeans.ExecuteSql(MyMeans.SQLstr); listBox1.Items.Remove(listBox1.SelectedItem); } }
private void button2_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("请输入要添加的数据"); } else { MyMeans.SQLstr = "Insert into changyongch values('" + textBox1.Text + "')"; MyMeans.ExecuteSql(MyMeans.SQLstr); listBox1.Items.Add(textBox1.Text); textBox1.Text = ""; } }
private void button1_Click(object sender, EventArgs e) { if (a + b + c + d + f == 5) //判断a、b、c、d、f的和是否等于5,若为5表示5个文本框都为非空; { try { MyMeans.SQLstr = "Select * from yonghu where WorkNumber =" + int.Parse(textBox1.Text.Trim()); SqlDataReader read = MyMeans.GgtDataReader(MyMeans.SQLstr); //判断对应输入的工号是否查询到用户数据,如果查询到继续执行命令; if (read.Read()) { //判断对应输入工号的用户名和密码是否输入正确; if (textBox2.Text.Trim() == read[0].ToString().Trim() & textBox3.Text.Trim() == read[2].ToString().Trim()) { //判断两次新密码输入是否一致; if (textBox4.Text == textBox5.Text) { MyMeans.SQLstr = "Update yonghu Set Password="******"where WorkNumber=" + int.Parse(textBox1.Text.Trim()); MyMeans.ExecuteSql(MyMeans.SQLstr); MessageBox.Show("修改成功"); } else { MessageBox.Show("新密码输入不一致"); } } else { MessageBox.Show("用户信息输入错误"); } } //如果根据输入的“工号”没有查询到用户信息,则显示“用户信息输入错误”; else { MessageBox.Show("用户信息输入错误"); } } catch { } } else { MessageBox.Show("请将信息输入完整"); } }
private void 达ToolStripMenuItem_Click(object sender, EventArgs e) { byte[] sendByts = new byte[1024]; //发送调度命令给服务器 string sendStr = dataGridView1.SelectedCells[0].Value.ToString().Trim() + "#" + dataGridView1.SelectedCells[1].Value.ToString().Trim() + "#" + dataGridView1.SelectedCells[3].Value.ToString().Trim() + "#" + dateTimePicker1.Text.Trim() + "#" + dataGridView1.SelectedCells[5].Value.ToString().Trim(); sendByts = Encoding.UTF8.GetBytes(sendStr); socket.Send(sendByts, sendByts.Length, 0); //发送受令车站信息给服务器; string SC_ml = dataGridView1.SelectedCells[0].Value.ToString().Trim(); MyMeans.SQLstr = "select*from 受令车站对应表 where 命令编号=" + int.Parse(SC_ml); SqlDataReader read = MyMeans.GgtDataReader(MyMeans.SQLstr); string SLchezhan = null; while (read.Read()) { SLchezhan += (read[1].ToString().Trim() + "#"); } sendByts = Encoding.UTF8.GetBytes(SLchezhan); socket.Send(sendByts, sendByts.Length, 0); MessageBox.Show("命令发送成功"); DataSet ds; MyMeans.SQLstr = "Insert into fasongml(命令编号,命令类型,调度员姓名,发令单位,发令时间,命令内容,当前状态)values(" + int.Parse(SC_ml) + ",'" + dataGridView1.SelectedCells[1].Value.ToString().Trim() + "','" + dataGridView1.SelectedCells[2].Value.ToString().Trim() + "','" + dataGridView1.SelectedCells[3].Value.ToString().Trim() + "','" + dateTimePicker1.Text.Trim() + "','" + dataGridView1.SelectedCells[5].Value.ToString().Trim() + "','已发送')";// 注意圆括号中的 , 用英文形式 MyMeans.ExecuteSql(MyMeans.SQLstr); ds = MyMeans.GetDataSet("Select*from fasongml"); dataGridView2.DataSource = ds.Tables[0]; MyMeans.Close(); MyMeans.SQLstr = "Delete from daifaml where 命令编号=" + int.Parse(SC_ml); MyMeans.ExecuteSql(MyMeans.SQLstr); MyMeans.SQLstr = "Select*from daifaml"; ds = MyMeans.GetDataSet(MyMeans.SQLstr); dataGridView1.DataSource = ds.Tables[0]; }
//接受车站发来的签收状态 public void RecMsg() { int i = 0; //0表示某条调度命令所有受令车站均已签收,1表示存在受令车站没有签收; while (true) { byte[] Msg = new byte[1024]; int Bytes = 1; string receiveMsg = null; char[] fenge = { '#' }; string[] msg; try { Bytes = socket.Receive(Msg, Msg.Length, 0); if (Bytes == 0) { label7.Text = "通信断开"; socket.Close(); //在调用Abort()方法的线程上引发ThreadAbortException异常,以开始终止线程。 //即调用此方法会自动引发一个异常,程序便运行到catch语句块 Thread.CurrentThread.Abort(); } } catch (Exception ex) { //GetType()获取当前实例的运行类型 //typeof()活动类型声明的泛型类型 if (ex.GetType() == typeof(ThreadAbortException)) //如果捕捉到的异常为ThreadAbortException异常,则什么都不做 { } else { label7.Text = "通信断开"; socket.Close(); Thread.CurrentThread.Abort(); } } receiveMsg = Encoding.UTF8.GetString(Msg, 0, Bytes); msg = receiveMsg.Split(fenge); if (msg[0] == "断开") //如果服务器发来的是断开通信连接的信息,则终止线程; { label7.Text = "通信断开"; socket.Close(); Thread.CurrentThread.Abort(); //获取当前正在运行的线程,并将其终止; } else { //根据命令编号和受令单位更新 调度命令的相应车站的签收状态 MyMeans.SQLstr = "Update 受令车站对应表 Set 签收状态='签收',签收人='" + msg[2] + "',签收时间='" + msg[3] + "',签收结果='" + msg[4] + "'where 命令编号=" + int.Parse(msg[0]) + "and 受令单位='" + msg[1] + "'"; MyMeans.ExecuteSql(MyMeans.SQLstr); MyMeans.SQLstr = "select*from 受令车站对应表 where 命令编号=" + int.Parse(msg[0]); SqlDataReader Sdr = MyMeans.GgtDataReader(MyMeans.SQLstr); while (Sdr.Read()) { //如果有受令车站没有签收,将i置为1; if (Sdr[2].ToString().Trim() == "") { i = 1; } } if (i == 0) //i=0表示所有车站均已签收; { MyMeans.SQLstr = "select*from fasongml where 命令编号=" + int.Parse(msg[0]); SqlDataReader read = MyMeans.GgtDataReader(MyMeans.SQLstr); read.Read(); MyMeans.SQLstr = "Insert into yifaml(命令编号,命令类型,调度员姓名,发令单位,发令时间,命令内容,签收状态)values(" + int.Parse(read[0].ToString().Trim()) + ",'" + read[1].ToString().Trim() + "','" + read[2].ToString().Trim() + "','" + read[3].ToString().Trim() + "','" + read[4].ToString().Trim() + "','" + read[5].ToString().Trim() + "','全部签收')"; MyMeans.ExecuteSql(MyMeans.SQLstr); MyMeans.SQLstr = "Delete from fasongml where 命令编号=" + int.Parse(msg[0]); MyMeans.ExecuteSql(MyMeans.SQLstr); } DataSet ds; ds = MyMeans.GetDataSet("Select*from fasongml"); dataGridView2.DataSource = ds.Tables[0]; MyMeans.Close(); ds = MyMeans.GetDataSet("Select*from yifaml"); dataGridView3.DataSource = ds.Tables[0]; MyMeans.Close(); } } }
private void button5_Click(object sender, EventArgs e) //“发送”按钮,点击发送调度命令,同时将调度命令保存在发令箱 { int a = 0, b = 0, c = 0, d = 0, f = 0, g = 0, h = 0; string SLchezhan = null; for (int i = 0; i < dataGridView4.Rows.Count; i++) { DataGridViewCheckBoxCell dgvCheckBoxCell = dataGridView4.Rows[i].Cells[0] as DataGridViewCheckBoxCell; //获取DataGridViewCheckBoxCell对象; if (dgvCheckBoxCell.Value == "1") //判断该DataGridViewCheckBoxCell是否选中; { SLchezhan += (dataGridView4.Rows[i].Cells[1].Value.ToString().Trim() + "#"); } } if (textBox2.Text.Trim() != "") { a = 1; } if (comboBox1.Text.Trim() != "") { b = 1; } if (textBox4.Text.Trim() != "") { c = 1; } if (textBox5.Text.Trim() != "") { d = 1; } if (dateTimePicker1.Text != "") { f = 1; } if (richTextBox1.Text.Trim() != "") { g = 1; } if (SLchezhan != "") { h = 1; } if (a == 1 & b == 1 & c == 1 & d == 1 & f == 1 & g == 1 & h == 1) { try { byte[] sendByts = new byte[1024]; //发送调度命令给服务器 string sendStr = textBox2.Text.Trim() + "#" + comboBox1.Text.Trim() + "#" + textBox5.Text.Trim() + "#" + dateTimePicker1.Text + "#" + richTextBox1.Text.Trim(); sendByts = Encoding.UTF8.GetBytes(sendStr); socket.Send(sendByts, sendByts.Length, 0); //发送受令车站信息给服务; sendByts = Encoding.UTF8.GetBytes(SLchezhan); socket.Send(sendByts, sendByts.Length, 0); MessageBox.Show("命令发送成功"); // 将已发送的调度命令存储到发送命令列表 MyMeans.SQLstr = "Insert into fasongml(命令编号,命令类型,调度员姓名,发令单位,发令时间,命令内容,当前状态)values(" + int.Parse(textBox2.Text.Trim()) + ",'" + comboBox1.Text.Trim() + "','" + textBox4.Text.Trim() + "','" + textBox5.Text.Trim() + "','" + dateTimePicker1.Text.Trim() + "','" + richTextBox1.Text.Trim() + "','已发送')";// 注意圆括号中的 , 用英文形式 MyMeans.ExecuteSql(MyMeans.SQLstr); //将调度命令的受令车站信息加入到“受令车站对应表”中; for (int i = 0; i < dataGridView4.Rows.Count; i++) { DataGridViewCheckBoxCell dgvCheckBoxCell = dataGridView4.Rows[i].Cells[0] as DataGridViewCheckBoxCell; //获取DataGridViewCheckBoxCell对象; if (dgvCheckBoxCell.Value == "1") //判断该DataGridViewCheckBoxCell是否选中; { MyMeans.SQLstr = "Insert into 受令车站对应表(命令编号,受令单位)values(" + int.Parse(textBox2.Text.Trim()) + ",'" + dataGridView4.Rows[i].Cells[1].Value.ToString().Trim() + "')"; MyMeans.ExecuteSql(MyMeans.SQLstr); } } //更新界面显示; DataSet ds; ds = MyMeans.GetDataSet("Select*from fasongml"); dataGridView2.DataSource = ds.Tables[0]; } catch { MessageBox.Show("命令发送失败"); // 将调度命令存储到待发命令列表; MyMeans.SQLstr = "Insert into daifaml(命令编号,命令类型,调度员姓名,发令单位,起草时间,命令内容,当前状态)values(" + int.Parse(textBox2.Text.Trim()) + ",'" + comboBox1.Text.Trim() + "','" + textBox4.Text.Trim() + "','" + textBox5.Text.Trim() + "','" + dateTimePicker1.Text.Trim() + "','" + richTextBox1.Text.Trim() + "','已发送')";// 注意圆括号中的 , 用英文形式 MyMeans.ExecuteSql(MyMeans.SQLstr); //将调度命令的受令车站信息加入到“受令车站对应表”中; for (int i = 0; i < dataGridView4.Rows.Count; i++) { DataGridViewCheckBoxCell dgvCheckBoxCell = dataGridView4.Rows[i].Cells[0] as DataGridViewCheckBoxCell; //获取DataGridViewCheckBoxCell对象; if (dgvCheckBoxCell.Value == "1") //判断该DataGridViewCheckBoxCell是否选中; { MyMeans.SQLstr = "Insert into 受令车站对应表(命令编号,受令单位)values(" + int.Parse(textBox2.Text.Trim()) + ",'" + dataGridView4.Rows[i].Cells[1].Value.ToString().Trim() + "')"; MyMeans.ExecuteSql(MyMeans.SQLstr); } } //更新界面显示; DataSet ds; ds = MyMeans.GetDataSet("Select*from daifaml"); dataGridView1.DataSource = ds.Tables[0]; } textBox2.Text = ""; textBox4.Text = ""; textBox5.Text = ""; comboBox1.Text = ""; richTextBox1.Text = ""; for (int i = 0; i < dataGridView4.Rows.Count; i++) { dataGridView4.Rows[i].Cells[0].Value = "0"; } } else { MessageBox.Show("请将命令补充完整"); } }
private void button4_Click(object sender, EventArgs e) //“保存”按钮,点击将当前调度命令保存到待发箱 { int a = 0, b = 0, c = 0, d = 0, f = 0, g = 0, h = 0; string SLchezhan = null; for (int i = 0; i < dataGridView4.Rows.Count; i++) { DataGridViewCheckBoxCell dgvCheckBoxCell = dataGridView4.Rows[i].Cells[0] as DataGridViewCheckBoxCell; //获取DataGridViewCheckBoxCell对象; if (dgvCheckBoxCell.Value == "1") //判断该DataGridViewCheckBoxCell是否选中; { SLchezhan += (dataGridView4.Rows[i].Cells[1].Value.ToString().Trim() + "#"); } } if (textBox2.Text.Trim() != "") { a = 1; } if (comboBox1.Text.Trim() != "") { b = 1; } if (textBox4.Text.Trim() != "") { c = 1; } if (textBox5.Text.Trim() != "") { d = 1; } if (dateTimePicker1.Text != "") { f = 1; } if (richTextBox1.Text.Trim() != "") { g = 1; } if (SLchezhan != "") { h = 1; } if (a == 1 & b == 1 & c == 1 & d == 1 & f == 1 & g == 1 & h == 1) { if (isChongxinBj == 0) { MyMeans.SQLstr = "Insert into daifaml(命令编号,命令类型,调度员姓名,发令单位,起草时间,命令内容,当前状态)values(" + int.Parse(textBox2.Text.Trim()) + ",'" + comboBox1.Text.Trim() + "','" + textBox4.Text.Trim() + "','" + textBox5.Text.Trim() + "','" + dateTimePicker1.Text + "','" + richTextBox1.Text.Trim() + "','未发送')";// 注意圆括号中的 , 用英文形式 MyMeans.ExecuteSql(MyMeans.SQLstr); for (int i = 0; i < dataGridView4.Rows.Count; i++) { DataGridViewCheckBoxCell dgvCheckBoxCell = dataGridView4.Rows[i].Cells[0] as DataGridViewCheckBoxCell; //获取DataGridViewCheckBoxCell对象; if (dgvCheckBoxCell.Value == "1") //判断该DataGridViewCheckBoxCell是否选中; { MyMeans.SQLstr = "Insert into 受令车站对应表(命令编号,受令单位)values(" + int.Parse(textBox2.Text.Trim()) + ",'" + dataGridView4.Rows[i].Cells[1].Value.ToString().Trim() + "')"; MyMeans.ExecuteSql(MyMeans.SQLstr); } } DataSet ds = MyMeans.GetDataSet("Select*from daifaml"); dataGridView1.DataSource = ds.Tables[0]; textBox2.Text = ""; textBox4.Text = ""; textBox5.Text = ""; comboBox1.Text = ""; richTextBox1.Text = ""; for (int i = 0; i < dataGridView4.Rows.Count; i++) { dataGridView4.Rows[i].Cells[0].Value = "0"; } } else { MyMeans.SQLstr = "delete from 受令车站对应表 where 命令编号=" + int.Parse(textBox2.Text.Trim()); MyMeans.ExecuteSql(MyMeans.SQLstr); //删除该条调度命令原来的受令车站信息; MyMeans.SQLstr = "update daifaml set 命令类型='" + comboBox1.Text.Trim() + "',调度员姓名='" + textBox4.Text.Trim() + "',起草时间='" + dateTimePicker1.Text.Trim() + "',命令内容='" + richTextBox1.Text.Trim() + "'where 命令编号=" + int.Parse(textBox2.Text.Trim()); MyMeans.ExecuteSql(MyMeans.SQLstr); for (int i = 0; i < dataGridView4.Rows.Count; i++) { DataGridViewCheckBoxCell dgvCheckBoxCell = dataGridView4.Rows[i].Cells[0] as DataGridViewCheckBoxCell; //获取DataGridViewCheckBoxCell对象; if (dgvCheckBoxCell.Value == "1") //判断该DataGridViewCheckBoxCell是否选中; { SLchezhan += (dataGridView4.Rows[i].Cells[1].Value.ToString().Trim() + "#"); MyMeans.SQLstr = "Insert into 受令车站对应表(命令编号,受令单位)values(" + int.Parse(textBox2.Text.Trim()) + ",'" + dataGridView4.Rows[i].Cells[1].Value.ToString().Trim() + "')"; MyMeans.ExecuteSql(MyMeans.SQLstr); } } DataSet ds = MyMeans.GetDataSet("Select*from daifaml"); dataGridView1.DataSource = ds.Tables[0]; textBox2.Text = ""; textBox4.Text = ""; textBox5.Text = ""; comboBox1.Text = ""; richTextBox1.Text = ""; for (int i = 0; i < dataGridView4.Rows.Count; i++) { dataGridView4.Rows[i].Cells[0].Value = "0"; } isChongxinBj = 0; //重新编辑并保存成功之后,将isChongxinBj的值置为0; } } else { MessageBox.Show("请将命令补充完整"); } }
private void button1_Click(object sender, EventArgs e) { //得到现在限速系统的文本,赋给变量XSXT; string XSXT = null; if (checkBox1.CheckState == CheckState.Checked) { XSXT = "列控中心"; } if (checkBox2.CheckState == CheckState.Checked) { XSXT += " RBC"; } //逐一比较指定限速命令的各个信息与现在编辑的信息是否一致; if (Form4.mlbh == textBox6.Text.Trim()) { a = true; } else { a = false; } if (Form4.mllx == comboBox1.Text.Trim()) { b = true; } else { b = false; } if (Form4.slcz == comboBox2.Text.Trim()) { c = true; } else { c = false; } if (Form4.xl == comboBox3.Text.Trim()) { d = true; } else { d = false; } if (Form4.qsz == comboBox4.Text.Trim()) { f = true; } else { f = false; } if (Form4.jsz == comboBox5.Text.Trim()) { g = true; } else { g = false; } if (Form4.xsqd == textBox1.Text.Trim() + "km" + textBox2.Text.Trim() + "m") { h = true; } else { h = false; } if (Form4.xszd == textBox3.Text.Trim() + "km" + textBox4.Text.Trim() + "m") { i = true; } else { i = false; } if (Form4.xsyy == textBox5.Text.Trim()) { j = true; } else { j = false; } if (Form4.xsxt == XSXT) { k = true; } else { k = false; } if (Form4.kssj == dateTimePicker1.Text) { l = true; } else { l = false; } if (Form4.jssj == dateTimePicker2.Text) { m = true; } else { m = false; } if (Form4.xsnr == comboBox7.Text.Trim()) { n = true; } else { n = false; } if (a == true & b == true & c == true & d == true & f == true & g == true & h == true & i == true & j == true & k == true & n == true) { MyMeans.SQLstr = "Update 临时限速命令 Set 是否检验='检验通过' where 命令编号='" + int.Parse(Form4.mlbh) + "'"; MyMeans.ExecuteSql(MyMeans.SQLstr); MessageBox.Show("检验通过"); } }