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

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string         TownCode      = DataBaseOperate.getTownCode(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("@TOWNCODE", TownCode),
                    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 = AggregateToTown.insert_Town_SOILNUTRIENT("insert_town_SOILNUTRIENT", param);
            }
            if (reslut > 0)
            {
                MessageBox.Show("数据库入库成功!");
            }
        }
        private void btn_calculation_Click(object sender, EventArgs e)
        {
            date_count = DataBaseOperate.get_DateCount(dT_maize_s.Value, dT_maize_e.Value, "SOILNUTRIENT_PLOT");
            date_list  = DataBaseOperate.get_DateDetail(dT_maize_s.Value, dT_maize_e.Value, "SOILNUTRIENT_PLOT");
            //获取Towncount
            TownCount = AggregateToTown.get_TownCount();
            //获取具体的TownCode
            TownCode_list = AggregateToTown.get_TownCode();
            CropCount     = DataBaseOperate.get_CropCount();
            CropCode_list = DataBaseOperate.get_CropCode();
            nutrientCount = DataBaseOperate.get_NutrientCount();
            nutrient_list = DataBaseOperate.get_NutrientCode();
            if (date_count != 0)
            {
                for (int i = 0; i < date_count; i++)        //datetime循环
                {
                    for (int j = 0; j < TownCount; 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("@towncode", TownCode_list[j]),
                                    new SqlParameter("@nutrient_code", nutrient_list[h]),
                                    new SqlParameter("@sum_result", SqlDbType.Float)
                                };
                                param[4].Direction = ParameterDirection.Output;
                                string value = AggregateToTown.get_SoilTownValue("calc_Town_SOILNUTRIENT", param);
                                if (value != "")
                                {
                                    DataRow row = dt.NewRow();
                                    row["作业区"]  = DataBaseOperate.getTownName(TownCode_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();
        }
Esempio n. 3
0
        //汇总
        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;
            }

            //获取Towncount
            int TownCount = AggregateToTown.get_TownCount();
            //获取具体的TownCode
            List <string> TownCode_list = AggregateToTown.get_TownCode();
            //获取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 < TownCount; 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("@towncode", TownCode_list[j]),
                                new SqlParameter("@sum_result", SqlDbType.Float)
                            };
                            param[3].Direction = ParameterDirection.Output;
                            string value = "";
                            switch (lbl_tablename.Text)
                            {
                            //计算汇总结果,并加入到datatable中
                            case "WATERRETRIEVAL":
                                value = AggregateToTown.get_TownValue("calc_town_WATERRETRIEVAL", param);
                                break;

                            case "CHLOROPHYLLRETRIEVAL":
                                value = AggregateToTown.get_TownValue("calc_town_CHLOROPHYLLRETRIEVAL", param);
                                break;

                            case "CROPYIELD":
                                value = AggregateToTown.get_TownValue("calc_town_CROPYIELD", param);
                                break;

                            case "MATUREPERIOD":
                                value = AggregateToTown.get_TownValue("calc_town_MATUREPERIOD", param);
                                break;
                            }
                            if (value != "")
                            {
                                DataRow row = dt.NewRow();
                                row["作业区"]  = DataBaseOperate.getTownName(TownCode_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();
        }
Esempio n. 4
0
        //数据入库
        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   TownCode    = DataBaseOperate.getTownCode(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("@TOWNCODE", TownCode),
                        new SqlParameter("@MONITORTIME", MONITORTIME),
                        new SqlParameter("@CROP_CODE", CROP_CODE),
                        new SqlParameter("@WATERVALUE", value),
                        new SqlParameter("@RECORDTIME", DateTime.Now.ToShortDateString())
                    };
                    reslut = AggregateToTown.insert_Town("insert_Town_WATERRETRIEVAL", param);
                    break;

                case "CHLOROPHYLLRETRIEVAL":
                    param = new SqlParameter[] {
                        new SqlParameter("@TOWNCODE", TownCode),
                        new SqlParameter("@MONITORTIME", MONITORTIME),
                        new SqlParameter("@CROP_CODE", CROP_CODE),
                        new SqlParameter("@CHLOROPHYLLVALUE", value),
                        new SqlParameter("@RECORDTIME", DateTime.Now.ToShortDateString())
                    };
                    reslut = AggregateToTown.insert_Town("insert_Town_CHLOROPHYLLRETRIEVAL", param);
                    break;

                case "CROPYIELD":
                    param = new SqlParameter[] {
                        new SqlParameter("@TOWNCODE", TownCode),
                        new SqlParameter("@MONITORTIME", MONITORTIME),
                        new SqlParameter("@CROP_CODE", CROP_CODE),
                        new SqlParameter("@CROP_YIELD", value),
                        new SqlParameter("@RECORDTIME", DateTime.Now.ToShortDateString())
                    };
                    reslut = AggregateToTown.insert_Town("insert_Town_CROPYIELD", param);
                    break;

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