Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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();
            }
        }