Beispiel #1
0
        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("数据库连接失败");
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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("请检查数据库连接设置", "提示");
                }
            }
        }
Beispiel #4
0
        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)
                {
                }
            }
        }
Beispiel #5
0
        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());
                }
            }
        }
Beispiel #6
0
 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)
     {
     }
 }
Beispiel #7
0
 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("请检查数据库设置");
         }
     }
 }
Beispiel #8
0
        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)
                {
                }
            }
        }
Beispiel #9
0
        /// <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("请检查数据库设置");
                    }
                }
            }
        }
Beispiel #10
0
        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("设置成功");
            }
        }
Beispiel #11
0
 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("请检查数据库是否创建好");
         }
     }
 }
Beispiel #12
0
        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("已存在该传感器编号", "提示");
                    }
                }
            }
        }
Beispiel #13
0
        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("请检查数据库是否创建好");
                    }
                }
            }
        }
Beispiel #14
0
        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("设置成功");
            }
        }
Beispiel #15
0
        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("请检查数据库连接设置", "提示");
                }
            }
        }
Beispiel #16
0
        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");
        }
Beispiel #17
0
        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("请勿修改工作面编号", "提示");
                }
            }
        }
Beispiel #18
0
        private void Button1_Click(object sender, EventArgs e)// 点击登录函数
        {
            if (textBox1.Text.Equals(""))
            {
                MessageBox.Show("请输入用户名", "提示");
            }
            else if (textBox2.Text.Equals(""))
            {
                MessageBox.Show("请输入密码", "提示");
            }
            else
            {
                try
                {
                    //DataBase db = new DataBase();
                    //db.command.CommandText = "select * from [user]";
                    //db.command.Connection = db.connection;

                    //db.Dr = db.command.ExecuteReader();
                    MySqlConn       msc = new MySqlConn();
                    string          sql = "select * from user";
                    MySqlDataReader rdr = msc.getDataFromTable(sql);
                    user_login.Logout();
                    while (rdr.Read())
                    {
                        if (rdr["UserName"].ToString().Equals(textBox1.Text.Trim()))
                        {//当存在用户时,首先将用户名提取出来
                            user_login.name = textBox1.Text;
                            if (rdr["PassWord"].ToString().Equals(textBox2.Text))
                            {//如果密码也相同,则提取权限
                                user_login.admin = rdr["Admin"].ToString();
                                label3.Visible   = true;
                                button1.Enabled  = false;
                                textBox2.Text    = "";
                                if (SaveUsrInfo == 1)
                                {//点击了保存用户名密码按钮
                                    string       path = System.Windows.Forms.Application.StartupPath;
                                    FileStream   fs   = new FileStream(path + "\\userinfo.txt", FileMode.Create, FileAccess.Write);
                                    StreamWriter sw   = new StreamWriter(fs);
                                    sw.WriteLine(user_login.name + "+" + rdr["PassWord"].ToString());
                                    sw.Flush();
                                    sw.Close();
                                    fs.Close();
                                }


                                Thread.Sleep(50);

                                new Thread((ParameterizedThreadStart)this.conTosql).Start();
                                break;
                                //Thread thread = new Thread(show_mainform);
                                //thread.IsBackground = false;
                                //thread.Start();
                            }
                            else
                            {
                                MessageBox.Show("密码错误", "提示");
                            }
                        }
                    }
                    if (user_login.name.Equals(""))
                    {
                        MessageBox.Show("用户不存在", "提示");
                    }
                    rdr.Close();
                }
                catch (Exception exc)
                {
                    //DataBase database = new DataBase();
                    //string sql_createT = "create table [user] (UserName nvarchar(MAX), PassWord nvarchar(MAX), Admin int);";
                    //database.command.CommandText = sql_createT;
                    //database.command.Connection = database.connection;
                    //database.command.ExecuteNonQuery();

                    //string sql_init = "insert into [user] values ('root', '123', 1);";
                    //database.command.CommandText = sql_init;
                    //database.command.ExecuteNonQuery();
                    MessageBox.Show("数据库连接出错,请检查数据库连接\r\n错误代码:" + exc.ToString(), "提示");
                    return;
                }
            }
        }
Beispiel #19
0
        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("请勿修改工作面编号", "提示");
                }
            }
        }
Beispiel #20
0
        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("请输入正确工作面编号", "提示");
                }
            }
        }
Beispiel #21
0
        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)
                {
                }
            }
        }