Esempio n. 1
0
        //转换表中的值
        public static DataTable convert_TableValue(string rankname, string typename, DataTable dt)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                switch (rankname)
                {
                case "PLOT":
                    dt.Rows[i][0] = DataBaseOperate.get_PlotName(dt.Rows[i][0].ToString());
                    break;

                case "COUNTY":
                    dt.Rows[i][0] = DataBaseOperate.getCountyName(dt.Rows[i][0].ToString());
                    break;

                case "VILLAGE":
                    dt.Rows[i][0] = DataBaseOperate.getVillName(dt.Rows[i][0].ToString());
                    break;

                case "TOWN":
                    dt.Rows[i][0] = DataBaseOperate.getTownName(dt.Rows[i][0].ToString());
                    break;
                }
                dt.Rows[i][2] = DataBaseOperate.get_CropCHName(dt.Rows[i][2].ToString());

                if (!typename.Contains("SOILNUTRIENT"))
                {
                    if (!string.IsNullOrEmpty(dt.Rows[i][3].ToString()))
                    {
                        dt.Rows[i][3] = Math.Round(Convert.ToDecimal(dt.Rows[i][3].ToString()), 3);
                    }
                }
                else
                {
                    dt.Rows[i][3] = DataBaseOperate.get_NutrientCHName(dt.Rows[i][3].ToString());
                    if (!string.IsNullOrEmpty(dt.Rows[i][4].ToString()))
                    {
                        dt.Rows[i][4] = Math.Round(Convert.ToDecimal(dt.Rows[i][4].ToString()), 3);
                    }
                }
            }

            return(dt);
        }
Esempio n. 2
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_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();
        }