/*
         * /// <summary>
         * /// 分页获取数据列表
         * /// </summary>
         * public DataSet GetList(int PageSize,int PageIndex,string strWhere)
         * {
         *      SqlParameter[] parameters = {
         *                      new SqlParameter("@tblName", SqlDbType.VarChar, 255),
         *                      new SqlParameter("@fldName", SqlDbType.VarChar, 255),
         *                      new SqlParameter("@PageSize", SqlDbType.Int),
         *                      new SqlParameter("@PageIndex", SqlDbType.Int),
         *                      new SqlParameter("@IsReCount", SqlDbType.Bit),
         *                      new SqlParameter("@OrderType", SqlDbType.Bit),
         *                      new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
         *                      };
         *      parameters[0].Value = "FarmlandMeg";
         *      parameters[1].Value = "Id";
         *      parameters[2].Value = PageSize;
         *      parameters[3].Value = PageIndex;
         *      parameters[4].Value = 0;
         *      parameters[5].Value = 0;
         *      parameters[6].Value = strWhere;
         *      return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
         * }*/

        #endregion  BasicMethod
        #region  ExtensionMethod
        /// <summary>
        /// 自己的 增加一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="Myconn"></param>
        /// <returns></returns>
        public int Add(SoilNutrientSoft.Model.FarmlandMeg model, Dictionary <SqlConnection, SqlTransaction> MyDict)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into FarmlandMeg(");
            strSql.Append("City,County,Town,Village,Sample_name,Lon,Lat,Name_of_householder,Phone_number,Irrigation_Conditions,Acreage,Fertility,Weeds)");
            strSql.Append(" values (");
            strSql.Append("@City,@County,@Town,@Village,@Sample_name,@Lon,@Lat,@Name_of_householder,@Phone_number,@Irrigation_Conditions,@Acreage,@Fertility,@Weeds)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@City",                  SqlDbType.NVarChar, 50),
                new SqlParameter("@County",                SqlDbType.NVarChar, 50),
                new SqlParameter("@Town",                  SqlDbType.NVarChar, 50),
                new SqlParameter("@Village",               SqlDbType.NVarChar, 50),
                new SqlParameter("@Sample_name",           SqlDbType.NVarChar, 50),
                new SqlParameter("@Lon",                   SqlDbType.Float,     8),
                new SqlParameter("@Lat",                   SqlDbType.Float,     8),
                new SqlParameter("@Name_of_householder",   SqlDbType.NVarChar, 50),
                new SqlParameter("@Phone_number",          SqlDbType.NVarChar, 11),
                new SqlParameter("@Irrigation_Conditions", SqlDbType.Int,       4),
                new SqlParameter("@Acreage",               SqlDbType.Float,     8),
                new SqlParameter("@Fertility",             SqlDbType.Int,       4),
                new SqlParameter("@Weeds",                 SqlDbType.NVarChar, 100)
            };
            parameters[0].Value  = model.City;
            parameters[1].Value  = model.County;
            parameters[2].Value  = model.Town;
            parameters[3].Value  = model.Village;
            parameters[4].Value  = model.Sample_name;
            parameters[5].Value  = model.Lon;
            parameters[6].Value  = model.Lat;
            parameters[7].Value  = model.Name_of_householder;
            parameters[8].Value  = model.Phone_number;
            parameters[9].Value  = model.Irrigation_Conditions;
            parameters[10].Value = model.Acreage;
            parameters[11].Value = model.Fertility;
            parameters[12].Value = model.Weeds;

            try
            {
                object obj = DbHelperSQL.GetSingle(strSql.ToString(), MyDict, parameters);
                if (obj == null)
                {
                    return(0);
                }
                else
                {
                    return(Convert.ToInt32(obj));
                }
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SoilNutrientSoft.Model.FarmlandMeg GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,City,County,Town,Village,Sample_name,Lon,Lat,Name_of_householder,Phone_number,Irrigation_Conditions,Acreage,Fertility,Weeds from FarmlandMeg ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            SoilNutrientSoft.Model.FarmlandMeg model = new SoilNutrientSoft.Model.FarmlandMeg();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //获取到标记对应的id
            int markerID = Convert.ToInt32(context.Request["id"]);

            //农田基本数据对象
            SoilNutrientSoft.BLL.FarmlandMeg   newFarmlandMegBll   = new SoilNutrientSoft.BLL.FarmlandMeg();
            SoilNutrientSoft.Model.FarmlandMeg newFarmlandMegModel = new SoilNutrientSoft.Model.FarmlandMeg();
            //根据id查询数据
            newFarmlandMegModel = newFarmlandMegBll.GetModel(markerID);

            //创建序列化对象
            JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer();

            //转换成JSON字符串
            // var dataStr = JavaScriptSerializer.Serialize(newFarmlandMegModel);

            //**************************************************
            //土壤养分信息
            SoilNutrientSoft.BLL.SoilNutrientMeg          newSoilNutrientMegBll  = new SoilNutrientSoft.BLL.SoilNutrientMeg();
            List <SoilNutrientSoft.Model.SoilNutrientMeg> newSoilNutrientMegList = newSoilNutrientMegBll.GetModelList(" All_id = " + markerID.ToString());

            //转换成JSON字符串
            // var dataStr = JavaScriptSerializer.Serialize(newSoilNutrientMegList[0]);

            //**************************************************


            //作物数据
            SoilNutrientSoft.BLL.CropsMeg          newCropsMegBll  = new SoilNutrientSoft.BLL.CropsMeg();
            List <SoilNutrientSoft.Model.CropsMeg> newCropsMegList = newCropsMegBll.GetModelList(" All_id = " + markerID.ToString());

            //转换成JSON字符串
            //var dataStr = JavaScriptSerializer.Serialize(newCropsMegList[0]);

            //***************************************

            //农田建议
            SoilNutrientSoft.BLL.FarmlandMSug          newFarmlandMSugBll  = new SoilNutrientSoft.BLL.FarmlandMSug();
            List <SoilNutrientSoft.Model.FarmlandMSug> newFarmlandMSugList = newFarmlandMSugBll.GetModelList(" All_id = " + markerID.ToString());

            //转换成JSON字符串
            //var dataStr = JavaScriptSerializer.Serialize(newFarmlandMSugList[0]);


            //***************************************

            //图片
            SoilNutrientSoft.BLL.Picture newPictureBll = new SoilNutrientSoft.BLL.Picture();
            //得到数据集合
            List <SoilNutrientSoft.Model.Picture> newPictureModelList = newPictureBll.GetModelList(" All_id = " + markerID.ToString());

            //添加至内部类List中
            List <Pic> newPicList = new List <Pic>();

            foreach (var item in newPictureModelList)
            {
                newPicList.Add(new Pic()
                {
                    picPath = item.picturePath
                });
            }
            //转换成JSON字符串
            //var dataStr = JavaScriptSerializer.Serialize(newPicList);


            SerializeObject newSerializeObject = new SerializeObject()
            {
                FarmlandMegObject     = newFarmlandMegModel,
                SoilNutrientMegObject = newSoilNutrientMegList[0],
                CropsMegObject        = newCropsMegList[0],
                FarmlandMSugObject    = newFarmlandMSugList[0],
                PicObject             = newPicList
            };

            var dataStr = JavaScriptSerializer.Serialize(newSerializeObject);


            context.Response.Write(dataStr);
        }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public SoilNutrientSoft.Model.FarmlandMeg DataRowToModel(DataRow row)
 {
     SoilNutrientSoft.Model.FarmlandMeg model = new SoilNutrientSoft.Model.FarmlandMeg();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["City"] != null)
         {
             model.City = row["City"].ToString();
         }
         if (row["County"] != null)
         {
             model.County = row["County"].ToString();
         }
         if (row["Town"] != null)
         {
             model.Town = row["Town"].ToString();
         }
         if (row["Village"] != null)
         {
             model.Village = row["Village"].ToString();
         }
         if (row["Sample_name"] != null)
         {
             model.Sample_name = row["Sample_name"].ToString();
         }
         if (row["Lon"] != null && row["Lon"].ToString() != "")
         {
             model.Lon = decimal.Parse(row["Lon"].ToString());
         }
         if (row["Lat"] != null && row["Lat"].ToString() != "")
         {
             model.Lat = decimal.Parse(row["Lat"].ToString());
         }
         if (row["Name_of_householder"] != null)
         {
             model.Name_of_householder = row["Name_of_householder"].ToString();
         }
         if (row["Phone_number"] != null)
         {
             model.Phone_number = row["Phone_number"].ToString();
         }
         if (row["Irrigation_Conditions"] != null && row["Irrigation_Conditions"].ToString() != "")
         {
             model.Irrigation_Conditions = int.Parse(row["Irrigation_Conditions"].ToString());
         }
         if (row["Acreage"] != null && row["Acreage"].ToString() != "")
         {
             model.Acreage = decimal.Parse(row["Acreage"].ToString());
         }
         if (row["Fertility"] != null && row["Fertility"].ToString() != "")
         {
             model.Fertility = int.Parse(row["Fertility"].ToString());
         }
         if (row["Weeds"] != null)
         {
             model.Weeds = row["Weeds"].ToString();
         }
     }
     return(model);
 }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SoilNutrientSoft.Model.FarmlandMeg model, Dictionary <SqlConnection, SqlTransaction> MyDict)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update FarmlandMeg set ");
                strSql.Append("City=@City,");
                strSql.Append("County=@County,");
                strSql.Append("Town=@Town,");
                strSql.Append("Village=@Village,");
                strSql.Append("Sample_name=@Sample_name,");
                strSql.Append("Lon=@Lon,");
                strSql.Append("Lat=@Lat,");
                strSql.Append("Name_of_householder=@Name_of_householder,");
                strSql.Append("Phone_number=@Phone_number,");
                strSql.Append("Irrigation_Conditions=@Irrigation_Conditions,");
                strSql.Append("Acreage=@Acreage,");
                strSql.Append("Fertility=@Fertility,");
                strSql.Append("Weeds=@Weeds");
                strSql.Append(" where Id=@Id");
                SqlParameter[] parameters =
                {
                    new SqlParameter("@City",                  SqlDbType.NVarChar,  50),
                    new SqlParameter("@County",                SqlDbType.NVarChar,  50),
                    new SqlParameter("@Town",                  SqlDbType.NVarChar,  50),
                    new SqlParameter("@Village",               SqlDbType.NVarChar,  50),
                    new SqlParameter("@Sample_name",           SqlDbType.NVarChar,  50),
                    new SqlParameter("@Lon",                   SqlDbType.Float,      8),
                    new SqlParameter("@Lat",                   SqlDbType.Float,      8),
                    new SqlParameter("@Name_of_householder",   SqlDbType.NVarChar,  50),
                    new SqlParameter("@Phone_number",          SqlDbType.NVarChar,  11),
                    new SqlParameter("@Irrigation_Conditions", SqlDbType.Int,        4),
                    new SqlParameter("@Acreage",               SqlDbType.Float,      8),
                    new SqlParameter("@Fertility",             SqlDbType.Int,        4),
                    new SqlParameter("@Weeds",                 SqlDbType.NVarChar, 100),
                    new SqlParameter("@Id",                    SqlDbType.Int, 4)
                };
                parameters[0].Value  = model.City;
                parameters[1].Value  = model.County;
                parameters[2].Value  = model.Town;
                parameters[3].Value  = model.Village;
                parameters[4].Value  = model.Sample_name;
                parameters[5].Value  = model.Lon;
                parameters[6].Value  = model.Lat;
                parameters[7].Value  = model.Name_of_householder;
                parameters[8].Value  = model.Phone_number;
                parameters[9].Value  = model.Irrigation_Conditions;
                parameters[10].Value = model.Acreage;
                parameters[11].Value = model.Fertility;
                parameters[12].Value = model.Weeds;
                parameters[13].Value = model.Id;

                int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), MyDict, parameters);
                if (rows > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #6
0
        public void ProcessRequest(HttpContext context)
        {
            Dictionary <SqlConnection, SqlTransaction> MyDict = new Dictionary <SqlConnection, SqlTransaction>();

            try
            {
                context.Response.ContentType = "text/plain";
                //第一张表单  农田信息数据录入后返回的最大id
                int getMaxId = 0;
                //第一张表单  农田信息数据录入返回的结果值
                int resultNumFLM = 0;

                //HttpPostedFile file = context.Request.Files["file"];
                #region 第一张表单  农田信息

                SoilNutrientSoft.Model.FarmlandMeg newFarmlandMegModel = new SoilNutrientSoft.Model.FarmlandMeg();

                newFarmlandMegModel.City                  = context.Request["city"];
                newFarmlandMegModel.County                = context.Request["country"];
                newFarmlandMegModel.Town                  = context.Request["townName"].Length == 0 ? "暂无" : context.Request["townName"];
                newFarmlandMegModel.Village               = context.Request["villageName"].Length == 0 ? "暂无" : context.Request["villageName"];
                newFarmlandMegModel.Sample_name           = context.Request["SampleName"].Length == 0 ? "暂无" : 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使用
                //以建立四张表的联系

                SoilNutrientSoft.BLL.FarmlandMeg newFarmlandMegBLL = new SoilNutrientSoft.BLL.FarmlandMeg();

                //提交数据,返回插入的id
                resultNumFLM = newFarmlandMegBLL.Add(newFarmlandMegModel, MyDict);
                if (resultNumFLM > 0)
                {
                    //表示农田信息表单成功录入
                    //该表中的最大id
                    getMaxId = resultNumFLM;    // newFarmlandMegBLL.GetMaxId()-1;
                }
                else
                {
                    context.Response.Write("农田信息表单数据录入失败");
                    //将信息返回给客户端,停止该页的执行
                    context.Response.End();
                }

                #endregion
                if (getMaxId <= 0)
                {
                    //如果getMaxId<=0表示第一张表插入失败
                    context.Response.Write("信息录入失败");
                    //将信息返回给客户端,停止该页的执行
                    context.Response.End();
                }
                else
                {
                    #region 第二张表单 土壤养分信息

                    SoilNutrientSoft.Model.SoilNutrientMeg newSoilNutrientMegModel = new SoilNutrientSoft.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;

                    //土壤养分信息录入
                    SoilNutrientSoft.BLL.SoilNutrientMeg newSoilNutrientMegBll = new SoilNutrientSoft.BLL.SoilNutrientMeg();

                    int resultNumSoil = newSoilNutrientMegBll.Add(newSoilNutrientMegModel, MyDict);

                    #endregion

                    #region 第三张表  作物信息

                    SoilNutrientSoft.Model.CropsMeg newCropsMegModel = new SoilNutrientSoft.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;

                    //作物信息录入
                    SoilNutrientSoft.BLL.CropsMeg newCropsMegBll = new SoilNutrientSoft.BLL.CropsMeg();
                    int resultNumCrops = newCropsMegBll.Add(newCropsMegModel, MyDict);
                    #endregion

                    #region 第四张表    农田管理建议

                    SoilNutrientSoft.Model.FarmlandMSug newFarmlandMSugModel = new SoilNutrientSoft.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;
                    //录入 农田管理建议
                    SoilNutrientSoft.BLL.FarmlandMSug newFarmlandMSugBll = new SoilNutrientSoft.BLL.FarmlandMSug();
                    int resultFLMS = newFarmlandMSugBll.Add(newFarmlandMSugModel, MyDict);
                    #endregion

                    //插入图片路径
                    //picPath:/UpImages/d5ceb1ff-319c-42e3-8881-5a8a87900a8b.jpeg
                    List <int> resultPic = new List <int>();
                    if (context.Request["picPath"].Length > 0)
                    {
                        string[] picPaths = context.Request["picPath"].Split(';');
                        SoilNutrientSoft.Model.Picture newPictureModel = new SoilNutrientSoft.Model.Picture();
                        SoilNutrientSoft.BLL.Picture   newPictureBll   = new SoilNutrientSoft.BLL.Picture();
                        foreach (var item in picPaths)
                        {
                            newPictureModel.picturePath = item;
                            newPictureModel.All_id      = getMaxId;
                            resultPic.Add(newPictureBll.Add(newPictureModel, MyDict));
                        }
                    }
                    else
                    {
                        resultPic.Add(1);
                    }

                    //判断四张表是否都插入
                    if (resultFLMS > 0 && resultNumCrops > 0 && resultNumFLM > 0 && resultNumSoil > 0 && resultPic.Min() > 0)
                    {
                        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";
            Dictionary <SqlConnection, SqlTransaction> MyDict = new Dictionary <SqlConnection, SqlTransaction>();

            try
            {
                //获取当前数据在数据库中对应的id
                int FarmlandMegId = Convert.ToInt32(context.Request["hiddenID"]);

                //根据“农田信息”表中的id分别查出其他三个表中的id

                //土壤养分信息录入表
                SoilNutrientSoft.BLL.SoilNutrientMeg          newSoilNutrientMegBll  = new SoilNutrientSoft.BLL.SoilNutrientMeg();
                List <SoilNutrientSoft.Model.SoilNutrientMeg> newSoilNutrientMegList = newSoilNutrientMegBll.GetModelList(" All_id = " + FarmlandMegId);
                //获取其在土壤养分信息录入表中对应的id
                int SoilNutrientMegId = newSoilNutrientMegList[0].Id;


                //作物信息录入表
                SoilNutrientSoft.BLL.CropsMeg          newCropsMegBll  = new SoilNutrientSoft.BLL.CropsMeg();
                List <SoilNutrientSoft.Model.CropsMeg> newCropsMegList = newCropsMegBll.GetModelList(" All_id = " + FarmlandMegId);
                //获取其在作物信息录入表中对应的id
                int CropsMegId = newCropsMegList[0].Id;


                //农田管理建议表
                SoilNutrientSoft.BLL.FarmlandMSug          newFarmlandMSugBll  = new SoilNutrientSoft.BLL.FarmlandMSug();
                List <SoilNutrientSoft.Model.FarmlandMSug> newFarmlandMSugList = newFarmlandMSugBll.GetModelList(" All_id = " + FarmlandMegId);
                //获取其在农田管理建议表中对应的id
                int FarmlandMSugId = newFarmlandMSugList[0].Id;


                #region 第一张表单  农田信息

                SoilNutrientSoft.Model.FarmlandMeg newFarmlandMegModel = new SoilNutrientSoft.Model.FarmlandMeg();

                newFarmlandMegModel.Id                    = FarmlandMegId;
                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"]);
                newFarmlandMegModel.Lat                   = Convert.ToDecimal(String.IsNullOrEmpty(context.Request["LatitudeDegree"]) ? "0" : context.Request["LatitudeDegree"]);
                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"]);
                newFarmlandMegModel.Fertility             = Convert.ToInt32(String.IsNullOrEmpty(context.Request["Fertility"]) ? "1" : context.Request["Fertility"]);
                newFarmlandMegModel.Weeds                 = context.Request["Weeds"];

                SoilNutrientSoft.BLL.FarmlandMeg newFarmlandMegBLL = new SoilNutrientSoft.BLL.FarmlandMeg();

                //更新数据,返回bool类型的值
                bool resultNumFLM = newFarmlandMegBLL.Update(newFarmlandMegModel, MyDict);

                #endregion

                #region 第二张表单 土壤养分信息

                SoilNutrientSoft.Model.SoilNutrientMeg newSoilNutrientMegModel = new SoilNutrientSoft.Model.SoilNutrientMeg();
                newSoilNutrientMegModel.Id            = SoilNutrientMegId;
                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        = FarmlandMegId;


                //更新数据,返回bool类型的值
                bool resultNumSoil = newSoilNutrientMegBll.Update(newSoilNutrientMegModel, MyDict);

                #endregion

                #region 第三张表  作物信息

                SoilNutrientSoft.Model.CropsMeg newCropsMegModel = new SoilNutrientSoft.Model.CropsMeg();
                newCropsMegModel.Id               = CropsMegId;
                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           = FarmlandMegId;

                //更新数据,返回bool类型的值
                bool resultNumCrops = newCropsMegBll.Update(newCropsMegModel, MyDict);


                #endregion

                #region 第四张表    农田管理建议

                SoilNutrientSoft.Model.FarmlandMSug newFarmlandMSugModel = new SoilNutrientSoft.Model.FarmlandMSug();
                newFarmlandMSugModel.Id              = FarmlandMSugId;
                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          = FarmlandMegId;

                //更新数据,返回bool类型的值
                bool resultFLMS = newFarmlandMSugBll.Update(newFarmlandMSugModel, MyDict);
                #endregion

                //判断四张表是否都更新
                if (resultFLMS && resultNumCrops && resultNumFLM && resultNumSoil)
                {
                    context.Response.Write("ok");
                }
                else
                {
                    context.Response.Write("信息录入失败");
                }
                QuitConnTrans(MyDict);
            }
            catch (Exception E)
            {
                ExceptionQuitConnTrans(MyDict);
                context.Response.Write("更新数据时发生异常:" + E.Message);
                //将信息返回给客户端,停止该页的执行
                context.Response.End();
            }
        }