php ajax 增删改查 分页,Jquery之Ajax_分页及增删改查

一、UserInfoList.html代码

用户列表

添加用户

编号用户名密码邮箱时间删除详细编辑

用户名

密码

邮箱

用户名

密码

邮箱

用户名

密码

邮箱

二、UserList.ashx.cs代码

using CZBK.ItcastProject.Model;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace CZBK.ItcastProject.WebApp._2015_6_3

{

/// /// UserList 的摘要说明

///

public class UserList : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "text/plain";

int pageIndex;

if (!int.TryParse(context.Request["pageIndex"], out pageIndex))

{

pageIndex = 1;

}

int pageSize = 5;

BLL.UserInfoService UserInfoService = new BLL.UserInfoService();

int pageCount = UserInfoService.GetPageCount(pageSize);//获取总页数.

//判断当前页码值的取值范围。

pageIndex = pageIndex < 1 ? 1 : pageIndex;

pageIndex=pageIndex>pageCount?pageCount:pageIndex;

//获取分页数据

Listlist=UserInfoService.GetPageList(pageIndex,pageSize);

//获取页码条。

string pageBar = Common.PageBarHelper.GetPagaBar(pageIndex, pageCount);

System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();

string str = js.Serialize(new { UList = list, MyPageBar = pageBar });//将数据序列化成JSON字符串。匿名类。

context.Response.Write(str);

}

public bool IsReusable

{

get

{

return false;

}

}

}

}

三、ShowDetail.ashx.cs代码

using CZBK.ItcastProject.Model;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace CZBK.ItcastProject.WebApp._2015_6_3

{

/// /// ShowDetail 的摘要说明

///

public class ShowDetail : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "text/plain";

int id = Convert.ToInt32(context.Request["id"]);

BLL.UserInfoService UserInfoService = new BLL.UserInfoService();

UserInfo userInfo=UserInfoService.GetUserInfo(id);

System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();

context.Response.Write(js.Serialize(userInfo));

}

public bool IsReusable

{

get

{

return false;

}

}

}

}

四、AddUserInfo.ashx.cs代码

using CZBK.ItcastProject.Model;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace CZBK.ItcastProject.WebApp._2015_6_3

{

/// /// AddUserInfo 的摘要说明

///

public class AddUserInfo : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "text/plain";

UserInfo userInfo = new UserInfo();

userInfo.UserName = context.Request["txtUserName"];

userInfo.UserPass = context.Request["txtUserPwd"];

userInfo.Email = context.Request["txtUserMail"];

userInfo.RegTime = DateTime.Now;

BLL.UserInfoService UserInfoService = new BLL.UserInfoService();

if (UserInfoService.AddUserInfo(userInfo))

{

context.Response.Write("ok");

}

else

{

context.Response.Write("no");

}

}

public bool IsReusable

{

get

{

return false;

}

}

}

}

五、DeleteUser.ashx.cs代码

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace CZBK.ItcastProject.WebApp._2015_6_3

{

/// /// DeleteUser 的摘要说明

///

public class DeleteUser : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "text/plain";

int id = Convert.ToInt32(context.Request["id"]);

BLL.UserInfoService UserInfoService = new BLL.UserInfoService();

if (UserInfoService.DeleteUserInfo(id))

{

context.Response.Write("ok");

}

else

{

context.Response.Write("no");

}

}

public bool IsReusable

{

get

{

return false;

}

}

}

}

六、EditUserInfo.ashx.cs代码

using CZBK.ItcastProject.Model;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace CZBK.ItcastProject.WebApp._2015_6_3

{

/// /// EditUserInfo 的摘要说明

///

public class EditUserInfo : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "text/plain";

UserInfo userInfo = new UserInfo();

userInfo.UserName = context.Request["txtEditUserName"];

userInfo.UserPass = context.Request["txtEditUserPwd"];

userInfo.Email = context.Request["txtEditUserMail"];

userInfo.Id = Convert.ToInt32(context.Request["txtEditUserId"]);

userInfo.RegTime = Convert.ToDateTime(context.Request["txtEditRegTime"]);

BLL.UserInfoService UserInfoService = new BLL.UserInfoService();

if (UserInfoService.EditUserInfo(userInfo))

{

context.Response.Write("yes");

}

else

{

context.Response.Write("no");

}

}

public bool IsReusable

{

get

{

return false;

}

}

}

}

七、PageBarHelper.cs代码

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace CZBK.ItcastProject.Common

{

public class PageBarHelper

{

public static string GetPagaBar(int pageIndex, int pageCount)

{

if (pageCount == 1)

{

return string.Empty;

}

int start = pageIndex - 5;//计算起始位置.要求页面上显示10个数字页码.

if (start < 1)

{

start = 1;

}

int end = start + 9;//计算终止位置.

if (end > pageCount)

{

end = pageCount;

//重新计算一下Start值.

start = end - 9 < 1 ? 1 : end - 9;

}

StringBuilder sb = new StringBuilder();

if (pageIndex > 1)

{

sb.AppendFormat("上一页", pageIndex - 1);

}

for (int i = start; i <= end; i++)

{

if (i == pageIndex)

{

sb.Append(i);

}

else

{

sb.AppendFormat("{0}",i);

}

}

if (pageIndex < pageCount)

{

sb.AppendFormat("下一页", pageIndex + 1);

}

return sb.ToString();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值