Recently want to study the rights management, see a group of people sent a ztrees template, I looked at the next, think Pen Easyui operation more flexible, so began to study.
Just started looking for a demo from the Internet, of course, this does not realize the permissions of what, but the implementation of the foreground call Ajax to the background to pass data, this has a way of thinking, that I separate a piece of blog, you can read this blog before looking at the http://www.cnblogs.com/ Shuai7boy/p/5645888.html
The following is the addition of database interaction and Rights management.
I designed this: first design permissions on the design of the user login, so there is a landing page, and then the user after landing according to different users to display different background information.
Then the problem comes, when I run the project, the first open is the background interface, this is wrong, so you have to control it does not login can not access the background page.
This is the general idea: below first put a picture to say the details ~
From the above you can see that a total of three tables were designed, a storage data, a storage information display data, an intermediate Table control authority, will log data and display data sheet linked.
When the user login successfully, according to the login user name to get the primary key ID, and then get the right according to the ID, that is, get the corresponding data in the middle table, then get a list<int> collection, and then pass the parameters, based on the parameters of the filter to show what data. Note that when you pass the reference, you cannot pass the list collection directly, so you have to figure out a way to make a string type, then pass the past and then get the array type.
---------above is the design idea, the following is the code analysis-----------
I used the MVC framework for this project and wrote three controllers, namely Basecontroller (base control), HomeController (Information display control), Logincontroller (login control).
Basecontroller Code Display:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Namespace Ztreedemo.controllers
{public
class Basecontroller:controller
{////Get
:/base/
protected override void OnActionExecuting (ActionExecutingContext filtercontext)
{
if (filtercontext.httpcontext.session["Loginuser"]==null)
{
FilterContext.HttpContext.Response.Redirect ("Login/index");}}}
View Code
Logincontroller Code Display:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Using Www.zTree.BLL;
Namespace Ztreedemo.controllers {public class Logincontroller:controller {////Get:/login/
Public ActionResult Index () {return View ();
Public ActionResult Logincheck () {String strName = request["LoginName"];
String strpwd = request["Loginpwd"];
TREEBLL BLL = new TREEBLL (); BOOL B=BLL.
Logincheck (StrName, strpwd);
if (b) {session["loginuser"] = StrName; Query the primary key ID based on the login name and then get the corresponding tree according to the primary key ID and pass the parameter to the past login jump int ID=BLL.
Getidbyloginname (StrName); List<int> listn = BLL.
Getlogfortable (ID);
Response.Redirect (Url.action ("GetData", "Home"));
Console.Write (LISTN);
string str = NULL; For(int i = 0; i < Listn.count; i++) {str = listn[i].
ToString () + ","; int N=STR.
LastIndexOf (', '); Str=str.
Substring (0,n);
return Content (str);
Return Content ("The username or password you entered is wrong!"); }
}
}View Code
logincontroller-index.cshtml Code Display:
@{Layout = null;} <! DOCTYPE html> View Code
HomeController Code Display:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Using Www.zTree.BLL;
Using Www.zTree.Model; Namespace Ztreedemo.controllers {public class Homecontroller:basecontroller {////Get:/h
Ome/public ActionResult Index () {if (request["data"]!=null) {
System.Web.Caching.Cache Cache = Httpruntime.cache;
session["data"] = request["Data"]; Cache.
Insert ("Data", request["data"]);
return View ();
Public ActionResult Edit () {var list = GetData ();
return Json (list, jsonrequestbehavior.allowget); Public list<tree> GetData () {//Get the data sent over System.Web.Caching.Cach
e cache = Httpruntime.cache; Dividing data into string recstr = CAChe. Get ("Data").
ToString ();
String[] Recn=recstr.split (', ');
list<tree> tree = new list<tree> ();
Get data from database stitching back to foreground treebll BLL = new TREEBLL ();
According to the user interpretation of the login and then according to the user decide which ID pass through//loop traversal string converted to int type then start query for (int i = 0; i < recn.length i++) {int n = Int.
Parse (Recn[i]); List<tree> rec = BLL.
Gettreelist (n); for (int j = 0; J < Rec.) Count; J + +) {tree.
ADD (new tree {id = rec[j].id, pId = rec[j].pid, name = rec[j].name, icon = Rec[j].icon}); }}//tree. ADD (new Tree {id = 1, pId = 0, name = "vegetable", Icon = "...)
/script/css/ztreestyle/img/diy/1_open.png "}); Tree. ADD (new Tree {id = 2, pId = 0, name = "Animal", Icon = "...)
/script/css/ztreestyle/img/diy/1_open.png "}); Tree. ADD (new Tree {id = 3, pId = 0, name = "Human", Icon = "...) /scrIpt/css/ztreestyle/img/diy/1_open.png "}); Tree. ADD (new Tree {id = 4, pId = 1, name = "Eggplant", Icon = "...)
/script/css/ztreestyle/img/diy/1_open.png "}); Tree. ADD (new Tree {id = 5, pId = 2, name = "Panda", Icon = "...)
/script/css/ztreestyle/img/diy/1_open.png "}); Tree. ADD (new Tree {id = 6, pId = 3, name = "Hu", Icon = "...)
/script/css/ztreestyle/img/diy/1_open.png "});
return to tree;
}//public Class Tree//{//public int ID {get; set;}
public int PId {get; set;}
public string name {get; set;}
public string icon {get; set;} //}
}
}View Code
homecontroller-index.cshtml Code Display:
@{Layout = null;} <! DOCTYPE html> View Code
Learning experience: When the controller encounters the use of global variables, then because each request will be rerun, then the last global variable assigned value, the next time may not request, and the request is NULL, then you can consider using cookies (recommended cookies, Because this does not access the database, or the session implementation saves fetch data.
Project Links: Links: Http://pan.baidu.com/s/1qYSs40W Password: CBJS