Exemplo n.º 1
0
        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("数据库异常", "提示");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据BinName找BinID
        /// </summary>
        /// <returns></returns>
        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");
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private void getFactory(object obj)
        {
            try
            {
                comboBox1.Items.Clear();

                string sql = "select * from equiptype";
                //DataBase db = new DataBase();
                //db.command.CommandText = sql;
                //db.command.Connection = db.connection;
                //db.Dr = db.command.ExecuteReader();
                MySqlDataReader rd = msc.getDataFromTable(sql);
                while (rd.Read())
                {
                    comboBox1.Items.Add(rd["Ename"].ToString());
                }
                rd.Close();
                if (comboBox1.Items.Count > 0)
                {
                    comboBox1.Text = comboBox1.Items[0].ToString();
                }
            }
            catch (SqlException se)
            {
                Log("sadfas" + se);
            }
        }
Exemplo n.º 5
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("数据库连接失败");
            }
        }
Exemplo n.º 6
0
        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("数据库异常", "提示");
            }
        }
Exemplo n.º 7
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("请检查数据库连接设置", "提示");
                }
            }
        }
Exemplo n.º 8
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)
     {
     }
 }
Exemplo n.º 9
0
        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();
                }
            }
        }
Exemplo n.º 10
0
        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("数据库异常", "提示");
            }
        }
Exemplo n.º 11
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;
                }
            }
        }
Exemplo n.º 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("已存在该传感器编号", "提示");
                    }
                }
            }
        }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 14
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("请检查数据库是否创建好");
         }
     }
 }
Exemplo n.º 15
0
        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);
            }
        }
Exemplo n.º 16
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("请检查数据库是否创建好");
                    }
                }
            }
        }
Exemplo n.º 17
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("请输入正确工作面编号", "提示");
                }
            }
        }
Exemplo n.º 18
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("请勿修改工作面编号", "提示");
                }
            }
        }
Exemplo n.º 19
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");
        }
Exemplo n.º 20
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("请检查数据库设置");
                    }
                }
            }
        }
Exemplo n.º 21
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));
        }
Exemplo n.º 22
0
        private Mutex file_mutex = new Mutex();//文件互斥锁

        private void getFactory(object obj)
        {
            try
            {
                comboBox1.Items.Clear();
                comboBox2.Items.Clear();
                comboBox3.Items.Clear();
                comboBox4.Items.Clear();
                string sql1 = "select * from work";

                MySqlDataReader rd1 = msc.getDataFromTable(sql1);
                while (rd1.Read())
                {
                    comboBox3.Items.Add(rd1["workname"].ToString());
                }
                rd1.Close();
                if (comboBox3.Items.Count > 0)
                {
                    comboBox3.Text = comboBox3.Items[0].ToString();
                }
                //comboBox2.Items.Add("所有");

                //string sql = "select * from equiptype";

                //MySqlDataReader rd = msc.getDataFromTable(sql);
                //while (rd.Read())
                //{
                //    comboBox2.Items.Add(rd["Ename"].ToString());
                //}
                //rd.Close();
                //if (comboBox2.Items.Count > 0)
                //{
                //    comboBox2.Text = comboBox2.Items[0].ToString();
                //}
                //comboBox4.Items.Add("所有");
                //string sql2 = "select equipment.Eid from equipment where workid in(1)";

                //MySqlDataReader rd2 = msc.getDataFromTable(sql2);

                //while (rd2.Read())
                //{
                //    comboBox4.Items.Add(rd2["Eid"].ToString());
                //}
                //rd2.Close();
                //if (comboBox4.Items.Count > 0)
                //{
                //    comboBox4.Text = comboBox4.Items[0].ToString();
                //}
                //comboBox1.Items.Add("所有");
                //string sql3 = "select Sid from dsensor where workid in(1)";

                //MySqlDataReader rd3 = msc.getDataFromTable(sql3);

                //while (rd3.Read())
                //{
                //    comboBox1.Items.Add(rd3["Sid"].ToString());
                //}
                //rd3.Close();
                //if (comboBox1.Items.Count > 0)
                //{
                //    comboBox1.Text = comboBox1.Items[0].ToString();
                //}
            }
            catch (SqlException se)
            {
                MessageBox.Show("数据库异常", "提示");
            }
        }