Building a backend management system for ASP. Mvc4+ef5+easyui+unity2.x Injection (10)-System menu bar

Source: Internet
Author: User
Tags syslog system log

It seems that we need more modules, we have a sample program, can help us in the future system development to do a lot of control, we later also have the System log and system exception record, when the browsing has been difficult, we this section to complete a people like things, system menu bar, We have a location on the left side of the system, where the menu is stored, and the menu can be divided into two main types,
1. Outlook mode, can be used Easyui accordion, do it can be very beautiful, blog Park Many people write system, I have seen with this, the menu can also put a menu icon, here to see an effect (this is the J-ui rich Client Framework menu bar) The advantage is beautiful ah, Shortcomings are also obvious, only two-storey structure, the system is huge, the menu is too much, display is very troublesome, not enough and not good looking, accordion with the tree looks very cumbersome, I prefer concise things

Accordion:accordion and tree combination:
2. Tree pattern, the structure of trees, the disadvantage is concise, no perspective on the enjoyment, the advantage is infinite level, Ajax asynchronous acquisition, fast. There are many tree jquery plugins that can use Easyui's tree, I don't have easyui tree here, I download a relatively lightweight jquery tree plugin--wdtree This rack is very lightweight and supports asynchronous

Do it! Download Wdtree plugin, I provide download here, I previously downloaded the wdtree is not very useful (do not know now there is no new version), but I re-fix this plugin, very well in line with the operation of the menu,
Wdtree Repair version Download

After decompression, put the JS file into the scripts directory, put the style into the content directory


We seem to be creating a menu table for the database, building a table SQL statement

Use [db]go/****** object:table [dbo].    [Sysmodule] Script date:11/19/2013 22:11:10 ******/set ansi_nulls ongoset quoted_identifier ongoset ansi_padding ONGOCREATE TABLE [db O]. [Sysmodule] ([Id] [varchar] () NOT NULL,--id [name] [varchar] (+) NOT NULL,--module name [englishname] [varchar] (+) NULL,--English Title (Prevention of future internationalization) [parentid] [varchar] (+) NULL,--ancestor ID This is a tree [URL] [varchar] ($) NULL,--link [iconic] [varchar] (200) Null,--icon, for link icon, or tab icon [sort] [int] null,--sort [Remark] [varchar] (4000) NULL,--description [state] [bit] null,--Status [C Reateperson] [varchar] (+) NULL,--creator [createtime] [datetime] NULL,--create event [islast] [bit] not NULL--is the last item [V Ersion] [timestamp] NULL,--version CONSTRAINT [pk_sysmodule] PRIMARY KEY CLUSTERED ([Id] ASC) with (Pad_index = OFF, Stati Stics_norecompute = off, Ignore_dup_key = off, Allow_row_locks = on, allow_page_locks = on) on [PRIMARY]) on [primary]g Oset ansi_padding offgoalter TABLE [dbo].  [Sysmodule] With NOCHECK ADD constrAINT [Fk_sysmodule_sysmodule] FOREIGN KEY ([ParentID]) REFERENCES [dbo]. [Sysmodule] ([Id]) Goalter TABLE [dbo]. [Sysmodule] NOCHECK CONSTRAINT [Fk_sysmodule_sysmodule]gosql

  

Update our table model in EF, don't know how to update the jump to the IV

Execute database command, insert some data

INSERT into [Sysmodule] ([id],[name],[englishname],[parentid],[url],[iconic],[sort],[remark],[state],[ Createperson],[createtime],[islast],[version] VALUES (' 0 ', ' top menu ', ' Root ', ' 0 ', ', ', ' 0, ' ', 1, ' Administrator ', ' 10 1 12:00AM ', 0,null) INSERT into [Sysmodule] ([Id],[name],[englishname],[parentid],[url],[iconic],[sort],[remark], [state],[createperson],[createtime],[islast],[version]) VALUES (' basesample ', ' Template sample ', ' Sample by Ajax ', ' samplefile ', ' Syssample ', ', 0, ', ' 1, ' Administrator ', Null,1,null ' INSERT into [Sysmodule] ([id],[name],[englishname],[parentid],[ Url],[iconic],[sort],[remark],[state],[createperson],[createtime],[islast],[version]) VALUES (' Document ', ' my desktop ', ' Start ', ' persondocument ', ' home/doc ', ' ', 0, ', 1, ' Administrator ', ' 1 12:00AM ', 1,null ' INSERT into [Sysmodule] ([ Id],[name],[englishname],[parentid],[url],[iconic],[sort],[remark],[state],[createperson],[createtime],[islast ],[version]) VALUES (' info ', ' My Profile ', ' info ', ' persondocument ', ' home/info ', ' ', 0, ', ' 1, ' Administrator ', ' 10 1 2012:00AM ', 1,null) INSERT into [Sysmodule] ([id],[name],[englishname],[parentid],[url],[iconic],[sort],[remark],[ State],[createperson],[createtime],[islast],[version]) VALUES (' Infohome ', ' home ', ' home ', ' information ', ' mis/article ', ', 1, ', 1, ' Administrator ', ' 1 12:00AM ', 1,null) INSERT into [Sysmodule] ([Id],[name],[englishname],[parentid] , [url],[iconic],[sort],[remark],[state],[createperson],[createtime],[islast],[version]) VALUES (' Information ', ' Information Center ', ' information ', ' OA ', ' ', ' ', ' 0, ' ', 1, ' Administrator ', ' 1 12:00AM ', 0,null ' INSERT into [Sysmodule] ([id],[name ],[englishname],[parentid],[url],[iconic],[sort],[remark],[state],[createperson],[createtime],[islast],[ Version]) VALUES (' Manageinfo ', ' admin center ', ' Manage article ', ' Information ', ' mis/managearticle ', ' ', 4, ', 1, ' Administrator ', ' 1 12:00AM ', 1,null) INSERT into [Sysmodule] ([id],[name],[englishname],[parentid],[url],[iconic],[sort],[ Remark],[state],[createperson],[createtime],[islast],[version]) VALUES (' modulesetting ', ' Module maintenance ', ' MoDule Setting ', ' rightmanage ', ' sysmodule ', ', ', ', ', 1, ' Administrator ', ' 1 12:00AM ', 1,null ' INSERT into [ Sysmodule] ([id],[name],[englishname],[parentid],[url],[iconic],[sort],[remark],[state],[createperson],[ Createtime],[islast],[version] VALUES (' MyInfo ', ' My message ', ' My article ', ' Information ', ' mis/myarticle ', ', 2, ', 1, ' Administrator ', ' 1 12:00AM ', 1,null) INSERT into [Sysmodule] ([id],[name],[englishname],[parentid],[url],[ Iconic],[sort],[remark],[state],[createperson],[createtime],[islast],[version]) VALUES (' PersonDocument ', ' Personal center ', ' Person Center ', ' 0 ', ' ', ' ', ' 2, ' ', 1, ' Administrator ', ' 1 12:00AM ', 0,null ' INSERT into [Sysmodule] ([id],[name],[ Englishname],[parentid],[url],[iconic],[sort],[remark],[state],[createperson],[createtime],[islast],[version]) VALUES (' rightmanage ', ' Rights Management ', ' authorities Management ', ' 0 ', ', ', ' 4, ' ', ' 1, ' Administrator ', ' 1 ' 12:00AM ', 0,null ') INSERT into [Sysmodule] ([id],[name],[englishname],[parentid],[url],[iconic],[sort],[remark],[state],[createpersOn],[createtime],[islast],[version]) VALUES (' roleauthorize ', ' role permission settings ', ' Roles authorize ', ' rightmanage ', ' sysright ', ' ', 6, ', 1, ' Administrator ', ' 1 12:00AM ', 1,null) INSERT into [Sysmodule] ([id],[name],[englishname],[parentid],[ Url],[iconic],[sort],[remark],[state],[createperson],[createtime],[islast],[version]) VALUES (' RoleManage ', ' role management ', ' Role Manage ', ' rightmanage ', ' sysrole ', ', ' 2, ' ', 1, ' Administrator ', ' 1 12:00AM ', 1,null ' INSERT into [sysmodule] ([id],[name],[englishname],[parentid],[url],[iconic],[sort],[remark],[state],[createperson],[createtime],[ Islast],[version] VALUES (' samplefile ', ' Development Guide sample ', ' samplefile ', ' 0 ', ' syssample ', ' ', ' 1, ' ', ' 1 ', ' Administrator ', null,0, NULL) INSERT into [Sysmodule] ([id],[name],[englishname],[parentid],[url],[iconic],[sort],[remark],[state],[ Createperson],[createtime],[islast],[version]) VALUES (' Systemconfig ', ' System configuration ', ' Systems config ', ' systemmanage ', ' SysConfig ', ', 0, ', 1, ' Administrator ', ' 1 12:00AM ', 1,null) INSERT into [Sysmodule] ([Id],[name],[engliShname],[parentid],[url],[iconic],[sort],[remark],[state],[createperson],[createtime],[islast],[version]) VALUES (' Systemexcepiton ', ' System exception ', ' Systems Exception ', ' systemmanage ', ' sysexception ', ' ', 2, ', ' 1, ' Administrator ', ' 10 1 12:00AM ', 1,null) INSERT into [Sysmodule] ([Id],[name],[englishname],[parentid],[url],[iconic],[sort],[remark], [state],[createperson],[createtime],[islast],[version]) VALUES (' Systemjobs ', ' System tasks ', ' systems Jobs ', ' taskscheduling ', ' jobs/jobs ', ', 0, ', 1, ' Administrator ', ' 1 12:00AM ', 1,null ' INSERT into [Sysmodule] ([id],[name],[englishname ],[parentid],[url],[iconic],[sort],[remark],[state],[createperson],[createtime],[islast],[version]) VALUES (' Systemlog ', ' syslog ', ' System log ', ' systemmanage ', ' SysLog ', ' ', 1, ', ' 1, ' Administrator ', ' 1 ' 12:00AM ', 1,null ' INSERT into [Sysmodule] ([id],[name],[englishname],[parentid],[url],[iconic],[sort],[remark],[state],[createperson],[ Createtime],[islast],[version] VALUES (' systemmanage ', ' Systems Management ', ' System Management ', ' 0 ', ' ', ' ', ' 3, ' ', 1, 'Administrator ', ' 1 12:00AM ', 0,null) INSERT into [Sysmodule] ([id],[name],[englishname],[parentid],[url],[ Iconic],[sort],[remark],[state],[createperson],[createtime],[islast],[version]) VALUES (' UserManage ', ' System administrator ', ' User Manage ', ' rightmanage ', ' Sysuser ', null,1,null,1, ' Administrator ', ' 1 12:00AM ', 1,null ' INSERT statement

  

We have data in the table.
Back to the front page, introduce Wdtree JS and its style sheet

Add the following code to the JS code below Home.js

$ (function () {    var o = {        showcheck:false,        URL: "/home/gettree",        onnodeclick:function (item) {            var Tabtitle = Item.text;            var url = ".. /.. /"+ Item.value;            var icon = Item. Icon;            if (!item.haschildren) {                addTab (tabtitle, URL, icon);            } else {                $ (this). The parent (). FIND ("img"). Trigger (" Click ");    }}} $.post ("/home/gettree", {"id": "0"},        function (data) {            if (data = = "0") {                window.location = "/account"; 
   }            o.data = data;            $ ("#RightTree"). TreeView (O);        }, "JSON");}); Js

  

Create the BLL layer and the DAL layer of the home

Using system;using system.collections.generic;using system.linq;using system.text;using App.Models;namespace app.idal{public    Interface ihomerepository    {        list<sysmodule> Getmenubypersonid (string moduleid);}    } Ihomerepository

  

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingApp.models;usingApp.idal;namespaceapp.dal{ Public classhomerepository:ihomerepository,idisposable { PublicList<sysmodule> Getmenubypersonid (stringModuleID) {            using(Dbcontainer db =NewDbcontainer ()) {                varMenus =                (                     fromMinchdb. SysmodulewhereM.parentid = =ModuleIDwhereM.id! ="0"                    Selectm). Distinct (). (A=a.sort).                ToList (); returnmenus; }        }               Public voidDispose () {}}} Homerepository
View Code

Using system;using system.collections.generic;using system.linq;using system.text;using App.Models;namespace app.ibll{public    Interface Ihomebll    {        list<sysmodule> Getmenubypersonid (string moduleid);}    } Ihomebll

  

Using system;using system.collections.generic;using system.linq;using system.text;using Microsoft.Practices.Unity; Using app.ibll;using app.models;using app.idal;namespace app.bll{public       class HOMEBLL:IHOMEBLL    {        [ Dependency] public        ihomerepository homerepository {get; set;}        Public list<sysmodule> Getmenubypersonid (string moduleid)        {            return Homerepository.getmenubypersonid ( ModuleID);}}}    

  

Modify the code for HomeController

usingAPP.IBLL;usingApp.models;usingMicrosoft.Practices.Unity;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSYSTEM.WEB.MVC;namespaceapp.admin.controllers{ Public classHomecontroller:controller {//        //GET:/home/[Dependency] PublicIHOMEBLL HOMEBLL {Get;Set; }  PublicActionResult Index () {returnView (); }        /// <summary>        ///Get navigation Menu/// </summary>        /// <param name= "id" >belongs to</param>        /// <returns>Tree</returns>         PublicJsonresult Gettree (stringID) {List<SysModule> menus =Homebll.getmenubypersonid (ID); varJsondata = (                         fromMinchMenusSelect New{ID=m.id, Text=M.name, Value=M.url, Showcheck=false, complete=false, Isexpand=false, CheckState=0, HasChildren= M.islast?false:true, Icon=m.iconic}).                ToArray (); returnJson (Jsondata, jsonrequestbehavior.allowget); }}}homecontroller
HomeController

Don't forget to inject app.core into the container.

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingAPP.BLL;usingApp.dal;usingAPP.IBLL;usingApp.idal;usingMicrosoft.Practices.Unity;namespaceapp.core{ Public classDependencyregistertype {//System Injection         Public Static voidContainer_sys (refUnityContainer Container) {container. Registertype&LT;ISYSSAMPLEBLL, syssamplebll> ();//Sample ExampleContainer. Registertype<isyssamplerepository, syssamplerepository>(); Container. Registertype&LT;IHOMEBLL, homebll>(); Container. Registertype<ihomerepository, homerepository>(); }}}dependencyregistertype.cs
Dependencyregistertype

Back to the front, preview the following effect, this section of code is more, everyone just put in, code I have comments, look down to know

We finally have the menu bar, the distance success is another step, if you have your own menu bar ideas, then skip this section of the content.

Building a backend management system for ASP. Mvc4+ef5+easyui+unity2.x Injection (10)-System menu bar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.