管理员模块:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Script.Serialization; using DIDAO.BLL; using DIDAO.Common; using DIDAO.Model; namespace DIDAO.Admin.Admin { /// <summary> /// AdminController 的摘要说明 /// </summary> public class AdminController : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; MyORM_BLL myORM_BLL = new MyORM_BLL(); string btnSave = context.Request["btnSave"]; string action = context.Request["action"]; if (string.IsNullOrWhiteSpace(btnSave)) { if (action == "list") //列表 { List<object> list = myORM_BLL.SelectModelByField(typeof(TD_ADMIN), "STATUS=1"); //查询正常的管理员 RazorHelper.RazorParse(context, "~/Admin/AdminList.cshtml", list); } else if (action == "addnew") //新增展示 { TD_ADMIN admin = new TD_ADMIN(); RazorHelper.RazorParse(context, "~/Admin/AdminAlter.cshtml", new { action = "addnew", admin = admin }); } else if (action == "edit") //编辑展示 { #region 编辑展示 string idStr = context.Request["id"]; int id = VolidHelper.CheckStrToInt(idStr); object obj = myORM_BLL.SelectModelById(typeof(TD_ADMIN), id); if (obj == null) { RazorHelper.RazorParse(context, "~/error.cshtml", new { Msg = "未找到用户:" + id }); //出错 return; } TD_ADMIN admin = obj as TD_ADMIN; RazorHelper.RazorParse(context, "~/Admin/AdminAlter.cshtml", new { action="edit",admin=admin}); #endregion } else if (action == "delete") //删除 { #region 删除 string idStr = context.Request["id"]; int id = VolidHelper.CheckStrToInt(idStr); bool flag = myORM_BLL.DeleteOrDisableModelByUpdateStatus(typeof(TD_ADMIN),2, id); //status=2 if (flag) { context.Response.Redirect("/Admin/AdminController.ashx?action=list"); } else { RazorHelper.RazorParse(context, "~/error.cshtml", new { Msg = "删除操作失败:"+id }); //出错 } #endregion } else if (action == "batchDelete") //批量删除 { string idStr = context.Request["idStr"].Trim(','); if (!VolidHelper.CheckStringIsAllInt(idStr)) //判断idStr是否每一项都是数字 { AjaxHelper.WriteJson(context, "error", "批量禁用失败:id字符串中含有非数字"); } bool flag = myORM_BLL.DeleteOrDiableModelByIdList(typeof(TD_ADMIN), 2, idStr); if (!flag) { AjaxHelper.WriteJson(context, "error", "批量禁用失败"); } AjaxHelper.WriteJson(context, "ok", "成功"); } else if (action == "disable") //禁用 { #region 禁用 string idStr = context.Request["id"]; int id = VolidHelper.CheckStrToInt(idStr); bool flag = myORM_BLL.DeleteOrDisableModelByUpdateStatus(typeof(TD_ADMIN), 3, id); //status=3 if (flag) { context.Response.Redirect("/Admin/AdminController.ashx?action=list"); } else { RazorHelper.RazorParse(context, "~/error.cshtml", new { Msg = "禁用操作失败:" + id }); //出错 } #endregion } else { throw new Exception("action错误:" + action); } } else //保存 { string USERNAME = context.Request["USERNAME"]; string PASSWORD = context.Request["PASSWORD"]; string RePASSWORD = context.Request["RePASSWORD"]; string REALNAME = context.Request["REALNAME"]; string MOBILE = context.Request["MOBILE"]; string EMAIL = context.Request["EMAIL"]; string IDCARD = context.Request["IDCARD"]; string ADDRESS = context.Request["ADDRESS"]; #region 验证 非空,长度,是否符合格式 //验证 非空,长度,是否符合格式 if (string.IsNullOrWhiteSpace(USERNAME) || USERNAME.Length < 3) { AjaxHelper.WriteJson(context, "error", "用户名至少3位"); return; } if (string.IsNullOrWhiteSpace(PASSWORD) || PASSWORD.Length < 6) { AjaxHelper.WriteJson(context, "error", "密码至少6位"); return; } if (string.IsNullOrWhiteSpace(RePASSWORD) || RePASSWORD != PASSWORD) { AjaxHelper.WriteJson(context, "error", "密码不一致"); return; } if (string.IsNullOrWhiteSpace(REALNAME) || REALNAME.Length < 2) { AjaxHelper.WriteJson(context, "error", "必须是真是姓名"); return; } if (string.IsNullOrWhiteSpace(MOBILE) || MOBILE.Length != 11) { AjaxHelper.WriteJson(context, "error", "