public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; if (context.Session != null)//初始为== { context.Response.Redirect("AdminLogin.ashx"); } else { string action = context.Request["Action"]; if (action == "add") { Admin admin = new Admin(); admin.UserName = context.Request["UserName"]; admin.Password = context.Request["UserName"]; //初始密码为用户名 admin.address = context.Request["address"]; admin.email = context.Request["email"]; admin.RealName = context.Request["RealName"]; AdminDAL.Insert(admin); context.Response.Redirect("AdminList.ashx"); } else { string html = CommonHelper.RenderHtml("../html/AdminAdd.htm", null); context.Response.Write(html); } } }
public static Admin ToAdmin(DataRow row) { Admin admin = new Admin(); admin.UserName = (string)row["UserName"]; admin.Password = (string)row["Password"]; admin.address = (string)row["address"]; admin.email = (string)row["email"]; admin.RealName = (string)row["RealName"]; return admin; }
public static void Insert(Admin admin) { //bit类型,在sql语句中要写0、1 //在.net中要用bool表示 SqlHelper.ExecuteNonQuery(@"insert into T_Admin( UserName,Password,address,email,RealName) values(@UserName,@Password,@address,@email,@RealName)", new SqlParameter("@UserName", admin.UserName), new SqlParameter("@Password", admin.Password), new SqlParameter("@address", admin.address), new SqlParameter("@email", admin.email), new SqlParameter("@RealName", admin.RealName)); }
//public void DeleteById(Guid Id) //{ // //软删除 // SqlHelper.ExecuteNonQuery("Update T_Users Set IsDeleted=1 where Id=@Id", // new SqlParameter("@Id", Id)); //} public Admin[] ListAll() { DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Admin"); Admin[] admin = new Admin[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { admin[i] = ToAdmin(dt.Rows[i]); } return admin; }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string AdminName = (string)context.Session["LoginAdminName"]; if (AdminName == null) { var data = new { Title = "现代科技体验中心", Msg = "" }; string html = CommonHelper.RenderHtml("../html/AdminLogin.htm", data); context.Response.Write(html); } else { string username = AdminName; string action = context.Request["Action"]; if (action == "Adm_edit") { DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Admin where UserName=@UserName", new SqlParameter("@UserName", username)); Admin admin = new Admin(); admin = AdminDAL.ToAdmin(dt.Rows[0]); var data = new { Title = "现代科技体验中心", Action = "Adm_update", admin, Name = username }; string html = CommonHelper.RenderHtml("../html/AdminEdit.htm", data); context.Response.Write(html); } else if (action == "Adm_update") { DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Admin where UserName=@UserName", new SqlParameter("@UserName", username)); if (dt.Rows.Count <= 0) { context.Response.Write("找不到用户名" + username + "用户"); } else if (dt.Rows.Count > 1) { context.Response.Write("错误!出现重名用户!"); } else { string RealName = context.Request["RealName"]; string email = context.Request["email"]; string address = context.Request["address"]; AdminDAL.Update(username, address, email, RealName); context.Response.Redirect("AdminEdit.ashx?Action=Adm_edit"); } } else if (action == "Admin_pwd") { string password = context.Request["NewPassword"]; DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Admin where UserName=@UserName", new SqlParameter("@UserName", username)); if (dt.Rows.Count <= 0) { context.Response.Write("找不到用户名" + username + "用户"); } else if (dt.Rows.Count > 1) { context.Response.Write("错误!出现重名用户!"); } else { AdminDAL.Update_Pwd(username, password); context.Session.Remove("LoginAdminName"); var data = new { Title = "现代科技体验中心", Msg = "密码修改成功,请重新登录!" }; string html = CommonHelper.RenderHtml("../html/AdminLogin.htm", data); context.Response.Write(html); } } else if (action == "Delete") { SqlHelper.ExecuteNonQuery("Delete from T_Admin where UserName=@UserName", new SqlParameter("@UserName", username)); context.Response.Redirect("AdminList.ashx"); } } }