重构菜单结构,以及相关导航条设置,面包屑导航更改到js脚本中,更改Navigations数据库结构

This commit is contained in:
Argo-Lenovo 2016-10-26 14:02:40 +08:00
parent 02cfbfd8bd
commit f111f3bc4e
13 changed files with 331 additions and 331 deletions

View File

@ -396,6 +396,10 @@ a.logo {
margin-bottom: 15px; margin-bottom: 15px;
} }
.modal-dialog .modal-body .form-inline .form-group input {
padding-right: 30px;
}
.modal-header { .modal-header {
background-color: #f5f5f5; background-color: #f5f5f5;
border-top-left-radius: 6px; border-top-left-radius: 6px;
@ -456,7 +460,7 @@ input.valid {
padding-left: 6px; padding-left: 6px;
} }
.lgbBreadcrumb { ul.breadcrumb {
position: absolute; position: absolute;
top: 56px; top: 56px;
left: 15px; left: 15px;
@ -464,20 +468,19 @@ input.valid {
border-color: #ddd; border-color: #ddd;
border-width: 1px 0 0 0; border-width: 1px 0 0 0;
border-style: solid; border-style: solid;
background-color: transparent;
border-top-left-radius: 0;
border-top-right-radius: 0;
} }
.lgbBreadcrumb > ul { ul.breadcrumb > li.active {
background-color: transparent; display: inline-block;
} }
.lgbBreadcrumb > ul > li.active { ul.breadcrumb > li.load {
display: inline-block; display: none;
} }
.lgbBreadcrumb > ul > li.load { ul.breadcrumb > li > a > i {
display: none; padding-right: 6px;
} }
.lgbBreadcrumb > ul > li > a > i {
padding-right: 6px;
}

View File

@ -164,6 +164,11 @@
})(jQuery); })(jQuery);
$(function () { $(function () {
// breadcrumb
var breadcrumb = $('.sidebar-menu > li > a.active > span').text();
if (breadcrumb === "") $('.breadcrumb > li + li').hide();
else $('.breadcrumb > li + li').text(breadcrumb);
if ($.isFunction($.validator)) { if ($.isFunction($.validator)) {
jQuery.validator.addMethod("ip", function (value, element) { jQuery.validator.addMethod("ip", function (value, element) {
return this.optional(element) || /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/.test(value); return this.optional(element) || /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/.test(value);

View File

@ -26,7 +26,6 @@ namespace Bootstrap.Admin.Controllers
public ActionResult Users() public ActionResult Users()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel();
v.BreadcrumbName = "用户管理";
v.ShowMenu = "hide"; v.ShowMenu = "hide";
v.Menus[1].Active = "active"; v.Menus[1].Active = "active";
v.HomeUrl = "~/Admin"; v.HomeUrl = "~/Admin";
@ -39,7 +38,6 @@ namespace Bootstrap.Admin.Controllers
public ActionResult Groups() public ActionResult Groups()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel();
v.BreadcrumbName = "部门管理";
v.ShowMenu = "hide"; v.ShowMenu = "hide";
v.Menus[3].Active = "active"; v.Menus[3].Active = "active";
v.HomeUrl = "~/Admin"; v.HomeUrl = "~/Admin";
@ -48,7 +46,6 @@ namespace Bootstrap.Admin.Controllers
public ActionResult Roles() public ActionResult Roles()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel();
v.BreadcrumbName = "角色管理";
v.ShowMenu = "hide"; v.ShowMenu = "hide";
v.Menus[2].Active = "active"; v.Menus[2].Active = "active";
v.HomeUrl = "~/Admin"; v.HomeUrl = "~/Admin";
@ -57,7 +54,6 @@ namespace Bootstrap.Admin.Controllers
public ActionResult Menus() public ActionResult Menus()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel();
v.BreadcrumbName = "菜单管理";
v.ShowMenu = "hide"; v.ShowMenu = "hide";
v.Menus[0].Active = "active"; v.Menus[0].Active = "active";
v.HomeUrl = "~/Admin"; v.HomeUrl = "~/Admin";

View File

@ -26,10 +26,6 @@ namespace Bootstrap.Admin.Models
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public string BreadcrumbName { get; set; }
/// <summary>
///
/// </summary>
public string ShowMenu { get; set; } public string ShowMenu { get; set; }
/// <summary> /// <summary>
/// ///

View File

@ -1,5 +1,6 @@
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Models namespace Bootstrap.Admin.Models
{ {
@ -7,7 +8,8 @@ namespace Bootstrap.Admin.Models
{ {
public NavigatorBarModel() public NavigatorBarModel()
{ {
Menus = Menu.RetrieveMenus(); Menus = MenuHelper.RetrieveMenus().ToList();
Menus.ForEach(m => m.Active = null);
} }
/// <summary> /// <summary>
/// ///

View File

@ -1,41 +1,36 @@
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using Longbow.Web.Mvc; using Longbow.Web.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
namespace Bootstrap.Admin.Models namespace Bootstrap.Admin.Models
{ {
public class QueryMenuOption : PaginationOption public class QueryMenuOption : PaginationOption
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public string Category { get; set; } public string Category { get; set; }
public QueryData<Menu> RetrieveData() public QueryData<Menu> RetrieveData()
{ {
// int limit, int offset, string name, string price, string sort, string order var data = MenuHelper.RetrieveMenus();
var data = MenuHelper.RetrieveMenus(string.Empty); if (!string.IsNullOrEmpty(Name))
if (!string.IsNullOrEmpty(Name)) {
{ data = data.Where(t => t.Name.Contains(Name));
data = data.Where(t => t.Name.Contains(Name)); }
} var ret = new QueryData<Menu>();
if (!string.IsNullOrEmpty(Category)) ret.total = data.Count();
{ // TODO: 通过option.Sort属性判断对那列进行排序现在统一对名称列排序
data = data.Where(t => t.Category.Contains(Category)); data = Order == "asc" ? data.OrderBy(t => t.Name) : data.OrderByDescending(t => t.Name);
} ret.rows = data.Skip(Offset).Take(Limit);
var ret = new QueryData<Menu>(); return ret;
ret.total = data.Count(); }
// TODO: 通过option.Sort属性判断对那列进行排序现在统一对名称列排序 }
data = Order == "asc" ? data.OrderBy(t => t.Name) : data.OrderByDescending(t => t.Name);
ret.rows = data.Skip(Offset).Take(Limit);
return ret;
}
}
} }

View File

@ -1,53 +1,51 @@
$(function () { $(function () {
var bsa = new BootstrapAdmin({ var bsa = new BootstrapAdmin({
url: '../api/Menus', url: '../api/Menus',
dataEntity: new DataEntity({ dataEntity: new DataEntity({
map: { map: {
ID: "menuID", ID: "menuID",
ParentId: "parentId", ParentId: "parentId",
Name: "name", Name: "name",
Order: "order", Order: "order",
Icon: "icon", Icon: "icon",
Url: "url", Url: "url",
Category: "category" Category: "category"
} }
}) })
}); });
$('table').smartTable({ $('table').smartTable({
url: '../api/Menus', //请求后台的URL* url: '../api/Menus', //请求后台的URL*
sortName: 'UserName', sortName: 'UserName',
queryParams: function (params) { return $.extend(params, { name: $("#txt_menus_name").val(), category: $('#txt_menus_category').val() }); }, //传递参数(* queryParams: function (params) { return $.extend(params, { name: $("#txt_menus_name").val(), category: $('#txt_menus_category').val() }); }, //传递参数(*
columns: [{ checkbox: true }, columns: [{ checkbox: true },
{ title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter }, { title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "父级Id", field: "ParentId", sortable: false }, { title: "父级Id", field: "ParentId", sortable: false },
{ title: "菜单名称", field: "Name", sortable: true }, { title: "菜单名称", field: "Name", sortable: true },
{ title: "菜单序号", field: "Order", sortable: false }, { title: "菜单序号", field: "Order", sortable: false },
{ title: "菜单图标", field: "Icon", sortable: false }, { title: "菜单图标", field: "Icon", sortable: false },
{ title: "菜单路径", field: "Url", sortable: false }, { title: "菜单路径", field: "Url", sortable: false },
{ title: "菜单类别", field: "Category", sortable: false } { title: "菜单类别", field: "Category", sortable: false }
] ]
}); });
// validate // validate
$('#dataForm').autoValidate({ $('#dataForm').autoValidate({
name: { name: {
required: true, required: true,
maxlength: 50 maxlength: 50
}, },
icon: { icon: {
required: true, required: true,
maxlength: 50 maxlength: 50
}, },
url: { url: {
required: true, required: true,
maxlength: 50 maxlength: 50
}, },
category: { category: {
required: true, required: true,
maxlength: 50 maxlength: 50
} }
}); });
//TODO: 客户端点击保存用户后,要更新页面右上角用户显示名称
}); });

View File

@ -33,7 +33,7 @@
<img alt="" src="../content/images/logo6.jpg"> <img alt="" src="../content/images/logo6.jpg">
<span class="username">@Model.DisplayName</span> <span class="username">@Model.DisplayName</span>
<b class="caret"></b> <b class="caret"></b>
<input id="userId" type="text" class="hide" value="@Model.UserID"/> <input id="userId" type="text" class="hide" value="@Model.UserID" />
</a> </a>
<ul class="dropdown-menu extended logout"> <ul class="dropdown-menu extended logout">
<div class="log-arrow-up"></div> <div class="log-arrow-up"></div>
@ -48,15 +48,10 @@
<!--search & user info end--> <!--search & user info end-->
</div> </div>
<!--breadcrumbs start --> <!--breadcrumbs start -->
<div class="lgbBreadcrumb"> <ul class="breadcrumb">
<ul class="breadcrumb"> <li><a href="@Url.Content(Model.HomeUrl)"><i class="fa fa-home"></i>首页</a></li>
<li><a href="@Url.Content(Model.HomeUrl)"><i class="fa fa-home"></i>首页</a></li> <li></li>
@if (!string.IsNullOrEmpty(Model.BreadcrumbName)) </ul>
{
<li>@Model.BreadcrumbName</li>
}
</ul>
</div>
<!--breadcrumbs end --> <!--breadcrumbs end -->
</header> </header>
<!--header end--> <!--header end-->

View File

@ -5,12 +5,7 @@
<ul class="sidebar-menu" id="nav-accordion"> <ul class="sidebar-menu" id="nav-accordion">
@foreach (var menu in Model.Menus) @foreach (var menu in Model.Menus)
{ {
<li> <li><a href="@Url.Content(menu.Url)" class="@menu.Active"><i class="@menu.Icon"></i><span>@menu.Name</span></a></li>
<a href="@menu.Url" class="@menu.Active">
<i class="fa @menu.Icon"></i>
<span>@menu.Name</span>
</a>
</li>
} }
</ul> </ul>
<!-- sidebar menu end--> <!-- sidebar menu end-->

View File

@ -34,23 +34,10 @@ namespace Bootstrap.DataAccess
/// <summary> /// <summary>
/// 获得/设置 菜单分类 /// 获得/设置 菜单分类
/// </summary> /// </summary>
public string Category { get; set; } public int Category { get; set; }
/// <summary> /// <summary>
/// /// 获得/设置 是否当前被选中 active为选中
/// </summary> /// </summary>
public string Active { get; set; } public string Active { get; set; }
public static List<Menu> RetrieveMenus()
{
return new List<Menu>() {
new Menu() { Name = "菜单管理", Icon = "fa-dashboard", Url="/Admin/Menus", Active = "" },
new Menu() { Name = "用户管理", Icon = "fa-user", Url="/Admin/Users", Active = "" },
new Menu() { Name = "角色管理", Icon = "fa-sitemap", Url="/Admin/Roles", Active = "" },
new Menu() { Name = "部门管理", Icon = "fa-home", Url="/Admin/Groups", Active = "" },
new Menu() { Name = "字典表维护", Icon = "fa-book", Url="javascript:;", Active = "" },
new Menu() { Name = "个性化维护", Icon = "fa-pencil", Url="javascript:;", Active = "" },
new Menu() { Name = "系统日志", Icon = "fa-lock", Url="javascript:;", Active = "" }
};
}
} }
} }

View File

@ -1,121 +1,130 @@
using Longbow; using Longbow;
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration; using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement; using Longbow.ExceptionManagement;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Data.Common; using System.Data.Common;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
namespace Bootstrap.DataAccess namespace Bootstrap.DataAccess
{ {
public static class MenuHelper public static class MenuHelper
{ {
private const string MenuDataKey = "MenuData-CodeMenuHelper"; private const string MenuDataKey = "MenuData-CodeMenuHelper";
/// <summary> /// <summary>
/// 查询所有菜单信息 /// 查询所有菜单信息
/// </summary> /// </summary>
/// <param name="tId"></param> /// <param name="tId"></param>
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Menu> RetrieveMenus(string tId = null) public static IEnumerable<Menu> RetrieveMenus(string tId = null)
{ {
string sql = "select * from Navigations"; string sql = "select * from Navigations";
var ret = CacheManager.GetOrAdd(MenuDataKey, CacheSection.RetrieveIntervalByKey(MenuDataKey), key => var ret = CacheManager.GetOrAdd(MenuDataKey, CacheSection.RetrieveIntervalByKey(MenuDataKey), key =>
{ {
List<Menu> Menus = new List<Menu>(); List<Menu> Menus = new List<Menu>();
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try try
{ {
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd)) using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
{ {
while (reader.Read()) while (reader.Read())
{ {
Menus.Add(new Menu() Menus.Add(new Menu()
{ {
ID = (int)reader[0], ID = (int)reader[0],
ParentId = (int)reader[1], ParentId = (int)reader[1],
Name = (string)reader[2], Name = (string)reader[2],
Order = LgbConvert.ReadValue((int)reader[3],0), Order = (int)reader[3],
Icon = (string)reader[4], Icon = (string)reader[4],
Url = LgbConvert.ReadValue((string)reader[5],string.Empty), Url = LgbConvert.ReadValue((string)reader[5], string.Empty),
Category = (string)reader[6] Category = (int)reader[6]
}); });
} }
} }
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return Menus; return Menus;
}, CacheSection.RetrieveDescByKey(MenuDataKey)); }, CacheSection.RetrieveDescByKey(MenuDataKey));
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase)); return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase));
} }
/// <summary> /// <summary>
/// 删除菜单信息 ///
/// </summary> /// </summary>
/// <param name="ids"></param> /// <param name="userId"></param>
public static bool DeleteMenu(string ids) /// <returns></returns>
{ public static IEnumerable<Menu> RetrieveMenusByUserId(int userId)
bool ret = false; {
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret; //UNDONE: 通过用户ID获得到当前用户配置的菜单
try return RetrieveMenus();
{ }
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Navigations where ID in ({0})", ids); /// <summary>
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) /// 删除菜单信息
{ /// </summary>
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); /// <param name="ids"></param>
} public static bool DeleteMenu(string ids)
ClearCache(); {
ret = true; bool ret = false;
} if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret;
catch (Exception ex) try
{ {
ExceptionManager.Publish(ex); string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Navigations where ID in ({0})", ids);
} using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
return ret; {
} DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
/// <summary> }
/// 保存新建/更新的菜单信息 ClearCache();
/// </summary> ret = true;
/// <param name="p"></param> }
/// <returns></returns> catch (Exception ex)
public static bool SaveMenu(Menu p) {
{ ExceptionManager.Publish(ex);
if (p == null) throw new ArgumentNullException("p"); }
bool ret = false; return ret;
if (p.Name.Length > 50) p.Name.Substring(0, 50); }
if (p.Icon.Length > 50) p.Icon.Substring(0, 50); /// <summary>
if (p.Url != null) { if (p.Url.Length > 50) p.Url.Substring(0, 50); } /// 保存新建/更新的菜单信息
if (p.Category.Length > 50) p.Category.Substring(0, 50); /// </summary>
string sql = p.ID == 0 ? /// <param name="p"></param>
"Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category)" : /// <returns></returns>
"Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category where ID = @ID"; public static bool SaveMenu(Menu p)
try {
{ if (p == null) throw new ArgumentNullException("p");
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) bool ret = false;
{ if (p.Name.Length > 50) p.Name.Substring(0, 50);
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.ID, ParameterDirection.Input)); if (p.Icon.Length > 50) p.Icon.Substring(0, 50);
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ParentId", p.ParentId, ParameterDirection.Input)); if (p.Url != null) { if (p.Url.Length > 50) p.Url.Substring(0, 50); }
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name, ParameterDirection.Input)); string sql = p.ID == 0 ?
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Order", p.Order, ParameterDirection.Input)); "Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category)" :
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Icon", p.Icon, ParameterDirection.Input)); "Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category where ID = @ID";
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Url", p.Url, ParameterDirection.Input)); try
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category, ParameterDirection.Input)); {
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
} {
ret = true; cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.ID, ParameterDirection.Input));
ClearCache(); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ParentId", p.ParentId, ParameterDirection.Input));
} cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name, ParameterDirection.Input));
catch (DbException ex) cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Order", p.Order, ParameterDirection.Input));
{ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Icon", p.Icon, ParameterDirection.Input));
ExceptionManager.Publish(ex); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Url", p.Url, ParameterDirection.Input));
} cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category, ParameterDirection.Input));
return ret; DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
} }
// 更新缓存 ret = true;
private static void ClearCache() ClearCache();
{ }
CacheManager.Clear(key => key == MenuDataKey); catch (DbException ex)
} {
} ExceptionManager.Publish(ex);
} }
return ret;
}
// 更新缓存
private static void ClearCache()
{
CacheManager.Clear(key => key == MenuDataKey);
}
}
}

View File

@ -1,62 +1,62 @@
using System.Linq; using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Bootstrap.DataAccess.Tests namespace Bootstrap.DataAccess.Tests
{ {
[TestClass] [TestClass]
public class MenuHelperTests public class MenuHelperTests
{ {
[TestMethod] [TestMethod]
public void RetrieveMenusTest() public void RetrieveMenusTest()
{ {
var result = MenuHelper.RetrieveMenus("1"); var result = MenuHelper.RetrieveMenus("1");
Assert.IsTrue((result.Count() == 0 || result.Count() == 1), "带有参数的MenuHelper.RetrieveMenus方法调用失败请检查数据库连接或者数据库SQL语句"); Assert.IsTrue((result.Count() == 0 || result.Count() == 1), "带有参数的MenuHelper.RetrieveMenus方法调用失败请检查数据库连接或者数据库SQL语句");
result = MenuHelper.RetrieveMenus(); result = MenuHelper.RetrieveMenus();
Assert.IsTrue(result.Count() >= 0, "不带参数的MenuHelper.RetrieveMenus方法调用失败请检查数据库连接或者数据库SQL语句"); Assert.IsTrue(result.Count() >= 0, "不带参数的MenuHelper.RetrieveMenus方法调用失败请检查数据库连接或者数据库SQL语句");
} }
[TestMethod] [TestMethod]
public void SaveMenuTest() public void SaveMenuTest()
{ {
Menu p = new Menu(); Menu p = new Menu();
p.ParentId = 1; p.ParentId = 1;
p.Name = "测试菜单名称"; p.Name = "测试菜单名称";
p.Order = 0; p.Order = 0;
p.Icon = "测试菜单Icon"; p.Icon = "测试菜单Icon";
p.Url = "urlTestAdd"; p.Url = "urlTestAdd";
p.Category = "测试菜单分组"; p.Category = 1;
var result = MenuHelper.SaveMenu(p); var result = MenuHelper.SaveMenu(p);
Assert.IsTrue(result, "增加菜单出错"); Assert.IsTrue(result, "增加菜单出错");
Menu p1 = new Menu(); Menu p1 = new Menu();
p1.ID = 7; p1.ID = 7;
p1.ParentId = 2; p1.ParentId = 2;
p1.Name = "测试菜单名称1"; p1.Name = "测试菜单名称1";
p1.Order = 0; p1.Order = 0;
p1.Icon = "测试菜单Icon1"; p1.Icon = "测试菜单Icon1";
p1.Url = "urlTestUpdate"; p1.Url = "urlTestUpdate";
p1.Category = "测试菜单分组1"; p1.Category = 1;
result = MenuHelper.SaveMenu(p1); result = MenuHelper.SaveMenu(p1);
Assert.IsTrue(result, "更新菜单出错"); Assert.IsTrue(result, "更新菜单出错");
} }
[TestMethod] [TestMethod]
public void DeleteMenuTest() public void DeleteMenuTest()
{ {
MenuHelper.SaveMenu(new Menu() MenuHelper.SaveMenu(new Menu()
{ {
ID = 0, ID = 0,
ParentId = 1, ParentId = 1,
Name = "菜单删除测试", Name = "菜单删除测试",
Order = 0, Order = 0,
Icon = "测试菜单Icon1", Icon = "测试菜单Icon1",
Url = "urlTestUpdate", Url = "urlTestUpdate",
Category = "测试菜单分组1" Category = 1
}); });
var menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == "菜单删除测试"); var menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == "菜单删除测试");
Assert.IsTrue(MenuHelper.DeleteMenu(menu.ID.ToString()),"删除菜单失败"); Assert.IsTrue(MenuHelper.DeleteMenu(menu.ID.ToString()),"删除菜单失败");
Assert.IsTrue(MenuHelper.DeleteMenu("1,2"), "带有参数的MenuHelper.DeleteMenu方法调用失败请检查数据库连接或者数据库SQL语句"); Assert.IsTrue(MenuHelper.DeleteMenu("1,2"), "带有参数的MenuHelper.DeleteMenu方法调用失败请检查数据库连接或者数据库SQL语句");
Assert.IsFalse(MenuHelper.DeleteMenu(string.Empty), "参数为空字符串的MenuHelper.DeleteMenu方法调用失败请检查数据库连接或者数据库SQL语句"); Assert.IsFalse(MenuHelper.DeleteMenu(string.Empty), "参数为空字符串的MenuHelper.DeleteMenu方法调用失败请检查数据库连接或者数据库SQL语句");
} }
} }
} }

View File

@ -148,10 +148,10 @@ CREATE TABLE [dbo].[Navigations](
[ID] [int] IDENTITY(1,1) NOT NULL, [ID] [int] IDENTITY(1,1) NOT NULL,
[ParentId] [int] NOT NULL, [ParentId] [int] NOT NULL,
[Name] [nvarchar](50) NOT NULL, [Name] [nvarchar](50) NOT NULL,
[Order] [int] NULL, [Order] [int] NOT NULL,
[Icon] [varchar](50) NOT NULL, [Icon] [varchar](50) NOT NULL,
[Url] [varchar](50) NULL, [Url] [varchar](50) NULL,
[Category] [varchar](50) NOT NULL, [Category] [int] NOT NULL,
CONSTRAINT [PK_Navigations] PRIMARY KEY CLUSTERED CONSTRAINT [PK_Navigations] PRIMARY KEY CLUSTERED
( (
[ID] ASC [ID] ASC
@ -163,5 +163,24 @@ GO
SET ANSI_PADDING OFF SET ANSI_PADDING OFF
GO GO
ALTER TABLE [dbo].[Navigations] ADD CONSTRAINT [DF_Navigations_ParentId] DEFAULT ((0)) FOR [ParentId]
GO
ALTER TABLE [dbo].[Navigations] ADD CONSTRAINT [DF_Navigations_Order] DEFAULT ((0)) FOR [Order]
GO
ALTER TABLE [dbo].[Navigations] ADD CONSTRAINT [DF_Navigations_Icon] DEFAULT ('none') FOR [Icon]
GO
ALTER TABLE [dbo].[Navigations] ADD CONSTRAINT [DF_Navigations_Category] DEFAULT ((0)) FOR [Category] ALTER TABLE [dbo].[Navigations] ADD CONSTRAINT [DF_Navigations_Category] DEFAULT ((0)) FOR [Category]
GO GO
SET IDENTITY_INSERT Navigations ON
insert into Navigations (ID, Name, [Order], Icon, Url) values (1, '菜单管理', 10, 'fa fa-dashboard', '~/Admin/Menus')
insert into Navigations (ID, Name, [Order], Icon, Url) values (2, '用户管理', 20, 'fa fa-user', '~/Admin/Users')
insert into Navigations (ID, Name, [Order], Icon, Url) values (3, '角色管理', 30, 'fa fa-sitemap', '~/Admin/Roles')
insert into Navigations (ID, Name, [Order], Icon, Url) values (4, '部门管理', 40, 'fa fa-home', '~/Admin/Groups')
insert into Navigations (ID, Name, [Order], Icon, Url) values (5, '字典表维护', 50, 'fa fa-book', '~/Admin/Dict')
insert into Navigations (ID, Name, [Order], Icon, Url) values (6, '个性化维护', 60, 'fa fa-pencil', '~/Admin/Profiles')
insert into Navigations (ID, Name, [Order], Icon, Url) values (7, '系统日志', 70, 'fa fa-gears', '~/Admin/EventLog')
SET IDENTITY_INSERT Navigations OFF