Simple unlimited grade tree C # code

xiaoxiao2021-03-06  119

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.OleDb;

Using

System.xml;

Using

System.Text;

Namespace

Tree

{/ ** ////

/// Table [Tree] /// Column [Treeid] int ITENTIN [TREENODE] VARCHAR / / / public class tree: System.Web.UI.Page {protected System.Web.UI.WebControls.Button btnDelete; protected System.Web.UI.WebControls.Button btnUpdate; protected System.Web.UI.WebControls.Button btnAdd; protected System .Web.UI.WebControls.Label lblTreeTitle; protected System.Web.UI.WebControls.TextBox txtAddTree; protected System.Web.UI.WebControls.TextBox txtUpdateTree; protected System.Web.UI.HtmlControls.HtmlInputHidden hidTreeid; protected System.Web .UI.WebControls.Label lblTree; protected System.Web.UI.WebControls.Label lblPrompt; protected System.Web.UI.WebControls.RequiredFieldValidator reqValAddTree; protected System.Web.UI.WebControls.LinkButton lbMakeXml; protected OleDbConnection conn = new OleDbConnection ("Provider = microso Ft.jet.oledb.4.0; data source = " httpContext.current.server.mappath (" tree.mdb ")); private void page_load (Object sender, system.eventargs e) {if (! ispostback) {INT TREEID = 0; if (Request.QueryString ["TreeID"]! = Null) {TREEID = INT.PARS (Request.QueryString ["TreeID"]);} catch {treei = 0;}}}}}}}}}}} 0) {lbltreetitle.text = "Tree roots";

hidTreeid.Value = "0"; txtUpdateTree.Enabled = false; btnUpdate.Enabled = false; btnDelete.Enabled = false;} else {string sqlStr = "SELECT treetitle, treenode FROM tree WHERE treeid =" treeid.ToString (); OleDbCommand cmd = new OleDbCommand (sqlStr, conn); conn.Open (); OleDbDataReader dr = cmd.ExecuteReader (CommandBehavior.SingleRow);. if (dr.Read ()) {lblTreeTitle.Text = dr [ "treetitle"] ToString (); TxtUpdatetree.text = DR ["treetitle"]. TOSTRING (); hidtreeid.value = Treeid.toString ();} Dr.close (); conn.close ();} if (Application ["tree" == NULL) {Treebuild (); } Else {lblTree.Visible = true; lblTree.Text = Application [ "tree"] ToString ();.}}} Private void treeBuild () {string sqlStr = "SELECT * FROM tree ORDER BY treenode"; OleDbDataAdapter da = new OLEDBDataAdapter (Sqlstr, Conn); DataTable DT = New DataTable (); da.fill (dt); Da.dispose (); int treeeevel; char nodechar; string Treenode; stringbuilder treestr =

New stringbuilder (""); for (int i = 0; i

] .Tostring ()); xw.writeAttributeString ("Treenode", DR ["Treenode"]. TOSTRING ()); xw.writeElementString ("treetitle", DR ["treetitle"]. TOSTRING ()); ptreeDepth = TreeDepth } For (int i = 0; i /// Designer supports the required method - do not use the code editor to modify the // / this method.

/// private void InitializeComponent () {this.btnAdd.Click = new System.EventHandler (this.btnAdd_Click); this.btnUpdate.Click = new System.EventHandler (this.btnUpdate_Click); this.btnDelete .Click = new System.EventHandler (this.btnDelete_Click); this.lbMakeXml.Click = new System.EventHandler (this.lbMakeXml_Click); this.Load = new System.EventHandler (this.Page_Load);} #endregion private void btnAdd_Click (object sender, System.EventArgs e) {int treeid = int.Parse (hidTreeid.Value); int nodeSerial; string treeTitle = txtAddTree.Text; string treeNode; string sqlStr; OleDbCommand cmd = new OleDbCommand (); cmd. Connection = conn; if (TreeId == 0) {SQLSTR = "SELECT TOP 1 TREENODE from Tree Where Treenode Like '___' Order By Treenode DESC"; cmd.commandt EXT = SQLSTR; conn.open (); object objtreenode = cmd.executescalar (); conn.close (); nodeserial = ((Objtreenode == null)? 0: int.parse (Objtreenode.toString ())) 1 ; treeNode = nodeSerial.ToString ( "D3");} else {sqlStr = "SELECT treenode FROM tree WHERE treeid =" treeid.ToString (); cmd.CommandText = sqlStr; conn.Open (); string parentTreeNode = cmd. EXECUTESCALAR (). TOSTRING (); conn.close ();

sqlStr = "SELECT TOP 1 treenode FROM tree WHERE treenode LIKE '" parentTreeNode ", ___' ORDER BY treenode DESC"; cmd.CommandText = sqlStr; conn.Open (); OleDbDataReader dr = cmd.ExecuteReader (CommandBehavior.SingleRow) ; If (Dr.Read ()) {string brothersRee = DR [0] .tostring (); NodeSerial = int.pars (brotherstee.lastindexof (',') 1, 3)) 1;} Else {nodeserial = 1;} Dr.close (); conn.close (); TREENODE = PARENTTREENODE "" NodeSerial.toString ("D3");} SQLSTR = "Insert Into Tree (Tree, Treenode) VALUES @treetitle, @treenode "; cmd.commandtext = SQLSTR; cmd.parameters.add (" @ treetitle ", OLEDBTYPE.VARCHAR, 50); cmd.parameters.add (" @ Treenode ", OLEDBTYPE.VARCHAR, 243);CMD.Parameters ["@ treetitle"]. Value = treetitle; cmd.parameters ["@ Treenode"]. value = treenode; conn.open (); int rt rowaffected = cmd.ExecutenonQuery (); conn.close (); if (Rowaffected> 0) {lblprompt.text = "Branch" Treetitle "Add success"; inittree ();} else {lblprompt.text = "Tree branch" Treetitle "Add failed;

}} Private void btnUpdate_Click (object sender, System.EventArgs e) {int treeid = int.Parse (hidTreeid.Value); string treeTitle = Request.Form [ "txtUpdateTree"]; string sqlStr = "UPDATE tree SET treetitle = @treetitle WHERE TREEID = " Treeid.toString (); OLEDBCommand cmd = new oledbcommand (sqlstr, conn); cmd.parameters.add (" @ treetitle ", OLEDBTYPE.VARCHAR, 50); cmd.parameters [" @ treetitle "]. Value = treetitle; conn.open (); int = cmd.executenonQuery (); conn.close (); if (Rowaffected> 0) {lblprompt.text = "Branch" Treetitle "Inittree () } Else {lblprompt.text = "Tree branches" Treetitle "Update Failed";}} private void btndelete_click (Object sender, system.eventargs e) {int treid = int.parse (hidtreeid.value); s tring sqlStr = "SELECT treenode FROM tree WHERE treeid =" treeid.ToString (); OleDbCommand cmd = new OleDbCommand (sqlStr, conn); conn.Open (); string treeNode = cmd.ExecuteScalar () ToString ();. sqlStr = "Delete from tree where treeid =" TREEID.TOSTRING () "or Treenode Like '" Treenode "%'"; cmd.comMandText = SQLSTR; int rotable = cmd.executenonQuery (); conn.close () ; If (Rowaffected>

转载请注明原文地址:https://www.9cbs.com/read-126221.html

New Post(0)