Пример #1
0
        private void toolStripButtonDelete_Click(object sender, EventArgs e)//删除
        {
            DataGridViewRow row = this.dataGView_Main.CurrentRow;

            if (row != null)
            {
                DialogResult result = MessageBox.Show("确定要删除选择的设备信息吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes) // 确认删除
                {
                    string       query = "DELETE FROM SensorProducer WHERE 序号=@序号";
                    MySqlCommand cmd   = MySQLDB.GetMySQLDB().giveCommand(query);
                    cmd.Parameters.Add("@序号", MySqlDbType.VarChar).Value = row.Cells["序号"];

                    if (cmd.ExecuteNonQuery() == 1)
                    {
                        MessageBox.Show("Data Deleted");
                    }
                    else
                    {
                        MessageBox.Show("Insertion Failed");
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择要删除的设备信息");
            }
        }
Пример #2
0
        //private void commandButton_Click(object sender, EventArgs e)
        //{
        //    if (m_MySQLDatabase == null) return;
        //    result_richText.Text += "\n-------------------------------------------------------------------";
        //    MySqlCommand cmd = m_MySQLDatabase.giveCommand(commandTextBox.Text);
        //    MySqlDataReader reader = null;
        //    try
        //    {
        //        reader = cmd.ExecuteReader();
        //    }
        //    catch (Exception eq)
        //    {
        //        MessageBox.Show("Error : " + eq.StackTrace);
        //    }

        //    int fieldNum = reader.FieldCount;
        //    if (commandTextBox.Text.Contains("select"))
        //        printData(fieldNum, reader);
        //    else if (commandTextBox.Text.Contains("update"))
        //    {
        //        //TODO : Set up getting updated strings.
        //        //string updated = result_richText.Text.Substring(result_richText.Text.IndexOf("set ", 4));
        //        result_richText.Text += "\n\tTable Updated";
        //    }
        //    reader.Close();
        //}

        //void printData(int fieldNum, MySqlDataReader reader)
        // {
        ////Add the column names
        //result_richText.Text += "\n";
        //for (int i = 0; i < fieldNum; i++)
        //{
        //    columnName.Add(reader.GetName(i));
        //    result_richText.Text += "\t" + reader.GetName(i);
        //}
        ////Add all the values of all rows
        //result_richText.Text += "\n";
        //while (reader.Read())
        //{
        //    result_richText.Text += "\n";
        //    for (int i = 0; i < fieldNum; i++)
        //    {
        //        values.Add(reader[i].ToString());
        //        result_richText.Text += "\t" + reader[i].ToString();
        //    }
        //}

        //int[] initOffset = new int[fieldNum];
        //for (int i = 0; i < fieldNum; i++)
        //    initOffset[i] = i;
        ////Gets all the values of a particular field each
        //for (int j = 0; j < fieldNum; j++)
        //{
        //    for (int i = 0; i < values.Count; i++)
        //    {
        //        if (initOffset[j] == i)
        //        {
        //            initOffset[j] += fieldNum;
        //        }
        //    }
        //}

        //}

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                MySQLDB.GetMySQLDB().closeConnection();
            }
            catch { }
        }
Пример #3
0
 private void connectButton_Click(object sender, EventArgs e)
 {
     if (userIdTextBox.Text != String.Empty && passwordTextBox.Text != String.Empty /*&& textBoxDatabase.Text != String.Empty*/)
     {
         DATABASE = textBoxDatabase.Text;
         MySQLDB.GetMySQLDB().connect(SERVER, DATABASE, userIdTextBox.Text, passwordTextBox.Text);
     }
 }
Пример #4
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (!this.isAdd)//编辑
            {
                string       query = "UPDATE SensorProducer SET 类型=@类型,型号=@型号,厂家全称和简称=@厂家全称和简称 ,信息描述=@信息描述 ,协议类型=@协议类型,通讯协议=@通讯协议,设备编号=@设备编号,制定日期=@制定日期, WHERE 序号=@序号";
                MySqlCommand cmd   = MySQLDB.GetMySQLDB().giveCommand(query);
                cmd.Parameters.Add("@序号", MySqlDbType.VarChar).Value = this._NextIndex;
                cmd.Parameters.Add("@类型", MySqlDbType.VarChar).Value = this.cboDeviceStyle.Text;

                cmd.Parameters.Add("@型号", MySqlDbType.VarChar).Value = this.yTextBox_XH.Text;

                cmd.Parameters.Add("@厂家全称和简称", MySqlDbType.VarChar).Value = this.cboCompany.Text;

                cmd.Parameters.Add("@信息描述", MySqlDbType.VarChar).Value = this.yTextBox_REASON.Text;

                cmd.Parameters.Add("@协议类型", MySqlDbType.VarChar).Value = this.cboProtocolStyle.Text;
                cmd.Parameters.Add("@通讯协议", MySqlDbType.VarChar).Value = this.cboProtocolNO.Text;
                cmd.Parameters.Add("@设备编号", MySqlDbType.VarChar).Value = this.yTextBox_BH.Text;

                cmd.Parameters.Add("@制定日期", MySqlDbType.VarChar).Value = this.ytDateTime_MakeTime.Text;

                if (cmd.ExecuteNonQuery() == 1)
                {
                    MessageBox.Show("修改成功");
                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }
            else
            {
                string       query = "INSERT INTO SensorProducer(序号,类型,型号,厂家全称和简称,信息描述,协议类型,通讯协议,设备编号,制定日期) VALUES (@序号,@类型,@型号,@厂家全称和简称,@信息描述,@协议类型,@通讯协议,@设备编号,@制定日期)";
                MySqlCommand cmd   = MySQLDB.GetMySQLDB().giveCommand(query);
                cmd.Parameters.Add("@序号", MySqlDbType.VarChar).Value      = this._NextIndex;
                cmd.Parameters.Add("@类型", MySqlDbType.VarChar).Value      = this.cboDeviceStyle.Text;
                cmd.Parameters.Add("@型号", MySqlDbType.VarChar).Value      = this.yTextBox_XH.Text;
                cmd.Parameters.Add("@厂家全称和简称", MySqlDbType.VarChar).Value = this.cboCompany.Text;
                cmd.Parameters.Add("@信息描述", MySqlDbType.VarChar).Value    = this.yTextBox_REASON.Text;
                cmd.Parameters.Add("@协议类型", MySqlDbType.VarChar).Value    = this.cboProtocolStyle.Text;
                cmd.Parameters.Add("@通讯协议", MySqlDbType.VarChar).Value    = this.cboProtocolNO.Text;
                cmd.Parameters.Add("@设备编号", MySqlDbType.VarChar).Value    = this.yTextBox_BH.Text;
                cmd.Parameters.Add("@制定日期", MySqlDbType.VarChar).Value    = this.ytDateTime_MakeTime.Text;

                if (cmd.ExecuteNonQuery() == 1)
                {
                    _NextIndex++;
                    MessageBox.Show("添加成功");
                }
                else
                {
                    MessageBox.Show("添加失败");
                }
            }

            this.DialogResult = DialogResult.OK;
        }
Пример #5
0
        private void LoadList()
        {
            //SensorDeviceTable = { "ID", "单位名称", "类型", "ADRNO", "DTUID", "POS_X", "POS_Y", "POS_Z" };

            dgvList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            string           query   = "SELECT DEVICEID,单位名称,类型,ADRNO,DTUID FROM SensorDevice";
            MySqlDataAdapter adapter = MySQLDB.GetMySQLDB().getAdapter(query);
            DataTable        table   = new DataTable();

            adapter.Fill(table);
            dgvList.DataSource = table;
        }
Пример #6
0
        private void dgvList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //获取双击的行数据
            var row = dgvList.Rows[e.RowIndex];

            //将行中的数据显示到控件中

            textSensorID.Text      = row.Cells[0].Value.ToString();
            cboDeviceProducer.Text = row.Cells[1].Value.ToString();
            cboDeviceStyle.Text    = row.Cells[2].Value.ToString();
            txtSensorADR.Text      = row.Cells[3].Value.ToString();
            txtDTUID.Text          = row.Cells[4].Value.ToString();

            btnSave.Text = "修改";

            btnDelete.Enabled = true;

            //获取行数据
            string sql = string.Format("SELECT * FROM SensorDevice WHERE DEVICEID='{0}'",
                                       row.Cells[0].Value.ToString());

            double PosX = 0, PosY = 0;
            bool   error = false;  // 标识是否出现错误

            try
            {
                // 查询
                MySqlCommand    command    = MySQLDB.GetMySQLDB().giveCommand(sql);
                MySqlDataReader dataReader = command.ExecuteReader();

                if (dataReader.Read())
                {
                    PosX = Convert.ToDouble(dataReader["POS_X"]);
                    PosY = Convert.ToDouble(dataReader["POS_Y"]);
                }
                dataReader.Close();
            }
            catch (Exception ex)
            {
                error = true;
                MessageBox.Show(ex.Message);
            }
            if (!error)
            {
                GeoPoint gp = new GeoPoint(PosX, PosY);
                sender = gp;
                if (CameraDataAdjustHandler != null)
                {
                    CameraDataAdjustHandler(sender);
                }
            }
        }
Пример #7
0
        public void ShowInfo(string searchValue)
        {
            string query = "SELECT * FROM SensorProducer WHERE CONCAT(序号,类型,型号,厂家全称和简称,信息描述,协议类型,通讯协议,设备编号,制定日期) LIKE '%" + searchValue + "%'";

            MySqlDataAdapter adapter = MySQLDB.GetMySQLDB().getAdapter(query);
            DataTable        table   = new DataTable();

            adapter.Fill(table);
            dataGView_Main.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGView_Main.RowTemplate.Height  = 60;
            dataGView_Main.AllowUserToAddRows  = false;
            dataGView_Main.DataSource          = table;
        }
Пример #8
0
        private void LoadList()
        {
            string sql = string.Format("SELECT * FROM DeviceCompany");

            try
            {
                dgvList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                MySqlDataAdapter adapter = MySQLDB.GetMySQLDB().getAdapter(sql);
                DataTable        table   = new DataTable();
                adapter.Fill(table);
                dgvList.DataSource = table;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #9
0
        // 删除传感
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = this.dgvList.CurrentRow;

            DialogResult result;           // 对话框结果
            int          deleteResult = 0; // 操作结果

            if (row != null)
            {
                result = MessageBox.Show("确实要删除该传感吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes) // 确认删除
                {
                    string sql = string.Format("DELETE FROM SensorDevice WHERE DEVICEID='{0}'",
                                               row.Cells[0].Value.ToString());

                    try
                    {
                        MySqlCommand command = MySQLDB.GetMySQLDB().giveCommand(sql);
                        deleteResult = command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    if (deleteResult == 1)
                    {
                        if (DeleteModelHandler != null)
                        {
                            sender = row.Cells[0].Value.ToString();
                            DeleteModelHandler(sender, e);
                        }

                        LoadList();

                        btnDelete.Enabled = false;
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择要删除的传感信息");
            }
        }
Пример #10
0
        private void m_buttonOK_Click(object sender, EventArgs e)
        {
            // 如果输入验证成功,就验证身份,并转到相应的窗体
            if (ValidateInput())
            {
                int num = 0;  // 数据库操作结果

                try
                {
                    // 查询用的sql语句
                    //string sql = string.Format("SELECT COUNT(*) FROM Users WHERE ID={0} AND LoginPwd = '{1}'",
                    //    int.Parse(m_textBoxUser.Text.Trim()), m_textBoxPassword.Text.Trim());

                    string sql = string.Format("SELECT COUNT(*) FROM Users WHERE ID='{0}' AND LoginPwd = '{1}'",
                                               (m_textBoxUser.Text.Trim()), m_textBoxPassword.Text.Trim());
                    // 创建Command 对象
                    MySqlCommand command = MySQLDB.GetMySQLDB().giveCommand(sql);
                    num = Convert.ToInt32(command.ExecuteScalar());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "登录提示");
                }

                if (num == 1)  // 验证通过
                {
                    // 设置登录的用户号码
                    //UserHelper.loginId = int.Parse(m_textBoxUser.Text.Trim());
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("输入的用户名或密码有误!", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #11
0
        public void UpdateListView(Data.UDPData data)
        {
            if (this.加速计listResult.InvokeRequired)
            {
                Action <Data.UDPData> action = new Action <Data.UDPData>(UpdateListView);
                this.Invoke(action, data);
                return;
            }

            int indexOfFirstNotUse = -1;

            for (int i = 0; i < UserHelper.JIASUDUDataList.Count; ++i)
            {
                if (UserHelper.JIASUDUDataList[i].Key == data.DeviceID)
                {
                    indexOfFirstNotUse = i;
                    break;
                }
            }


            if (indexOfFirstNotUse == -1)
            {
                return;
            }

            string NOID = UserHelper.JIASUDUDataList[indexOfFirstNotUse].Value.strNOID;
            float  X初始值 = UserHelper.JIASUDUDataList[indexOfFirstNotUse].Value.JIASUDU_OX;
            float  Y初始值 = UserHelper.JIASUDUDataList[indexOfFirstNotUse].Value.JIASUDU_OY;
            float  Z初始值 = UserHelper.JIASUDUDataList[indexOfFirstNotUse].Value.JIASUDU_OZ;

            float X测试值 = data.JIASUDU_X;
            float Y测试值 = data.JIASUDU_Y;
            float Z测试值 = data.JIASUDU_Z;

            float X单次变化量 = data.JIASUDU_X - UserHelper.JIASUDUDataList[indexOfFirstNotUse].Value.JIASUDU_TX;
            float Y单次变化量 = data.JIASUDU_Y - UserHelper.JIASUDUDataList[indexOfFirstNotUse].Value.JIASUDU_TY;
            float Z单次变化量 = data.JIASUDU_Z - UserHelper.JIASUDUDataList[indexOfFirstNotUse].Value.JIASUDU_TZ;

            float X累计变化量 = data.JIASUDU_X - X初始值;
            float Y累计变化量 = data.JIASUDU_Y - Y初始值;
            float Z累计变化量 = data.JIASUDU_Z - Z初始值;

            UserHelper.JIASUDUDataList[indexOfFirstNotUse].Value.JIASUDU_TX = data.JIASUDU_X;
            UserHelper.JIASUDUDataList[indexOfFirstNotUse].Value.JIASUDU_TY = data.JIASUDU_Y;
            UserHelper.JIASUDUDataList[indexOfFirstNotUse].Value.JIASUDU_TZ = data.JIASUDU_Z;

            this.加速计listResult.Items.Add(new ListViewItem(
                                             new string[]
            {
                _NextJSIndex.ToString(),
                NOID,
                X初始值.ToString(),
                Y初始值.ToString(),
                Z初始值.ToString(),
                X测试值.ToString(),
                Y测试值.ToString(),
                Z测试值.ToString(),
                X单次变化量.ToString(),
                Y单次变化量.ToString(),
                Z单次变化量.ToString(),
                X累计变化量.ToString(),
                Y累计变化量.ToString(),
                Z累计变化量.ToString(),
                data.Time.ToString()
            })
            {
                BackColor = (0 == _NextJSIndex % 2) ? System.Drawing.Color.LightGray : System.Drawing.Color.Green
            });


            if (this.加速计listResult.Items.Count == 100)
            {
                this.加速计listResult.Items.RemoveAt(0);
            }

            try
            {
                //构造insert语句
                string sql = "INSERT INTO SensorJSData (ID,NOID,X初始值,Y初始值,Z初始值,X测试值,Y测试值,Z测试值,X单次变化量,Y单次变化量,Z单次变化量,X累计变化量,Y累计变化量,Z累计变化量,TIME) VALUES(@ID,@NOID,@X初始值,@Y初始值,@Z初始值,@X测试值,@Y测试值,@Z测试值,@X单次变化量,@Y单次变化量,@Z单次变化量,@X累计变化量,@Y累计变化量,@Z累计变化量,@TIME)";
                //构造sql语句的参数
                MySqlParameter[] ps = //使用数组初始化器
                {
                    new MySqlParameter("@ID",     _NextJSIndex),
                    new MySqlParameter("@NOID",   NOID),
                    new MySqlParameter("@X初始值",   X初始值),
                    new MySqlParameter("@Y初始值",   Y初始值),
                    new MySqlParameter("@Z初始值",   Z初始值),
                    new MySqlParameter("@X测试值",   X测试值),
                    new MySqlParameter("@Y测试值",   Y测试值),
                    new MySqlParameter("@Z测试值",   Z测试值),
                    new MySqlParameter("@X单次变化量", X单次变化量),
                    new MySqlParameter("@Y单次变化量", Y单次变化量),
                    new MySqlParameter("@Z单次变化量", Z单次变化量),
                    new MySqlParameter("@X累计变化量", X累计变化量),
                    new MySqlParameter("@Y累计变化量", Y累计变化量),
                    new MySqlParameter("@Z累计变化量", Z累计变化量),
                    new MySqlParameter("@TIME",   data.Time)
                };
                //执行插入操作
                int index = MySQLDB.GetMySQLDB().ExecuteNonQuery(sql, ps);

                //添加操作
                if (index > 0)
                {
                    //MessageBox.Show("添加成功!");
                    _NextJSIndex++;
                }
                else
                {
                    //MessageBox.Show("添加失败,请稍候重试");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "注册失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #12
0
        public void UpdateListView(Data.UDPData data)
        {
            if (this.水准仪listResult.InvokeRequired)
            {
                Action <Data.UDPData> action = new Action <Data.UDPData>(UpdateListView);
                this.Invoke(action, data);
                return;
            }

            int indexOfFirstNotUse = -1;

            for (int i = 0; i < UserHelper.ShuiZhunDataList.Count; ++i)
            {
                if (UserHelper.ShuiZhunDataList[i].Key == data.DeviceID)
                {
                    indexOfFirstNotUse = i;
                    break;
                }
            }

            if (indexOfFirstNotUse == -1)
            {
                return;
            }

            string NOID = UserHelper.ShuiZhunDataList[indexOfFirstNotUse].Value.strNOID;
            //float 振动初始值 = UserHelper.ShuiZhunDataList[indexOfFirstNotUse].Value.ZHENDONGO;
            float 沉降初始值 = UserHelper.ShuiZhunDataList[indexOfFirstNotUse].Value.CHENJIANGO;

            //float 振动测试值 = data.ZHENDONG - UserHelper.ShuiZhunDataList[indexOfFirstNotUse].Value.ZHENDONGT;
            float 沉降测试值 = data.CHENJIANG - UserHelper.ShuiZhunDataList[indexOfFirstNotUse].Value.CHENJIANGT;

            //float 振动单次变化量 = data.ZHENDONG;
            float 沉降单次变化量 = data.CHENJIANG;

            //float 振动累计变化量 = data.ZHENDONG - 振动初始值;
            float 沉降累计变化量 = data.CHENJIANG - 沉降初始值;

            //UserHelper.ShuiZhunDataList[indexOfFirstNotUse].Value.ZHENDONGT = data.ZHENDONG;
            UserHelper.ShuiZhunDataList[indexOfFirstNotUse].Value.CHENJIANGT = data.CHENJIANG;

            this.水准仪listResult.Items.Add(new ListViewItem(
                                             new string[]
            {
                _NextSZIndex.ToString(),
                NOID.ToString(),
                //振动初始值.ToString(),
                沉降初始值.ToString(),
                //振动测试值.ToString(),
                沉降测试值.ToString(),
                //振动单次变化量.ToString(),
                沉降单次变化量.ToString(),
                //振动累计变化量.ToString(),
                沉降累计变化量.ToString(),
                data.Time.ToString()
            })
            {
                BackColor = (0 == _NextSZIndex % 2) ? System.Drawing.Color.LightGray : System.Drawing.Color.Green
            });

            if (this.水准仪listResult.Items.Count == 100)
            {
                this.水准仪listResult.Items.RemoveAt(0);
            }

            try
            {
                //构造insert语句
                string sql = "INSERT INTO SensorSZData (ID,NOID,沉降初始值,沉降测试值,沉降单次变化量,沉降累计变化量,TIME) VALUES(@ID,@NOID,@沉降初始值,@沉降测试值,@沉降单次变化量,@沉降累计变化量,@TIME)";
                //构造sql语句的参数
                MySqlParameter[] ps = //使用数组初始化器
                {
                    new MySqlParameter("@ID",      _NextSZIndex),
                    new MySqlParameter("@NOID",    NOID),
                    new MySqlParameter("@沉降初始值",   沉降初始值),
                    new MySqlParameter("@沉降测试值",   沉降测试值),
                    new MySqlParameter("@沉降单次变化量", 沉降单次变化量),
                    new MySqlParameter("@沉降累计变化量", 沉降累计变化量),
                    new MySqlParameter("@TIME",    data.Time)
                };
                //执行插入操作
                int index = MySQLDB.GetMySQLDB().ExecuteNonQuery(sql, ps);

                //添加操作
                if (index > 0)
                {
                    //MessageBox.Show("添加成功!");
                    _NextSZIndex++;
                }
                else
                {
                    //MessageBox.Show("添加失败,请稍候重试");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "注册失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #13
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // 查找
            int num = 0;  // 数据库操作结果

            try
            {
                // 查询用的sql语句
                string sql = string.Format("SELECT COUNT(*) FROM DeviceCompany WHERE 单位名称='{0}'",
                                           cboDeviceProducer.Text.Trim());
                // 创建Command 对象
                MySqlCommand command = MySQLDB.GetMySQLDB().giveCommand(sql);
                num = Convert.ToInt32(command.ExecuteScalar());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "抱歉");
            }

            if (num == 1)  // 验证通过
            {
                MessageBox.Show(("已注册!"), "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            try
            {
                //构造insert语句
                string sql = "INSERT INTO DeviceCompany (单位名称) VALUES(@单位名称)";
                //构造sql语句的参数
                MySqlParameter[] ps = //使用数组初始化器
                {
                    new MySqlParameter("@单位名称", cboDeviceProducer.Text),
                };
                //执行插入操作
                int index = MySQLDB.GetMySQLDB().ExecuteNonQuery(sql, ps);

                //添加操作
                if (index > 0)
                {
                    LoadList();

                    //sql = "SELECT @@Identity FROM SensorDevice";  // 查询新增加的记录的标识号
                    //command.CommandText = sql;             // 重新指定 Command 对象的 SQL 语句
                    //Convert.ToInt32(command.ExecuteScalar());  // 强制类型转换会出错
                    MessageBox.Show("注册成功!");
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("添加失败,请稍候重试");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "注册失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            //恢复控件的值
            RestControls();
        }
Пример #14
0
        private void ShowDeviceList(int GroupIndex, StreamWriter outputFile)
        {
            // 查找
            string sql = string.Format(
                "SELECT * FROM SensorDevice WHERE 类型 like '%{0}%'", UserHelper.sDeviceName[GroupIndex].Trim());

            try
            {
                // 执行查询
                MySqlCommand    command = MySQLDB.GetMySQLDB().giveCommand(sql);
                MySqlDataReader dataReader = command.ExecuteReader();
                double          PosX = 0, PosY = 0, PosZ = 0;
                // 循环添加列表
                while (dataReader.Read())
                {
                    string strID   = dataReader["DEVICEID"].ToString();
                    string strNOID = dataReader["ADRNO"].ToString();

                    if (AddModelIDHandler != null)
                    {
                        List <string> lst = new List <string>();
                        lst.Add(strID);
                        lst.Add(strNOID);

                        object sender = lst;
                        AddModelIDHandler(sender);
                    }

                    //{ "水准仪", "倾角仪", "加速计" };
                    if (GroupIndex == 0)
                    {
                        UserHelper.ShuiZhunData ShuiZhunData = new UserHelper.ShuiZhunData();
                        ShuiZhunData.strNOID = strNOID;
                        strID = "SZ" + strNOID;
                        UserHelper.ShuiZhunDataList.Add(new KeyValuePair <string, UserHelper.ShuiZhunData>(strID, ShuiZhunData));
                    }

                    if (GroupIndex == 1)
                    {
                        UserHelper.QINGJIAOData QINGJIAOData = new UserHelper.QINGJIAOData();
                        QINGJIAOData.strNOID = strNOID;
                        strID = "QJ" + strNOID;
                        UserHelper.QINGJIAODataList.Add(new KeyValuePair <string, UserHelper.QINGJIAOData>(strID, QINGJIAOData));
                    }

                    if (GroupIndex == 2)
                    {
                        UserHelper.JIASUDUData JIASUDUData = new UserHelper.JIASUDUData();
                        JIASUDUData.strNOID = strNOID;
                        strID = "JS" + strNOID;
                        UserHelper.JIASUDUDataList.Add(new KeyValuePair <string, UserHelper.JIASUDUData>(strID, JIASUDUData));
                    }

                    char[] buffer = new char[2];
                    buffer[0] = (char)GroupIndex;
                    int byteArray = int.Parse(strNOID);
                    buffer[1] = (char)byteArray;
                    outputFile.WriteLine(buffer);

                    if (AddModelHandler != null)
                    {
                        PosX = Convert.ToDouble(dataReader["POS_X"]);
                        PosY = Convert.ToDouble(dataReader["POS_Y"]);
                        PosZ = Convert.ToDouble(dataReader["POS_Z"]);

                        Point2Ds Point2Ds = new Point2Ds();
                        Point2D  gp1D     = new Point2D(PosX, PosY);
                        Point2D  gp2D     = new Point2D(PosZ, GroupIndex);
                        Point2Ds.Add(gp1D);
                        Point2Ds.Add(gp2D);

                        object sender = Point2Ds;
                        AddModelHandler(sender);

                        GeoPoint gp = new GeoPoint(PosX, PosY);
                        sender = gp;
                        if (CameraDataAdjustHandler != null)
                        {
                            CameraDataAdjustHandler(sender);
                        }
                    }
                }

                dataReader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #15
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //判断输入有效性
            if (string.IsNullOrWhiteSpace(cboDeviceStyle.Text))
            {
                MessageBox.Show("请输入类型");
                cboDeviceStyle.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(cboDeviceProducer.Text))
            {
                MessageBox.Show("请输入单位");
                cboDeviceStyle.Focus();
                return;
            }

            if (textSensorID.Text.Trim() == "")
            {
                MessageBox.Show("请输入设备ID!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSensorADR.Focus();
                return;
            }

            if (txtSensorADR.Text.Trim() == "")
            {
                MessageBox.Show("请输入地址!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSensorADR.Focus();
                return;
            }

            if (txtDTUID.Text.Trim() == "")
            {
                MessageBox.Show("请输入DTUID!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtDTUID.Focus();
                return;
            }


            //接收用户输入数据
            AddressBook address = new AddressBook()
            {
                Style    = cboDeviceStyle.Text,
                Company  = cboDeviceProducer.Text,
                SENSORID = textSensorID.Text,
                NOID     = txtSensorADR.Text,
                DTUId    = txtDTUID.Text
            };

            if (btnSave.Text.Equals("添加"))
            {
                // 查找
                int num = 0;  // 数据库操作结果

                try
                {
                    // 查询用的sql语句
                    string sql = string.Format("SELECT COUNT(*) FROM SensorDevice WHERE DEVICEID='{0}'",
                                               textSensorID.Text.Trim());
                    // 创建Command 对象
                    MySqlCommand command = MySQLDB.GetMySQLDB().giveCommand(sql);
                    num = Convert.ToInt32(command.ExecuteScalar());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "抱歉");
                }

                if (num == 1)  // 验证通过
                {
                    MessageBox.Show(("ID已注册!"), "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                try
                {
                    // 查询用的sql语句
                    string sql = string.Format("SELECT COUNT(*) FROM SensorDevice WHERE DEVICEID='{0}'",
                                               textSensorID.Text.Trim());
                    // 创建Command 对象
                    MySqlCommand command = MySQLDB.GetMySQLDB().giveCommand(sql);
                    num = Convert.ToInt32(command.ExecuteScalar());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "抱歉");
                }

                if (num == 1)  // 验证通过
                {
                    MessageBox.Show(("编号已注册!"), "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                try
                {
                    nModelIndex  = cboDeviceStyle.SelectedIndex;
                    strModelID   = textSensorID.Text;
                    strModelNOID = txtSensorADR.Text;

                    if (nModelIndex == 0)
                    {
                        UserHelper.ShuiZhunData ShuiZhunData = new UserHelper.ShuiZhunData();
                        ShuiZhunData.strNOID = strModelNOID;
                        strModelID           = "SZ" + strModelNOID;
                        UserHelper.ShuiZhunDataList.Add(new KeyValuePair <string, UserHelper.ShuiZhunData>(strModelID, ShuiZhunData));
                    }

                    if (nModelIndex == 1)
                    {
                        UserHelper.QINGJIAOData QINGJIAOData = new UserHelper.QINGJIAOData();
                        QINGJIAOData.strNOID = strModelNOID;
                        strModelID           = "QJ" + strModelNOID;
                        UserHelper.QINGJIAODataList.Add(new KeyValuePair <string, UserHelper.QINGJIAOData>(strModelID, QINGJIAOData));
                    }

                    if (nModelIndex == 2)
                    {
                        UserHelper.JIASUDUData JIASUDUData = new UserHelper.JIASUDUData();
                        JIASUDUData.strNOID = strModelNOID;
                        strModelID          = "JS" + strModelNOID;
                        UserHelper.JIASUDUDataList.Add(new KeyValuePair <string, UserHelper.JIASUDUData>(strModelID, JIASUDUData));
                    }

                    //构造insert语句
                    string sql = "INSERT INTO SensorDevice (DEVICEID,单位名称,类型,ADRNO,DTUID,POS_X,POS_Y,POS_Z) VALUES(@DEVICEID,@单位名称,@类型,@ADRNO,@DTUID,@POS_X,@POS_Y,@POS_Z)";
                    //构造sql语句的参数
                    MySqlParameter[] ps = //使用数组初始化器
                    {
                        new MySqlParameter("@DEVICEID", address.SENSORID),
                        new MySqlParameter("@单位名称",     address.Company),
                        new MySqlParameter("@类型",       address.Style),
                        new MySqlParameter("@ADRNO",    address.NOID),
                        new MySqlParameter("@DTUID",    address.DTUId),
                        new MySqlParameter("@POS_X",    m_point3D.X),
                        new MySqlParameter("@POS_Y",    m_point3D.Y),
                        new MySqlParameter("@POS_Z",    m_point3D.Z)
                    };
                    //执行插入操作
                    int index = MySQLDB.GetMySQLDB().ExecuteNonQuery(sql, ps);

                    //添加操作
                    if (index > 0)
                    {
                        LoadList();

                        //sql = "SELECT @@Identity FROM SensorDevice";  // 查询新增加的记录的标识号
                        //command.CommandText = sql;             // 重新指定 Command 对象的 SQL 语句
                        //Convert.ToInt32(command.ExecuteScalar());  // 强制类型转换会出错
                        MessageBox.Show("注册成功!");
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        MessageBox.Show("添加失败,请稍候重试");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "注册失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                //修改操作
                //构造sql语句及参数
                string           sql = "UPDATE SensorDevice SET DEVICEID=@DEVICEID,单位名称=@单位名称,类型=@类型,ADRNO=@ADRNO,DTUID=@DTUID WHERE DEVICEID=@DEVICEID";
                MySqlParameter[] ps  =
                {
                    new MySqlParameter("@DEVICEID", address.SENSORID),
                    new MySqlParameter("@单位名称",     address.Company),
                    new MySqlParameter("@类型",       address.Style),
                    new MySqlParameter("@ADRNO",    address.NOID),
                    new MySqlParameter("@DTUID",    address.DTUId)
                };
                //执行并返回
                int index = MySQLDB.GetMySQLDB().ExecuteNonQuery(sql, ps);
                if (index > 0)
                {
                    LoadList();
                }
                else
                {
                    MessageBox.Show("修改失败,请稍候重试");
                }
            }

            //恢复控件的值
            RestControls();
        }
Пример #16
0
 public void ConnectMySQL()
 {
     userIdTextBox.Text   = "root";
     passwordTextBox.Text = "123456";
     MySQLDB.GetMySQLDB().connect(SERVER, DATABASE, userIdTextBox.Text, passwordTextBox.Text);
 }