private void AddOrModify(HttpContext context)
        {
            //===============================================================
            //获取字段:【用户name】
            string id, name, year, administratorArea, batchTypeId, totalArea, addConsArea, consArea, agriArea, unusedArea, arabArea, approvalAuthority, approvalNo, approvalTime, des;
            id = name = year = administratorArea = batchTypeId = totalArea = addConsArea = unusedArea = consArea = agriArea = arabArea = approvalAuthority = approvalNo = approvalTime = des = "";

            if (null != context.Request.QueryString["id"])
            {
                id = context.Request.QueryString["id"].ToString().Trim();
            }
            if (null != context.Request.QueryString["name"])
            {
                name = context.Request.QueryString["name"].ToString().Trim();
            }
            if (null != context.Request.QueryString["year"])
            {
                year = context.Request.QueryString["year"].ToString().Trim();
            }
            if (null != context.Request.QueryString["administratorArea"])
            {
                administratorArea = context.Request.QueryString["administratorArea"].ToString().Trim();
            }
            if (null != context.Request.QueryString["batchTypeId"])
            {
                batchTypeId = context.Request.QueryString["batchTypeId"].ToString().Trim();
            }
            if (null != context.Request.QueryString["totalArea"])
            {
                totalArea = context.Request.QueryString["totalArea"].ToString().Trim();
            }
            if (null != context.Request.QueryString["addConsArea"])
            {
                addConsArea = context.Request.QueryString["addConsArea"].ToString().Trim();
            }
            if (null != context.Request.QueryString["consArea"])
            {
                consArea = context.Request.QueryString["consArea"].ToString().Trim();
            }
            if (null != context.Request.QueryString["agriArea"])
            {
                agriArea = context.Request.QueryString["agriArea"].ToString().Trim();
            }
            if (null != context.Request.QueryString["arabArea"])
            {
                arabArea = context.Request.QueryString["arabArea"].ToString().Trim();
            }
            if (null != context.Request.QueryString["unusedArea"])
            {
                unusedArea = context.Request.QueryString["unusedArea"].ToString().Trim();
            }
            if (null != context.Request.QueryString["approvalNo"])
            {
                approvalNo = context.Request.QueryString["approvalNo"].ToString().Trim();
            }
            if (null != context.Request.QueryString["approvalAuthority"])
            {
                approvalAuthority = context.Request.QueryString["approvalAuthority"].ToString().Trim();
            }
            if (null != context.Request.QueryString["approvalTime"])
            {
                approvalTime = context.Request.QueryString["approvalTime"].ToString().Trim();
            }
            if (null != context.Request.QueryString["des"])
            {
                des = context.Request.QueryString["des"].ToString().Trim();
            }

            if (id == "")
            {
                Model.T_Batch model = new Model.T_Batch();

                model.name = name;
                model.year = year;
                model.administratorArea = administratorArea;
                if (batchTypeId != "")
                {
                    model.batchTypeId = Convert.ToInt32(batchTypeId);
                }
                else
                {
                    model.batchTypeId = 0;
                }
                if (totalArea != "")
                {
                    model.totalArea = Convert.ToDecimal(totalArea);
                }
                else
                {
                    model.totalArea = 0;
                }
                model.hasLevyArea = 0;
                if (addConsArea != "")
                {
                    model.addConsArea = Convert.ToDecimal(addConsArea);
                }
                else
                {
                    model.addConsArea = 0;
                }
                if (agriArea != "")
                {
                    model.agriArea = Convert.ToDecimal(agriArea);
                }
                else
                {
                    model.agriArea = 0;
                }
                if (arabArea != "")
                {
                    model.arabArea = Convert.ToDecimal(arabArea);
                }
                else
                {
                    model.arabArea = 0;
                }
                if (consArea != "")
                {
                    model.consArea = Convert.ToDecimal(consArea);
                }
                else
                {
                    model.consArea = 0;
                }
                if (unusedArea != "")
                {
                    model.unusedArea = Convert.ToDecimal(unusedArea);
                }
                else
                {
                    model.unusedArea = 0;
                }

                model.approvalNo = approvalNo;
                model.approvalAuthority = approvalAuthority;
                if (approvalTime != "")
                {
                    model.approvalTime = Convert.ToDateTime(approvalTime);
                }
                else
                {
                    model.approvalTime = System.DateTime.Now;
                }
                if (context.Session["user_id"].ToString() != "")
                {
                    model.userId = Convert.ToInt32(context.Session["user_id"]);
                }
                else
                {
                    model.userId = 0;
                }
                model.createTime = System.DateTime.Now;
                model.isSubmited = 0;
                model.isDeleted = 0;
                model.des = des;

                int n = bll_batch.Add(model);
                if (n > 0)
                {
                    message.flag = true;
                    message.msg = "添加成功";
                }
                else
                {
                    message.flag = false;
                    message.msg = "添加失败";
                }
            }
            else
            {
                Model.T_Batch model = bll_batch.GetModel(Convert.ToInt32(id));

                model.name = name;
                model.year = year;
                model.administratorArea = administratorArea;
                if (batchTypeId != "")
                {
                    model.batchTypeId = Convert.ToInt32(batchTypeId);
                }
                if (totalArea != "")
                {
                    model.totalArea = Convert.ToDecimal(totalArea);
                }
                else
                {
                    model.totalArea = 0;
                }

                if (addConsArea != "")
                {
                    model.addConsArea = Convert.ToDecimal(addConsArea);
                }
                else
                {
                    model.addConsArea = 0;
                }
                if (agriArea != "")
                {
                    model.agriArea = Convert.ToDecimal(agriArea);
                }
                else
                {
                    model.agriArea = 0;
                }
                if (arabArea != "")
                {
                    model.arabArea = Convert.ToDecimal(arabArea);
                }
                else
                {
                    model.arabArea = 0;
                }
                if (consArea != "")
                {
                    model.consArea = Convert.ToDecimal(consArea);
                }
                else
                {
                    model.consArea = 0;
                }
                if (unusedArea != "")
                {
                    model.unusedArea = Convert.ToDecimal(unusedArea);
                }
                else
                {
                    model.unusedArea = 0;
                }

                model.approvalNo = approvalNo;
                model.approvalAuthority = approvalAuthority;
                if (approvalTime != "")
                {
                    model.approvalTime = Convert.ToDateTime(approvalTime);
                }
                else
                {
                    model.approvalTime = System.DateTime.Now;
                }
                if (context.Session["user_id"].ToString() != "")
                {
                    model.userId = Convert.ToInt32(context.Session["user_id"]);
                }
                else
                {
                    model.userId = 0;
                }
                model.createTime = System.DateTime.Now;
                model.isDeleted = 0;
                model.des = des;

                bool flag = bll_batch.Update(model);
                if (flag)
                {
                    message.flag = true;
                    message.msg = "修改成功";
                }
                else
                {
                    message.flag = false;
                    message.msg = "修改失败";
                }
            }

            String jsonString = JsonHelper.Object2Json<Message>(message);
            context.Response.Write(jsonString);
        }
        private void Query(HttpContext context)
        {
            string name, year, administratorArea, isDeleted, planTypeId, startTime, endTime, order, sort, oderby;

            //===============================================================
            //获取查询条件:【用户名,开始时间,结束时间】
            name = year = administratorArea = isDeleted = planTypeId = startTime = endTime = order = sort = oderby = "";

            //获取前台传来的值
            if (null != context.Request.QueryString["name"])
            {
                name = context.Request.QueryString["name"].ToString().Trim();
            }
            if (null != context.Request.QueryString["year"])
            {
                year = context.Request.QueryString["year"].ToString().Trim();
            }
            if (null != context.Request.QueryString["administratorArea"])
            {
                administratorArea = context.Request.QueryString["administratorArea"].ToString().Trim();
            }
            if (null != context.Request.QueryString["planTypeId"])
            {
                planTypeId = context.Request.QueryString["planTypeId"].ToString().Trim();
            }
            if (null != context.Request.QueryString["isDeleted"])
            {
                isDeleted = context.Request.QueryString["isDeleted"].ToString().Trim();
            }
            if (null != context.Request.QueryString["startTime"])
            {
                startTime = context.Request.QueryString["startTime"].ToString().Trim();
            }
            if (null != context.Request.QueryString["endTime"])
            {
                endTime = context.Request.QueryString["endTime"].ToString().Trim();
            }

            //================================================================
            //获取分页和排序信息:页大小,页码,排序方式,排序字段
            int pageRows, page;

            pageRows = 10;
            page     = 1;

            if (null != context.Request.QueryString["rows"])
            {
                pageRows = int.Parse(context.Request.QueryString["rows"].ToString().Trim());
            }
            if (null != context.Request.QueryString["page"])
            {
                page = int.Parse(context.Request.QueryString["page"].ToString().Trim());
            }
            if (null != context.Request.QueryString["sort"])
            {
                order = context.Request.QueryString["sort"].ToString().Trim();
            }
            if (null != context.Request.QueryString["order"])
            {
                sort = context.Request.QueryString["order"].ToString().Trim();
            }

            //===================================================================
            //组合查询语句:条件+排序
            StringBuilder strWhere = new StringBuilder();

            strWhere.Append(" 1=1 and");
            if (name != "")
            {
                strWhere.AppendFormat(" L.name like '%{0}%' and ", name);
            }

            if (year != "")
            {
                strWhere.AppendFormat(" T.year = '{0}' and ", year);
            }
            if (administratorArea != "")
            {
                strWhere.AppendFormat(" T.administratorArea = '{0}' and ", administratorArea);
            }
            if (planTypeId != "")
            {
                strWhere.AppendFormat(" planTypeId = '{0}' and ", planTypeId);
            }

            if (startTime != "")
            {
                strWhere.AppendFormat(" create_time >= '{0}' and ", startTime);
            }
            if (endTime != "")
            {
                strWhere.AppendFormat(" create_time <= '{0}' and ", endTime);
            }
            if (isDeleted != "" && isDeleted != "-1")
            {
                strWhere.AppendFormat(" isDeleted = '{0}' and ", isDeleted);
            }

            //删除多余的and
            int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置

            if (startindex >= 0)
            {
                strWhere.Remove(startindex, 3);//删除多余的and关键字
            }
            if (sort != "" && order != "")
            {
                //strWhere.AppendFormat(" order by {0} {1}", sort, order);//添加排序
                oderby = order + " " + sort;
            }

            //调用分页的GetList方法
            DataSet ds = bll_levy.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);

            //插入其他字段,行政区administratorArea、批次类型batchTypeName、创建人createUserName
            ds.Tables[0].Columns.Add("administratorAreaName", typeof(System.String));
            ds.Tables[0].Columns.Add("batchTypeName", typeof(System.String));
            ds.Tables[0].Columns.Add("batchName", typeof(System.String));
            ds.Tables[0].Columns.Add("createUserName", typeof(System.String));

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                int batchTypeId = 0; int administratorAreaId = 0;
                int batchId = 0;
                int userId  = 0;

                if (dr["administratorArea"].ToString() != "" && dr["administratorArea"] != null)
                {
                    administratorAreaId = Convert.ToInt32(dr["administratorArea"].ToString());
                }
                if (dr["batchTypeId"].ToString() != "" && dr["batchTypeId"] != null)
                {
                    batchTypeId = Convert.ToInt32(dr["batchTypeId"].ToString());
                }
                if (dr["batchId"].ToString() != "" && dr["batchId"] != null)
                {
                    batchId = Convert.ToInt32(dr["batchId"].ToString());
                }
                //if (dr["landblockId"].ToString() != "" && dr["landblockId"] != null)
                //{
                //    landblockId = Convert.ToInt32(dr["landblockId"].ToString());
                //}
                if (dr["userId"].ToString() != "" && dr["userId"] != null)
                {
                    userId = Convert.ToInt32(dr["userId"].ToString());
                }
                Model.T_AdministratorArea t_administrator_area = bll_administrator_area.GetModel(administratorAreaId);
                if (t_administrator_area != null)
                {
                    dr["administratorAreaName"] = t_administrator_area.name;
                }
                else
                {
                    dr["administratorAreaName"] = "";
                }
                Model.T_BatchType t_batch_type = bll_batch_type.GetModel(batchTypeId);
                if (t_batch_type != null)
                {
                    dr["batchTypeName"] = t_batch_type.name;
                }
                else
                {
                    dr["batchTypeName"] = "";
                }

                Model.T_Batch t_batch = bll_batch.GetModel(batchId);
                if (t_batch != null)
                {
                    dr["batchName"] = t_batch.name;
                }
                else
                {
                    dr["batchName"] = "";
                }

                //Model.T_LandBlock t_land_block = bll_land_block.GetModel(landblockId);
                //if (t_land_block != null) { dr["landBlockName"] = t_land_block.name; } else { dr["landBlockName"] = ""; }

                Model.T_User t_user = bll_user.GetModel(userId);
                if (t_user != null)
                {
                    dr["createUserName"] = t_user.name;
                }
                else
                {
                    dr["createUserName"] = "";
                }
            }

            int    count   = bll_levy.GetRecordCount(strWhere.ToString()); //获取条数
            string strJson = JsonHelper.Dataset2Json(ds, count);           //DataSet数据转化为Json数据

            context.Response.Write(strJson);                               //返回给前台页面
        }