public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //省Num int ProvinceNum = Convert.ToInt32(context.Request["ProvinceDropdown"]); //县Num int CountryNum = Convert.ToInt32(context.Request["CountryDropdown"]); // int NutrientDivide = Convert.ToInt32(context.Request["NutrientDivideDropdown"]); BLL.FarmlandMeg newFarmlandMegBll = new BLL.FarmlandMeg(); List <Model.FarmlandMeg> newFarmlandMegModel = new List <Model.FarmlandMeg>(); //获取到符合条件的集合并返回 GetListSoilAllInfo(ProvinceNum, CountryNum); //GetListSoilAllInfo(21, 198); //创建序列化对象 JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer(); //转换成JSON字符串 var dataStr = JavaScriptSerializer.Serialize(ListSoilAllInfo); context.Response.Write(dataStr); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; StringBuilder sb = new StringBuilder(); sb.AppendFormat("<option value='{0}'>{1}</option>", -1, "全选"); //获取到城市的id int cId = int.Parse(context.Request["cId"] ?? "1"); BLL.FarmlandMeg newFarmlandMegBll = new BLL.FarmlandMeg(); //获取表中该城市下存在的区/县 DataSet newFarmlandMegAllList = newFarmlandMegBll.GetList("City = " + cId); //遍历DataSet foreach (DataTable dt in newFarmlandMegAllList.Tables) { List <Model.FarmlandMeg> FarmlandMegList = newFarmlandMegBll.DataTableToList(dt); List <int> existCountry = new List <int>(); //遍历List中的FarmlandMeg foreach (SoilNutrientSoft.Model.FarmlandMeg FM in FarmlandMegList) { //判断是否存在该区/县 if (!existCountry.Contains(Convert.ToInt32(FM.County))) { //获取到区/县ID int CountryNum = Convert.ToInt32(FM.County); BLL.Areas newAreasBll = new BLL.Areas(); List <Model.Areas> newAreasModelList = newAreasBll.GetModelList("AreaID = " + CountryNum); foreach (SoilNutrientSoft.Model.Areas item in newAreasModelList) { //如果不存在该区/县,就将其添加 sb.AppendFormat("<option value='{0}'>{1}</option>", item.AreaID, item.AreaName); } //将其添加至已存List中 existCountry.Add(CountryNum); } } } context.Response.Write(sb.ToString()); }
public void ProcessRequest(HttpContext context) { Dictionary <SqlConnection, SqlTransaction> MyDict = new Dictionary <SqlConnection, SqlTransaction>(); //用在处理存储表单的事物的时候判断是否完毕 List <int> LFormTimes = new List <int>(); LFormTimes.Add(0); //第一张表单 农田信息数据录入后返回的最大id int getMaxId = 0; //第一张表单 农田信息数据录入返回的结果值 int resultNumFLM = 0; #region 第一张表单 农田信息 Model.FarmlandMeg newFarmlandMegModel = new Model.FarmlandMeg(); try { newFarmlandMegModel.City = context.Request["city"]; newFarmlandMegModel.County = context.Request["country"]; newFarmlandMegModel.Town = context.Request["townName"]; newFarmlandMegModel.Village = context.Request["villageName"]; newFarmlandMegModel.Sample_name = context.Request["SampleName"]; newFarmlandMegModel.Lon = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["LongitudeDegree"]) ? "0" : context.Request["LongitudeDegree"]) + Convert.ToDecimal(String.IsNullOrEmpty(context.Request["LongitudeMinute"]) ? "0" : context.Request["LongitudeMinute"]) / (decimal)60.0 + Convert.ToDecimal(String.IsNullOrEmpty(context.Request["LongitudeSecond"]) ? "0" : context.Request["LongitudeSecond"]) / (decimal)3600.0; newFarmlandMegModel.Lat = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["LatitudeDegree"]) ? "0" : context.Request["LatitudeDegree"]) + Convert.ToDecimal(String.IsNullOrEmpty(context.Request["LatitudeMinute"]) ? "0" : context.Request["LatitudeMinute"]) / (decimal)60.0 + Convert.ToDecimal(String.IsNullOrEmpty(context.Request["LatitudeSecond"]) ? "0" : context.Request["LatitudeSecond"]) / (decimal)3600.0; newFarmlandMegModel.Name_of_householder = context.Request["NameOfHouseholder"]; newFarmlandMegModel.Phone_number = context.Request["PhoneNumber"]; newFarmlandMegModel.Irrigation_Conditions = Convert.ToInt32(String.IsNullOrEmpty(context.Request["IrrigationConditions"]) ? "1" : context.Request["IrrigationConditions"]); newFarmlandMegModel.Acreage = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["Acreage"]) ? "0" : context.Request["Acreage"]); //int.Parse(context.Request["Acreage"]); newFarmlandMegModel.Fertility = Convert.ToInt32(String.IsNullOrEmpty(context.Request["Fertility"]) ? "1" : context.Request["Fertility"]); newFarmlandMegModel.Weeds = context.Request["Weeds"]; //需要先将农田信息写入数据库 //然后返回农田信息表中的最大ID给其他三张表的All_id使用 //以建立四张表的联系 BLL.FarmlandMeg newFarmlandMegBLL = new BLL.FarmlandMeg(); //提交数据,返回插入的id resultNumFLM = newFarmlandMegBLL.Add(newFarmlandMegModel, MyDict); if (resultNumFLM > 0) { //表示农田信息表单成功录入 //该表中的最大id getMaxId = resultNumFLM; // newFarmlandMegBLL.GetMaxId()-1; } else { context.Response.Write("农田信息表单数据录入失败"); //将信息返回给客户端,停止该页的执行 context.Response.End(); } } catch (Exception E) { //如有异常 将异常信息返回 context.Response.Write(E.Message); //将信息返回给客户端,停止该页的执行 context.Response.End(); } #endregion if (getMaxId <= 0) { //如果getMaxId<=0表示第一张表插入失败 context.Response.Write("信息录入失败"); //将信息返回给客户端,停止该页的执行 context.Response.End(); } else { try { #region 第二张表单 土壤养分信息 Model.SoilNutrientMeg newSoilNutrientMegModel = new Model.SoilNutrientMeg(); newSoilNutrientMegModel.N = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["N_SoilNutrient"]) ? "0" : context.Request["N_SoilNutrient"]); newSoilNutrientMegModel.P = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["P_SoilNutrient"]) ? "0" : context.Request["P_SoilNutrient"]); newSoilNutrientMegModel.K = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["K_SoilNutrient"]) ? "0" : context.Request["K_SoilNutrient"]); newSoilNutrientMegModel.HydrolyticN = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["HydrolyticN_SoilNutrient"]) ? "0" : context.Request["HydrolyticN_SoilNutrient"]); newSoilNutrientMegModel.QuickP = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["QuickP_SoilNutrient"]) ? "0" : context.Request["QuickP_SoilNutrient"]); newSoilNutrientMegModel.QUicK = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["QuickK_SoilNutrient"]) ? "0" : context.Request["QuickK_SoilNutrient"]); newSoilNutrientMegModel.OrganicMatter = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["OrganicMatter_SoilNutrient"]) ? "0" : context.Request["OrganicMatter_SoilNutrient"]); newSoilNutrientMegModel.PH = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["PH_SoilNutrient"]) ? "0" : context.Request["PH_SoilNutrient"]); newSoilNutrientMegModel.All_id = getMaxId; //土壤养分信息录入 BLL.SoilNutrientMeg newSoilNutrientMegBll = new BLL.SoilNutrientMeg(); int resultNumSoil = newSoilNutrientMegBll.Add(newSoilNutrientMegModel, MyDict); #endregion #region 第三张表 作物信息 Model.CropsMeg newCropsMegModel = new Model.CropsMeg(); newCropsMegModel.CropType = context.Request["CropType_CropInfo"]; newCropsMegModel.Varieties = context.Request["Varieties_CropInfo"]; newCropsMegModel.Yield = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["Yield_CropInfo"]) ? "0" : context.Request["Yield_CropInfo"]); newCropsMegModel.urea = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["urea_CropInfo"]) ? "0" : context.Request["urea_CropInfo"]); newCropsMegModel.An = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["An_CropInfo"]) ? "0" : context.Request["An_CropInfo"]); newCropsMegModel.K = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["K_CropInfo"]) ? "0" : context.Request["K_CropInfo"]); newCropsMegModel.Organic_manure = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["Organic_manure_CropInfo"]) ? "0" : context.Request["Organic_manure_CropInfo"]); newCropsMegModel.Others = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["Others_CropInfo"]) ? "0" : context.Request["Others_CropInfo"]); newCropsMegModel.Irrigation_times = Convert.ToInt32(String.IsNullOrEmpty(context.Request["Irrigation_times"]) ? "0" : context.Request["Irrigation_times_CropInfo"]); newCropsMegModel.All_id = getMaxId; //作物信息录入 BLL.CropsMeg newCropsMegBll = new BLL.CropsMeg(); int resultNumCrops = newCropsMegBll.Add(newCropsMegModel, MyDict); #endregion #region 第四张表 农田管理建议 Model.FarmlandMSug newFarmlandMSugModel = new Model.FarmlandMSug(); newFarmlandMSugModel.CropType = context.Request["CropType_ManaSug"]; newFarmlandMSugModel.Varieties = context.Request["Varieties_ManaSug"]; newFarmlandMSugModel.TargetYield = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["TargetYield_ManaSug"]) ? "0" : context.Request["TargetYield_ManaSug"]); newFarmlandMSugModel.urea = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["urea_ManaSug"]) ? "0" : context.Request["urea_ManaSug"]); newFarmlandMSugModel.An = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["An_ManaSug"]) ? "0" : context.Request["An_ManaSug"]); newFarmlandMSugModel.K = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["K_ManaSug"]) ? "0" : context.Request["K_ManaSug"]); newFarmlandMSugModel.OrganicManure = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["Organic_manure_ManaSug"]) ? "0" : context.Request["Organic_manure_ManaSug"]); newFarmlandMSugModel.Others = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["Others_ManaSug"]) ? "0" : context.Request["Others_ManaSug"]); newFarmlandMSugModel.IrrigationTimes = Convert.ToInt32(String.IsNullOrEmpty(context.Request["Irrigation_times_ManaSug"]) ? "0" : context.Request["Irrigation_times_ManaSug"]); newFarmlandMSugModel.SowingAmount = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["SowingAmount_ManaSug"]) ? "0" : context.Request["SowingAmount_ManaSug"]); newFarmlandMSugModel.SowingMethod = context.Request["SowingMethod_ManaSug"]; newFarmlandMSugModel.WeedControl = context.Request["WeedControl_ManaSug"]; newFarmlandMSugModel.PestControl = context.Request["PestControl_ManaSug"]; newFarmlandMSugModel.FieldManagement = context.Request["FieldManagement_ManaSug"]; newFarmlandMSugModel.Remarks = context.Request["Remarks_ManaSug"]; newFarmlandMSugModel.All_id = getMaxId; //录入 农田管理建议 BLL.FarmlandMSug newFarmlandMSugBll = new BLL.FarmlandMSug(); int resultFLMS = newFarmlandMSugBll.Add(newFarmlandMSugModel, MyDict); #endregion //判断四张表是否都插入 if (resultFLMS > 0 && resultNumCrops > 0 && resultNumFLM > 0 && resultNumSoil > 0) { context.Response.Write("ok"); } else { context.Response.Write("信息录入失败"); } } catch (Exception E) { //如有异常 将异常信息返回 context.Response.Write(E.Message); //将信息返回给客户端,停止该页的执行 context.Response.End(); } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //ProvinceDropdown:-1 //CountryDropdown:-1 //NutrientDivideDropdown:1 //ProvinceDropdown:3 //CountryDropdown:49 //NutrientDivideDropdown:4 int ProvinceNum = Convert.ToInt32(context.Request["ProvinceDropdown"]); int CountryNum = Convert.ToInt32(context.Request["CountryDropdown"]); int NutrientDivide = Convert.ToInt32(context.Request["NutrientDivideDropdown"]); BLL.FarmlandMeg newFarmlandMegBll = new BLL.FarmlandMeg(); List <Model.FarmlandMeg> newFarmlandMegModel = new List <Model.FarmlandMeg>(); string selectStr = ""; //查询到满足条件的集合 if (ProvinceNum == -1 && CountryNum == -1) { //表示所有都全选 selectStr = " 0 = 0 "; } else if (ProvinceNum >= 0 && CountryNum == -1) { //表示只有“区县”全选 selectStr = " City = " + ProvinceNum; } else { // selectStr = " City = " + ProvinceNum + " and County = " + CountryNum; } newFarmlandMegModel = newFarmlandMegBll.GetModelList(selectStr); //遍历List集合 BLL.SoilNutrientMeg newSoilNutrientMegBll = new BLL.SoilNutrientMeg(); Model.SoilNutrientMeg newSoilNutrientMegModel = new Model.SoilNutrientMeg(); //获取最终数据结果 List <SoilNutrientMegList> newSoilNutrientMegList = new List <SoilNutrientMegList>(); foreach (var item in newFarmlandMegModel) { //获取id int id = item.Id; //获取土壤养分信息表的模板 newSoilNutrientMegModel = newSoilNutrientMegBll.GetModelList(" All_id = " + id)[0]; newSoilNutrientMegList.Add(new SoilNutrientMegList() { sampleName = item.Sample_name, N = Convert.ToDouble(newSoilNutrientMegModel.N), P = Convert.ToDouble(newSoilNutrientMegModel.P), K = Convert.ToDouble(newSoilNutrientMegModel.K), HydrolyticN = Convert.ToDouble(newSoilNutrientMegModel.HydrolyticN), QuickP = Convert.ToDouble(newSoilNutrientMegModel.QuickP), QUicK = Convert.ToDouble(newSoilNutrientMegModel.QUicK), OrganicMatter = Convert.ToDouble(newSoilNutrientMegModel.OrganicMatter), PH = Convert.ToDouble(newSoilNutrientMegModel.PH) }); } //创建序列化对象 JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer(); //转换成JSON字符串 var dataStr = JavaScriptSerializer.Serialize(newSoilNutrientMegList); context.Response.Write(dataStr); }
public void ProcessRequest(HttpContext context) { Dictionary <SqlConnection, SqlTransaction> MyDict = new Dictionary <SqlConnection, SqlTransaction>(); try { context.Response.ContentType = "text/plain"; //获取要删除的表的id int id = Convert.ToInt32(context.Request["Id"]); BLL.FarmlandMeg newFarmlandMegBll = new BLL.FarmlandMeg(); //删除操作 bool resultFarmlandMeg = newFarmlandMegBll.Delete(id, MyDict); BLL.SoilNutrientMeg newSoilNutrientMegBll = new BLL.SoilNutrientMeg(); List <Model.SoilNutrientMeg> newSoilNutrientMegModelList = newSoilNutrientMegBll.GetModelList(" All_id = " + id); bool resultSoilNutrientMeg = newSoilNutrientMegBll.Delete(newSoilNutrientMegModelList[0].Id, MyDict); BLL.CropsMeg newCropsMegBll = new BLL.CropsMeg(); List <Model.CropsMeg> newCropsMegModelList = newCropsMegBll.GetModelList(" All_id = " + id); bool resultCropsMeg = newCropsMegBll.Delete(newCropsMegModelList[0].Id, MyDict); BLL.FarmlandMSug newFarmlandMSugBll = new BLL.FarmlandMSug(); List <Model.FarmlandMSug> newFarmlandMSugModelList = newFarmlandMSugBll.GetModelList(" All_id = " + id); bool resultFarmlandMSug = newFarmlandMSugBll.Delete(newFarmlandMSugModelList[0].Id, MyDict); BLL.Picture newPictureBll = new BLL.Picture(); List <Model.Picture> newPictureModelList = newPictureBll.GetModelList(" All_id = " + id); List <bool> resultPictureList = new List <bool>(); //判断是否存在图片 if (newPictureModelList.Count > 0) { //用于存储图片绝对路径的集合 List <String> filesPath = new List <string>(); //如果存在将其删除 foreach (Model.Picture Pic in newPictureModelList) { Model.Picture newPictureModel = newPictureBll.GetModel(Pic.Id); //图片相对路径 string picPath = newPictureModel.picturePath; //图片绝对路径 string absolutePath = context.Request.MapPath(picPath); //将绝对路径添加到集合中 filesPath.Add(absolutePath); //将删除结果累计添加到集合中 resultPictureList.Add(newPictureBll.Delete(Pic.Id, MyDict)); } //删除图片操作 foreach (String path in filesPath) { if (File.Exists(path)) { //如果文件存在,则删除 File.Delete(path); } } } if (resultFarmlandMeg && resultSoilNutrientMeg && resultFarmlandMSug && resultCropsMeg && !resultPictureList.Contains(false)) { context.Response.Write("ok"); } else { context.Response.Write("删除失败"); } QuitConnTrans(MyDict); } catch (Exception E) { ExceptionQuitConnTrans(MyDict); //如有异常 将异常信息返回 context.Response.Write(E.Message); //将信息返回给客户端,停止该页的执行 context.Response.End(); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; StringBuilder newSb = new StringBuilder(); newSb.Append("["); //农田信息对象 BLL.FarmlandMeg newFarmlandMeg = new BLL.FarmlandMeg(); //需要的数据集合 DataSet st = newFarmlandMeg.GetAllList(); //遍历每张表 foreach (DataTable item in st.Tables) { //将表转换成集合 List <Model.FarmlandMeg> FarmlandMegList = newFarmlandMeg.DataTableToList(item); //用于检测是否已经加载过该市的节点 防止多个相同的“市”节点出现 List <int> existNum = new List <int>(); //遍历表集合 int idNum = 1; foreach (var data in FarmlandMegList) { //地域对象 BLL.Areas newAreas = new BLL.Areas(); //获取城市对应的ID int cityNum = int.Parse(data.City); //判断该城市是否已经加载,如果已经加载则无需重复加载 if (!existNum.Contains(cityNum)) { //将表中的城市加到集合中 existNum.Add(cityNum); newSb.Append("{"); newSb.AppendFormat("\"tags\":[\"-1\"],", idNum); //获取地域数据 DataTable d = newAreas.GetList(" AreaID = " + cityNum).Tables[0]; List <Model.Areas> newAerasModel = newAreas.DataTableToList(d); string cityName = newAerasModel[0].AreaName; //节点名称 newSb.AppendFormat("\"text\":\"{0}\",", cityName); newSb.Append("\"state\":{\"backColor\": \"#428BCA\"},"); //子节点集合 newSb.Append("\"nodes\":["); //如果集合中不存在该数就继续加载数据 //获取同一个市下的县区 DataSet newSameCity = newFarmlandMeg.GetList("City=" + cityNum); foreach (DataTable countryTable in newSameCity.Tables) { // 县/区 同一个城市下的县区集合 List <Model.FarmlandMeg> countriesList = newFarmlandMeg.DataTableToList(countryTable); int countryIdNum = 1; //用于检测是否已经加载过该市的节点 防止多个相同的“区/县”节点出现 List <int> exitCountry = new List <int>(); foreach (var country in countriesList) { //判断是否添加过该 县/区 if (!exitCountry.Contains(Convert.ToInt32(country.County))) { exitCountry.Add(Convert.ToInt32(country.County)); newSb.Append("{"); //通过区县 获取地域数据 DataTable areasCountry = newAreas.GetList(" AreaID = " + country.County).Tables[0]; List <Model.Areas> areasCountryList = newAreas.DataTableToList(areasCountry); //区县名称 string countryName = areasCountryList[0].AreaName; //newSb.Append("\"id\":" + idNum.ToString() + countryIdNum.ToString() + ","); newSb.AppendFormat("\"tags\":[\"-1\"],", idNum.ToString() + countryIdNum.ToString()); //newSb.Append("\"state\":{\"expanded\": \"false\"},"); newSb.AppendFormat("\"text\":\"{0}\",", countryName); newSb.Append("\"nodes\":["); //获取同一个市区下的集合 DataTable townTable = newFarmlandMeg.GetList(" City= " + cityNum + " and County= " + country.County).Tables[0]; List <Model.FarmlandMeg> townList = newFarmlandMeg.DataTableToList(townTable); //int townNum = 1; foreach (var key in townList) { newSb.Append("{"); string sampleName = key.Sample_name; string townId = key.Id.ToString(); //newSb.Append("\"id\":" + idNum.ToString() + countryIdNum.ToString() + townNum.ToString()+ ","); //newSb.AppendFormat("\"id\":\"{0}\",", idNum.ToString() + countryIdNum.ToString() + townNum.ToString()); //将数据库中的id给终极子节点 newSb.AppendFormat("\"tags\":[\"{0}\"],", townId); //添加采样点名称 newSb.AppendFormat("\"text\":\"{0}\"", sampleName); newSb.Append("},"); //townNum++; } //将最后一个“,”移除 newSb.Remove(newSb.Length - 1, 1); newSb.Append("]"); countryIdNum++; newSb.Append("},"); } } //将最后一个“,”移除 newSb.Remove(newSb.Length - 1, 1); } newSb.Append("]"); newSb.Append("},"); idNum++; } } } if (!(newSb.ToString() == "[")) { //如果StringBuilder中不止“[”,则移除,否则不移除 //将最后一个“,”移除 newSb.Remove(newSb.Length - 1, 1); } newSb.Append("]"); //context.Response.Write(dataStr); context.Response.Write(newSb.ToString()); }