protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { Model.Admin admin1 = new Model.Admin(); BLL.AdminManager admin2 = new BLL.AdminManager(); int adminID = Convert.ToInt32((GridView1.Rows[e.RowIndex].FindControl("LabelID") as Label).Text); bool bo = admin2.Delete(adminID); if (bo == true) { Bind(); } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { Model.Admin admin1 = new Model.Admin(); BLL.AdminManager admin2 = new BLL.AdminManager(); int adminID = Convert.ToInt32((GridView1.Rows[e.RowIndex].FindControl("Label1") as Label).Text); bool bo = admin2.Delete(adminID); if (bo == true) { Bind(); } // Model.Users users = new Model.Users(); //BLL.UsersManager users1 = new UsersManager(); //bool bo = users1.Add(users); //if (bo == true) //{ // Response.Redirect("~/Default.aspx"); //} }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; BLL.AdminManager bll = new BLL.AdminManager(); string action = context.Request["action"]; // 获取分页 if (action == "get") { int pageIndex, pageSize; try { pageIndex = Convert.ToInt32(context.Request["pageIndex"]); pageSize = Convert.ToInt32(context.Request["pageSize"]); } catch { return; } pageIndex = pageIndex < 1 ? 1 : pageIndex; pageSize = pageSize <= 0 || pageSize > 10 ? 10 : pageSize; int pageCount = (int)Math.Ceiling((double)bll.GetModelCount() / (double)pageSize); List <Model.Admin> list = bll.GetPageList(pageIndex, pageSize); object obj = new { pageIndex, pageSize, pageCount, data = list, }; JavaScriptSerializer js = new JavaScriptSerializer(); context.Response.Write(js.Serialize(obj)); } //获得一个 else if (action == "getById") { int id = 0; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } var admin = bll.GetModel(id); if (admin == null) { context.Response.Write("no:该用户不存在"); return; } JavaScriptSerializer js = new JavaScriptSerializer(); context.Response.Write("ok:" + js.Serialize(admin)); } // 删除 else if (action == "delete") { int id = 0; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } if (bll.Delete(id)) { context.Response.Write("ok:删除成功"); } else { context.Response.Write("no:删除失败"); } } // 修改 else if (action == "edit") { int id = 0; string adminName = context.Request["adminName"]; string pwd = context.Request["pwd"]; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } Model.Admin admin = bll.GetModel(id); if (admin == null) { context.Response.Write("no:该用户不存在"); return; } admin.AdminName = adminName; if (!string.IsNullOrWhiteSpace(pwd)) { admin.Pwd = pwd; } if (bll.Update(admin)) { context.Response.Write("ok:修改成功"); } else { context.Response.Write("no:修改失败"); } } // 添加 else if (action == "add") { Model.Admin admin = new Model.Admin { AdminName = context.Request["adminName"], Pwd = context.Request["pwd"] }; if (bll.Add(admin)) { context.Response.Write("ok:添加成功"); } else { context.Response.Write("no:添加失败"); } } else { context.Response.Write("error:非法的action"); } }