一、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();
}
}
}