Hander.ashx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
namespace pgDiv
{
    /// <summary>
    /// Summary description for Handler
    /// </summary>
    public class Handler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            System.Web.HttpResponse Response = context.Response;
            System.Web.HttpRequest Request = context.Request;
            //string sql = "select * from wr_menu_b order by id asc";
            //string cols = Request["cols"].ToString();
            //string table = Request["table"].ToString();
            //string orderField = Request["orderField"].ToString();
            //string dir = Request["dir"].ToString();
            int pageSize = Convert.ToInt32(Request["pageSize"] != null ? Request["pageSize"].ToString() : "10");
            int pageIndex = Convert.ToInt32(Request["pageIndex"] != null ? Request["pageIndex"].ToString() : "1");
            string start = ((pageIndex - 1) * pageSize).ToString();  //从哪条记录开始
            //string sql = "select " + cols + " from " + table + " order by " + orderField + " " + dir+" limit "+start+","+pageSize;
 
            //Response.Write(sql);
            //pageSize = 10;
            //pageIndex = 4;
            int recordCount = 0;
            //(int pageindex, int pagesize, string orderfield, string ordertype, string condition, ref int recordCount)
            //Sql = "select top " + pagesize + " * from dbo.hr where " + condition + " order by " + orderfield + " " + ordertype;
            IList<CityInfo> citys = CityInfo.GetListByPage(pageIndex, pageSize, "ID", "asc", "1=1", ref recordCount);
            string result = JsonConvert.SerializeObject(citys);
            int totalpage = 0;
            if (recordCount % pageSize == 0)
                totalpage = recordCount / pageSize;
            else
                totalpage = recordCount / pageSize + 1;
 
 
            Response.Write("{\"total\": \"" + totalpage.ToString() + "\",\"curPage\":\"" + pageIndex + "\", \"records\": \"" + recordCount.ToString() + "\", \"rows\" : " + result + "}");
        }
 
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值