系统角色篇
数据结构
用户管理
Controller代码
1 public class SystemUserController : Controller 2 { 3 //public void Log() 4 //{ 5 // string meg = ""; 6 // int user = int.Parse(CookieHelper.GetValue("SysUserID")); 7 // string ip = IPHelper.GetUserIp; 8 // foreach (var item in RouteData.Values) 9 // { 10 // meg += item.Key.ToUpper() + ":" + item.Value + "|"; 11 // } 12 // AuditLogConfig.InsertAuditLog(meg, user, ip); 13 //} 14 SystemUserRepository sysuserrepository = new SystemUserRepository(); 15 RoleRepository roleryrepository = new RoleRepository(); 16 DepartmentRepository departmentryrepository = new DepartmentRepository(); 17 JobRepository jobryrepository = new JobRepository(); 18 #region 列表页 19 /// <summary> 20 /// 列表页 21 /// </summary> 22 /// <param name="page">当前页</param> 23 /// <returns></returns> 24 [Authorize] 25 public ActionResult Index(int? page) 26 { 27 ViewBag.ControllerName=RouteData.Values["controller"].ToString().ToLower(); 28 CookieHelper.Del("LogName"); 29 var source = sysuserrepository.GetPageModelList(10, page ?? 1, -1); 30 return View(source); 31 } 32 #endregion 33 34 #region 添加管理员 35 /// <summary> 36 /// 添加页 37 /// </summary> 38 /// <param name="model">管理员实体类</param> 39 /// <returns></returns> 40 [Authorize] 41 public ActionResult Add(SystemUser model) 42 { 43 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 44 45 var rolelist = roleryrepository.GetModelListByState(1); 46 ViewBag.RoleID = SelectListExtension.ToSelectList(rolelist, d => d.RoleName, d => d.RoleID.ToString()); 47 48 var departmentlist = departmentryrepository.GetModelListByState(1); 49 ViewBag.DepartmentID = SelectListExtension.ToSelectList(departmentlist, d => d.DepartmentName, d => d.DepartmentID.ToString()); 50 51 var joblist = jobryrepository.GetModelListByState(1); 52 ViewBag.JobID = SelectListExtension.ToSelectList(joblist, d => d.JobName, d => d.JobID.ToString()); 53 54 // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0); 55 return View(); 56 } 57 58 /// <summary> 59 /// 添加事件 60 /// </summary> 61 /// <param name="model">实体类</param> 62 /// <param name="fc"></param> 63 /// <returns></returns> 64 [Authorize, HttpPost, ValidateInput(false)] 65 public ActionResult Add(SystemUser model, FormCollection fc) 66 { 67 model.State = 1; 68 model.CreateTime = DateTime.Now; 69 sysuserrepository.SaveOrEditModel(model); 70 return RedirectToAction("Index"); 71 } 72 #endregion 73 74 #region 删除 75 /// <summary> 76 /// 删除 77 /// </summary> 78 /// <param name="id">删除编号</param> 79 /// <returns></returns> 80 [Authorize] 81 public ActionResult Delete(int id) 82 { 83 try 84 { 85 var model = sysuserrepository.GetModel(id); 86 if (model != null) 87 { 88 sysuserrepository.DeleteModel(id); 89 return RedirectToAction("Index"); 90 } 91 else 92 return View("404"); 93 //throw new Exception("方法出错!"); 94 95 } 96 catch (Exception ex) 97 { 98 Log4netHelper.InvokeErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "删除方法出错-Author:ryanding IP地址[" + IPHelper.GetUserIp + "]" + "操作人ID:" + CookieHelper.GetValue("SystemUserID"), ex); 99 return View("404"); 100 } 101 102 103 } 104 #endregion 105 106 #region 查询 107 [Authorize] 108 public ActionResult Search(int? page) 109 { 110 string logname = ""; 111 if (page == null) 112 { 113 logname = Request.Form["KeyWord"]; 114 CookieHelper.SetObj("KeyWord", 0, logname); 115 } 116 else 117 logname = CookieHelper.GetValue("KeyWord"); 118 119 var query = QueryBuilder.Create<SystemUser>().Like(d => d.LogName, logname); 120 var source = sysuserrepository.GetModelList().Where(query.Expression); 121 return View(new Pager<SystemUser>(source, page ?? 1)); 122 } 123 124 #endregion 125 126 #region 编辑 127 [Authorize] 128 public ActionResult Edit(int id) 129 { 130 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 131 var model = sysuserrepository.GetModel(id); 132 if (model != null) 133 { 134 var rolelist = roleryrepository.GetModelListByState(1); 135 ViewBag.RoleID = SelectListExtension.ToSelectList(rolelist, d => d.RoleName, d => d.RoleID.ToString(),model.RoleID); 136 137 var departmentlist = departmentryrepository.GetModelListByState(1); 138 ViewBag.DepartmentID = SelectListExtension.ToSelectList(departmentlist, d => d.DepartmentName, d => d.DepartmentID.ToString(), model.DepartmentID); 139 140 var joblist = jobryrepository.GetModelListByState(1); 141 ViewBag.JobID = SelectListExtension.ToSelectList(joblist, d => d.JobName, d => d.JobID.ToString(), model.JobID); 142 ViewData["State"] = SelectListHelper.GetStateSelectList(model.State); 143 return View(model); 144 } 145 else 146 return View("404"); 147 } 148 149 [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)] 150 public ActionResult Edit(int id, FormCollection fc) 151 { 152 var model = sysuserrepository.GetModel(id); 153 154 if (model != null) 155 { 156 string password = model.Password; 157 if (Request.Form["PassWord"] != "") 158 { 159 UpdateModel(model); 160 sysuserrepository.SaveOrEditModel(model); 161 } 162 else 163 { 164 UpdateModel(model); 165 model.Password = password; 166 sysuserrepository.SaveOrEditModel(model); 167 } 168 return RedirectToAction("index"); 169 } 170 else 171 return View("404"); 172 } 173 #endregion 174 175 #region 用户名是否可用 176 //检测用户名是否可用 177 [HttpPost] 178 public ActionResult GetUsers(string param, string name) 179 { 180 if (sysuserrepository.IsExist(param)) 181 return Content("y"); 182 else 183 return Content("用户名已存在"); 184 } 185 #endregion 186 187 188 public bool Login() 189 { 190 try 191 { 192 //TODO: 193 throw new Exception("方法出错!"); 194 195 } 196 catch (Exception ex) 197 { 198 Log4netHelper.InvokeErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "登录方法Login出错-Author:ryanding IP地址[" + IPHelper.GetUserIp + "]" + "操作人ID:" + CookieHelper.GetValue("SystemUserID"), ex); 199 return false; 200 } 201 return true; 202 } 203 }
View代码
Index.cshtml
1 @{ 2 ViewBag.Title = "Index"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 6 @model SJCRM.Helpers.Pager<SJCRM.Models.SystemUser> 7 <div class="contrgcon"> 8 <div class="contrg_list"> 9 <div class="rgtit"> 10 <form method="post" action="/@ViewBag.ControllerName/search"> 11 <dl> 12 <dd>关键词:</dd> 13 <dd> 14 <input name="KeyWord" type="text" class="rgtxt2" /></dd> 15 <dd> 16 <input type="submit" value="查 询" class="rgbut1" /></dd> 17 </dl> 18 </form> 19 </div> 20 <div class="rgc"> 21 <dl class="rgt11"> 22 <dt> 23 <span class="sple"><a href="/systemuser/add">添加用户</a></span> 24 </dt> 25 </dl> 26 27 <div class="rg3"> 28 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 29 <tr> 30 <td class="rgtd2">用户编号</td> 31 <td class="rgtd3">登录名</td> 32 <td class="rgtd3">手机</td> 33 <td class="rgtd3">Email</td> 34 <td class="rgtd3">昵称</td> 35 <td class="rgtd3">状态</td> 36 <td class="rgtd4">操作</td> 37 </tr> 38 </table> 39 40 </div> 41 <div class="rg4"> 42 @{int classnum = 1;} 43 @foreach (var item in Model) 44 { 45 <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0) 46 {<text>class="rgbg2"</text>}> 47 <tr> 48 <td class="rgtd2">@item.SystemUserID</td> 49 <td class="rgtd3">@(item.LogName)</td> 50 <td class="rgtd3">@item.Mobile</td> 51 <td class="rgtd3">@item.Email</td> 52 <td class="rgtd3">@item.TrueName</td> 53 <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td> 54 <td class="rgtd4"><a href="/systemuser/delete/@item.SystemUserID">删除</a> | <a href="/systemuser/edit/@item.SystemUserID">编辑</a> </td> 55 </tr> 56 </table> 57 classnum = classnum + 1; 58 } 59 </div> 60 61 </div> 62 <div class="rg5"> 63 @UIHelper.PagesHelper(ViewBag.ControllerName, Model.TotalPages, Model.PageIndex, Model.PageSize, Model.TotalCount, Model.HasPreviousPage, Model.HasNextPage, Model.PageList) 64 </div> 65 </div> 66 </div> 67 <script> 68 //菜单显示 69 $("#@(ViewBag.ControllerName)sys").addClass("hbg"); 70 $("#@(ViewBag.ControllerName)").removeClass("navli"); 71 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 72 $(".@(ViewBag.ControllerName)sys").each(function (index, item) { 73 $(this).show(); 74 }); 75 </script>
Add.cshtml
1 @{ 2 ViewBag.Title = "Add"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 <div class="contrgcon"> 6 <div class="rgtit3"> 7 <div class="tit1"> 8 <h3>添加用户</h3> 9 </div> 10 <div class="rgtit3con"> 11 @using (Html.BeginForm()) 12 { 13 <dl> 14 <dd class="dc1">用户名:</dd> 15 <dd> 16 <input name="LogName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" /> 17 </dd> 18 </dl> 19 20 <dl> 21 <dd class="dc1">昵称:</dd> 22 <dd> 23 <input name="TrueName" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" /> 24 </dd> 25 </dl> 26 27 <dl> 28 <dd class="dc1">Email:</dd> 29 <dd> 30 <input type="text" name="Email" id="Email" class="rgtxt2" /> 31 </dd> 32 </dl> 33 <dl> 34 <dd class="dc1">手机号:</dd> 35 <dd> 36 <input type="text" name="Mobile" id="Mobile" class="rgtxt2" /> 37 </dd> 38 </dl> 39 <dl> 40 <dd class="dc1">密码:</dd> 41 <dd> 42 <input type="text" name="Password" id="Password" class="rgtxt2" /> 43 </dd> 44 </dl> 45 <dl> 46 <dd class="dc1">确认密码:</dd> 47 <dd> 48 <input type="text" name="PassWordto" id="PassWordto" class="rgtxt2" /> 49 </dd> 50 </dl> 51 <dl> 52 <dd class="dc1">岗位:</dd> 53 <dd> 54 @Html.DropDownList("JobID", ViewBag.JobID as SelectList) 55 </dd> 56 </dl> 57 <dl> 58 <dd class="dc1">部门:</dd> 59 <dd> 60 @Html.DropDownList("DepartmentID", ViewBag.DepartmentID as SelectList) 61 </dd> 62 </dl> 63 <dl> 64 <dd class="dc1">角色:</dd> 65 <dd> 66 @Html.DropDownList("RoleID", ViewBag.RoleID as SelectList) 67 </dd> 68 </dl> 69 70 <dl> 71 <dd> 72 <input type="submit" value="提 交" class="rgbut4" /> 73 </dd> 74 </dl> 75 } 76 </div> 77 </div> 78 </div> 79 <script> 80 //菜单显示 81 $("#@(ViewBag.ControllerName)sys").addClass("hbg"); 82 $("#@(ViewBag.ControllerName)").removeClass("navli"); 83 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 84 $(".@(ViewBag.ControllerName)sys").each(function (index, item) { 85 $(this).show(); 86 }); 87 </script>
Edit.cshtml
1 @{ 2 ViewBag.Title = "Add"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 @model SJCRM.Models.SystemUser 6 <div class="contrgcon"> 7 <div class="rgtit3"> 8 <div class="tit1"> 9 <h3>编辑用户</h3> 10 </div> 11 <div class="rgtit3con"> 12 @using (Html.BeginForm()) 13 { 14 <dl> 15 <dd class="dc1">用户名:</dd> 16 <dd> 17 <input name="LogName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@Model.LogName"/> 18 </dd> 19 </dl> 20 21 <dl> 22 <dd class="dc1">昵称:</dd> 23 <dd> 24 <input name="TrueName" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" value="@Model.TrueName" /> 25 </dd> 26 </dl> 27 28 <dl> 29 <dd class="dc1">Email:</dd> 30 <dd> 31 <input type="text" name="Email" id="Email" class="rgtxt2" value="@Model.Email" /> 32 </dd> 33 </dl> 34 <dl> 35 <dd class="dc1">手机号:</dd> 36 <dd> 37 <input type="text" name="Mobile" id="Mobile" class="rgtxt2" value="@Model.Mobile" /> 38 </dd> 39 </dl> 40 <dl> 41 <dd class="dc1">修改密码:</dd> 42 <dd> 43 <input type="text" name="Password" id="Password" class="rgtxt2" value="@Model.Password" /> 44 </dd> 45 </dl> 46 47 <dl> 48 <dd class="dc1">岗位:</dd> 49 <dd> 50 @Html.DropDownList("JobID", ViewBag.JobID as SelectList) 51 </dd> 52 </dl> 53 <dl> 54 <dd class="dc1">部门:</dd> 55 <dd> 56 @Html.DropDownList("DepartmentID", ViewBag.DepartmentID as SelectList) 57 </dd> 58 </dl> 59 <dl> 60 <dd class="dc1">角色:</dd> 61 <dd> 62 @Html.DropDownList("RoleID", ViewBag.RoleID as SelectList) 63 </dd> 64 </dl> 65 66 <dl> 67 <dd> 68 <input type="submit" value="提 交" class="rgbut4" /> 69 </dd> 70 </dl> 71 } 72 </div> 73 </div> 74 </div> 75 <script> 76 //菜单显示 77 $("#@(ViewBag.ControllerName)sys").addClass("hbg"); 78 $("#@(ViewBag.ControllerName)").removeClass("navli"); 79 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 80 $(".@(ViewBag.ControllerName)sys").each(function (index, item) { 81 $(this).show(); 82 }); 83 </script>
Search.cshtml
@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } @model SJCRM.Helpers.Pager<SJCRM.Models.SystemUser> <div class="contrgcon"> <div class="contrg_list"> <div class="rgtit"> <form method="post" action="/@ViewBag.ControllerName/search"> <dl> <dd>关键词:</dd> <dd> <input name="KeyWord" type="text" class="rgtxt2" /></dd> <dd> <input type="submit" value="查 询" class="rgbut1" /></dd> </dl> </form> </div> <div class="rgc"> <dl class="rgt11"> <dt> <span class="sple"><a href="/systemuser/add">添加用户</a></span> </dt> </dl> <div class="rg3"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="rgtd2">用户编号</td> <td class="rgtd3">登录名</td> <td class="rgtd3">手机</td> <td class="rgtd3">Email</td> <td class="rgtd3">昵称</td> <td class="rgtd3">状态</td> <td class="rgtd4">操作</td> </tr> </table> </div> <div class="rg4"> @{int classnum = 1;} @foreach (var item in Model) { <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0) {<text>class="rgbg2"</text>}> <tr> <td class="rgtd2">@item.SystemUserID</td> <td class="rgtd3">@(item.LogName)</td> <td class="rgtd3">@item.Mobile</td> <td class="rgtd3">@item.Email</td> <td class="rgtd3">@item.TrueName</td> <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td> <td class="rgtd4"><a href="/systemuser/delete/@item.SystemUserID">删除</a> | <a href="/systemuser/edit/@item.SystemUserID">编辑</a> </td> </tr> </table> classnum = classnum + 1; } </div> </div> </div> </div> <script> //菜单显示 $("#@(ViewBag.ControllerName)sys").addClass("hbg"); $("#@(ViewBag.ControllerName)").removeClass("navli"); $("#@(ViewBag.ControllerName)").addClass("navlihg"); $(".@(ViewBag.ControllerName)sys").each(function (index, item) { $(this).show(); }); </script>
角色管理
Controller代码
1 public class RoleController : Controller 2 { 3 RoleRepository roleryrepository = new RoleRepository(); 4 MenuRepository menurepository = new MenuRepository(); 5 RoleMenuMappingRepository rmmrepositoy = new RoleMenuMappingRepository(); 6 7 #region 列表 8 /// <summary> 9 /// 默认页面 10 /// </summary> 11 /// <returns></returns> 12 /// 13 [Authorize] 14 public ActionResult Index(int? page) 15 { 16 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 17 var source = roleryrepository.GetModelList(); 18 return View(roleryrepository.GetPageModelList(source, 10, page ?? 1)); 19 } 20 #endregion 21 22 #region 添加 23 /// <summary> 24 /// 添加页 25 /// </summary> 26 /// <param name="model">实体类</param> 27 /// <returns></returns> 28 [Authorize] 29 public ActionResult Add(Role model) 30 { 31 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 32 var menu = menurepository.GetModelListByState(1); 33 34 ViewBag.Menu = new SelectList(menu, "MenuID", "MenuName"); 35 // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0); 36 return View(); 37 } 38 public string Log() 39 { 40 string meg = ""; 41 //int user = int.Parse(CookieHelper.GetValue("SysUserID")); 42 //string ip = IPHelper.GetUserIp; 43 foreach (var item in RouteData.Values) 44 { 45 meg += item.Key.ToUpper() + ":" + item.Value + "|"; 46 } 47 return meg; 48 } 49 /// <summary> 50 /// 添加事件 51 /// </summary> 52 /// <param name="model">实体类</param> 53 /// <param name="fc"></param> 54 /// <returns></returns> 55 [Authorize, HttpPost, ValidateInput(false)] 56 public ActionResult Add(Role model, FormCollection fc, int[] Menu) 57 { 58 try 59 { 60 61 62 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 63 model.State = 1; 64 65 model.CreateTime = DateTime.Now; 66 roleryrepository.SaveOrEditModel(model); 67 if (Menu.Length > 0) 68 { 69 70 foreach (int gsi in Menu) 71 { 72 RoleMenuMapping rmm = new RoleMenuMapping(); 73 rmm.MenuID = gsi; 74 rmm.RoleID = model.RoleID; 75 rmmrepositoy.SaveOrEditModel(rmm); 76 } 77 } 78 else 79 { 80 return RedirectToAction("Index"); 81 } 82 83 } 84 catch (Exception ex) 85 { 86 87 Log4netHelper.InvokeErrorLog(MethodBase.GetCurrentMethod().DeclaringType, ViewBag.ControllerName + "添加方法出错-Author:ryanding IP地址[" + IPHelper.GetUserIp + "]" + "操作人ID:" + CookieHelper.GetValue("SystemUserID") + "当前来源信息:" + Log(), ex); 88 } 89 return View("404"); 90 91 } 92 #endregion 93 94 #region 删除 95 /// <summary> 96 /// 删除 97 /// </summary> 98 /// <param name="id">删除编号</param> 99 /// <returns></returns> 100 [Authorize] 101 public ActionResult Delete(int id) 102 { 103 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 104 var model = roleryrepository.GetModel(id); 105 model.State = 0; 106 if (model != null) 107 { 108 roleryrepository.SaveOrEditModel(model); 109 return RedirectToAction("index"); 110 } 111 else 112 return View("404"); 113 114 115 } 116 #endregion 117 118 #region 查询 119 [Authorize] 120 public ActionResult Search(int? page) 121 { 122 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 123 string name = ""; 124 if (page == null) 125 { 126 name = Request.Form["KeyWord"]; 127 CookieHelper.SetObj("KeyWord", 0, name); 128 } 129 else 130 name = CookieHelper.GetValue("KeyWord"); 131 132 var query = QueryBuilder.Create<Role>().Like(d => d.RoleName, name); 133 var source = roleryrepository.GetModelList().Where(query.Expression); 134 return View(new Pager<Role>(source, page ?? 1, 10)); 135 } 136 #endregion 137 138 #region 编辑 139 [Authorize] 140 public ActionResult Edit(int id) 141 { 142 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 143 var rmmList = rmmrepositoy.GetModelList().Where(d => d.RoleID == id); 144 145 146 var menu = menurepository.GetModelListByState(1); 147 ViewBag.Menu = new SelectList(menu, "MenuID", "MenuName", string.Join(",", rmmList.Select(p => p.MenuID))); 148 var model = roleryrepository.GetModel(id); 149 if (model != null) 150 { 151 ViewData["State"] = SelectListHelper.GetStateSelectList(model.State); 152 return View(model); 153 } 154 else 155 return View("404"); 156 } 157 158 [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)] 159 public ActionResult Edit(int id, FormCollection fc, int[] Menu) 160 { 161 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 162 var model = roleryrepository.GetModel(id); 163 164 if (model != null) 165 { 166 if (Menu.Length > 0) 167 { 168 rmmrepositoy.DeleteModel(rmmrepositoy.GetModelList().Where(d => d.RoleID == model.RoleID)); 169 foreach (int gsi in Menu) 170 { 171 RoleMenuMapping rmm = new RoleMenuMapping(); 172 rmm.MenuID = gsi; 173 rmm.RoleID = model.RoleID; 174 rmmrepositoy.SaveOrEditModel(rmm); 175 } 176 } 177 178 179 UpdateModel(model); 180 roleryrepository.SaveOrEditModel(model); 181 return RedirectToAction("index"); 182 } 183 else 184 return View("404"); 185 } 186 #endregion 187 }
View代码
Index.cshtml
1 @{ 2 ViewBag.Title = "Index"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 6 @model SJCRM.Helpers.Pager<SJCRM.Models.Role> 7 <div class="contrgcon"> 8 <div class="contrg_list"> 9 <div class="rgtit"> 10 <form method="post" action="/@ViewBag.ControllerName/search"> 11 <dl> 12 <dd>关键词:</dd> 13 <dd> 14 <input name="KeyWord" type="text" class="rgtxt2" /></dd> 15 <dd> 16 <input type="submit" value="查 询" class="rgbut1" /></dd> 17 </dl> 18 </form> 19 </div> 20 <div class="rgc"> 21 <dl class="rgt11"> 22 <dt> 23 <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span> 24 </dt> 25 </dl> 26 27 <div class="rg3"> 28 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 29 <tr> 30 <td class="rgtd2">编号</td> 31 <td class="rgtd2">角色名称</td> 32 <td class="rgtd3">角色内容</td> 33 <td class="rgtd3">创建时间</td> 34 <td class="rgtd3">状态</td> 35 <td class="rgtd4">操作</td> 36 </tr> 37 </table> 38 39 </div> 40 <div class="rg4"> 41 @{int classnum = 1;} 42 @foreach (var item in Model) 43 { 44 <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0) 45 {<text>class="rgbg2"</text>}> 46 <tr> 47 <td class="rgtd2">@item.RoleID</td> 48 <td class="rgtd2">@item.RoleName</td> 49 <td class="rgtd3">@item.RoleContent</td> 50 <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td> 51 <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td> 52 <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.RoleID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.RoleID">编辑</a> </td> 53 </tr> 54 </table> 55 classnum = classnum + 1; 56 } 57 </div> 58 59 </div> 60 <div class="rg5"> 61 @UIHelper.PagesHelper(ViewBag.ControllerName, Model.TotalPages, Model.PageIndex, Model.PageSize, Model.TotalCount, Model.HasPreviousPage, Model.HasNextPage, Model.PageList); 62 63 </div> 64 </div> 65 </div> 66 <script> 67 //菜单显示 68 $("#systemusersys").addClass("hbg"); 69 $("#@(ViewBag.ControllerName)").removeClass("navli"); 70 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 71 $(".systemusersys").each(function (index, item) { 72 $(this).show(); 73 }); 74 </script>
Add.cshtml
1 @using SJCRM.Helpers 2 @{ 3 ViewBag.Title = "Add"; 4 Layout = "~/Views/Shared/_Layout.cshtml"; 5 } 6 <div class="contrgcon"> 7 <div class="rgtit3"> 8 <div class="tit1"> 9 <h3>添加</h3> 10 </div> 11 <div class="rgtit3con"> 12 @using (Html.BeginForm()) 13 { 14 <dl> 15 <dd class="dc1">角色名称:</dd> 16 <dd> 17 <input name="RoleName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入名称" /> 18 </dd> 19 </dl> 20 21 <dl> 22 <dd class="dc1">角色权限:</dd> 23 <dd> 24 @Html.CheckBoxList("Menu") 25 </dd> 26 </dl> 27 28 <dl> 29 <dd class="dc1">角色内容:</dd> 30 <dd> 31 <textarea rows="10" cols="82" name="RoleContent" id="RoleContent"></textarea> 32 </dd> 33 </dl> 34 <dl> 35 <dd> 36 <input type="submit" value="提 交" class="rgbut4" /> 37 </dd> 38 </dl> 39 } 40 </div> 41 </div> 42 </div> 43 <script> 44 //菜单显示 45 $("#systemusersys").addClass("hbg"); 46 $("#@(ViewBag.ControllerName)").removeClass("navli"); 47 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 48 $(".systemusersys").each(function (index, item) { 49 $(this).show(); 50 }); 51 </script>
Edit.cshtml
1 @using SJCRM.Helpers 2 @{ 3 ViewBag.Title = "Add"; 4 Layout = "~/Views/Shared/_Layout.cshtml"; 5 } 6 @model SJCRM.Models.Role 7 <div class="contrgcon"> 8 <div class="rgtit3"> 9 <div class="tit1"> 10 <h3>编辑</h3> 11 </div> 12 <div class="rgtit3con"> 13 @using (Html.BeginForm()) 14 { 15 <dl> 16 <dd class="dc1">角色名称:</dd> 17 <dd> 18 <input name="RoleName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入名称" value="@Model.RoleName"/> 19 </dd> 20 </dl> 21 22 <dl> 23 <dd class="dc1">角色权限:</dd> 24 <dd> 25 26 @Html.CheckBoxList("Menu") 27 </dd> 28 </dl> 29 30 <dl> 31 <dd class="dc1">角色内容:</dd> 32 <dd> 33 <textarea rows="10" cols="82" name="RoleContent" id="RoleContent">@Model.RoleName</textarea> 34 </dd> 35 </dl> 36 <dl> 37 <dd> 38 <input type="submit" value="提 交" class="rgbut4" /> 39 </dd> 40 </dl> 41 } 42 </div> 43 </div> 44 </div> 45 <script> 46 //菜单显示 47 $("#systemusersys").addClass("hbg"); 48 $("#@(ViewBag.ControllerName)").removeClass("navli"); 49 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 50 $(".systemusersys").each(function (index, item) { 51 $(this).show(); 52 }); 53 </script>
Search.cshtml
1 @{ 2 ViewBag.Title = "Index"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 6 @model SJCRM.Helpers.Pager<SJCRM.Models.Role> 7 <div class="contrgcon"> 8 <div class="contrg_list"> 9 <div class="rgtit"> 10 <form method="post" action="/@ViewBag.ControllerName/search"> 11 <dl> 12 <dd>关键词:</dd> 13 <dd> 14 <input name="KeyWord" type="text" class="rgtxt2" /></dd> 15 <dd> 16 <input type="submit" value="查 询" class="rgbut1" /></dd> 17 </dl> 18 </form> 19 </div> 20 <div class="rgc"> 21 <dl class="rgt11"> 22 <dt> 23 <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span> 24 </dt> 25 </dl> 26 27 <div class="rg3"> 28 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 29 <tr> 30 <td class="rgtd2">编号</td> 31 <td class="rgtd2">角色名称</td> 32 <td class="rgtd3">角色内容</td> 33 <td class="rgtd3">创建时间</td> 34 <td class="rgtd3">状态</td> 35 <td class="rgtd4">操作</td> 36 </tr> 37 </table> 38 39 </div> 40 <div class="rg4"> 41 @{int classnum = 1;} 42 @foreach (var item in Model) 43 { 44 <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0) 45 {<text>class="rgbg2"</text>}> 46 <tr> 47 <td class="rgtd2">@item.RoleID</td> 48 <td class="rgtd2">@item.RoleName</td> 49 <td class="rgtd3">@item.RoleContent</td> 50 <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td> 51 <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td> 52 <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.RoleID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.RoleID">编辑</a> </td> 53 </tr> 54 </table> 55 classnum = classnum + 1; 56 } 57 </div> 58 59 </div> 60 61 </div> 62 </div> 63 <script> 64 //菜单显示 65 $("#systemusersys").addClass("hbg"); 66 $("#@(ViewBag.ControllerName)").removeClass("navli"); 67 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 68 $(".systemusersys").each(function (index, item) { 69 $(this).show(); 70 }); 71 </script>
菜单管理
Controller代码
1 public class MenuController : Controller 2 { 3 MenuRepository repository = new MenuRepository(); 4 5 #region 列表 6 /// <summary> 7 /// 默认页面 8 /// </summary> 9 /// <returns></returns> 10 /// 11 [Authorize] 12 public ActionResult Index(int? page) 13 { 14 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 15 var source = repository.GetModelListByState(1); 16 return View(repository.GetPageModelList(source, 10, page ?? 1)); 17 } 18 #endregion 19 20 #region 添加 21 /// <summary> 22 /// 添加页 23 /// </summary> 24 /// <param name="model">实体类</param> 25 /// <returns></returns> 26 [Authorize] 27 public ActionResult Add(Menu model) 28 { 29 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 30 // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0); 31 return View(); 32 } 33 34 /// <summary> 35 /// 添加事件 36 /// </summary> 37 /// <param name="model">实体类</param> 38 /// <param name="fc"></param> 39 /// <returns></returns> 40 [Authorize, HttpPost, ValidateInput(false)] 41 public ActionResult Add(Menu model, FormCollection fc) 42 { 43 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 44 model.State = 1; 45 model.CreateTime = DateTime.Now; 46 repository.SaveOrEditModel(model); 47 return RedirectToAction("Index"); 48 } 49 #endregion 50 51 #region 删除 52 /// <summary> 53 /// 删除 54 /// </summary> 55 /// <param name="id">删除编号</param> 56 /// <returns></returns> 57 [Authorize] 58 public ActionResult Delete(int id) 59 { 60 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 61 var model = repository.GetModel(id); 62 model.State = 0; 63 if (model != null) 64 { 65 repository.SaveOrEditModel(model); 66 return RedirectToAction("index"); 67 } 68 else 69 return View("404"); 70 //var model = categoryrepository.GetModel(id); 71 //if (model != null) 72 //{ 73 // categoryrepository.DeleteModel(id); 74 // return RedirectToAction("Index"); 75 //} 76 //else 77 // return View("404"); 78 79 } 80 #endregion 81 82 #region 查询 83 [Authorize] 84 public ActionResult Search(int? page) 85 { 86 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 87 string name = ""; 88 if (page == null) 89 { 90 name = Request.Form["KeyWord"]; 91 CookieHelper.SetObj("KeyWord", 0, name); 92 } 93 else 94 name = CookieHelper.GetValue("KeyWord"); 95 96 var query = QueryBuilder.Create<Menu>().Like(d => d.MenuName, name); 97 var source = repository.GetModelList().Where(query.Expression); 98 return View(new Pager<Menu>(source, page ?? 1, 10)); 99 } 100 #endregion 101 102 #region 编辑 103 [Authorize] 104 public ActionResult Edit(int id) 105 { 106 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 107 var model = repository.GetModel(id); 108 if (model != null) 109 { 110 ViewData["State"] = SelectListHelper.GetStateSelectList(model.State); 111 return View(model); 112 } 113 else 114 return View("404"); 115 } 116 117 [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)] 118 public ActionResult Edit(int id, FormCollection fc) 119 { 120 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 121 var model = repository.GetModel(id); 122 123 if (model != null) 124 { 125 UpdateModel(model); 126 repository.SaveOrEditModel(model); 127 return RedirectToAction("index"); 128 } 129 else 130 return View("404"); 131 } 132 #endregion 133 }
View代码
Index.cshtml
1 @{ 2 ViewBag.Title = "Index"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 6 @model SJCRM.Helpers.Pager<SJCRM.Models.Menu> 7 <div class="contrgcon"> 8 <div class="contrg_list"> 9 <div class="rgtit"> 10 <form method="post" action="/@ViewBag.ControllerName/search"> 11 <dl> 12 <dd>关键词:</dd> 13 <dd> 14 <input name="KeyWord" type="text" class="rgtxt2" /></dd> 15 <dd> 16 <input type="submit" value="查 询" class="rgbut1" /></dd> 17 </dl> 18 </form> 19 </div> 20 <div class="rgc"> 21 <dl class="rgt11"> 22 <dt> 23 <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span> 24 </dt> 25 </dl> 26 27 <div class="rg3"> 28 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 29 <tr> 30 <td class="rgtd2">编号</td> 31 <td class="rgtd3">菜单名称</td> 32 <td class="rgtd3">别名样式</td> 33 <td class="rgtd3">连接地址</td> 34 <td class="rgtd3">创建时间</td> 35 <td class="rgtd3">状态</td> 36 <td class="rgtd4">操作</td> 37 </tr> 38 </table> 39 40 </div> 41 <div class="rg4"> 42 @{int classnum = 1;} 43 @foreach (var item in Model) 44 { 45 <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0) 46 {<text>class="rgbg2"</text>}> 47 <tr> 48 <td class="rgtd2">@item.MenuID</td> 49 <td class="rgtd3">@item.MenuName</td> 50 <td class="rgtd3">@item.Alias</td> 51 <td class="rgtd3">@item.Url</td> 52 <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td> 53 <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td> 54 <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.MenuID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.MenuID">编辑</a> </td> 55 </tr> 56 </table> 57 classnum = classnum + 1; 58 } 59 </div> 60 61 </div> 62 <div class="rg5"> 63 @UIHelper.PagesHelper(ViewBag.ControllerName, Model.TotalPages, Model.PageIndex, Model.PageSize, Model.TotalCount, Model.HasPreviousPage, Model.HasNextPage, Model.PageList); 64 65 </div> 66 </div> 67 </div> 68 <script> 69 //菜单显示 70 $("#systemusersys").addClass("hbg"); 71 $("#@(ViewBag.ControllerName)").removeClass("navli"); 72 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 73 $(".systemusersys").each(function (index, item) { 74 $(this).show(); 75 }); 76 </script>
Add.cshtml
1 @{ 2 ViewBag.Title = "Add"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 <div class="contrgcon"> 6 <div class="rgtit3"> 7 <div class="tit1"> 8 <h3>添加菜单</h3> 9 </div> 10 <div class="rgtit3con"> 11 @using (Html.BeginForm()) 12 { 13 <dl> 14 <dd class="dc1">菜单名称:</dd> 15 <dd> 16 <input name="MenuName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" /> 17 </dd> 18 </dl> 19 20 <dl> 21 <dd class="dc1">连接地址:</dd> 22 <dd> 23 <input name="Url" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" /> 24 </dd> 25 </dl> 26 <dl> 27 <dd class="dc1">别名样式:</dd> 28 <dd> 29 <input name="Alias" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" /> 30 </dd> 31 </dl> 32 33 34 <dl> 35 <dd> 36 <input type="submit" value="提 交" class="rgbut4" /> 37 </dd> 38 </dl> 39 } 40 </div> 41 </div> 42 </div> 43 <script> 44 //菜单显示 45 $("#systemusersys").addClass("hbg"); 46 $("#@(ViewBag.ControllerName)").removeClass("navli"); 47 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 48 $(".systemusersys").each(function (index, item) { 49 $(this).show(); 50 }); 51 </script>
Edit.cshtml
1 @{ 2 ViewBag.Title = "Add"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 @model SJCRM.Models.Menu 6 <div class="contrgcon"> 7 <div class="rgtit3"> 8 <div class="tit1"> 9 <h3>编辑</h3> 10 </div> 11 <div class="rgtit3con"> 12 @using (Html.BeginForm()) 13 { 14 <dl> 15 <dd class="dc1">菜单名称:</dd> 16 <dd> 17 <input name="MenuName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@Model.MenuName" /> 18 </dd> 19 </dl> 20 21 <dl> 22 <dd class="dc1">连接地址:</dd> 23 <dd> 24 <input name="Url" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" value="@Model.Url" /> 25 </dd> 26 </dl> 27 <dl> 28 <dd class="dc1">别名样式:</dd> 29 <dd> 30 <input name="Alias" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" value="@Model.Alias" /> 31 </dd> 32 </dl> 33 34 35 <dl> 36 <dd> 37 <input type="submit" value="提 交" class="rgbut4" /> 38 </dd> 39 </dl> 40 } 41 </div> 42 </div> 43 </div> 44 <script> 45 //菜单显示 46 $("#systemusersys").addClass("hbg"); 47 $("#@(ViewBag.ControllerName)").removeClass("navli"); 48 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 49 $(".systemusersys").each(function (index, item) { 50 $(this).show(); 51 }); 52 </script>
Search.cshtml
1 @{ 2 ViewBag.Title = "Index"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 6 @model SJCRM.Helpers.Pager<SJCRM.Models.Menu> 7 <div class="contrgcon"> 8 <div class="contrg_list"> 9 <div class="rgtit"> 10 <form method="post" action="/@ViewBag.ControllerName/search"> 11 <dl> 12 <dd>关键词:</dd> 13 <dd> 14 <input name="KeyWord" type="text" class="rgtxt2" /></dd> 15 <dd> 16 <input type="submit" value="查 询" class="rgbut1" /></dd> 17 </dl> 18 </form> 19 </div> 20 <div class="rgc"> 21 <dl class="rgt11"> 22 <dt> 23 <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span> 24 </dt> 25 </dl> 26 27 <div class="rg3"> 28 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 29 <tr> 30 <td class="rgtd2">编号</td> 31 <td class="rgtd3">菜单名称</td> 32 <td class="rgtd3">别名样式</td> 33 <td class="rgtd3">连接地址</td> 34 <td class="rgtd3">创建时间</td> 35 <td class="rgtd3">状态</td> 36 <td class="rgtd4">操作</td> 37 </tr> 38 </table> 39 40 </div> 41 <div class="rg4"> 42 @{int classnum = 1;} 43 @foreach (var item in Model) 44 { 45 <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0) 46 {<text>class="rgbg2"</text>}> 47 <tr> 48 <td class="rgtd2">@item.MenuID</td> 49 <td class="rgtd3">@item.MenuName</td> 50 <td class="rgtd3">@item.Alias</td> 51 <td class="rgtd3">@item.Url</td> 52 <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td> 53 <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td> 54 <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.MenuID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.MenuID">编辑</a> </td> 55 </tr> 56 </table> 57 classnum = classnum + 1; 58 } 59 </div> 60 61 </div> 62 63 </div> 64 </div> 65 <script> 66 //菜单显示 67 $("#systemusersys").addClass("hbg"); 68 $("#@(ViewBag.ControllerName)").removeClass("navli"); 69 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 70 $(".systemusersys").each(function (index, item) { 71 $(this).show(); 72 }); 73 </script>
部门管理
Controller代码
1 public class DepartmentController : Controller 2 { 3 DepartmentRepository departmentryrepository = new DepartmentRepository(); 4 5 #region 列表 6 /// <summary> 7 /// 默认页面 8 /// </summary> 9 /// <returns></returns> 10 /// 11 [Authorize] 12 public ActionResult Index(int? page) 13 { 14 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 15 var source = departmentryrepository.GetModelList(); 16 return View(departmentryrepository.GetPageModelList(source, 10, page ?? 1)); 17 } 18 #endregion 19 20 #region 添加 21 /// <summary> 22 /// 添加页 23 /// </summary> 24 /// <param name="model">实体类</param> 25 /// <returns></returns> 26 [Authorize] 27 public ActionResult Add(Department model) 28 { 29 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 30 // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0); 31 return View(); 32 } 33 34 /// <summary> 35 /// 添加事件 36 /// </summary> 37 /// <param name="model">实体类</param> 38 /// <param name="fc"></param> 39 /// <returns></returns> 40 [Authorize, HttpPost, ValidateInput(false)] 41 public ActionResult Add(Department model, FormCollection fc) 42 { 43 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 44 model.State = 1; 45 model.CreateTime = DateTime.Now; 46 departmentryrepository.SaveOrEditModel(model); 47 return RedirectToAction("Index"); 48 } 49 #endregion 50 51 #region 删除 52 /// <summary> 53 /// 删除 54 /// </summary> 55 /// <param name="id">删除编号</param> 56 /// <returns></returns> 57 [Authorize] 58 public ActionResult Delete(int id) 59 { 60 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 61 var model = departmentryrepository.GetModel(id); 62 model.State = 0; 63 if (model != null) 64 { 65 departmentryrepository.SaveOrEditModel(model); 66 return RedirectToAction("index"); 67 } 68 else 69 return View("404"); 70 //var model = categoryrepository.GetModel(id); 71 //if (model != null) 72 //{ 73 // categoryrepository.DeleteModel(id); 74 // return RedirectToAction("Index"); 75 //} 76 //else 77 // return View("404"); 78 79 } 80 #endregion 81 82 #region 查询 83 [Authorize] 84 public ActionResult Search(int? page) 85 { 86 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 87 string jobname = ""; 88 if (page == null) 89 { 90 jobname = Request.Form["KeyWord"]; 91 CookieHelper.SetObj("KeyWord", 0, jobname); 92 } 93 else 94 jobname = CookieHelper.GetValue("KeyWord"); 95 96 var query = QueryBuilder.Create<Department>().Like(d => d.DepartmentName, jobname); 97 var source = departmentryrepository.GetModelList().Where(query.Expression); 98 return View(new Pager<Department>(source, page ?? 1, 10)); 99 } 100 #endregion 101 102 #region 编辑 103 [Authorize] 104 public ActionResult Edit(int id) 105 { 106 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 107 var model = departmentryrepository.GetModel(id); 108 if (model != null) 109 { 110 ViewData["State"] = SelectListHelper.GetStateSelectList(model.State); 111 return View(model); 112 } 113 else 114 return View("404"); 115 } 116 117 [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)] 118 public ActionResult Edit(int id, FormCollection fc) 119 { 120 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 121 var model = departmentryrepository.GetModel(id); 122 123 if (model != null) 124 { 125 UpdateModel(model); 126 departmentryrepository.SaveOrEditModel(model); 127 return RedirectToAction("index"); 128 } 129 else 130 return View("404"); 131 } 132 #endregion 133 }
View代码
Index.cshtml
1 @{ 2 ViewBag.Title = "Index"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 6 @model SJCRM.Helpers.Pager<SJCRM.Models.Department> 7 <div class="contrgcon"> 8 <div class="contrg_list"> 9 <div class="rgtit"> 10 <form method="post" action="/@ViewBag.ControllerName/search"> 11 <dl> 12 <dd>关键词:</dd> 13 <dd> 14 <input name="KeyWord" type="text" class="rgtxt2" /></dd> 15 <dd> 16 <input type="submit" value="查 询" class="rgbut1" /></dd> 17 </dl> 18 </form> 19 </div> 20 <div class="rgc"> 21 <dl class="rgt11"> 22 <dt> 23 <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span> 24 </dt> 25 </dl> 26 27 <div class="rg3"> 28 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 29 <tr> 30 <td class="rgtd2">编号</td> 31 <td class="rgtd2">部门名称</td> 32 <td class="rgtd3">是否销售</td> 33 <td class="rgtd3">创建时间</td> 34 <td class="rgtd3">状态</td> 35 <td class="rgtd4">操作</td> 36 </tr> 37 </table> 38 39 </div> 40 <div class="rg4"> 41 @{int classnum = 1;} 42 @foreach (var item in Model) 43 { 44 <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0) 45 {<text>class="rgbg2"</text>}> 46 <tr> 47 <td class="rgtd2">@item.DepartmentID</td> 48 <td class="rgtd2">@item.DepartmentName</td> 49 <td class="rgtd3">@(item.IsSale == 1 ? "是" : "否")</td> 50 <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td> 51 <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td> 52 <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.DepartmentID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.DepartmentID">编辑</a> </td> 53 </tr> 54 </table> 55 classnum = classnum + 1; 56 } 57 </div> 58 59 </div> 60 <div class="rg5"> 61 @UIHelper.PagesHelper(ViewBag.ControllerName, Model.TotalPages, Model.PageIndex, Model.PageSize, Model.TotalCount, Model.HasPreviousPage, Model.HasNextPage, Model.PageList); 62 63 </div> 64 </div> 65 </div> 66 <script> 67 //菜单显示 68 $("#systemusersys").addClass("hbg"); 69 $("#@(ViewBag.ControllerName)").removeClass("navli"); 70 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 71 $(".systemusersys").each(function (index, item) { 72 $(this).show(); 73 }); 74 </script>
Add.cshtml
1 @{ 2 ViewBag.Title = "Add"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 <div class="contrgcon"> 6 <div class="rgtit3"> 7 <div class="tit1"> 8 <h3>添加</h3> 9 </div> 10 <div class="rgtit3con"> 11 @using (Html.BeginForm()) 12 { 13 <dl> 14 <dd class="dc1">部门名称:</dd> 15 <dd> 16 <input name="DepartmentName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" /> 17 </dd> 18 </dl> 19 20 21 <dl> 22 <dd class="dc1">是否销售:</dd> 23 <dd> 24 <select name="IsSale"> 25 <option value="1">是</option> 26 <option value="0">否</option> 27 </select> 28 </dd> 29 </dl> 30 31 <dl> 32 <dd> 33 <input type="submit" value="提 交" class="rgbut4" /> 34 </dd> 35 </dl> 36 } 37 </div> 38 </div> 39 </div> 40 <script> 41 //菜单显示 42 $("#systemusersys").addClass("hbg"); 43 $("#@(ViewBag.ControllerName)").removeClass("navli"); 44 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 45 $(".systemusersys").each(function (index, item) { 46 $(this).show(); 47 }); 48 </script>
Edit.cshtml
1 @{ 2 ViewBag.Title = "Add"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 @model SJCRM.Models.Department 6 <div class="contrgcon"> 7 <div class="rgtit3"> 8 <div class="tit1"> 9 <h3>编辑</h3> 10 </div> 11 <div class="rgtit3con"> 12 @using (Html.BeginForm()) 13 { 14 <dl> 15 <dd class="dc1">部门名称:</dd> 16 <dd> 17 <input name="DepartmentName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@Model.DepartmentName" /> 18 </dd> 19 </dl> 20 21 22 <dl> 23 <dd class="dc1">是否销售:</dd> 24 <dd> 25 @UIHelper.IsSelect("IsSale", @Model.IsSale.ToString()); 26 27 </dd> 28 </dl> 29 30 <dl> 31 <dd> 32 <input type="submit" value="提 交" class="rgbut4" /> 33 </dd> 34 </dl> 35 } 36 </div> 37 </div> 38 </div> 39 <script> 40 //菜单显示 41 $("#systemusersys").addClass("hbg"); 42 $("#@(ViewBag.ControllerName)").removeClass("navli"); 43 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 44 $(".systemusersys").each(function (index, item) { 45 $(this).show(); 46 }); 47 </script>
Search.cshtml
1 @{ 2 ViewBag.Title = "Index"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 6 @model SJCRM.Helpers.Pager<SJCRM.Models.Department> 7 <div class="contrgcon"> 8 <div class="contrg_list"> 9 <div class="rgtit"> 10 <form method="post" action="/@ViewBag.ControllerName/search"> 11 <dl> 12 <dd>关键词:</dd> 13 <dd> 14 <input name="KeyWord" type="text" class="rgtxt2" /></dd> 15 <dd> 16 <input type="submit" value="查 询" class="rgbut1" /></dd> 17 </dl> 18 </form> 19 </div> 20 <div class="rgc"> 21 <dl class="rgt11"> 22 <dt> 23 <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span> 24 </dt> 25 </dl> 26 27 <div class="rg3"> 28 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 29 <tr> 30 <td class="rgtd2">编号</td> 31 <td class="rgtd2">部门名称</td> 32 <td class="rgtd3">是否销售</td> 33 <td class="rgtd3">创建时间</td> 34 <td class="rgtd3">状态</td> 35 <td class="rgtd4">操作</td> 36 </tr> 37 </table> 38 39 </div> 40 <div class="rg4"> 41 @{int classnum = 1;} 42 @foreach (var item in Model) 43 { 44 <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0) 45 {<text>class="rgbg2"</text>}> 46 <tr> 47 <td class="rgtd2">@item.DepartmentID</td> 48 <td class="rgtd2">@item.DepartmentName</td> 49 <td class="rgtd3">@(item.IsSale == 1 ? "是" : "否")</td> 50 <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td> 51 <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td> 52 <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.DepartmentID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.DepartmentID">编辑</a> </td> 53 </tr> 54 </table> 55 classnum = classnum + 1; 56 } 57 </div> 58 59 </div> 60 61 </div> 62 </div> 63 <script> 64 //菜单显示 65 $("#systemusersys").addClass("hbg"); 66 $("#@(ViewBag.ControllerName)").removeClass("navli"); 67 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 68 $(".systemusersys").each(function (index, item) { 69 $(this).show(); 70 }); 71 </script>
岗位管理
Controller代码
1 public class JobController : Controller 2 { 3 4 JobRepository jobryrepository = new JobRepository(); 5 6 #region 岗位列表 7 /// <summary> 8 /// 默认页面 9 /// </summary> 10 /// <returns></returns> 11 /// 12 [Authorize] 13 public ActionResult Index(int? page) 14 { 15 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 16 var source = jobryrepository.GetModelListByState(1); 17 return View(jobryrepository.GetPageModelList(source, 10, page ?? 1)); 18 } 19 #endregion 20 21 #region 添加 22 /// <summary> 23 /// 添加页 24 /// </summary> 25 /// <param name="model">实体类</param> 26 /// <returns></returns> 27 [Authorize] 28 public ActionResult Add(Job model) 29 { 30 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 31 // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0); 32 return View(); 33 } 34 35 /// <summary> 36 /// 添加事件 37 /// </summary> 38 /// <param name="model">实体类</param> 39 /// <param name="fc"></param> 40 /// <returns></returns> 41 [Authorize, HttpPost, ValidateInput(false)] 42 public ActionResult Add(Job model, FormCollection fc) 43 { 44 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 45 model.State = 1; 46 model.CreateTime = DateTime.Now; 47 jobryrepository.SaveOrEditModel(model); 48 return RedirectToAction("Index"); 49 } 50 #endregion 51 52 #region 删除 53 /// <summary> 54 /// 删除 55 /// </summary> 56 /// <param name="id">删除编号</param> 57 /// <returns></returns> 58 [Authorize] 59 public ActionResult Delete(int id) 60 { 61 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 62 var model = jobryrepository.GetModel(id); 63 model.State = 0; 64 if (model != null) 65 { 66 jobryrepository.SaveOrEditModel(model); 67 return RedirectToAction("index"); 68 } 69 else 70 return View("404"); 71 //var model = categoryrepository.GetModel(id); 72 //if (model != null) 73 //{ 74 // categoryrepository.DeleteModel(id); 75 // return RedirectToAction("Index"); 76 //} 77 //else 78 // return View("404"); 79 80 } 81 #endregion 82 83 #region 查询 84 [Authorize] 85 public ActionResult Search(int? page) 86 { 87 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 88 string jobname = ""; 89 if (page == null) 90 { 91 jobname = Request.Form["KeyWord"]; 92 CookieHelper.SetObj("KeyWord", 0, jobname); 93 } 94 else 95 jobname = CookieHelper.GetValue("KeyWord"); 96 97 var query = QueryBuilder.Create<Job>().Like(d => d.JobName, jobname); 98 var source = jobryrepository.GetModelList().Where(query.Expression); 99 return View(new Pager<Job>(source, page ?? 1, 10)); 100 } 101 #endregion 102 103 #region 编辑 104 [Authorize] 105 public ActionResult Edit(int id) 106 { 107 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 108 var model = jobryrepository.GetModel(id); 109 if (model != null) 110 { 111 ViewData["State"] = SelectListHelper.GetStateSelectList(model.State); 112 return View(model); 113 } 114 else 115 return View("404"); 116 } 117 118 [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)] 119 public ActionResult Edit(int id, FormCollection fc) 120 { 121 ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower(); 122 var model = jobryrepository.GetModel(id); 123 124 if (model != null) 125 { 126 UpdateModel(model); 127 jobryrepository.SaveOrEditModel(model); 128 return RedirectToAction("index"); 129 } 130 else 131 return View("404"); 132 } 133 #endregion 134 }
View代码
Index.cshtml
1 @{ 2 ViewBag.Title = "Index"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 6 @model SJCRM.Helpers.Pager<SJCRM.Models.Job> 7 <div class="contrgcon"> 8 <div class="contrg_list"> 9 <div class="rgtit"> 10 <form method="post" action="/@ViewBag.ControllerName/search"> 11 <dl> 12 <dd>关键词:</dd> 13 <dd> 14 <input name="KeyWord" type="text" class="rgtxt2" /></dd> 15 <dd> 16 <input type="submit" value="查 询" class="rgbut1" /></dd> 17 </dl> 18 </form> 19 </div> 20 <div class="rgc"> 21 <dl class="rgt11"> 22 <dt> 23 <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span> 24 </dt> 25 </dl> 26 27 <div class="rg3"> 28 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 29 <tr> 30 <td class="rgtd2">编号</td> 31 <td class="rgtd2">岗位名称</td> 32 <td class="rgtd3">岗位说明</td> 33 <td class="rgtd3">是否主管</td> 34 <td class="rgtd3">状态</td> 35 <td class="rgtd4">操作</td> 36 </tr> 37 </table> 38 39 </div> 40 <div class="rg4"> 41 @{int classnum = 1;} 42 @foreach (var item in Model) 43 { 44 <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0) 45 {<text>class="rgbg2"</text>}> 46 <tr> 47 <td class="rgtd2">@item.JobID</td> 48 <td class="rgtd2">@item.JobName</td> 49 <td class="rgtd3">@item.JobContent</td> 50 <td class="rgtd3">@(item.IsManager == 1 ? "是" : "否")</td> 51 <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td> 52 <td class="rgtd4"><a href="/job/delete/@item.JobID">删除</a> | <a href="/job/edit/@item.JobID">编辑</a> </td> 53 </tr> 54 </table> 55 classnum = classnum + 1; 56 } 57 </div> 58 59 </div> 60 <div class="rg5"> 61 @UIHelper.PagesHelper(ViewBag.ControllerName, Model.TotalPages, Model.PageIndex, Model.PageSize, Model.TotalCount, Model.HasPreviousPage, Model.HasNextPage, Model.PageList); 62 63 </div> 64 </div> 65 </div> 66 <script> 67 //菜单显示 68 $("#systemusersys").addClass("hbg"); 69 $("#@(ViewBag.ControllerName)").removeClass("navli"); 70 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 71 $(".systemusersys").each(function (index, item) { 72 $(this).show(); 73 }); 74 </script>
Add.cshtml
1 @{ 2 ViewBag.Title = "Add"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 <div class="contrgcon"> 6 <div class="rgtit3"> 7 <div class="tit1"> 8 <h3>添加</h3> 9 </div> 10 <div class="rgtit3con"> 11 @using (Html.BeginForm()) 12 { 13 <dl> 14 <dd class="dc1">岗位名称:</dd> 15 <dd> 16 <input name="JobName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" /> 17 </dd> 18 </dl> 19 20 21 <dl> 22 <dd class="dc1">是否主管:</dd> 23 <dd> 24 <select name="IsManager"> 25 <option value="1">是</option> 26 <option value="0">否</option> 27 </select> 28 </dd> 29 </dl> 30 <dl> 31 <dd class="dc1">岗位说明:</dd> 32 <dd> 33 <textarea rows="10" cols="82" name="JobContent" id="JobContent"></textarea> 34 </dd> 35 </dl> 36 <dl> 37 <dd> 38 <input type="submit" value="提 交" class="rgbut4" /> 39 </dd> 40 </dl> 41 } 42 </div> 43 </div> 44 </div> 45 <script> 46 //菜单显示 47 $("#systemusersys").addClass("hbg"); 48 $("#@(ViewBag.ControllerName)").removeClass("navli"); 49 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 50 $(".systemusersys").each(function (index, item) { 51 $(this).show(); 52 }); 53 </script>
Edit.cshtml
1 @{ 2 ViewBag.Title = "Add"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 @model SJCRM.Models.Job 6 <div class="contrgcon"> 7 <div class="rgtit3"> 8 <div class="tit1"> 9 <h3>编辑</h3> 10 </div> 11 <div class="rgtit3con"> 12 @using (Html.BeginForm()) 13 { 14 <dl> 15 <dd class="dc1">岗位名称:</dd> 16 <dd> 17 <input name="JobName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@Model.JobName" /> 18 </dd> 19 </dl> 20 21 22 <dl> 23 <dd class="dc1">是否主管:</dd> 24 <dd> 25 @UIHelper.IsSelect("IsManager",Model.IsManager.ToString()); 26 27 </dd> 28 </dl> 29 <dl> 30 <dd class="dc1">岗位说明:</dd> 31 <dd> 32 <textarea rows="10" cols="82" name="JobContent" id="JobContent">@Model.JobContent</textarea> 33 </dd> 34 </dl> 35 <dl> 36 <dd> 37 <input type="submit" value="提 交" class="rgbut4" /> 38 </dd> 39 </dl> 40 } 41 </div> 42 </div> 43 </div> 44 <script> 45 //菜单显示 46 $("#systemusersys").addClass("hbg"); 47 $("#@(ViewBag.ControllerName)").removeClass("navli"); 48 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 49 $(".systemusersys").each(function (index, item) { 50 $(this).show(); 51 }); 52 </script> 53 @*<script src="/Content/Scripts/Validform_v5.3.2.js"></script> 54 <script> 55 $(document).ready(function () { 56 $("#addform").Validform({ 57 tiptype: 3 58 }); 59 }); 60 </script>*@ 61 <script src="@Url.Content("~/Content/kindeditor/kindeditor-min.js")" type="text/javascript"></script> 62 @*<script type="text/javascript"> 63 KindEditor.ready(function (K) { 64 K.create('#JobContent', { 65 allowFileManager: true 66 }); 67 }); 68 </script>*@
Search.cshtml
1 @{ 2 ViewBag.Title = "Index"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 6 @model SJCRM.Helpers.Pager<SJCRM.Models.Job> 7 <div class="contrgcon"> 8 <div class="contrg_list"> 9 <div class="rgtit"> 10 <form method="post" action="/@ViewBag.ControllerName/search"> 11 <dl> 12 <dd>关键词:</dd> 13 <dd> 14 <input name="KeyWord" type="text" class="rgtxt2" /></dd> 15 <dd> 16 <input type="submit" value="查 询" class="rgbut1" /></dd> 17 </dl> 18 </form> 19 </div> 20 <div class="rgc"> 21 <dl class="rgt11"> 22 <dt> 23 <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span> 24 </dt> 25 </dl> 26 27 <div class="rg3"> 28 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 29 <tr> 30 <td class="rgtd2">编号</td> 31 <td class="rgtd2">岗位名称</td> 32 <td class="rgtd3">岗位说明</td> 33 <td class="rgtd3">是否主管</td> 34 <td class="rgtd3">状态</td> 35 <td class="rgtd4">操作</td> 36 </tr> 37 </table> 38 39 </div> 40 <div class="rg4"> 41 @{int classnum = 1;} 42 @foreach (var item in Model) 43 { 44 <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0) 45 {<text>class="rgbg2"</text>}> 46 <tr> 47 <td class="rgtd2">@item.JobID</td> 48 <td class="rgtd2">@item.JobName</td> 49 <td class="rgtd3">@item.JobContent</td> 50 <td class="rgtd3">@(item.IsManager == 1 ? "是" : "否")</td> 51 <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td> 52 <td class="rgtd4"><a href="/job/delete/@item.JobID">删除</a> | <a href="/job/edit/@item.JobID">编辑</a> </td> 53 </tr> 54 </table> 55 classnum = classnum + 1; 56 } 57 </div> 58 59 </div> 60 61 </div> 62 </div> 63 <script> 64 //菜单显示 65 $("#systemusersys").addClass("hbg"); 66 $("#@(ViewBag.ControllerName)").removeClass("navli"); 67 $("#@(ViewBag.ControllerName)").addClass("navlihg"); 68 $(".systemusersys").each(function (index, item) { 69 $(this).show(); 70 }); 71 </script>