private void getFactory(object obj) { try { comboBox1.Items.Clear(); string sql1 = "select * from work"; MySqlDataReader rd1 = msc.getDataFromTable(sql1); while (rd1.Read()) { comboBox1.Items.Add(rd1["workid"].ToString()); } rd1.Close(); msc.Close(); if (comboBox1.Items.Count > 0) { comboBox1.Text = comboBox1.Items[0].ToString(); } sql1 = "select * from work where workid =" + comboBox1.Text + ""; MySqlDataReader rd2 = msc.getDataFromTable(sql1); while (rd2.Read()) { label2.Text = rd2["workname"].ToString(); } rd2.Close(); msc.Close(); } catch (SqlException se) { MessageBox.Show("数据库异常", "提示"); } }
private string selectID(string str) { string sql = "select workid from work where workname = '" + str + "'"; try { //DataBase db = new DataBase(); //db.command.CommandText = sql; //db.command.Connection = db.connection; string ret = ""; //db.Dr = db.command.ExecuteReader(); MySqlDataReader rd = msc.getDataFromTable(sql); while (rd.Read()) { ret = rd["workid"].ToString(); } rd.Close(); msc.Close(); return(ret); } catch (SqlException se) { string message_error = se.ToString(); string path = System.Windows.Forms.Application.StartupPath; FileStream fs = new FileStream(path + "\\log.txt", FileMode.Create | FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("错误信息是:" + message_error + " 时间是:" + DateTime.Now.ToString()); sw.Flush(); sw.Close(); fs.Close(); return("error"); } }
private void getFactory(object obj) { try { string sql = "select * from user"; //DataBase db = new DataBase(); //db.command.CommandText = sql; //db.command.Connection = db.connection; //db.Dr = db.command.ExecuteReader(); MySqlConn ms = new MySqlConn(); MySqlDataReader rd = ms.getDataFromTable(sql); while (rd.Read()) { if (rd["UserName"].ToString().Equals("root")) { continue; } else { comboBox7.Items.Add(rd["UserName"].ToString()); } } rd.Close(); ms.Close(); } catch (Exception exc) { //MessageBox.Show("数据库连接失败", "提示"); new Thread(new ParameterizedThreadStart(showBox)).Start("数据库连接失败"); } }
string shuju(string s, string sse, string ss) { string sql66 = "SELECT * from equiptype where Etype = " + ss + ""; string hh = ""; MySqlConn msc1 = new MySqlConn(); MySqlDataReader rd31 = msc1.getDataFromTable(sql66); while (rd31.Read()) { hh = rd31["Ename"].ToString(); } rd31.Close(); msc1.Close(); string sql19 = "SELECT count(*) FROM dsensor where workid =" + s + " and dsensor.Ename ='" + hh + "' and dsensor.Eid =" + sse + ""; string aaa = " 01"; MySqlConn msc2 = new MySqlConn(); MySqlDataReader rd3 = msc2.getDataFromTable(sql19); while (rd3.Read()) { aaa = rd3["count(*)"].ToString(); } rd3.Close(); msc2.Close(); return(aaa); }
private void getFactory(object obj) { try { comboBox1.Items.Clear(); string sql1 = "select * from work"; MySqlDataReader rd1 = msc.getDataFromTable(sql1); while (rd1.Read()) { comboBox1.Items.Add(rd1["workid"].ToString()); } rd1.Close(); msc.Close(); if (comboBox1.Items.Count > 0) { comboBox1.Text = comboBox1.Items[0].ToString(); } string sql = "select workname from work where workid =" + "" + comboBox1.Text + ""; MySqlDataReader rd = msc.getDataFromTable(sql); while (rd.Read()) { skinLabel4.Text = rd["workname"].ToString(); } rd.Close(); msc.Close(); //string sql2 = "select * from ip where workid =" + "" + comboBox1.Text + ""; //MySqlDataReader rd2 = msc.getDataFromTable(sql2); //while (rd2.Read()) //{ // Label2.Text = rd2["ip"].ToString(); // Label3.Text = rd2["duankou"].ToString(); //} //rd2.Close(); //msc.Close(); } catch (SqlException se) { MessageBox.Show("数据库异常", "提示"); } }
private void getFactory(object obj) { try { comboBox1.Items.Clear(); string sql1 = "select * from work"; MySqlDataReader rd1 = msc.getDataFromTable(sql1); while (rd1.Read()) { comboBox1.Items.Add(rd1["workid"].ToString()); } rd1.Close(); msc.Close(); if (comboBox1.Items.Count > 0) { comboBox1.Text = comboBox1.Items[0].ToString(); } string sql = "select workname from work where workid =" + "" + comboBox1.Text + ""; MySqlDataReader rd = msc.getDataFromTable(sql); while (rd.Read()) { skinLabel4.Text = rd["workname"].ToString(); } rd.Close(); msc.Close(); string sql3 = "select * from equiptype"; MySqlDataReader rd3 = msc.getDataFromTable(sql3); while (rd3.Read()) { comboBox2.Items.Add(rd3["Ename"].ToString()); } rd3.Close(); msc.Close(); if (comboBox2.Items.Count > 0) { comboBox2.Text = comboBox2.Items[0].ToString(); } //string sql2 = "select * from equipment WHERE Etype = 1 and workid =" + "" + comboBox1.Text + ""; //MySqlDataReader rd2 = msc.getDataFromTable(sql2); //while (rd2.Read()) //{ // comboBox4.Items.Add(rd2["Eid"].ToString()); //} //rd2.Close(); //msc.Close(); //if (comboBox4.Items.Count > 0) //{ // comboBox4.Text = comboBox4.Items[0].ToString(); //} } catch (SqlException se) { MessageBox.Show("数据库异常", "提示"); } }
private void skinButton1_Click(object sender, EventArgs e) { if (skinTextBox1.Text.Equals("")) { //MessageBox.Show("请输入原密码", "提示"); new Thread(new ParameterizedThreadStart(ShowBox)).Start("请输入新名称"); } else { try { //MessageBox.Show("====33333=" + old_passwd); //string sql = "update user set PassWord='******' where UserName ='******';"; string sql = "update company set company = '" + skinTextBox1.Text + "' where company is not NULL"; MySqlConn ms1 = new MySqlConn(); int res = ms1.nonSelect(sql); ms1.Close(); Label2.Text = ""; try { string sql1 = "select company from company where company is not NULL"; MySqlConn ms = new MySqlConn(); MySqlDataReader rd = ms.getDataFromTable(sql1); while (rd.Read()) { Label2.Text = rd["company"].ToString(); } rd.Close(); ms.Close(); } catch (SqlException se) { } if (res > 0) { MessageBox.Show("修改公司名称成功", "提示"); } else { MessageBox.Show("修改公司名称失败", "提示"); } } catch (Exception exc) { //MessageBox.Show("请检查数据库连接设置", "提示"); } } }
private void skinButton3_Click_1(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("确认删除", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { //点确定的代码 int p1 = 1; string t2; if (comboBox1.Text.Equals("压力计")) { t2 = "1"; } else if (comboBox1.Text.Equals("减速机")) { t2 = "2"; } else { t2 = "3"; } string sql = "DELETE FROM equipment WHERE workid =" + bz + " AND Eid =" + bz1 + " and Etype =" + t2 + " "; MySqlConn ms2 = new MySqlConn(); int n = ms2.nonSelect(sql); ms2.Close(); MessageBox.Show(" 删除设备成功", "提示"); skinTextBox1.Text = ""; skinTextBox2.Text = ""; try { string sql2 = "select equipment.workid,workname,equipment.Eid,equiptype.Ename,equipment.caiji,equipment.shangchuan from work,equipment,equiptype where `work`.workid = equipment.workid and equipment.Etype = equiptype.Etype ORDER BY workid asc"; MySqlConnection conn = msc.GetConn(); MySqlDataAdapter sda = new MySqlDataAdapter(sql2, conn); //获取数据表 //DataTable table = new DataTable(); DataSet ds = new DataSet(); sda.Fill(ds, "ds"); //填充数据库 this.dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ee) { } } }
private void company_Load(object sender, EventArgs e) { Label2.Text = ""; try { string sql = "select company from company where company is not NULL"; MySqlConn ms = new MySqlConn(); MySqlDataReader rd = ms.getDataFromTable(sql); while (rd.Read()) { Label2.Text = rd["company"].ToString(); } rd.Close(); ms.Close(); } catch (SqlException se) { } }
private void button3_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("确认删除", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { //点确定的代码 string sql = "DELETE FROM dsensor WHERE workid =" + bz + " AND Eid =" + bz1 + " AND Sid =" + bz2 + ""; MySqlConn ms2 = new MySqlConn(); int n = ms2.nonSelect(sql); ms2.Close(); MessageBox.Show(" 删除设备成功", "提示"); skinTextBox1.Text = ""; skinTextBox2.Text = ""; skinTextBox3.Text = ""; skinTextBox4.Text = ""; skinTextBox5.Text = ""; skinTextBox6.Text = ""; skinTextBox7.Text = ""; skinTextBox8.Text = ""; skinTextBox9.Text = ""; try { sql = "select dsensor.workid,workname,Ename,Eid,Sid,Sname,Smax,Smin,dsensor.caiji,dsensor.shangchuan from work,dsensor where `work`.workid = dsensor.workid ORDER BY workid asc"; MySqlConnection conn = msc.GetConn(); MySqlDataAdapter sda = new MySqlDataAdapter(sql, conn); //获取数据表 //DataTable table = new DataTable(); DataSet ds = new DataSet(); sda.Fill(ds, "ds"); //填充数据库 this.dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ee) { MessageBox.Show("查询数据库错误:" + ee.ToString()); } } }
private void button16_Click(object sender, EventArgs e) { if (comboBox8.Text.Equals("")) { MessageBox.Show("请输入用户名", "提示"); } else if (textBox14.Text.Equals("")) { MessageBox.Show("请输入密码", "提示"); } else { try { string sql = "update user set PassWord='******' where UserName='******';"; MySqlConn ms = new MySqlConn(); int res = ms.nonSelect(sql); ms.Close(); if (res > 0) { MessageBox.Show("用户初始化成功", "提示"); //让文本框获取焦点,不过注释这行也能达到效果 // richTextBox1.Focus(); //设置光标的位置到文本尾 // richTextBox1.Select(richTextBox1.TextLength, 0); //滚动到控件光标处 //richTextBox1.ScrollToCaret(); //richTextBox1.AppendText(DateTime.Now.ToString("G") + "\r\n" + "用户初始化成功\r\n\r\n"); } else { MessageBox.Show("用户初始化失败", "提示"); } } catch (Exception exc) { //MessageBox.Show("请检查数据库设置", "提示"); new Thread(new ParameterizedThreadStart(showBox)).Start("请检查数据库设置"); } } }
private void shebeishu_Load(object sender, EventArgs e) { TreeNode rootTreeNode = treeView1.Nodes.Add("Root", "XX煤矿"); string sql = "select * from work"; MySqlDataReader rd = msc.getDataFromTable(sql); string[] workid = { }; string[] workname = { }; int i = 0, j = 0; List <string> _list = new List <string>(workid); List <string> _list1 = new List <string>(workname); while (rd.Read()) { _list.Add(rd["workid"].ToString()); _list1.Add(rd["workname"].ToString()); i++; } rd.Close(); msc.Close(); workid = _list.ToArray(); workname = _list1.ToArray(); if (i > 0) { for (j = 0; j < i; j++) { TreeNode mTreeNode = rootTreeNode.Nodes.Add(workname[j]); TreeNode mTreeNode2 = mTreeNode.Nodes.Add("减速机"); sql = "select * from equipment where Etype =2 and workid = " + workid[j] + ""; MySqlDataReader rd1 = msc.getDataFromTable(sql); while (rd1.Read()) { TreeNode mTreeNode3 = mTreeNode2.Nodes.Add(rd1["Eid"].ToString() + "号设备 " + workid[j]); } rd1.Close(); msc.Close(); TreeNode mTreeNode4 = mTreeNode.Nodes.Add("压力计"); sql = "select * from equipment where Etype =1 and workid = " + workid[j] + ""; MySqlDataReader rd2 = msc.getDataFromTable(sql); while (rd2.Read()) { TreeNode mTreeNode3 = mTreeNode4.Nodes.Add(rd2["Eid"].ToString() + "号设备 " + workid[j]); } rd2.Close(); msc.Close(); } } }
private void skinButton3_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("确认删除", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { //点确定的代码 string sql = "DELETE FROM work WHERE workid =" + bz + ""; MySqlConn ms2 = new MySqlConn(); int n = ms2.nonSelect(sql); ms2.Close(); MessageBox.Show(" 删除工作面成功", "提示"); TextBox1.Text = ""; TextBox2.Text = ""; extBox3.Text = ""; extBox4.Text = ""; extBox5.Text = ""; TextBox6.Text = ""; try { string sql2 = "select * from work order by workid asc"; MySqlConnection conn = msc.GetConn(); MySqlDataAdapter sda = new MySqlDataAdapter(sql2, conn); //获取数据表 //DataTable table = new DataTable(); DataSet ds = new DataSet(); sda.Fill(ds, "ds"); //填充数据库 this.dataGridView1.DataSource = ds.Tables[0]; msc.Close(); } catch (Exception ee) { } } }
private void equipment_Load(object sender, EventArgs e) { Thread fac_thread = new Thread(getFactory); fac_thread.Start(); try { string sql = "select equipment.workid,workname,equipment.Eid,equiptype.Ename,equipment.caiji,equipment.shangchuan from work,equipment,equiptype where `work`.workid = equipment.workid and equipment.Etype = equiptype.Etype ORDER BY workid asc"; MySqlConnection conn = msc.GetConn(); MySqlDataAdapter sda = new MySqlDataAdapter(sql, conn); //获取数据表 //DataTable table = new DataTable(); DataSet ds = new DataSet(); sda.Fill(ds, "ds"); //填充数据库 this.dataGridView1.DataSource = ds.Tables[0]; msc.Close(); } catch (Exception ee) { MessageBox.Show("查询数据库错误:" + ee.ToString()); } }
private void button1_Click(object sender, EventArgs e) { if (skinTextBox1.Text == "") { MessageBox.Show("请输入设置的高阈值"); } else if (skinTextBox2.Text == "") { MessageBox.Show("请输入设置的低阈值"); } else { string sql4 = "select workid from work where workname =" + "'" + comboBox3.Text + "'"; string workbzid = ""; MySqlDataReader rd4 = msc.getDataFromTable(sql4); while (rd4.Read()) { workbzid = rd4["workid"].ToString(); } rd4.Close(); msc.Close(); if (comboBox2.Text == "所有" && comboBox4.Text == "所有") { string zuida = skinTextBox1.Text; string zuixiao = skinTextBox2.Text; // //MessageBox.Show("skinTextBox2.Text是" + bz, "提示"); // string sql = "update equipment set caiji = '" + ss + "' where workid = " + workbzid + ""; MySqlConn ms2 = new MySqlConn(); // int n = ms2.nonSelect(sql); // ms2.Close(); // string sql1 = "update dsensor set caiji = '" + ss + "' where workid = " + workbzid + ""; // int m = ms2.nonSelect(sql1); // ms2.Close(); } //else if (comboBox1.Text == "所有" && comboBox4.Text != "所有") //{ // string ss = skinTextBox1.Text + "分" + skinTextBox2.Text + "秒" + skinTextBox3.Text + "毫秒"; // MySqlConn ms2 = new MySqlConn(); // //MessageBox.Show("skinTextBox2.Text是" + bz, "提示"); // string sql = "update equipment set caiji = '" + ss + "' where Eid =" + comboBox4.Text + " AND workid = " + workbzid + ""; // int n = ms2.nonSelect(sql); // ms2.Close(); // string sql1 = "update dsensor set caiji = '" + ss + "' where Eid =" + comboBox4.Text + " AND workid = " + workbzid + ""; // int m = ms2.nonSelect(sql1); // ms2.Close(); //} //else if (comboBox1.Text != "所有" && comboBox4.Text != "所有") //{ // string ss = skinTextBox1.Text + "分" + skinTextBox2.Text + "秒" + skinTextBox3.Text + "毫秒"; // //MessageBox.Show("skinTextBox2.Text是" + bz, "提示"); // MySqlConn ms2 = new MySqlConn(); // string sql1 = "update dsensor set caiji = '" + ss + "' where Eid =" + comboBox4.Text + " AND Sid =" + comboBox1.Text + " AND workid = " + workbzid + ""; // int m = ms2.nonSelect(sql1); // ms2.Close(); //} string bz2 = Ten2Hex(workbzid); if (bz2.Length == 2) { data = Ten2Hex(workbzid); } else { data = "0" + Ten2Hex(workbzid); } data = data + " 11 00 09"; //设备类型 if (comboBox2.Text.Equals("所有")) { data = data + " " + "FF"; } else if (comboBox2.Text.Equals("压力计")) { data = data + " " + "01"; } else if (comboBox2.Text.Equals("减速机")) { data = data + " " + "02"; } else if (comboBox2.Text.Equals("中继")) { data = " " + "03"; } //设备编号 if (comboBox4.Text.Equals("所有")) { data = data + " FF"; } else { string bz = Ten2Hex(comboBox4.Text); if (bz.Length == 2) { data = data + " " + Ten2Hex(comboBox4.Text); } else { data = data + " 0" + Ten2Hex(comboBox4.Text); } } //传感器编号 if (comboBox1.Text.Equals("所有")) { data = data + " FF"; } else { string bz1 = Ten2Hex(comboBox1.Text); if (bz1.Length == 2) { data = data + " " + Ten2Hex(comboBox1.Text); } else { data = data + " 0" + Ten2Hex(comboBox1.Text); } } int gYvalue = 0; int dYvalue = 0; //MessageBox.Show("高阈值前:" + skinTextBox1.Text); if (int.Parse(skinTextBox1.Text) < 0) { data += " 00"; gYvalue = Math.Abs(int.Parse(skinTextBox1.Text)); } else { data += " 80"; gYvalue = int.Parse(skinTextBox1.Text); } string bz3 = Ten2Hex(gYvalue.ToString()); if (bz3.Length == 1) { data = data + " 00 0" + bz3; } else if (bz3.Length == 2) { data = data + " 00 " + bz3; } else if (bz3.Length == 3) { data = data + " 0" + bz3[0] + " " + bz3.Substring(1, 2); } if (int.Parse(skinTextBox2.Text) < 0) { data += " 00"; dYvalue = Math.Abs(int.Parse(skinTextBox2.Text)); } else { data += " 80"; dYvalue = int.Parse(skinTextBox2.Text); } string bz4 = Ten2Hex(dYvalue.ToString()); if (bz4.Length == 1) { data = data + " 00 0" + bz4; } else if (bz4.Length == 2) { data = data + " 00 " + bz4; } else if (bz4.Length == 3) { data = data + " 0" + bz4[0] + " " + bz4.Substring(1, 2); } Log("设置阈值:" + data); this.addOne.Invoke(data.ToString()); MessageBox.Show("设置成功"); } }
private void skinButton1_Click(object sender, EventArgs e) { if (skinTextBox1.Text.Equals("")) { //MessageBox.Show("请输入原密码", "提示"); new Thread(new ParameterizedThreadStart(ShowBox)).Start("请输入新ip"); } else if (skinTextBox2.Text.Equals("")) { //MessageBox.Show("请输入原密码", "提示"); new Thread(new ParameterizedThreadStart(ShowBox)).Start("请输入新端口"); } else { try { //MessageBox.Show("====33333=" + old_passwd); string sql = ""; if (Label2.Text != "") { sql = "update ip set ip='" + skinTextBox1.Text + "',duankou='" + skinTextBox2.Text + "' where workid = " + comboBox1.Text + ""; } else { sql = "insert into ip (workid,ip,duankou) values(" + comboBox1.Text + ", '" + skinTextBox1.Text + "', " + skinTextBox2.Text + ")"; } //string sql = "update user set PassWord='******' where UserName ='******';"; MySqlConn ms1 = new MySqlConn(); int res = ms1.nonSelect(sql); ms1.Close(); Label2.Text = ""; try { string sql2 = "select * from ip where workid =" + "" + comboBox1.Text + ""; MySqlDataReader rd2 = msc.getDataFromTable(sql2); while (rd2.Read()) { string bbb = ""; string ccc = ""; bbb = rd2["ip"].ToString(); if (bbb == "") { Label2.Text = ""; } else { Label2.Text = bbb; } ccc = rd2["duankou"].ToString(); if (ccc == "") { Label3.Text = ""; } else { Label3.Text = ccc; } } rd2.Close(); msc.Close(); try//传ip的操作 { string bz2 = Ten2Hex(comboBox1.Text); if (bz2.Length == 2) { sendip = bz2; } else { sendip = "0" + bz2; } sendip = sendip + " 05 00 0C"; sql = "select * from ip where workid =" + "" + comboBox1.Text + ""; string localip = GetLocalIP(); string ip = ""; string duankou = ""; MySqlDataReader rd = msc.getDataFromTable(sql); while (rd.Read()) { ip = rd["ip"].ToString(); duankou = rd["duankou"].ToString(); } rd.Close(); int i = 0, j = 0, geshu = 0; while (!ip[i].Equals('.')) { i++; geshu++; } string bz1 = Ten2Hex(ip.Substring(j, geshu)); if (bz1.Length == 2) { sendip1[0] = bz1; } else { sendip1[0] = "0" + bz1; } geshu = 0; i++; j = i; while (!ip[i].Equals('.')) { i++; geshu++; } bz1 = Ten2Hex(ip.Substring(j, geshu)); if (bz1.Length == 2) { sendip1[1] = bz1; } else { sendip1[1] = "0" + bz1; } geshu = 0; i++; j = i; while (!ip[i].Equals('.')) { i++; geshu++; } bz1 = Ten2Hex(ip.Substring(j, geshu)); if (bz1.Length == 2) { sendip1[2] = bz1; } else { sendip1[2] = "0" + bz1; } i++; j = i; geshu = ip.Length - i; bz1 = Ten2Hex(ip.Substring(j, geshu)); if (bz1.Length == 2) { sendip1[3] = bz1; } else { sendip1[3] = "0" + bz1; } while (duankou.Length < 4) { duankou = "0" + duankou; } string tt2 = Ten2Hex(duankou.Substring(0, 4)); sendip1[4] = tt2[0] + "" + tt2[1]; sendip1[5] = tt2[2] + "" + tt2[3]; //bz1 = Ten2Hex(duankou.Substring(0, 2)); //if (bz1.Length == 2) //{ // sendip1[4] = bz1; //} //else //{ // sendip1[4] = "0" + bz1; //} //bz1 = Ten2Hex(duankou.Substring(2, 2)); //if (bz1.Length == 2) //{ // sendip1[5] = bz1; //} //else //{ // sendip1[5] = "0" + bz1; //} i = 0; j = 0; geshu = 0; while (!localip[i].Equals('.')) { i++; geshu++; } bz1 = Ten2Hex(localip.Substring(j, geshu)); if (bz1.Length == 2) { sendip1[6] = bz1; } else { sendip1[6] = "0" + bz1; } geshu = 0; i++; j = i; while (!localip[i].Equals('.')) { i++; geshu++; } bz1 = Ten2Hex(localip.Substring(j, geshu)); if (bz1.Length == 2) { sendip1[7] = bz1; } else { sendip1[7] = "0" + bz1; } geshu = 0; i++; j = i; while (!localip[i].Equals('.')) { i++; geshu++; } bz1 = Ten2Hex(localip.Substring(j, geshu)); if (bz1.Length == 2) { sendip1[8] = bz1; } else { sendip1[8] = "0" + bz1; } i++; j = i; geshu = localip.Length - i; bz1 = Ten2Hex(localip.Substring(j, geshu)); if (bz1.Length == 2) { sendip1[9] = bz1; } else { sendip1[9] = "0" + bz1; } string duankou1 = "8001"; string temp = Ten2Hex(duankou1.Substring(0, 4)); sendip1[10] = temp[0] + "" + temp[1]; sendip1[11] = temp[2] + "" + temp[3]; for (i = 0; i < 12; i++) { sendip = sendip + " " + sendip1[i]; } } catch (SqlException se1) { } } catch (SqlException se) { } if (res > 0) { MessageBox.Show("修改成功", "提示"); counter = "abcd"; //【4】调用 this.addOne.Invoke(sendip.ToString()); } else { MessageBox.Show("修改失败", "提示"); } } catch (Exception exc) { //MessageBox.Show("请检查数据库连接设置", "提示"); } } }
private void button1_Click(object sender, EventArgs e) { shebei = " 01"; int length = 12;//数据初始长度 string ss = ""; string bz = ""; int elength = 0; string sss = ""; int o; string sql1 = "SELECT count(*) FROM equipment where workid =" + comboBox1.Text + ""; MySqlDataReader rd2 = msc.getDataFromTable(sql1); while (rd2.Read()) { ss = rd2["count(*)"].ToString(); } rd2.Close(); msc.Close(); try { bz = Ten2Hex(ss); o = 0; if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } elength = int.Parse(ss); string qqq = bz; length = length + elength * 9; sss = ""; string sql2 = "SELECT * FROM equipment where workid =" + comboBox1.Text + ""; MySqlDataReader rd = msc1.getDataFromTable(sql2); string temp1; while (rd.Read()) { ss = rd["Etype"].ToString(); shebei = shebei + " 0" + ss; sss = rd["Eid"].ToString(); bz = Ten2Hex(sss); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } string ss1 = shuju(comboBox1.Text, sss, ss); bz = Ten2Hex(ss1); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } ss = rd["caiji"].ToString(); if (ss == "") { shebei = shebei + " 00 00 00"; } else { string s = ""; int i = 0; while (ss[i] != '分') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } s = ""; i++; while (ss[i] != '秒') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } s = ""; i++; while (ss[i] != '毫') { s = s + ss[i]; i++; } int a1 = int.Parse(s); a1 = a1 / 100; s = a1.ToString(); bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } ss = rd["shangchuan"].ToString(); if (ss == "") { shebei = shebei + " 00 00 00"; } else { s = ""; i = 0; while (ss[i] != '分') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } s = ""; i++; while (ss[i] != '秒') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } s = ""; i++; while (ss[i] != '毫') { s = s + ss[i]; i++; } a1 = int.Parse(s); a1 = a1 / 100; s = a1.ToString(); bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } } } } rd.Close(); msc1.Close(); shebei = shebei + " 02"; sql1 = "SELECT count(*) FROM dsensor where workid =" + comboBox1.Text + ""; MySqlDataReader rd5 = msc.getDataFromTable(sql1); while (rd5.Read()) { ss = rd5["count(*)"].ToString(); } rd5.Close(); msc.Close(); bz = Ten2Hex(ss); o = 0; if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } //length = length + 2; elength = int.Parse(ss); length = length + elength * 16; sss = ""; sql2 = "SELECT equiptype.Etype,Eid,type.bzid,Sid,Smax,Smin,caiji,shangchuan FROM equiptype,dsensor,type where equiptype.Ename=dsensor.Ename and type.type= dsensor.Sname and workid = " + comboBox1.Text + " ORDER BY Eid asc"; MySqlDataReader rd6 = msc1.getDataFromTable(sql2); while (rd6.Read()) { ss = rd6["Etype"].ToString(); shebei = shebei + " 0" + ss; sss = rd6["Eid"].ToString(); bz = Ten2Hex(sss); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } ss = rd6["bzid"].ToString(); shebei = shebei + " 0" + ss; sss = rd6["Sid"].ToString(); bz = Ten2Hex(sss); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } sss = rd6["Smax"].ToString(); if (sss[0] == '-') { shebei = shebei + " 00"; } else { shebei = shebei + " 08"; } bz = Ten2Hex(sss); if (bz.Length == 4) { shebei = shebei + " " + bz[0] + bz[1] + " " + bz[2] + bz[3]; } else if (bz.Length == 3) { shebei = shebei + " 0" + bz[0] + " " + bz[1] + bz[2]; } else if (bz.Length == 2) { shebei = shebei + " 00 " + bz; } else if (bz.Length == 1) { shebei = shebei + " 00 0" + bz; } sss = rd6["Smin"].ToString(); if (sss[0] == '-') { shebei = shebei + " 00"; } else { shebei = shebei + " 08"; } bz = Ten2Hex(sss); if (bz.Length == 4) { shebei = shebei + " " + bz[0] + bz[1] + " " + bz[2] + bz[3]; } else if (bz.Length == 3) { shebei = shebei + " 0" + bz[0] + " " + bz[1] + bz[2]; } else if (bz.Length == 2) { shebei = shebei + " 00 " + bz; } else if (bz.Length == 1) { shebei = shebei + " 00 0" + bz; } ss = rd6["caiji"].ToString(); if (ss == "") { shebei = shebei + " 00 00 00"; } else { string s = ""; int i = 0; while (ss[i] != '分') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } s = ""; i++; while (ss[i] != '秒') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } s = ""; i++; while (ss[i] != '毫') { s = s + ss[i]; i++; } int a1 = int.Parse(s); a1 = a1 / 100; s = a1.ToString(); bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } ss = rd6["shangchuan"].ToString(); if (ss == "") { shebei = shebei + " 00 00 00"; } else { //Log1("ss " + ss+" "+ss[1]); s = ""; i = 0; while (ss[i] != '分') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } s = ""; i++; while (ss[i] != '秒') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } s = ""; i++; while (ss[i] != '毫') { s = s + ss[i]; i++; } a1 = int.Parse(s); a1 = a1 / 100; s = a1.ToString(); bz = Ten2Hex(s); if (bz.Length == 2) { shebei = shebei + " " + bz; } else { shebei = shebei + " 0" + bz; } } } //Log1("shebei " + shebei); } rd6.Close(); msc1.Close(); if (Ten2Hex(comboBox1.Text).Length == 1) { data = "0" + Ten2Hex(comboBox1.Text); } else { data = Ten2Hex(comboBox1.Text); } data = data + " 0F "; string qq = Ten2Hex(length.ToString()); if (qq.Length == 4) { data = data + qq[0] + qq[1] + " " + qq[3] + qq[4]; } if (qq.Length == 3) { data = data + "0" + qq[0] + " " + qq[1] + qq[2]; } if (qq.Length == 2) { data = data + "00" + " " + qq[0] + qq[1]; } if (qq.Length == 1) { data = data + "00 0" + qq[0]; } data = data + " " + "00"; sql2 = "SELECT * FROM `work` where workid = " + comboBox1.Text + " "; MySqlDataReader rd7 = msc1.getDataFromTable(sql2); while (rd7.Read()) { ss = rd7["caiji"].ToString(); if (ss == "") { data = data + " 00 00 00"; } else { string s = ""; int i = 0; while (ss[i] != '分') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { data = data + " " + bz; } else { data = data + " 0" + bz; } s = ""; i++; while (ss[i] != '秒') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { data = data + " " + bz; } else { data = data + " 0" + bz; } s = ""; i++; while (ss[i] != '毫') { s = s + ss[i]; i++; } int a1 = int.Parse(s); a1 = a1 / 100; s = a1.ToString(); bz = Ten2Hex(s); if (bz.Length == 2) { data = data + " " + bz; } else { data = data + " 0" + bz; } } ss = rd7["shangchuan"].ToString(); if (ss == "") { data = data + " 00 00 00"; } else { string s = ""; string temp = ""; int i = 0; while (ss[i] != '分') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { data = data + " " + bz; temp = temp + " 0" + bz; } else { data = data + " 0" + bz; temp = temp + " 0" + bz; } s = ""; i++; while (ss[i] != '秒') { s = s + ss[i]; i++; } bz = Ten2Hex(s); if (bz.Length == 2) { data = data + " " + bz; temp = temp + " 0" + bz; } else { data = data + " 0" + bz; temp = temp + " 0" + bz; } s = ""; i++; while (ss[i] != '毫') { s = s + ss[i]; i++; } int a1 = int.Parse(s); a1 = a1 / 100; s = a1.ToString(); bz = Ten2Hex(s); if (bz.Length == 2) { data = data + " " + bz; temp = temp + bz; } else { data = data + " 0" + bz; temp = temp + bz; } } } rd6.Close(); msc1.Close(); if (qqq.Length == 1) { qqq = "0" + qqq; } //else if (qqq.Length == 2) //{ // qqq = "00 " + qqq; //} //else if (qqq.Length == 3) //{ // qqq = "0"+qqq[0]+" "+qqq[1]+qqq[2]; //} //else if (qqq.Length == 3) //{ // qqq = qqq[0]+qqq[1] + " " + qqq[2] + qqq[3]; //} data = data + " " + qqq + shebei; Log1("data " + data); MessageBox.Show("发送成功"); this.addOne.Invoke(data.ToString()); } catch (Exception eee) { Log1("错误" + eee); } }
private void button2_Click(object sender, EventArgs e) { if (skinTextBox1.Text.Equals("")) { MessageBox.Show("请输入传感器编号", "提示"); } else if (comboBox3.Text.Equals("")) { MessageBox.Show("请选择传感器的类型", "提示"); } else if (skinTextBox2.Text.Equals("")) { MessageBox.Show("请输入高阈值", "提示"); } else if (skinTextBox3.Text.Equals("")) { MessageBox.Show("请输入低阈值", "提示"); } else { if (comboBox1.Text != bz) { MessageBox.Show("请勿修改工作面", "提示"); } else if (comboBox4.Text != bz1) { MessageBox.Show("请勿修改设备", "提示"); } else { int p1 = 1; //int A= int.Parse(skinTextBox1.Text); //MessageBox.Show(""+skinTextBox1.Text, "提示"); string sql11 = "SELECT Sid FROM dsensor WHERE workid = " + comboBox1.Text + " and Eid = " + comboBox4.Text + " "; MySqlConn ms = new MySqlConn(); MySqlDataReader rd = ms.getDataFromTable(sql11); while (rd.Read()) { t1 = rd["Sid"].ToString(); //MessageBox.Show("t1是" +t1, "提示"); if (skinTextBox1.Text.Equals(t1) && skinTextBox1.Text != bz2) { p1 = 0; break; } } rd.Close(); ms.Close(); int t2; if (p1 != 0) { try { if (skinTextBox4.Text == "") { skinTextBox4.Text = "0"; } if (skinTextBox5.Text == "") { skinTextBox5.Text = "0"; } if (skinTextBox6.Text == "") { skinTextBox6.Text = "0"; } if (skinTextBox7.Text == "") { skinTextBox7.Text = "0"; } if (skinTextBox8.Text == "") { skinTextBox8.Text = "0"; } if (skinTextBox9.Text == "") { skinTextBox9.Text = "0"; } string ss = skinTextBox4.Text + "分" + skinTextBox5.Text + "秒" + skinTextBox6.Text + "毫秒"; string sss = skinTextBox7.Text + "分" + skinTextBox8.Text + "秒" + skinTextBox9.Text + "毫秒"; string sql = "update dsensor set Sid = " + skinTextBox1.Text + ",Sname = '" + comboBox3.Text + "',Smax=" + skinTextBox2.Text + ",Smin=" + skinTextBox3.Text + ",caiji = '" + ss + "',shangchuan = '" + sss + "' where Eid =" + bz1 + " AND workid = " + bz + " and Sid = " + bz2 + ""; MySqlConn ms2 = new MySqlConn(); int n = ms2.nonSelect(sql); ms2.Close(); MessageBox.Show("修改成功", "提示"); skinTextBox1.Text = ""; skinTextBox2.Text = ""; sql = "select dsensor.workid,workname,Ename,Eid,Sid,Sname,Smax,Smin,dsensor.caiji,dsensor.shangchuan from work,dsensor where `work`.workid = dsensor.workid ORDER BY workid asc"; MySqlConnection conn = msc.GetConn(); MySqlDataAdapter sda = new MySqlDataAdapter(sql, conn); //获取数据表 //DataTable table = new DataTable(); DataSet ds = new DataSet(); sda.Fill(ds, "ds"); //填充数据库 this.dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ee) { MessageBox.Show("查询数据库错误:" + ee.ToString()); } } else { MessageBox.Show("已存在该传感器编号", "提示"); } } } }
public void loadReport() { DataTable dt = new DataTable(); //定义本地数据表的列,名称应跟之前所建的testDataTable表中列相同。 dt.Columns.Add("Eid", typeof(string)); dt.Columns.Add("gmax", typeof(string)); dt.Columns.Add("gmin", typeof(string)); dt.Columns.Add("chu", typeof(string)); dt.Columns.Add("momax", typeof(string)); dt.Columns.Add("momin", typeof(string)); dt.Columns.Add("time", typeof(string)); dt.Columns.Add("workid", typeof(string)); string sql = "select count(Eid) from equipment where Etype=1 and workid = " + workid + ""; MySqlDataReader rd = msc.getDataFromTable(sql); string cout = ""; int i = 0, j = 0; string[] eid = { }; while (rd.Read()) { cout = rd["count(Eid)"].ToString(); } rd.Close(); msc.Close(); j = int.Parse(cout); string a = ""; string sql1 = "select Eid from equipment where Etype=1 and workid = " + workid + ""; MySqlDataReader rd1 = msc.getDataFromTable(sql1); List <string> _list = new List <string>(eid); while (rd1.Read()) { _list.Add(rd1["Eid"].ToString()); } rd1.Close(); msc.Close(); eid = _list.ToArray(); //for(i=0;i<3;i++) //{ // MessageBox.Show("shebei" + eid[i]); //} //动态生成一些测试用数据 for (i = 0; i < j; i++) { DataRow row = dt.NewRow(); row[0] = eid[i]; int[] shuju = { }; sql = "select * from sensordata where workid = " + workid + " and Eid = " + eid[i] + " and time between '" + time + "' and '" + end + "' order by time asc"; //MessageBox.Show("sql" + sql); MySqlDataReader rd2 = msc.getDataFromTable(sql); List <int> list3 = new List <int>(shuju); int sum = 0; while (rd2.Read()) { try { list3.Add(int.Parse(rd2["value"].ToString())); sum++; } catch { } } rd2.Close(); msc.Close(); shuju = list3.ToArray(); if (sum > 5) { int[] chucheng = { }; int[] mozu = { }; List <int> list1 = new List <int>(chucheng); List <int> list2 = new List <int>(mozu); int c1 = 0; int m1 = 0; for (int b = 1; b < sum - 1; b++) { if ((shuju[b] - shuju[b - 1] > 2) && ((shuju[b + 1] - shuju[b]) < 2) && ((shuju[b + 1] - shuju[b - 1]) > 2) && (shuju[b] > 18)) { list1.Add(b); //MessageBox.Show("chu" + b); c1++; } else if ((shuju[b] - shuju[b - 1] > -2) && (shuju[b + 1] - shuju[b] < -2) && (shuju[b + 1] - shuju[b - 1] < -2) && (shuju[b] > 18)) { list2.Add(b); //MessageBox.Show("mo" + b); m1++; } } chucheng = list1.ToArray(); mozu = list2.ToArray(); //MessageBox.Show(c1+"="+m1); //MessageBox.Show(chucheng[1].ToString()); if (chucheng[0] < mozu[0]) { double max = shuju[chucheng[0]]; int q = 0; double y = 0; if (c1 > m1) { c1 = c1 - 1; } for (int ac = 0; ac < c1; ac++) { int ab = chucheng[ac] + 1; while (ab < mozu[ac]) { y = y + shuju[ab]; q++; if (shuju[ab] > max) { max = shuju[ab]; } ab++; } } row[1] = (max).ToString(); row[2] = (y / q * 1.00).ToString(); double y1 = 0; for (int i1 = 0; i1 < c1; i1++) { y1 = y1 + shuju[chucheng[i1]]; } row[3] = (y1 / c1).ToString(); double y2 = 0; double max1 = shuju[mozu[0]]; for (int i2 = 0; i2 < m1; i2++) { y2 = y2 + shuju[mozu[i2]]; if (shuju[mozu[i2]] > max1) { max1 = shuju[mozu[i2]]; } } row[4] = (max1).ToString(); row[5] = (y2 / m1).ToString(); } } else { row[1] = (0).ToString(); row[2] = (0).ToString(); row[3] = (0).ToString(); row[4] = (0).ToString(); row[5] = (0).ToString(); } string[] ids1 = time.Split(' '); string abc = ids1[0]; row[6] = abc; row[7] = workid + "号工作面"; dt.Rows.Add(row); } //设置本地报表,使程序与之前所建的testReport.rdlc报表文件进行绑定。 this.reportViewer1.LocalReport.ReportPath = "testReport.rdlc"; this.reportViewer1.LocalReport.DataSources.Clear(); this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetName", dt)); }
private void button1_Click(object sender, EventArgs e) { if (textBox8.Text.Equals("")) { MessageBox.Show("请输入用户名", "提示"); } else if (textBox9.Text.Equals("")) { MessageBox.Show("请输入密码", "提示"); } else if (textBox10.Text.Equals("")) { MessageBox.Show("请确认密码", "提示"); } else if (textBox10.Text.Equals(textBox9.Text) != true) { MessageBox.Show("两次输入的密码不一致", "提示"); } else { try { string sql = "select * from user"; //DataBase db = new DataBase(); //db.command.CommandText = sql; //db.command.Connection = db.connection; //db.Dr = db.command.ExecuteReader(); MySqlConn ms = new MySqlConn(); MySqlDataReader rd = ms.getDataFromTable(sql); bool isExit = false; while (rd.Read()) { //richTextBox1.AppendText(db.Dr["UserName"].ToString() + " " + textBox8.Text + "\r\n"); if (rd["UserName"].ToString().Equals(textBox8.Text.Trim())) { isExit = true; break; } } rd.Close(); ms.Close(); if (isExit) { MessageBox.Show("用户已存在", "提示"); } else { sql = "insert into user values('" + textBox8.Text.Trim() + "','" + textBox9.Text + "',0);"; MySqlConn ms2 = new MySqlConn(); int res = ms2.nonSelect(sql); ms2.Close(); if (res > 0) { MessageBox.Show("添加成功", "提示"); //让文本框获取焦点,不过注释这行也能达到效果 //richTextBox1.Focus(); //设置光标的位置到文本尾 //richTextBox1.Select(richTextBox1.TextLength, 0); //滚动到控件光标处 //richTextBox1.ScrollToCaret(); //richTextBox1.AppendText(DateTime.Now.ToString("G") + "\r\n" + "添加用户成功\r\n\r\n"); } else { MessageBox.Show("添加失败", "提示"); } } } catch (Exception exc) { //MessageBox.Show("请检查数据库是否创建好", "提示"); new Thread(new ParameterizedThreadStart(showBox)).Start("请检查数据库是否创建好"); } } }
private void button1_Click(object sender, EventArgs e) { int a1 = int.Parse(skinTextBox3.Text); if (skinTextBox1.Text == "") { MessageBox.Show("请输入设置的分"); } else if (skinTextBox2.Text == "") { MessageBox.Show("请输入设置的秒"); } else if (skinTextBox3.Text == "") { MessageBox.Show("请输入设置的毫秒"); } else if (a1 % 100 != 0) { MessageBox.Show("请将毫秒设置为100的整数倍"); } else { string sql4 = "select workid from work where workname =" + "'" + comboBox3.Text + "'"; string workbzid = ""; MySqlDataReader rd4 = msc.getDataFromTable(sql4); while (rd4.Read()) { workbzid = rd4["workid"].ToString(); } rd4.Close(); msc.Close(); if (comboBox2.Text == "所有" && comboBox4.Text == "所有") { string ss = skinTextBox1.Text + "分" + skinTextBox2.Text + "秒" + skinTextBox3.Text + "毫秒"; //MessageBox.Show("skinTextBox2.Text是" + bz, "提示"); string sql = "update equipment set caiji = '" + ss + "' where workid = " + workbzid + ""; MySqlConn ms2 = new MySqlConn(); int n = ms2.nonSelect(sql); ms2.Close(); string sql1 = "update dsensor set caiji = '" + ss + "' where workid = " + workbzid + ""; int m = ms2.nonSelect(sql1); ms2.Close(); } else if (comboBox1.Text == "所有" && comboBox4.Text != "所有") { string ss = skinTextBox1.Text + "分" + skinTextBox2.Text + "秒" + skinTextBox3.Text + "毫秒"; MySqlConn ms2 = new MySqlConn(); //MessageBox.Show("skinTextBox2.Text是" + bz, "提示"); string sql = "update equipment set caiji = '" + ss + "' where Eid =" + comboBox4.Text + " AND workid = " + workbzid + ""; int n = ms2.nonSelect(sql); ms2.Close(); string sql1 = "update dsensor set caiji = '" + ss + "' where Eid =" + comboBox4.Text + " AND workid = " + workbzid + ""; int m = ms2.nonSelect(sql1); ms2.Close(); } else if (comboBox1.Text != "所有" && comboBox4.Text != "所有") { string ss = skinTextBox1.Text + "分" + skinTextBox2.Text + "秒" + skinTextBox3.Text + "毫秒"; //MessageBox.Show("skinTextBox2.Text是" + bz, "提示"); MySqlConn ms2 = new MySqlConn(); string sql1 = "update dsensor set caiji = '" + ss + "' where Eid =" + comboBox4.Text + " AND Sid =" + comboBox1.Text + " AND workid = " + workbzid + ""; int m = ms2.nonSelect(sql1); ms2.Close(); } string bz2 = Ten2Hex(workbzid); if (bz2.Length == 2) { data = Ten2Hex(workbzid); } else { data = "0" + Ten2Hex(workbzid); } data = data + " 09 00 06"; if (comboBox2.Text.Equals("所有")) { data = data + " " + "FF"; } else if (comboBox2.Text.Equals("压力计")) { data = data + " " + "01"; } else if (comboBox2.Text.Equals("减速机")) { data = data + " " + "02"; } else if (comboBox2.Text.Equals("中继")) { data = " " + "03"; } if (comboBox4.Text.Equals("所有")) { data = data + " FF"; } else { string bz = Ten2Hex(comboBox4.Text); if (bz.Length == 2) { data = data + " " + Ten2Hex(comboBox4.Text); } else { data = data + " 0" + Ten2Hex(comboBox4.Text); } } if (comboBox1.Text.Equals("所有")) { data = data + " FF"; } else { string bz1 = Ten2Hex(comboBox1.Text); if (bz1.Length == 2) { data = data + " " + Ten2Hex(comboBox1.Text); } else { data = data + " 0" + Ten2Hex(comboBox1.Text); } } string bz3 = Ten2Hex(skinTextBox1.Text); if (bz3.Length == 2) { data = data + " " + Ten2Hex(skinTextBox1.Text); } else if (bz3.Length == 1) { data = data + " 0" + Ten2Hex(skinTextBox1.Text); } else { MessageBox.Show("请检查分的格式"); } string bz4 = Ten2Hex(skinTextBox2.Text); if (bz4.Length == 2) { data = data + " " + Ten2Hex(skinTextBox2.Text); } else if (bz4.Length == 1) { data = data + " 0" + Ten2Hex(skinTextBox2.Text); } else { MessageBox.Show("请检查秒的格式"); } a1 = int.Parse(skinTextBox3.Text); a1 = a1 / 100; string s = a1.ToString(); //MessageBox.Show("s " + s); string bz5 = Ten2Hex(s); if (bz5.Length == 2) { data = data + " " + Ten2Hex(s); } else if (bz5.Length == 1) { data = data + " 0" + Ten2Hex(s); } else { MessageBox.Show("请检查毫秒的格式"); } //Log("data " + data); this.addOne.Invoke(data.ToString()); MessageBox.Show("设置成功"); } }
private void button14_Click(object sender, EventArgs e) { if (comboBox7.Text.Equals("")) { MessageBox.Show("请输入用户名", "提示"); } else if (textBox12.Text.Equals("")) { MessageBox.Show("请输入管理员密码", "提示"); } else { MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("确认要删除用户 " + comboBox7.Text + " 吗?", "提示", messButton); if (dr == DialogResult.OK) { try { string sql1 = "select * from user where UserName = '******';"; MySqlConn ms = new MySqlConn(); MySqlDataReader rd = ms.getDataFromTable(sql1); string str = ""; while (rd.Read()) { str = rd["PassWord"].ToString(); } rd.Close(); ms.Close(); if (str.Equals(textBox12.Text)) { MySqlConn ms1 = new MySqlConn(); string sql = "delete from user where UserName='******';"; int res = ms1.nonSelect(sql); //MessageBox.Show("====33333=" + res); ms1.Close(); if (res > 0) { MessageBox.Show("删除成功", "提示"); //让文本框获取焦点,不过注释这行也能达到效果 //richTextBox1.Focus(); //设置光标的位置到文本尾 //richTextBox1.Select(richTextBox1.TextLength, 0); //滚动到控件光标处 //richTextBox1.ScrollToCaret(); //richTextBox1.AppendText(DateTime.Now.ToString("G") + "\r\n" + "删除用户成功\r\n\r\n"); } else { MessageBox.Show("用户不存在", "提示"); } } else { MessageBox.Show("管理员密码错误", "提示"); } } catch (Exception exc) { //MessageBox.Show("请检查数据库是否创建好", "提示"); new Thread(new ParameterizedThreadStart(showBox)).Start("请检查数据库是否创建好"); } } } }
/// <summary> /// 加载定时信息。。一开始加载窗体的时候就将所有的定时操作加载出来 /// </summary> /// <param name="obj"></param> private void button10_Click_1(object sender, EventArgs e) { if (textBox1.Text.Equals("")) { //MessageBox.Show("请输入原密码", "提示"); new Thread(new ParameterizedThreadStart(ShowBox)).Start("请输入原密码"); } else if (textBox6.Text.Equals("")) { MessageBox.Show("请输入新密码", "提示"); } else if (textBox7.Text.Equals("")) { MessageBox.Show("请输入确认密码", "提示"); } else { if (textBox6.Text.Equals(textBox7.Text) == false) { MessageBox.Show("两次输入的密码不一致", "提示"); } else { try { //MessageBox.Show("====33333=" + old_passwd); //string sql_find = "select * from user where UserName = '******'"; string sql_find = "select * from user where UserName = '******'"; MySqlConn ms = new MySqlConn(); MySqlDataReader rd = ms.getDataFromTable(sql_find); string old_passwd = ""; while (rd.Read()) { old_passwd = rd["PassWord"].ToString(); break; } rd.Close(); ms.Close(); if (old_passwd.Equals(textBox1.Text)) { //string sql = "update user set PassWord='******' where UserName ='******';"; string sql = "update user set PassWord='******' where UserName ='******';"; MySqlConn ms1 = new MySqlConn(); int res = ms1.nonSelect(sql); ms1.Close(); if (res > 0) { MessageBox.Show("修改密码成功", "提示"); } else { MessageBox.Show("修改密码失败", "提示"); } } else { MessageBox.Show("原密码输入错误", "提示"); } } catch (Exception exc) { //MessageBox.Show("请检查数据库连接设置", "提示"); new Thread(new ParameterizedThreadStart(ShowBox)).Start("请检查数据库设置"); } } } }
private void skinButton1_Click(object sender, EventArgs e) { if (TextBox1.Text.Equals("")) { MessageBox.Show("请输入工作面的名称", "提示"); } else if (TextBox2.Text.Equals("")) { MessageBox.Show("请输入支架型式", "提示"); } else if (extBox3.Text.Equals("")) { MessageBox.Show("请输入缸径", "提示"); } else if (extBox4.Text.Equals("")) { MessageBox.Show("请输入压力上限", "提示"); } else if (extBox5.Text.Equals("")) { MessageBox.Show("请输入压力下限", "提示"); } else if (TextBox6.Text.Equals("")) { MessageBox.Show("请输入工作面编号", "提示"); } else { string sql11 = "SELECT max(workid) from work"; MySqlConn ms = new MySqlConn(); MySqlDataReader rd = ms.getDataFromTable(sql11); while (rd.Read()) { t1 = rd["max(workid)"].ToString(); } rd.Close(); ms.Close(); //int A = int.Parse(skinTextBox6.Text); //int B = int.Parse(t1); int p1 = 1; //int A= int.Parse(skinTextBox1.Text); //MessageBox.Show(""+skinTextBox1.Text, "提示"); string sql12 = "SELECT workid FROM work"; MySqlConn ms1 = new MySqlConn(); MySqlDataReader rd1 = ms1.getDataFromTable(sql12); while (rd1.Read()) { t1 = rd1["workid"].ToString(); //MessageBox.Show("t1是" +t1, "提示"); if (TextBox6.Text.Equals(t1)) { p1 = 0; break; } } rd1.Close(); ms1.Close(); if (p1 == 1) { if (skinTextBox4.Text == "") { skinTextBox4.Text = "0"; } if (skinTextBox5.Text == "") { skinTextBox5.Text = "0"; } if (skinTextBox6.Text == "") { skinTextBox6.Text = "0"; } if (skinTextBox7.Text == "") { skinTextBox7.Text = "0"; } if (skinTextBox8.Text == "") { skinTextBox8.Text = "0"; } if (skinTextBox9.Text == "") { skinTextBox9.Text = "0"; } string ss = skinTextBox4.Text + "分" + skinTextBox5.Text + "秒" + skinTextBox6.Text + "毫秒"; string sss = skinTextBox7.Text + "分" + skinTextBox8.Text + "秒" + skinTextBox9.Text + "毫秒"; string sql = "insert into work values(" + TextBox6.Text + ", '" + TextBox1.Text + "',' " + TextBox2.Text + "', " + extBox3.Text + ", " + extBox4.Text + ", " + extBox5.Text + ", '" + ss + "', '" + sss + "')"; MySqlConn ms2 = new MySqlConn(); int n = ms2.nonSelect(sql); ms2.Close(); MessageBox.Show("添加工作面成功", "提示"); TextBox1.Text = ""; TextBox2.Text = ""; extBox3.Text = ""; extBox4.Text = ""; extBox5.Text = ""; TextBox6.Text = ""; //if (dataGridView1.DataSource != null) //{ // DataTable dt = (DataTable)dataGridView1.DataSource; // dt.Rows.Clear(); // dataGridView1.DataSource = dt; //} //else //{ // dataGridView1.Rows.Clear(); //} try { string sql1 = "select * from work order by workid asc"; MySqlConnection conn = msc.GetConn(); MySqlDataAdapter sda = new MySqlDataAdapter(sql1, conn); //获取数据表 //DataTable table = new DataTable(); DataSet ds = new DataSet(); sda.Fill(ds, "ds"); //填充数据库 this.dataGridView1.DataSource = ds.Tables[0]; msc.Close(); } catch (Exception ee) { } } else { MessageBox.Show("请输入正确工作面编号", "提示"); } } }
private void skinButton2_Click_1(object sender, EventArgs e) { if (skinTextBox1.Text.Equals("")) { MessageBox.Show("请输入所属工作面的编号", "提示"); } else if (skinTextBox2.Text.Equals("")) { MessageBox.Show("请输入设备号", "提示"); } else if (comboBox1.Text.Equals("")) { MessageBox.Show("请输入", "提示"); } else { if (skinTextBox1.Text.Equals(bz)) { int p1 = 1; string t2; if (comboBox1.Text.Equals("压力计")) { t2 = "1"; } else if (comboBox1.Text.Equals("减速机")) { t2 = "2"; } else { t2 = "3"; } //int A= int.Parse(skinTextBox1.Text); //MessageBox.Show(""+skinTextBox1.Text, "提示"); string sql11 = "SELECT equipment.Eid FROM equipment WHERE workid = " + skinTextBox1.Text + " and Etype =" + t2 + " ";; MySqlConn ms = new MySqlConn(); MySqlDataReader rd = ms.getDataFromTable(sql11); while (rd.Read()) { t1 = rd["Eid"].ToString(); //MessageBox.Show("t1是" +t1, "提示"); if (skinTextBox2.Text.Equals(t1) && skinTextBox2.Text != bz1) { p1 = 0; break; } } rd.Close(); ms.Close(); if (p1 != 0) { if (skinTextBox4.Text == "") { skinTextBox4.Text = "0"; } if (skinTextBox5.Text == "") { skinTextBox5.Text = "0"; } if (skinTextBox6.Text == "") { skinTextBox6.Text = "0"; } if (skinTextBox7.Text == "") { skinTextBox7.Text = "0"; } if (skinTextBox8.Text == "") { skinTextBox8.Text = "0"; } if (skinTextBox9.Text == "") { skinTextBox9.Text = "0"; } string ss = skinTextBox4.Text + "分" + skinTextBox5.Text + "秒" + skinTextBox6.Text + "毫秒"; string sss = skinTextBox7.Text + "分" + skinTextBox8.Text + "秒" + skinTextBox9.Text + "毫秒"; //MessageBox.Show("skinTextBox2.Text是" + bz, "提示"); string sql = "update equipment set Eid = " + skinTextBox2.Text + ",Etype = " + t2 + ",caiji = '" + ss + "',shangchuan = '" + sss + "' where Eid =" + bz1 + " AND workid = " + skinTextBox1.Text + ""; MySqlConn ms2 = new MySqlConn(); int n = ms2.nonSelect(sql); ms2.Close(); MessageBox.Show("修改设备成功", "提示"); skinTextBox1.Text = ""; skinTextBox2.Text = ""; try { string sql2 = "select equipment.workid,workname,equipment.Eid,equiptype.Ename,equipment.caiji,equipment.shangchuan from work,equipment,equiptype where `work`.workid = equipment.workid and equipment.Etype = equiptype.Etype ORDER BY workid asc"; MySqlConnection conn = msc.GetConn(); MySqlDataAdapter sda = new MySqlDataAdapter(sql2, conn); //获取数据表 //DataTable table = new DataTable(); DataSet ds = new DataSet(); sda.Fill(ds, "ds"); //填充数据库 this.dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ee) { } } } else { MessageBox.Show("请勿修改工作面编号", "提示"); } } }
private string conTosql()//创建数据库 { try { Log("检查数据库"); int sum_table = 9;//一共需要9个表,存在一个就减减..再加上一个由于mqtt的code.20190429添加groupinfo表 string[] tables = { "company", "work", "equipment", "Dsensor", "sensordata", "user", "Equiptype", "type", "ip" }; //string[] tables = { "user" }; string sql = "select table_name from information_schema.tables where table_schema='kj'";//获取数据库kaungjing中的和数据表 MySqlConn ms = new MySqlConn(); MySqlDataReader rd = ms.getDataFromTable(sql); while (rd.Read()) { for (int i = 0; i < tables.Length; i++) { if (rd["table_name"].ToString().Equals(tables[i]))//若有对应的表名,说明存在表 { tables[i] = ""; sum_table--; } } } Log("没有表的数目:" + sum_table); rd.Close(); ms.Close(); if (sum_table == 0) { return("1"); } else { Log("创建表"); string table = ""; for (int i = 0; i < 9; i++) { if (tables[i].Equals("") != true) { table += (tables[i] + "|"); string sql_createT = ""; string sql_initdata = ""; if (tables[i].Equals("type")) { sql_createT = "create table `type` ( `bzid` int,`type` varchar(255));"; sql_initdata = "insert into type values( '0' ,'压力'),( '1' ,'油温'),('2' ,'油压'),('3', '油位'),('4', '轴承温度'),('5', '水压'),('6', '冷却水温度'),('7', '载荷'),('8', '振动')"; //sql_initdata2 = "insert into type values( '2', '油压')"; //sql_initdata3 = "insert into type values( '3', '油位')"; //sql_initdata4 = "insert into type values( '4', '轴承温度')"; //sql_initdata5 = "insert into type values( '5', '水压')"; //sql_initdata6 = "insert into type values( '6', '冷却水温度')"; //sql_initdata7 = "insert into type values( '7', '载荷')"; //sql_initdata8 = "insert into type values( '8', '振动')"; //'1', '油温','2', '油压','3', '油位','4', '轴承温度','5', '水压','6', '冷却水温度','7', '载荷','8', '振动' } else if (tables[i].Equals("company")) { sql_createT = "create table `company` ( `company` varchar(255));"; sql_initdata = "insert into company values( '物联智讯有限公司')"; } else if (tables[i].Equals("work")) { sql_createT = "create table `work` (`workid` int null, `workname` varchar(255),`Bracket type` varchar(255), `Bore diameter` varchar(255), `maxpressure` int,`minpressure` int,`caiji` varchar(255), `shangchuan` varchar(255));"; } else if (tables[i].Equals("equipment")) { sql_createT = "create table `equipment` (`workid` int,`Eid` int, `Etype` int, `caiji` varchar(255), `shangchuan` varchar(255));"; } else if (tables[i].Equals("Dsensor")) { sql_createT = "create table `Dsensor` (`workid` int,`Eid` int,`Ename` varchar(255),`Sid` int,`Sname` varchar(255), `Smax` int,`Smin` int, `caiji` varchar(255), `shangchuan` varchar(255));"; } else if (tables[i].Equals("sensordata")) { sql_createT = "create table `sensordata` (`workid` int,`Eid` int, `Sid` int,`time` varchar(255),`value` varchar(255),`Electric` varchar(255),`biaozhi` int );"; } else if (tables[i].Equals("user")) { sql_createT = "create table user (UserName varchar(255), PassWord varchar(255), Admin int);"; sql_initdata = "insert into user values('root', '123','1')"; } else if (tables[i].Equals("Equiptype")) { sql_createT = "create table Equiptype ( Etype int , Ename varchar(255) );"; sql_initdata = "insert into Equiptype values( '1' ,'压力计'),('2' ,'减速机'),('3', '中继')"; } else if (tables[i].Equals("ip")) { sql_createT = "create table ip ( workid int , ip varchar(255),duankou,int);"; } try { MySqlConn ms1 = new MySqlConn(); int iRet = ms1.nonSelect(sql_createT); ms1.Close(); Log("iRet大小=" + iRet); if (iRet == 1) { Log("建表执行成功"); } if (sql_initdata.Equals("") != true) { MySqlConn ms2 = new MySqlConn(); int iRet2 = ms2.nonSelect(sql_initdata); ms2.Close(); if (iRet2 == 1) { Log("插入数据成功"); } else { Log("插入数据失败"); } } } catch (Exception e) { Log("建表时出错" + e.ToString()); return("0"); } } } Log("数据库表格已完善");//数据库表格已完善 return(sum_table.ToString() + "|" + table); } } #pragma warning disable CS0168 // 声明了变量“ee”,但从未使用过 catch (Exception ee) #pragma warning restore CS0168 // 声明了变量“ee”,但从未使用过 { Log("数据库建表失败"); } return("0"); }
public void loadReport() { DataTable dt = new DataTable(); //定义本地数据表的列,名称应跟之前所建的testDataTable表中列相同。 dt.Columns.Add("Eid", typeof(string)); dt.Columns.Add("youwen", typeof(string)); dt.Columns.Add("youwen1", typeof(string)); dt.Columns.Add("youya", typeof(string)); dt.Columns.Add("youya1", typeof(string)); dt.Columns.Add("youwei", typeof(string)); dt.Columns.Add("youwei1", typeof(string)); dt.Columns.Add("zhoucheng", typeof(string)); dt.Columns.Add("zhoucheng1", typeof(string)); dt.Columns.Add("shuiya", typeof(string)); dt.Columns.Add("shuiya1", typeof(string)); dt.Columns.Add("lengque", typeof(string)); dt.Columns.Add("lengque1", typeof(string)); dt.Columns.Add("zaihe", typeof(string)); dt.Columns.Add("zaihe1", typeof(string)); dt.Columns.Add("zhendong", typeof(string)); dt.Columns.Add("zhendong1", typeof(string)); dt.Columns.Add("time", typeof(string)); dt.Columns.Add("workid", typeof(string)); string sql = "select count(Eid) from equipment where Etype=2 and workid = " + workid + ""; MySqlDataReader rd = msc.getDataFromTable(sql); string cout = ""; int i = 0, j = 0; string[] eid = { }; while (rd.Read()) { cout = rd["count(Eid)"].ToString(); } rd.Close(); msc.Close(); j = int.Parse(cout); string a = ""; string sql1 = "select Eid from equipment where Etype=2 and workid = " + workid + ""; MySqlDataReader rd1 = msc.getDataFromTable(sql1); List <string> _list = new List <string>(eid); while (rd1.Read()) { _list.Add(rd1["Eid"].ToString()); } rd1.Close(); msc.Close(); eid = _list.ToArray(); for (i = 0; i < j; i++) { DataRow row = dt.NewRow(); row[0] = eid[i]; dt.Rows.Add(row); string sql2 = "select * from dsensor where workid = " + workid + " and Eid = " + eid[i] + " and Sname = '油温'"; MySqlDataReader rd2 = msc.getDataFromTable(sql2); while (rd2.Read()) { sid = rd2["Sid"].ToString(); } msc.Close(); rd2.Close(); sql = "select * from sensordata where workid = " + workid + " and Eid = " + eid[i] + " and Sid = " + sid + " and time between '" + time + "' and '" + end + "' order by time asc"; //MessageBox.Show("sql" + sql); MySqlDataReader rd3 = msc.getDataFromTable(sql); int sum = 0; float abc = 0; while (rd3.Read()) { try { sum++; int ab = int.Parse(rd3["value"].ToString()); if (ab > max) { max = ab; } abc = abc + int.Parse(rd3["value"].ToString()); } catch { } } rd3.Close(); msc.Close(); if (sum > 0) { row[1] = (max).ToString(); row[2] = (abc / sum).ToString(); } else { row[1] = (0).ToString(); row[2] = (0).ToString(); } sql2 = "select * from dsensor where workid = " + workid + " and Eid = " + eid[i] + " and Sname = '油压'"; rd2 = msc.getDataFromTable(sql2); while (rd2.Read()) { sid = rd2["Sid"].ToString(); } msc.Close(); rd2.Close(); sql = "select * from sensordata where workid = " + workid + " and Eid = " + eid[i] + " and Sid = " + sid + " and time between '" + time + "' and '" + end + "' order by time asc"; //MessageBox.Show("sql" + sql); rd3 = msc.getDataFromTable(sql); sum = 0; abc = 0; max = 0; while (rd3.Read()) { try { sum++; int ab = int.Parse(rd3["value"].ToString()); if (ab > max) { max = ab; } abc = abc + int.Parse(rd3["value"].ToString()); } catch { } } rd3.Close(); msc.Close(); if (sum > 0) { row[3] = (max).ToString(); row[4] = (abc / sum).ToString(); } else { row[3] = (0).ToString(); row[4] = (0).ToString(); } sql2 = "select * from dsensor where workid = " + workid + " and Eid = " + eid[i] + " and Sname = '油位'"; rd2 = msc.getDataFromTable(sql2); while (rd2.Read()) { sid = rd2["Sid"].ToString(); } msc.Close(); rd2.Close(); sql = "select * from sensordata where workid = " + workid + " and Eid = " + eid[i] + " and Sid = " + sid + " and time between '" + time + "' and '" + end + "' order by time asc"; //MessageBox.Show("sql" + sql); rd3 = msc.getDataFromTable(sql); sum = 0; abc = 0; max = 0; while (rd3.Read()) { try { sum++; int ab = int.Parse(rd3["value"].ToString()); if (ab > max) { max = ab; } abc = abc + int.Parse(rd3["value"].ToString()); } catch { } } rd3.Close(); msc.Close(); if (sum > 0) { row[5] = (max).ToString(); row[6] = (abc / sum).ToString(); } else { row[5] = (0).ToString(); row[6] = (0).ToString(); } sql2 = "select * from dsensor where workid = " + workid + " and Eid = " + eid[i] + " and Sname = '轴承温度'"; rd2 = msc.getDataFromTable(sql2); while (rd2.Read()) { sid = rd2["Sid"].ToString(); } msc.Close(); rd2.Close(); sql = "select * from sensordata where workid = " + workid + " and Eid = " + eid[i] + " and Sid = " + sid + " and time between '" + time + "' and '" + end + "' order by time asc"; //MessageBox.Show("sql" + sql); rd3 = msc.getDataFromTable(sql); sum = 0; abc = 0; max = 0; while (rd3.Read()) { try { sum++; int ab = int.Parse(rd3["value"].ToString()); if (ab > max) { max = ab; } abc = abc + int.Parse(rd3["value"].ToString()); } catch { } } rd3.Close(); msc.Close(); if (sum > 0) { row[7] = (max).ToString(); row[8] = (abc / sum).ToString(); } else { row[7] = (0).ToString(); row[8] = (0).ToString(); } sql2 = "select * from dsensor where workid = " + workid + " and Eid = " + eid[i] + " and Sname = '水压'"; rd2 = msc.getDataFromTable(sql2); while (rd2.Read()) { sid = rd2["Sid"].ToString(); } msc.Close(); rd2.Close(); sql = "select * from sensordata where workid = " + workid + " and Eid = " + eid[i] + " and Sid = " + sid + " and time between '" + time + "' and '" + end + "' order by time asc"; //MessageBox.Show("sql" + sql); rd3 = msc.getDataFromTable(sql); sum = 0; abc = 0; max = 0; while (rd3.Read()) { try { sum++; int ab = int.Parse(rd3["value"].ToString()); if (ab > max) { max = ab; } abc = abc + int.Parse(rd3["value"].ToString()); } catch { } } rd3.Close(); msc.Close(); if (sum > 0) { row[9] = (max).ToString(); row[10] = (abc / sum).ToString(); } else { row[9] = (0).ToString(); row[10] = (0).ToString(); } sql2 = "select * from dsensor where workid = " + workid + " and Eid = " + eid[i] + " and Sname = '冷却水温度'"; rd2 = msc.getDataFromTable(sql2); while (rd2.Read()) { sid = rd2["Sid"].ToString(); } msc.Close(); rd2.Close(); sql = "select * from sensordata where workid = " + workid + " and Eid = " + eid[i] + " and Sid = " + sid + " and time between '" + time + "' and '" + end + "' order by time asc"; //MessageBox.Show("sql" + sql); rd3 = msc.getDataFromTable(sql); sum = 0; abc = 0; max = 0; while (rd3.Read()) { try { sum++; int ab = int.Parse(rd3["value"].ToString()); if (ab > max) { max = ab; } abc = abc + int.Parse(rd3["value"].ToString()); } catch { } } rd3.Close(); msc.Close(); if (sum > 0) { row[11] = (max).ToString(); row[12] = (abc / sum).ToString(); } else { row[11] = (0).ToString(); row[12] = (0).ToString(); } sql2 = "select * from dsensor where workid = " + workid + " and Eid = " + eid[i] + " and Sname = '载荷'"; rd2 = msc.getDataFromTable(sql2); while (rd2.Read()) { sid = rd2["Sid"].ToString(); } msc.Close(); rd2.Close(); sql = "select * from sensordata where workid = " + workid + " and Eid = " + eid[i] + " and Sid = " + sid + " and time between '" + time + "' and '" + end + "' order by time asc"; //MessageBox.Show("sql" + sql); rd3 = msc.getDataFromTable(sql); sum = 0; abc = 0; max = 0; while (rd3.Read()) { try { sum++; int ab = int.Parse(rd3["value"].ToString()); if (ab > max) { max = ab; } abc = abc + int.Parse(rd3["value"].ToString()); } catch { } } rd3.Close(); msc.Close(); if (sum > 0) { row[13] = (max).ToString(); row[14] = (abc / sum).ToString("F2"); } else { row[13] = (0).ToString(); row[14] = (0).ToString(); } sql2 = "select * from dsensor where workid = " + workid + " and Eid = " + eid[i] + " and Sname = '振动'"; rd2 = msc.getDataFromTable(sql2); while (rd2.Read()) { sid = rd2["Sid"].ToString(); } msc.Close(); rd2.Close(); sql = "select * from sensordata where workid = " + workid + " and Eid = " + eid[i] + " and Sid = " + sid + " and time between '" + time + "' and '" + end + "' order by time asc"; //MessageBox.Show("sql" + sql); rd3 = msc.getDataFromTable(sql); sum = 0; abc = 0; max = 0; while (rd3.Read()) { try { sum++; int ab = int.Parse(rd3["value"].ToString()); if (ab > max) { max = ab; } abc = abc + int.Parse(rd3["value"].ToString()); } catch { } } rd3.Close(); msc.Close(); if (sum > 0) { row[15] = (max).ToString(); row[16] = (abc / sum).ToString(); } else { row[15] = (0).ToString(); row[16] = (0).ToString(); } string[] ids1 = time.Split(' '); string abcd = ids1[0]; row[17] = abcd; row[18] = workid + "号工作面"; } //设置本地报表,使程序与之前所建的testReport.rdlc报表文件进行绑定。 this.reportViewer1.LocalReport.ReportPath = "Report1.rdlc"; this.reportViewer1.LocalReport.DataSources.Clear(); this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetName", dt)); }
private void skinButton2_Click(object sender, EventArgs e) { if (TextBox1.Text.Equals("")) { MessageBox.Show("请输入工作面的名称", "提示"); } else if (TextBox2.Text.Equals("")) { MessageBox.Show("请输入支架型式", "提示"); } else if (extBox3.Text.Equals("")) { MessageBox.Show("请输入缸径", "提示"); } else if (extBox4.Text.Equals("")) { MessageBox.Show("请输入压力上限", "提示"); } else if (extBox5.Text.Equals("")) { MessageBox.Show("请输入压力下限", "提示"); } else if (TextBox6.Text.Equals("")) { MessageBox.Show("请输入工作面编号", "提示"); } else { if (TextBox6.Text.Equals(bz)) { if (skinTextBox4.Text == "") { skinTextBox4.Text = "0"; } if (skinTextBox5.Text == "") { skinTextBox5.Text = "0"; } if (skinTextBox6.Text == "") { skinTextBox6.Text = "0"; } if (skinTextBox7.Text == "") { skinTextBox7.Text = "0"; } if (skinTextBox8.Text == "") { skinTextBox8.Text = "0"; } if (skinTextBox9.Text == "") { skinTextBox9.Text = "0"; } string ss = skinTextBox4.Text + "分" + skinTextBox5.Text + "秒" + skinTextBox6.Text + "毫秒"; string sss = skinTextBox7.Text + "分" + skinTextBox8.Text + "秒" + skinTextBox9.Text + "毫秒"; //MessageBox.Show("skinTextBox2.Text是" + bz, "提示"); string sql = "update work set workid = " + TextBox6.Text + ",workname ='" + TextBox1.Text + "',`Bracket type` = ' " + TextBox2.Text + "',`Bore diameter` = " + extBox3.Text + ", maxpressure = " + extBox4.Text + ",minpressure= " + extBox5.Text + " ,caiji = '" + ss + "',shangchuan = '" + sss + "'where workid =" + bz + ""; MySqlConn ms2 = new MySqlConn(); int n = ms2.nonSelect(sql); ms2.Close(); MessageBox.Show("修改工作面成功", "提示"); TextBox1.Text = ""; TextBox2.Text = ""; extBox3.Text = ""; extBox4.Text = ""; extBox5.Text = ""; TextBox6.Text = ""; try { string sql2 = "select * from work order by workid asc"; MySqlConnection conn = msc.GetConn(); MySqlDataAdapter sda = new MySqlDataAdapter(sql2, conn); //获取数据表 //DataTable table = new DataTable(); DataSet ds = new DataSet(); sda.Fill(ds, "ds"); //填充数据库 this.dataGridView1.DataSource = ds.Tables[0]; msc.Close(); } catch (Exception ee) { } } else { MessageBox.Show("请勿修改工作面编号", "提示"); } } }
private void trans_sensor(char[] r) //数据存数据库 { string workId = r[0] + "" + r[1]; //工作面id string device_type = r[2] + "" + r[3]; // string device_id = r[4] + "" + r[5]; // string sensorid = r[6] + "" + r[7]; int sensor_id_int = Int32.Parse(sensorid, System.Globalization.NumberStyles.HexNumber); float year = Int32.Parse(r[8] + "" + r[9], System.Globalization.NumberStyles.HexNumber);//年 float month = Int32.Parse(r[10] + "" + r[11], System.Globalization.NumberStyles.HexNumber); //月 float day = Int32.Parse(r[12] + "" + r[13], System.Globalization.NumberStyles.HexNumber); //日 float shi = Int32.Parse(r[14] + "" + r[15], System.Globalization.NumberStyles.HexNumber); //时 float fen = Int32.Parse(r[16] + "" + r[17], System.Globalization.NumberStyles.HexNumber); //分 float miao = Int32.Parse(r[18] + "" + r[19], System.Globalization.NumberStyles.HexNumber); //秒 float hmiao = Int32.Parse(r[20] + "" + r[21], System.Globalization.NumberStyles.HexNumber); //毫秒 int device_type_int = Int32.Parse(device_type, System.Globalization.NumberStyles.HexNumber); //整型设备类型 string miao_g = miao.ToString(); if (miao_g.Length == 1) { miao_g = "0" + miao_g; } string fen_g = fen.ToString(); if (fen_g.Length == 1) { fen_g = "0" + fen_g; } string shi_g = shi.ToString(); if (shi_g.Length == 1) { shi_g = "0" + shi_g; } int device_id_int = Int32.Parse(device_id, System.Globalization.NumberStyles.HexNumber); string time = "20" + year.ToString() + "/" + month.ToString() + "/" + day.ToString() + " " + shi_g + ":" + fen_g + ":" + miao_g.ToString(); string flag = "" + r[23]; string Zh = r[24] + "" + r[25]; float zh_int = Int32.Parse(Zh, System.Globalization.NumberStyles.HexNumber); string Zl = r[26] + "" + r[27]; float zi_int = Int32.Parse(Zl, System.Globalization.NumberStyles.HexNumber); string xS = r[28] + "" + r[29]; float i_xs = Int32.Parse(xS, System.Globalization.NumberStyles.HexNumber); float and = zh_int * 100 + zi_int + i_xs / 100; string dataq = and.ToString(); if (flag.Equals("0")) { dataq = "-" + dataq; } if (flag.Equals("F") == true) { } else { try { string sql = "insert into sensordata (workid,Eid,Sid,time,value,biaozhi,Etype) values(" + workId + ", " + device_id_int + ", " + sensor_id_int + ", '" + time + "', " + dataq + ", " + device_type_int + "," + device_type + ")"; MySqlConn ms2 = new MySqlConn(); int n = ms2.nonSelect(sql); ms2.Close(); } catch (Exception se) { } } }