[Original] Use Microsoft.Web.ui.WebControls to easily resolve permission tree issues (unlimited level permission management) 2

xiaoxiao2021-03-05  26

TreeControl.cs: Operation of the tree

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls ; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.Text.RegularExpressions; using System.IO; using System.Text; using System.Xml; using Microsoft.Web.UI.WebControls;

Namespace Yljweb.classes {///

/// TreeControl's summary description. /// public class treecontrol {public dataable dt;

public TreeControl () {// // TODO: Add constructor logic here //} public void BindTreeView1 (string f_key, string f_parentkey, string location, string f_text, string str_Sql, string Frame, string Url, Label lbl_Curnodeid, TreeView TreeView1) {DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet (str_Sql); dt = ds.Tables [0]; TreeView1.Nodes.Clear (); // Clear tree TreeNode rootnode = new TreeNode (); rootnode.Text = Dt.Rows [0] [f_text] .tostring (); // Give node binding value rootnode.nodedata = dt.rows [0] [f_key] .tostring (); // Bind the key value LBL_CurnodeID to the node. Text = dt.rows [0] [f_key] .tostring (); // Save the selected key value rootnode.expanded = true; // The default root node is expanded rootnode.target = frame; rootnode.navigateurl = url "?"? " Location "=" DT.ROWS [0] [location] .tostring (); TreeView1.nodes.add (rootnode); string parentid = dt.rows [0] [f_parentKey] .tostring () DT.ROWS [ 0] [f_key] .tostring () "_"; // His ParentID field value Createnode1 (f_key, f_parentkey, location, f_text, frame, url, parentid, rootnode); // Add all root nodes Node} public void bindtreeView2 ( string f_key, string f_parentkey, string location, string f_text, string str_Sql, string Frame, string Url, Label lbl_Curnodeid, TreeView TreeView1) {DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet (str_Sql); dt = ds.Tables [0] TreeView1.nodes.clear (); // Empty Tree Treenode RootNode = New Treenode (); rootnode.text = dt.rows [0] [f_text] .tostring (); // Give node binding value rootnode.nodedata = DT.ROWS [0] [f_key] .tostring (); // Bind the node LBL_CurnodeId.Text = DT.ROWS [0] [f_key] .tostring (); // Save Select KEY Value Rootnode.expanded = true; // The default root node is to expand rootnode.target = frame; rootnode.navigateURL = URL "? location2 ="

Dt.Rows [0] [location] .tostring (); TreeView1.nodes.add (rootnode); string parentid = dt.rows [0] [f_parentKey] .tostring () DT.ROWS [0] [f_key]. TOSTRING () "_"; // His ParentID field value cretenode2 (f_key, f_parentkey, location, f_text, frame, url, parentid, rootnode); // joins the node below all root nodes} PUBLIC VOID CreateNode1 (string f_key, string f_parentkey, string location, string f_text, string Frame, string Url, string parentid, TreeNode parentnode) {DataRow [] drs = dt.Select (f_parentkey "= '" parentid "'"); // Select all child nodes // Traverse all child nodes foreach (DATAROW R IN DRS) {Treenode TempNode = NEW TREENODE (); tempnode.text = r [f_text] .tostring (); tempnode.nodedata = r [f_key] .ToString (); parentnode.Nodes.Add (tempnode); tempnode.Expanded = true; tempnode.Target = Frame; "?" tempnode.NavigateUrl = Url location "=" r [location] .ToString (); parentid = r [f_parentkey] .tostring () r [f_key] .tostring () "_"; createnode1 (f_key, f_parentKey, Location, f_text, frame, url, parentid, tempnode);}} PUBLIC void CreateNode2 (string f_key, string f_parentkey, string location, string f_text, string Frame, string Url, string parentid, TreeNode parentnode) {DataRow [] drs = dt.Select (f_parentkey "= '" parentid "'") ; // select all child nodes // Traverse all child nodes foreach (DataRow R in DRS) {Treenode TempNode = New Treenode (); TempNode.Text = R [f_text] .tostring (); TempNode.NodeData = R [f_key) ] .Tostring (); parentnode.nodes.add (tempnode.expanded = true; tempnode.target = frame; tempnode.navigateurl = url "? Location2 =

" r [location] .tostring (); parentid = r [f_parentKey] .tostring () r [f_key] .tostring () " _ "; createnode2 (f_key, f_parentKey, location, f_text, frame, url, parentid) , TempNode);}}

public void BindTreeViewShow (string f_key, string f_parentkey, string location, string f_text, string str_Sql, Label lbl_Curnodeid, TreeView TreeView1) {DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet (str_Sql); dt = ds.Tables [0]; TreeView1 .Nodes.clear (); // empty tree Treenode rootnode = new Treenode (); rootnode.text = dt.rows [0] [f_text] .tostring (); // Bind the node binding display value rootnode.nodedata = DT .ROWS [0] [f_key] .tostring (); // Give node binding key value // lbl_curnodeid.text = dt.rows [0] [f_key] .tostring (); // Save Select Key Value rootnode.expanded = True; // The default root node is expanded rootnode.navigateURL = "?" location "=" dt.rows [0] [f_text] .tostring (); TreeView1.nodes.add (rootnode); string parentId = DT.ROWS [0] [f_parentkey] .tostring () Dt.Rows [0] [f_key] .tostring () "_"; // His ParentID field value cretenodeshow (f_key, f_parentKey, location, f_text , parentid, rootnode; // joins the nodes below all root nodes} public void createnodeshow (string f_key, string f_parentKey, string location, string f_text, string parentid, trentnotnode) {DATARO w [] DRS = DT.SELECT (f_ParentKey "= '" ParentID ""); // Select all child nodes // Traverse all child nodes "{Treenode TempNode = New Treenode" (DataRow R in DRS) ); Tempnode.text = r [f_text] .tostring (); tempnode.nodedata = r [f_key] .tostring (); parentnode.nodes.add (tempnode.expanded = true; tempnode.naVigateurl = "?"? " Location "=" R [f_text] .tostring (); parentid = r [f_parentkey] .tostring () r [f_key] .tostring () "_"; createnodeshow (f_key, f_parentKey, location, f_text, parentid) , TEMPNODE);

}} Public string GetFirstStr (string strOriginal, string strSymbol) {int strPlace = strOriginal.IndexOf (strSymbol); if (strPlace = - 1!) StrOriginal = strOriginal.Substring (0, strPlace); return strOriginal;} /// < Summary> /// Get a string after the last occurrence of the last appearance, all characters /// /// The character to be processed // / symbol /// return value public string GetLastStr (string strOriginal, string strSymbol) {int strPlace = strOriginal.LastIndexOf (strSymbol) strSymbol.Length Stroriginal = Stroriginal.Substring (STRPLACE); Return Struct;} ///

/// Get all characters /// //// Characters to be processed /// Which character /// neot this character // / return value public string GetTwoMiddleLastStr (string strOriginal, string strFirst, string strLast) {strOriginal = GetLastStr (strOriginal, strFirst); strOriginal = GetFirstStr (strOriginal, strLast); return strOriginal;} public void AddRootNode (string nodeid, string order_id, string parentid, string location, string text, string tablename, string MyText) {if (! MyText = "") {string str_Sql = "INSERT INTO" tablename " (" Nodeid ", " Parentid ", " Location ", " TEXT ", " Order_id ") VALUES ('1', '0 _', '0_1 _', '" MyText "',' 0 ')";

YljWeb.Classes.SqlConn.ExecuteSql (str_Sql);}} public void AddChildNode (string nodeid, string order_id, string parentid, string location, string text, string tablename, int Curnodeid, string MyText) {if (! MyText = "") {Str_maxid = (int.Pars (Yljweb.classes.sqlconn.getmaxid ("NodeID", TABLENAME) .tostring ()) 1) .tostring (); int newnotid = int.parse (str_maxid); string str_sql = " Select * from " Tablename " Where " nodeid " = " CurnodeId; DataSet DS = YLJWEB.CLASS.SQLCONN.EXECUTESQLFORDATASET (STR_SQL); DATAROW DR = DS.TABLES [0] .ROWS [0]; str_ = DR [PARENTID] CURNODEID.TOSTRING () "_"; string str_location = STR_ STR_MAXID "_"; string str_sql1 = "INSERT INTO" TABLENAME "(" NodeID "," Parentid "," Location "," TEXT "," Order_id ") VALUES (" NewNodeid ", '" STR_ ",'" STR_LOCATION ", '" mytext "," " NewNodeID ")"; yljweb.classes.sqlconn.executesql (str_sql1);}} public void addchildnode2 (string nodeid, string order_id, string p arentid, string location, string text, string text2, string tablename, int Curnodeid, string MyText, string MyText2) {if (MyText! = "") {string str_MaxId = (int.Parse (YljWeb.Classes.SqlConn.GetMaxId ( " NodeID ", TABLENAME) .TOSTRING ()) 1) .tostring (); int newnotid = int.parse (str_maxid); string str_sql =" select * from " Tablename " Where "

NodeID "=" CurnodeId; DataSet DS = YLJWEB.CLASES.SQLCONN.EXECUTESQLFORDATASET (STR_SQL); DATAROW DR = DS.TABLES [0] .ROWS [0]; String STR_ = DR [ParentID] CurnodeId.Tostring ) "_"; Str_location = STR_ STR_MAXID "_"; string str_sql1 = "INSERT INTO" TABLENAME "(" Nodeid "," "," Location "," TEXT " " '," NewNodeId ")"; YljWeb.Classes.SqlConn.ExecuteSql (str_Sql1);}} public void AddBrotherNode (string nodeid, string order_id, string parentid, string location, string text, string tablename, int Curnodeid, String mytext) {if (mytext! = "") {string str_maxid = (int.Pars (Yljweb.classes.sqlconn.getmaxid ("nodeid", TableName) .tostring ()) 1) .tostring (); int newnodeID = int.parse; string str_sql = "select * from" Tablename "where" nodeid "=" curnodeid; dataset ds = yljweb.classes.sqlconn.executesqlFordatase T (str_sql); DATAROW DR = DS.TABLES [0]. ROWS [0]; string str_ = dr [ParentID] .tostring (); string str_location = STR_ STR_MAXID "_"; str_sql = "insert INTO" TABLENAME "( Nodeid ", " Parentid ", " Location ", "

TEXT "," ORDER_ID ") VALUES (" NewNodeid ", '" STR_ ",'" STR_LOCATION ", '" MyText "," NewNodeID ")"; YljWeb.Classes.SqlConn.ExecuteSql (str_Sql);}} public void AddBrotherNode2 (string nodeid, string order_id, string parentid, string location, string text, string text2, string tablename, int Curnodeid, string MyText, string MyText2) {if ( MyText! = "" "{String str_maxid = (int.pars (Yljweb.classes.sqlconn.getmaxid (" nodeid ", Tablename) .tostring ()) 1) .tostring (); int newnotid = int.parse (str_maxid ); string str_Sql = "select * from" tablename "where" nodeid "=" Curnodeid; DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet (str_Sql); DataRow dr = ds.Tables [0] .Rows [0]; String STR_ = DR [ParentID] .tostring (); string str_location = STR_ STR_MAXID "_"; str_sql = "INSERT INTO" TABLENAME "(" NodeID "," "," " Location "," TEXT "," Text2 "," Order_id ") Values ​​(" NewNodeid ", '" STR_ ",'" Str_Location ", '" MyText "', ' " MyText2 "', " NewNodeId ") "; YljWeb.Classes.SqlConn.ExecuteSql (str_Sql);}} public void DelTreeViewNode (string nodeid, string parentid, string tablename, int Curnodeid) {string str_Sql =" Delete from " TableName "

WHERE " NodeID " = " CurnodeID " OR " ParentID " Like '% " CurnodeID "%' "; YLJWEB.CLASS.SQLCONN.EXECUTESQL (STR_SQL);}}} PurView_all_LEFT.ASPX.CS: Permissions Tree display

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls Using system.web.ui.htmlcontrols; using microsoft.web.ui.webControls;

Namespace Yljweb._admin.purview_manage {///

/// Tree_left's summary description. /// public class Purview_All_Left: System.Web.UI.Page {protected System.Web.UI.WebControls.Label lbl_Curnodeid; protected Microsoft.Web.UI.WebControls.TreeView TreeView1; protected Microsoft.Web.UI. WebControls.TreeView Treeview1; protected YljWeb.Classes.TreeControl tree = new YljWeb.Classes.TreeControl (); private void Page_Load (object sender, System.EventArgs e) {// Put user code to initialize the page here string str_Sql = " Select * from purview_all order by order_id "; if (yljweb.classes.sqlconn.isexist (str_sql)) // Traversed tree {Tree.BindtreeView1 (" NodeID "," ParentID "," Location "," MyText ", Str_SQL," Mainframe "," purview_all_operate.aspx ", lbl_curnodeid, treec}}

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private () {this.load = new system.eventhandler (this.page_load);

} #Endregion private void TreeView_Selected (object sender, Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e) {lbl_Curnodeid.Text = ((TreeNode) TreeView1.GetNodeFromIndex (e.NewNode)) NodeData;.}}} Purview_All_Operate.aspx.cs : Management of system functions (fill, modify, delete, etc.)

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls Using system.web.ui.htmlcontrols; using microsoft.web.ui.webControls;

Namespace Yljweb._admin.purview_manage {///

/// Tree_operate summary description. /// public class Purview_All_Operate: System.Web.UI.Page {protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; protected System.Web.UI.WebControls.Button btn_AddChildNode; protected System.Web.UI. WebControls.Button btn_AddBrotherNode; protected System.Web.UI.WebControls.Button btn_DelNode; protected System.Web.UI.WebControls.Button btn_AddRootNode; protected System.Web.UI.WebControls.TextBox txt_Mytext; protected System.Web.UI.WebControls. Label LBL_ERROR;

Protected Yljweb.classes.treeControl Tree = New Yljweb.classes.treeControl ();

public static DataView dv1; // view public string str_Sql; public string str_Location; public string cru_location; public int Curnodeid; protected System.Web.UI.WebControls.TextBox Txt_Command; protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2; public string MyText; protected System.Web.UI.WebControls.Label lbl_name; protected System.Web.UI.WebControls.Label lbl_command; protected System.Web.UI.WebControls.Button btn_CruNode_Modify; public string MyText2; public string cru_user; private void Page_Load (Object sender, system.eventargs e) {// Place the user code here to initialize the page btn_delnode.attributes.add ("OnClick", "JavaScript: Return Confirm ('you sure you want to delete this node and its sub-node ? ') "); If (Request [" location "]! = Null) {str_location = request [" location "]. Tostring (). Substring (0, Request [" location "]. Tostring ()"]. 1); curnodeid = int.parse (Tree.getTWomidDlelaststr (str_location, "_", "_")); mytext = this.txt_mytext.text.Replace ("," "); mytext2 = this.txt_command.text .Replace ("", ""); Control the button's authority IF (session ["" ""]! = Null) {CRU_USER = session ["adminName"]. Tostring ();} else {CRU_USER = "------"; /// Us, as long as the value does not exist in the user database}}}}}}} (YLJWEB.CLASS.PURVIEW.PURVIEW_VERIFY (CRU_USER, "PURVIEW_ALL_NODE_DEL") {this.btn_delnode.visible = true } // else // {// this.showerrmsg ("You do not have permission deletion! "); //} / this.btn_crunode_modify.visible = true; get_crunode_info (); // bindgrid ();} str_sql =" select * from purview_all ";

IF (yljweb.classes.sqlconn.getrowcount (str_sql)> 0) // tree table exists record, do traversal operation {btn_addrootnode.visible = false;} else // number table does not have record, do not do traversal operation {btn_delnode.visible = false; btn_addbrothernode.visible = false; btn_addchildnode.visible = false;}} #Region Web Form Designer Generated Code Override Protected Void OnInit (Eventargs E) {// // Codegen: This call is ASP.NET web window The body designer is required. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private void InitializeComponent () {this.btn_AddRootNode.Click = new System.EventHandler (this.btn_AddRootNode_Click); this.btn_AddChildNode.Click = new System.EventHandler (this.btn_AddChildNode_Click); this.btn_AddBrotherNode .Click = new System.EventHandler (this.btn_AddBrotherNode_Click); this.btn_DelNode.Click = new System.EventHandler (this.btn_DelNode_Click); this.btn_CruNode_Modify.Click = new System.EventHandler (this.btn_CruNode_Modify_Click); this. Load = new system.eventhandler (this.page_load);

} #Endregion private void Get_CruNode_Info () {cru_location = Request [ "location"] ToString ();. String str_Sql = "Select * from Purview_All where location = '" cru_location "'"; DataSet ds1 = new DataSet (); DS1 = yljweb.classes.sqlconn.executesqlfordataset (STR_SQL); this.lbl_name.text = ds1.tables [0] .ROWS [0] ["mytext"]. Tostring (); this.lbl_command.text = ds1.tables [ 0] .ROWS [0] ["command_name"]. ToString (); ds1.dispose ();} ///

/// / /// // public void bindgrid () /// {// str_location = request ["location"]. TOSTRING (); // str_sql = "select * from purview_all where parentid = '" str_location "' Order by Order_ID"; // viewstate ["sort"] = " "; // DataSet myds1 = new DataSet (); // myds1 = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet (str_Sql); // call YljWeb.Classes.SqlConn.ExecuteSqlForDataSet // dv1 = myds1.Tables [0] .DefaultView; // dv1.table.acceptchange (); // DV1.Sort / // if (! Object.equals (viewState ["sort"], null) // {// dv1.sort = viewstate ["s Ort "]. TOSTRING (); //} //// ViewState [" pageDataCount "] = DV1.COUNT; / / Record the number of data from each page // if (dv1.count == 0) // judgment Whether there is record // {// dv1.dispose (); //} // show_all.dataasource = DV1; // Specify data source // show_all.database //// } /// /// // /// /// /// private Void btn_addchildnode_click (object sender, system.eventargs e) {if (Request ["location"] ==

NULL) // Judgment whether to choose the left navigation tree navigation {// this.showerrmsg ("Please select the left navigation tree node, do the addition operation!"); // string str_show = yljweb.classes.mymethod.showerrmsg ("Please select The left navigation tree node, then add actions! "); This.response.write (Yljweb.classes.mymethod.showerrmsg (" Please select the left navigation tree node, then add actions! ")); Return;} STR_SQL =" Select * from purview_all where command_name = '" mytext2 "' "; if (yljweb.classes.sqlconn.isexist (Str_SQL)) {this.showerrmsg (" Sorry, there is this command, please re-enter! "); return!") } // The following is an increased child node tree.addchildNode2 ("NodeID", "Order_ID", "ParentID", "Location", "MyText", "Command_name", "PurView_all", CurnodeId, MyText, MyText2; // the latest addition to the permissions applied to fill Purview_User_Have predefined Add_To_Purview_User_Have (); // refresh the tree on the left navigation lbl_Error.Text = "