Exemple #1
0
        private void btn_Input_Click(object sender, EventArgs e)
        {
            int reslut = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string         CountyCode    = DataBaseOperate.getCountyCode(dt.Rows[i][0].ToString());
                DateTime       MONITORTIME   = Convert.ToDateTime(dt.Rows[i][1]);
                string         CROP_CODE     = DataBaseOperate.get_CropCode(dt.Rows[i][2].ToString());
                string         nutrient_code = DataBaseOperate.get_NutrientCode(dt.Rows[i][3].ToString());
                float          value         = float.Parse(dt.Rows[i][4].ToString());
                SqlParameter[] param         = new SqlParameter[] {
                    new SqlParameter("@COUNTYCODE", CountyCode),
                    new SqlParameter("@MONITORTIME", MONITORTIME),
                    new SqlParameter("@CROP_CODE", CROP_CODE),
                    new SqlParameter("@NUTRIENT_CODE", nutrient_code),
                    new SqlParameter("@SOIL_NUTRIENT", value),
                    new SqlParameter("@RECORDTIME", DateTime.Now.ToShortDateString())
                };
                reslut = AggregateToCounty.insert_County_SOILNUTRIENT("insert_County_SOILNUTRIENT", param);
            }
            if (reslut > 0)
            {
                MessageBox.Show("数据库入库成功!");
            }
        }
        private void btn_calculation_Click(object sender, EventArgs e)
        {
            //开始汇总
            int           date_count = 0;
            List <string> date_list  = null;

            switch (lbl_tablename.Text)
            {
            case "WATERRETRIEVAL":
                //处在选择的时间范围内的天数
                date_count = DataBaseOperate.get_DateCount(dT_maize_s.Value, dT_maize_e.Value, "WATERRETRIEVAL_PLOT");
                //获取具体的时间列表
                date_list = DataBaseOperate.get_DateDetail(dT_maize_s.Value, dT_maize_e.Value, "WATERRETRIEVAL_PLOT");
                break;

            case "CHLOROPHYLLRETRIEVAL":
                date_count = DataBaseOperate.get_DateCount(dT_maize_s.Value, dT_maize_e.Value, "CHLOROPHYLLRETRIEVAL_PLOT");
                //获取具体的时间列表
                date_list = DataBaseOperate.get_DateDetail(dT_maize_s.Value, dT_maize_e.Value, "CHLOROPHYLLRETRIEVAL_PLOT");
                break;

            case "CROPYIELD":
                date_count = DataBaseOperate.get_DateCount(dT_maize_s.Value, dT_maize_e.Value, "CROPYIELD_PLOT");
                //获取具体的时间列表
                date_list = DataBaseOperate.get_DateDetail(dT_maize_s.Value, dT_maize_e.Value, "CROPYIELD_PLOT");
                break;

            case "MATUREPERIOD":
                date_count = DataBaseOperate.get_DateCount(dT_maize_s.Value, dT_maize_e.Value, "MATUREPERIOD_PLOT");
                //获取具体的时间列表
                date_list = DataBaseOperate.get_DateDetail(dT_maize_s.Value, dT_maize_e.Value, "MATUREPERIOD_PLOT");
                break;
            }

            //获取Countycount
            int Countycount = AggregateToCounty.getCountyCount();
            //获取具体的CountyCode
            List <string> CountyCode_list = AggregateToCounty.get_CountyCode();
            //获取CropCount
            int CropCount = DataBaseOperate.get_CropCount();
            //获取具体的CropCode
            List <string> CropCode_list = DataBaseOperate.get_CropCode();

            //开始汇总
            if (date_count != 0)
            {
                for (int i = 0; i < date_count; i++)        //datetime循环
                {
                    for (int j = 0; j < Countycount; j++)   //villagecode循环
                    {
                        for (int k = 0; k < CropCount; k++) //crop_count循环
                        {
                            //输入查询限制条件,执行存储过程
                            SqlParameter[] param = new SqlParameter[] {
                                new SqlParameter("@time", Convert.ToDateTime(date_list[i])),
                                new SqlParameter("@code", CropCode_list[k]),
                                new SqlParameter("@countycode", CountyCode_list[j]),
                                new SqlParameter("@sum_result", SqlDbType.Float)
                            };
                            param[3].Direction = ParameterDirection.Output;
                            string value = "";
                            switch (lbl_tablename.Text)
                            {
                            //计算汇总结果,并加入到datatable中
                            case "WATERRETRIEVAL":
                                value = AggregateToCounty.get_CountyValue("calc_county_WATERRETRIEVAL", param);
                                break;

                            case "CHLOROPHYLLRETRIEVAL":
                                value = AggregateToCounty.get_CountyValue("calc_county_CHLOROPHYLLRETRIEVAL", param);
                                break;

                            case "CROPYIELD":
                                value = AggregateToCounty.get_CountyValue("calc_county_CROPYIELD", param);
                                break;

                            case "MATUREPERIOD":
                                value = AggregateToCounty.get_CountyValue("calc_county_MATUREPERIOD", param);
                                break;
                            }
                            if (value != "")
                            {
                                DataRow row = dt.NewRow();
                                row["农场"]   = DataBaseOperate.getCountyName(CountyCode_list[j]);
                                row["监测时间"] = Convert.ToDateTime(date_list[i]).ToShortDateString();
                                row["作物类型"] = DataBaseOperate.get_CropCHName(CropCode_list[k]);
                                row["汇总结果"] = float.Parse(value);
                                row["汇总时间"] = DateTime.Now.ToShortDateString();
                                dt.Rows.Add(row);
                            }
                        }
                    }
                }
                if (dt.Rows.Count == 0)
                {
                    MessageBox.Show("请检查输入条件或统计数据!");
                }
                else
                {
                    dataGridView1.DataSource = dt;
                }
            }
            else
            {
                MessageBox.Show("此时间段内,没有统计数据!");
            }

            InitDataSet();
        }
Exemple #3
0
        private void btn_calculation_Click(object sender, EventArgs e)
        {
            int           date_count    = DataBaseOperate.get_DateCount(dT_maize_s.Value, dT_maize_e.Value, "SOILNUTRIENT_PLOT");
            List <string> date_list     = DataBaseOperate.get_DateDetail(dT_maize_s.Value, dT_maize_e.Value, "SOILNUTRIENT_PLOT");
            int           CropCount     = DataBaseOperate.get_CropCount();
            List <string> CropCode_list = DataBaseOperate.get_CropCode();
            int           nutrientCount = DataBaseOperate.get_NutrientCount();
            List <string> nutrient_list = DataBaseOperate.get_NutrientCode();
            //获取Countycount
            int Countycount = AggregateToCounty.getCountyCount();
            //获取具体的CountyCode
            List <string> CountyCode_list = AggregateToCounty.get_CountyCode();

            if (date_count != 0)
            {
                for (int i = 0; i < date_count; i++)        //datetime循环
                {
                    for (int j = 0; j < Countycount; j++)   //villagecode循环
                    {
                        for (int k = 0; k < CropCount; k++) //crop_count循环
                        {
                            for (int h = 0; h < nutrientCount; h++)
                            {
                                //输入查询限制条件,执行存储过程
                                SqlParameter[] param = new SqlParameter[] {
                                    new SqlParameter("@time", Convert.ToDateTime(date_list[i])),
                                    new SqlParameter("@code", CropCode_list[k]),
                                    new SqlParameter("@countycode", CountyCode_list[j]),
                                    new SqlParameter("@nutrient_code", nutrient_list[h]),
                                    new SqlParameter("@sum_result", SqlDbType.Float)
                                };
                                param[4].Direction = ParameterDirection.Output;
                                string value = AggregateToCounty.get_SoilCountyValue("calc_county_SOILNUTRIENT", param);
                                if (value != "")
                                {
                                    DataRow row = dt.NewRow();
                                    row["农场"]   = DataBaseOperate.getCountyName(CountyCode_list[j]);
                                    row["监测时间"] = Convert.ToDateTime(date_list[i]).ToShortDateString();
                                    row["作物类型"] = DataBaseOperate.get_CropCHName(CropCode_list[k]);
                                    row["养分类型"] = DataBaseOperate.get_NutrientCHName(nutrient_list[h]);
                                    row["汇总结果"] = float.Parse(value);
                                    row["汇总时间"] = DateTime.Now.ToShortDateString();
                                    dt.Rows.Add(row);
                                }
                            }
                        }
                    }
                }
                if (dt.Rows.Count == 0)
                {
                    MessageBox.Show("请检查输入条件或统计数据!");
                }
                else
                {
                    dataGridView1.DataSource = dt;
                }
            }

            else
            {
                MessageBox.Show("此时间段内,没有统计数据!");
            }

            InitDataSet();
        }
        //数据入库
        private void btn_Input_Click(object sender, EventArgs e)
        {
            int reslut = 0;

            SqlParameter[] param = null;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string   CountyCode  = DataBaseOperate.getCountyCode(dt.Rows[i][0].ToString());
                DateTime MONITORTIME = Convert.ToDateTime(dt.Rows[i][1]).Date;
                string   CROP_CODE   = DataBaseOperate.get_CropCode(dt.Rows[i][2].ToString());
                float    value       = float.Parse(dt.Rows[i][3].ToString());
                switch (lbl_tablename.Text)
                {
                case "WATERRETRIEVAL":
                    param = new SqlParameter[] {
                        new SqlParameter("@COUNTYCODE", CountyCode),
                        new SqlParameter("@MONITORTIME", MONITORTIME),
                        new SqlParameter("@CROP_CODE", CROP_CODE),
                        new SqlParameter("@WATERVALUE", value),
                        new SqlParameter("@RECORDTIME", DateTime.Now.ToShortDateString())
                    };
                    reslut = AggregateToCounty.insert_County("insert_County_WATERRETRIEVAL", param);
                    break;

                case "CHLOROPHYLLRETRIEVAL":
                    param = new SqlParameter[] {
                        new SqlParameter("@COUNTYCODE", CountyCode),
                        new SqlParameter("@MONITORTIME", MONITORTIME),
                        new SqlParameter("@CROP_CODE", CROP_CODE),
                        new SqlParameter("@CHLOROPHYLLVALUE", value),
                        new SqlParameter("@RECORDTIME", DateTime.Now.ToShortDateString())
                    };
                    reslut = AggregateToCounty.insert_County("insert_County_CHLOROPHYLLRETRIEVAL", param);
                    break;

                case "CROPYIELD":
                    param = new SqlParameter[] {
                        new SqlParameter("@COUNTYCODE", CountyCode),
                        new SqlParameter("@MONITORTIME", MONITORTIME),
                        new SqlParameter("@CROP_CODE", CROP_CODE),
                        new SqlParameter("@CROP_YIELD", value),
                        new SqlParameter("@RECORDTIME", DateTime.Now.ToShortDateString())
                    };
                    reslut = AggregateToCounty.insert_County("insert_County_CROPYIELD", param);
                    break;

                case "MATUREPERIOD":
                    param = new SqlParameter[] {
                        new SqlParameter("@COUNTYCODE", CountyCode),
                        new SqlParameter("@MONITORTIME", MONITORTIME),
                        new SqlParameter("@CROP_CODE", CROP_CODE),
                        new SqlParameter("@MATURE_PERIOD", value),
                        new SqlParameter("@RECORDTIME", DateTime.Now.ToShortDateString())
                    };
                    reslut = AggregateToCounty.insert_County("insert_County_MATUREPERIOD", param);
                    break;
                }
            }
            if (reslut > 0)
            {
                MessageBox.Show("数据库入库成功!");
            }
        }