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_Chart_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(rankCHname)) { typename = DataManager.get_TableEName(cmb_Type.SelectedItem.ToString()); tablename = typename + "_" + rankname; if (!tablename.Contains("SOILNUTRIENT")) { ChartObject co = new ChartObject(); co.cropcode = DataBaseOperate.get_CropCode(cmbCropType.SelectedItem.ToString()); co.datemin = dT_maize_s.Value; co.datemax = dT_maize_e.Value; co.treeNodeEName = treeNodeEName; co.chartType = cmb_ChartType.SelectedItem.ToString(); BindDataSource(co); } else { ChartObject co = new ChartObject(); co.cropcode = DataBaseOperate.get_CropCode(cmbCropType.SelectedItem.ToString()); co.datemin = dT_maize_s.Value; co.datemax = dT_maize_e.Value; co.treeNodeEName = treeNodeEName; co.nutrientcode = DataBaseOperate.get_NutrientCode(cmb_Nutrient.SelectedItem.ToString()); co.chartType = cmb_ChartType.SelectedItem.ToString(); BindSoilDataSource(co); } InitDataSet(); } else { MessageBox.Show("请选择监测类型!"); } }
/// <summary> /// 返回满足查询条件的Soil数据表 /// </summary> /// <param name="tablename"></param> /// <param name="cropcode"></param> /// <returns></returns> public static DataTable get_SelectSoilResult(string tablename, string cropName, string nutrientName, DateTime date1, DateTime date2) { string cropcode = DataBaseOperate.get_CropCode(cropName); string nutrient = DataBaseOperate.get_NutrientCode(nutrientName); string strsql = string.Format("select * from {0} where CROP_CODE='{1}' and NUTRIENT_CODE='{2}' and MONITORTIME between '{3}' and '{4}'", tablename, cropcode, nutrient, date1, date2); return(return_DataTable(strsql)); }
public static DataTable getSoilPlotSelectResult(string tablename, string cropName, string nutrientName, DateTime date1, DateTime date2, string Villagename) { string cropcode = DataBaseOperate.get_CropCode(cropName); string nutrient = DataBaseOperate.get_NutrientCode(nutrientName); string Villagecode = DataBaseOperate.getVillCode(Villagename); string strsql = string.Format("select * from {0} where CROP_CODE='{1}' and NUTRIENT_CODE='{2}' and MONITORTIME between '{3}' and '{4}' and PLOTID in (select PlotID from PLOT_DKINFO where JMZ='{5}')", tablename, cropcode, nutrient, date1, date2, Villagecode); return(return_DataTable(strsql)); }
public static DataTable get_VillageSoilResult(string tablename, string cropName, string nutrientName, DateTime date1, DateTime date2, string townname) { string cropcode = DataBaseOperate.get_CropCode(cropName); string nutrient = DataBaseOperate.get_NutrientCode(nutrientName); string towncode = DataBaseOperate.getTownCode(townname); string strsql = string.Format("select * from {0} where CROP_CODE='{1}' and NUTRIENT_CODE='{2}' and MONITORTIME between '{3}' and '{4}' and VILLAGECODE in (select VillCode from VILLAGE where TowCode='{5}')", tablename, cropcode, nutrient, date1, date2, towncode); return(return_DataTable(strsql)); }
public Dictionary <string, string> return_Dicts(List <string> list_value) { Dictionary <string, string> dicts = new Dictionary <string, string>(); string column1 = ""; switch (rankname) { case "PLOT": column1 = DataBaseOperate.get_PlotCodeName(list_value[0]); break; case "COUNTY": column1 = DataBaseOperate.getCountyCode(list_value[0]); break; case "VILLAGE": column1 = DataBaseOperate.getVillCode(list_value[0]); break; case "TOWN": column1 = DataBaseOperate.getTownCode(list_value[0]); break; } dicts.Add(DataManager.get_TableEName(dataGridView1.Columns[0].Name), column1); dicts.Add(DataManager.get_TableEName(dataGridView1.Columns[1].Name), list_value[1]); dicts.Add(DataManager.get_TableEName(dataGridView1.Columns[2].Name), DataBaseOperate.get_CropCode(list_value[2])); if (tablename.Contains("SOILNUTRIENT")) { dicts.Add(DataManager.get_TableEName(dataGridView1.Columns[3].Name), DataBaseOperate.get_NutrientCode(list_value[3])); dicts.Add(DataManager.get_TableEName(dataGridView1.Columns[4].Name), list_value[4]); } else { dicts.Add(DataManager.get_TableEName(dataGridView1.Columns[3].Name), list_value[3]); } return(dicts); }
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(); }