俄罗斯贵宾会-俄罗斯贵宾会官网
做最好的网站

主攻ASP.NET.4.5.1俄罗斯贵宾会: MVC5.0之重生:系统角色与权限(二)

View Code

 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                     <a href="/@ViewBag.ControllerName/add">添加</a>
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>&nbsp;|&nbsp;<a href="/job/edit/@item.JobID">编辑</a>&nbsp; </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>
MemoryStream ms = HttpUtil.HttpDownloadFile(url);
Bitmap bmp = new Bitmap(ms);

EncoderParameters encoderParameters = new EncoderParameters(1);
EncoderParameter encoderParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 75L);
encoderParameters.Param[0] = encoderParameter;

MemoryStream msCompress = new MemoryStream();
bmp.Save(msCompress, GetImageCodecInfo(ImageFormat.Jpeg), encoderParameters);
Bitmap bmpCompress = new Bitmap(msCompress);
bmpCompress.Save(path);
bmp.Save(path2);

msCompress.Close();
ms.Close();

数据结构

代码:

View Code

 

俄罗斯贵宾会 1俄罗斯贵宾会 2

俄罗斯贵宾会 3俄罗斯贵宾会 4

View Code

View Code

  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     }

俄罗斯贵宾会 5俄罗斯贵宾会 6

俄罗斯贵宾会 7

代码:

 

private static ImageCodecInfo GetImageCodecInfo(ImageFormat imageFormat)
{
    ImageCodecInfo[] imageCodecInfoArr = ImageCodecInfo.GetImageDecoders();
    foreach (ImageCodecInfo imageCodecInfo in imageCodecInfoArr)
    {
        if (imageCodecInfo.FormatID == imageFormat.Guid)
        {
            return imageCodecInfo;
        }
    }
    return null;
}

 

Controller代码

View Code

 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>

俄罗斯贵宾会 8俄罗斯贵宾会 9

俄罗斯贵宾会 10俄罗斯贵宾会 11

Edit.cshtml

View Code

俄罗斯贵宾会 12俄罗斯贵宾会 13

Search.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>

俄罗斯贵宾会 14俄罗斯贵宾会 15

View Code

 菜单管理

 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>

View Code

俄罗斯贵宾会 16俄罗斯贵宾会 17

俄罗斯贵宾会 18俄罗斯贵宾会 19

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                    <a href="/@ViewBag.ControllerName/add">添加</a>
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>&nbsp;|&nbsp;<a href="/@ViewBag.ControllerName/edit/@item.RoleID">编辑</a>&nbsp; </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>

View Code

 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>

系统角色篇

 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>
 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                    <a href="/@ViewBag.ControllerName/add">添加</a>
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>&nbsp;|&nbsp;<a href="/@ViewBag.ControllerName/edit/@item.DepartmentID">编辑</a>&nbsp; </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>

View Code

俄罗斯贵宾会 20俄罗斯贵宾会 21

View Code

俄罗斯贵宾会 22俄罗斯贵宾会 23

 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                    <a href="/@ViewBag.ControllerName/add">添加</a>
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>&nbsp;|&nbsp;<a href="/@ViewBag.ControllerName/edit/@item.MenuID">编辑</a>&nbsp; </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>
 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>
 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                     <a href="/systemuser/add">添加用户</a>
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>&nbsp;|&nbsp;<a href="/systemuser/edit/@item.SystemUserID">编辑</a>&nbsp; </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>

View代码

俄罗斯贵宾会 24俄罗斯贵宾会 25

Index.cshtml

俄罗斯贵宾会 26俄罗斯贵宾会 27

俄罗斯贵宾会 28俄罗斯贵宾会 29

 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>

俄罗斯贵宾会 30俄罗斯贵宾会 31

俄罗斯贵宾会 32

俄罗斯贵宾会 33俄罗斯贵宾会 34

View代码

View Code

Add.cshtml

俄罗斯贵宾会,View Code

  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     }
 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                    <a href="/@ViewBag.ControllerName/add">添加</a>
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>&nbsp;|&nbsp;<a href="/@ViewBag.ControllerName/edit/@item.DepartmentID">编辑</a>&nbsp; </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>

View Code

Controller代码

俄罗斯贵宾会 35

俄罗斯贵宾会 36俄罗斯贵宾会 37

Index.cshtml

本文由俄罗斯贵宾会发布于编程,转载请注明出处:主攻ASP.NET.4.5.1俄罗斯贵宾会: MVC5.0之重生:系统角色与权限(二)

您可能还会对下面的文章感兴趣: