Exemplo n.º 1
0
 private void Btn_Confirm_Click(object sender, EventArgs e)
 {
     if (this.dateTime.Value != null && this.cbo_weather.Text != null && this.tbo_temperature.Text != null && this.tbo_wind.Text != null)
     {
         float temperature;
         if (float.TryParse(this.tbo_temperature.Text, out temperature))
         {
             DateTime           dt        = this.dateTime.Value;
             string             weather   = this.cbo_weather.Text.ToString();
             string             wind      = this.tbo_wind.Text;
             Client.MySqlHelper mysql     = new Client.MySqlHelper();
             string             sqlString = string.Format("INSERT INTO tb_weather SET time='{0}',weather='{1}',temperature={2},wind='{3}';", dt, weather, temperature, wind);
             try
             {
                 mysql.ExecuteNonQuery(sqlString);
                 WeatherDetail detail = new WeatherDetail();
                 detail.weather             = new Weather();
                 detail.wind                = new Wind();
                 detail.publish_time        = dt.ToString();
                 detail.weather.temperature = temperature;
                 detail.wind.power          = wind;
                 detail.weather.info        = weather;
                 WeatherUpdate.update(detail);
                 this.tbo_temperature.Text = "";
                 this.tbo_wind.Text        = "";
                 this.cbo_weather.Text     = "";
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.Message);
                 MessageBox.Show("写入数据库失败");
             }
         }
         else
         {
             MessageBox.Show("请输入正确温度");
         }
     }
     else
     {
         MessageBox.Show("请输入全部信息");
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="dgv"></param>
        public void SaveParam(DataGridView dgv)
        {
            DataTable dt_new = (dgv.DataSource as DataTable);

            if (IsCamFlag)//如果是摄像头参数
            {
                if (addFlag)
                {
                    int count = 0;
                    foreach (DataRow dr in dt_new.Rows)//获取已有行数
                    {
                        if (dr["ID"].ToString() != "")
                        {
                            count++;
                        }
                    }

                    if (count < dt_new.Rows.Count)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            string str = string.Format("UPDATE TB_PARAM SET CamID={0},Position='{1}',RTSPAdress='{2}',Url='{3}',UserName='******',Password='******',Port='{6}',VideoWidth='{7}',VideoHeight='{8}',Remarks='{9}',DensityThreshold={10} ,SpeedThresshold={11} WHERE ID={12}",
                                                       dt.Rows[i]["CamID"], dt.Rows[i]["Position"], dt.Rows[i]["RTSPAdress"], dt.Rows[i]["Url"], dt.Rows[i]["UserName"], dt.Rows[i]["Password"], dt.Rows[i]["Port"], dt.Rows[i]["VideoWidth"], dt.Rows[i]["VideoHeight"], dt.Rows[i]["Remarks"], dt.Rows[i]["DensityThreshold"], dt.Rows[i]["SpeedThresshold"], dt.Rows[i]["ID"]);
                            try
                            {
                                mysql.ExecuteNonQuery(str);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                MessageBox.Show("出现错误!");
                                break;
                            }
                        }

                        for (int i = count; i < dt_new.Rows.Count; i++)
                        {
                            string str = string.Format("INSERT INTO TB_PARAM (CamID,Position,RTSPAdress,Url,UserName,Password,Port,VideoWidth,VideoHeight,Remarks,DensityThreshold ,SpeedThresshold)VALUE('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", dt.Rows[i]["CamID"], dt.Rows[i]["Position"], dt.Rows[i]["RTSPAdress"], dt.Rows[i]["Url"], dt.Rows[i]["UserName"], dt.Rows[i]["Password"], dt.Rows[i]["Port"], dt.Rows[i]["VideoWidth"], dt.Rows[i]["VideoHeight"], dt.Rows[i]["Remarks"], dt.Rows[i]["DensityThreshold"], dt.Rows[i]["SpeedThresshold"]);
                            try
                            {
                                mysql.ExecuteNonQuery(str);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                MessageBox.Show("出现错误(保证DensityThreshold ,SpeedThresshold不为空)!");
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = count; i < dt_new.Rows.Count; i++)
                        {
                            string str = string.Format("UPDATE TB_PARAM SET CamID={0},Position='{1}',RTSPAdress='{2}',Url='{3}',UserName='******',Password='******',Port='{6}',VideoWidth='{7}',VideoHeight='{8}',Remarks='{9}' ,DensityThreshold={10} ,SpeedThresshold={11} WHERE ID={12}",
                                                       dt.Rows[i]["CamID"], dt.Rows[i]["Position"], dt.Rows[i]["RTSPAdress"], dt.Rows[i]["Url"], dt.Rows[i]["UserName"], dt.Rows[i]["Password"], dt.Rows[i]["Port"], dt.Rows[i]["VideoWidth"], dt.Rows[i]["VideoHeight"], dt.Rows[i]["Remarks"], dt.Rows[i]["DensityThreshold"], dt.Rows[i]["SpeedThresshold"], dt.Rows[i]["ID"]);

                            try
                            {
                                mysql.ExecuteNonQuery(str);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                MessageBox.Show("出现错误!");
                                break;
                            }
                        }
                    }
                }
                else if (deleteFlag)
                {
                    for (int i = 0; i < index_list.Count; i++)
                    {
                        string str = string.Format("DELETE FROM TB_PARAM WHERE ID={0}", index_list[i]);
                        try
                        {
                            mysql.ExecuteNonQuery(str);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            MessageBox.Show("出现错误!");
                            break;
                        }
                    }
                    index_list.Clear();
                }
                else
                {
                    for (int i = 0; i < dt_new.Rows.Count; i++)
                    {
                        string str = string.Format("UPDATE TB_PARAM SET CamID={0},Position='{1}',RTSPAdress='{2}',Url='{3}',UserName='******',Password='******',Port='{6}',VideoWidth='{7}',VideoHeight='{8}',Remarks='{9}' ,DensityThreshold={10} ,SpeedThresshold={11} WHERE ID={10}",
                                                   dt.Rows[i]["CamID"], dt.Rows[i]["Position"], dt.Rows[i]["RTSPAdress"], dt.Rows[i]["Url"], dt.Rows[i]["UserName"], dt.Rows[i]["Password"], dt.Rows[i]["Port"], dt.Rows[i]["VideoWidth"], dt.Rows[i]["VideoHeight"], dt.Rows[i]["Remarks"], dt.Rows[i]["DensityThreshold"], dt.Rows[i]["SpeedThresshold"], dt.Rows[i]["ID"]);
                        try
                        {
                            mysql.ExecuteNonQuery(str);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            MessageBox.Show("出现错误!");
                            break;
                        }
                    }
                }
            }
            else//如果是计算参数
            {
                if (addFlag)
                {
                    int count = 0;
                    foreach (DataRow dr in dt_new.Rows)//获取已有行数
                    {
                        if (dr["ID"].ToString() != "")
                        {
                            count++;
                        }
                    }

                    if (count < dt_new.Rows.Count)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            string str = string.Format("UPDATE TB_CACULATEPARAM SET CamID={0},StartPos_x='{1}',StartPos_y='{2}',EndPos_x='{3}',EndPos_y='{4}',StartNeg_x='{5}',StartNeg_y='{6}',EndNeg_x='{7}',EndNeg_y='{8}',CameraHeight='{9}',MeasureAngle='{10}',TiltAngle='{11}' WHERE ID={12}",
                                                       dt.Rows[i]["CamID"], dt.Rows[i]["StartPos_x"], dt.Rows[i]["StartPos_y"], dt.Rows[i]["EndPos_x"], dt.Rows[i]["EndPos_y"], dt.Rows[i]["StartNeg_x"], dt.Rows[i]["StartNeg_y"], dt.Rows[i]["EndNeg_x"], dt.Rows[i]["EndNeg_y"], dt.Rows[i]["CameraHeight"], dt.Rows[i]["MeasureAngle"], dt.Rows[i]["TiltAngle"], dt.Rows[i]["ID"]);
                            try
                            {
                                mysql.ExecuteNonQuery(str);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                MessageBox.Show("出现错误!");
                                break;
                            }
                        }

                        for (int i = count; i < dt_new.Rows.Count; i++)
                        {
                            string str = string.Format("INSERT INTO TB_CACULATEPARAM (CamID,StartPos_x,StartPos_y,EndPos_x,EndPos_y,StartNeg_x,StartNeg_y,EndNeg_x,EndNeg_y,CameraHeight,MeasureAngle,TiltAngle)VALUE({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", dt.Rows[i]["CamID"], dt.Rows[i]["StartPos_x"], dt.Rows[i]["StartPos_y"], dt.Rows[i]["EndPos_x"], dt.Rows[i]["EndPos_y"], dt.Rows[i]["StartNeg_x"], dt.Rows[i]["StartNeg_y"], dt.Rows[i]["EndNeg_x"], dt.Rows[i]["EndNeg_y"], dt.Rows[i]["CameraHeight"], dt.Rows[i]["MeasureAngle"], dt.Rows[i]["TiltAngle"]);
                            try
                            {
                                mysql.ExecuteNonQuery(str);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                MessageBox.Show("出现错误!");
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = count; i < dt_new.Rows.Count; i++)
                        {
                            string str = string.Format("INSERT INTO TB_CACULATEPARAM (CamID,StartPos_x,StartPos_y,EndPos_x,EndPos_y,StartNeg_x,StartNeg_y,EndNeg_x,EndNeg_y,CameraHeight,MeasureAngle,TiltAngle)VALUE({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", dt.Rows[i]["CamID"], dt.Rows[i]["StartPos_x"], dt.Rows[i]["StartPos_y"], dt.Rows[i]["EndPos_x"], dt.Rows[i]["EndPos_y"], dt.Rows[i]["StartNeg_x"], dt.Rows[i]["StartNeg_y"], dt.Rows[i]["EndNeg_x"], dt.Rows[i]["EndNeg_y"], dt.Rows[i]["CameraHeight"], dt.Rows[i]["MeasureAngle"], dt.Rows[i]["TiltAngle"]);
                            try
                            {
                                mysql.ExecuteNonQuery(str);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                MessageBox.Show("出现错误!");
                                break;
                            }
                        }
                    }
                }
                if (deleteFlag)
                {
                    for (int i = 0; i < index_list.Count; i++)
                    {
                        string str = string.Format("DELETE FROM TB_CACULATEPARAM WHERE ID={0}", index_list[i]);
                        try
                        {
                            mysql.ExecuteNonQuery(str);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            MessageBox.Show("出现错误!");
                            break;
                        }
                    }
                    index_list.Clear();
                }
            }
            CancelParam(dgv);
        }