TreeView

zhaozj2021-02-12  141

?

Here is a TreeView control code I wrote by myself:

using System; using System.Text; using System.Web.UI; using System.Drawing; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.ComponentModel; using System.IO;

USING WIM.DATA; USING WIM.DATA.COLLECTIONS; USING WIM.BUSINESSFACADE

Namespace Wim.WebControls {?? ///

?? /// TreeView's summary description. ?? ///

?? [DefaultProperty ("ID"), ToolboxData ("

")]

?? [Designer (TreeViewDesigner)]]]]

?? Public class treeview: wim.webcontrols.controlbase

?? {

????? #Region member variable

????? private string m_SchemaName; ????? private string m_TreeCodeColumn; ????? private string m_ValueColumn; ????? private string m_TextColumn; ????? private string m_ChildClick; ????? private string m_ImageUrl; ????? private string m_DataValue; ????? private string m_RedirectUrl; ????? private string m_TargetFrame; ????? private bool m_IsClearTrack = true; ????? private int m_SelectIndex = -1; ????? private DOC M_DATASOURCE; ????? private queryconditioncollection m_dataqueryconditions; ????? private sortcondition m_datasortcondition;

????? #endregion

????? #Region property settings

????? ///

????? /// architecture name ????? ///

????? [bindable (TRUE), Category ("Wim"), DefaultValue ("ORG_Organ"), Description ("Schema Name")]]

????? public string schemaname

????? {

???????? get

???????? {

??????????? Return M_SChemaname;

????????}

???????? set

???????? {

??????????? m_schemaname = value;

????????}

?????}

????? ///

????? /// encoding column name ????? ///

????? [Bindable (TRUE), Category ("WIM"), DefaultValue ("Treecode"), Description ("Code Column Name)]

????? public string? Treecodecolumn

????? {

???????? get

???????? {

??????????? Return M_Treecodecolumn

????????}

???????? set

???????? {??????????? m_treecodecolumn = value;

????????}

?????}

????? ///

????? /// 取 value column name ????? ///

????? [bindable (TRUE), Category ("Wim"), DefaultValue ("ID"), Description ("Value Route Name")]

????? public string? ValueColumn

????? {

???????? get

???????? {

??????????? Return M_ValueColumn

????????}

???????? set

???????? {

??????????? m_Valuecolumn = value;

????????}

?????}

????? ///

????? /// display column name ????? ///

????? [Bindable (True), Category ("Wim"), DefaultValue ("Name"), Description ("Show Column Name)]

????? public string? TextColumn

????? {

???????? get

???????? {

??????????? Return M_TextColumn

????????}

???????? set

???????? {

??????????? m_textColumn = value;

????????}

?????}

????? ///

????? /// Click the event ????? ///

????? [Bindable (True), Category ("Wim"), DefaultValue (""), Description ("Click Events"]

????? public string? ChildClick

????? {

???????? get

???????? {

??????????? Return M_ChildClick;

????????}

???????? set

???????? {

???????????? m_childclick = value;

????????}

?????}

????? ///

????? /// picture path ????? ///

????? [bindable (TRUE), Category ("WIM"), DefaultValue ("../ images / organtree /"), Description ("Image Path")]

????? public string? imageurl

????? {

???????? get

???????? {

??????????? RETURN M_IMAGEURL;

????????}

???????? set

???????? {

??????????? m_imageurl = value;

????????}

?????}

????? ///

????? /// data source document object ????? ///

????? [Bindable (True), Category ("WIM"), DefaultValue (NULL), Description ("Data Source Document Object")]

????? public doc datasource

????? {

???????? get

???????? {

??????????? Return M_DataSource;

????????}

???????? set

???????? {

??????????? m_datasource = value; ????????}

?????}

?????

????? ///

????? /// The initial default value ????? ///

????? [Bindable (True), Category ("WIM"), DefaultValue (""), Description ("Initial Default")]

????? public string DataValue

????? {

???????? get

???????? {

??????????? Return M_DataValue;

????????}

???????? set

???????? {

??????????? m_datavalue = value;

????????}

?????}

????? ///

????? /// The connection address when you click the node ????? ///

????? [Bindable (True), Category ("WIM"), DefaultValue (""), Description ("Click the connection address when the node.")]

????? public string redirecturl

????? {

???????? get

???????? {

??????????? Return M_RedirectURL;

????????}

???????? set

???????? {

??????????? m_redirecturl = value;

????????}

?????}

????? ///

????? /// The target object name when you click the node ????? ///

????? [Bindable (True), Category ("Wim"), DefaultValue (""), Description ("Click on the node to redirect the target object name.")]

????? public string targetframe

????? {

???????? get

???????? {

??????????? Return M_TargetFrame

????????}

???????? set

???????? {

??????????? m_targetframe = value;

????????}

?????}

????? ///

????? /// Do you need to clear the history path ????? ///

????? [Bindable (True), Category ("WIM"), DefaultValue (TRUE), Description ("Do you need to clear history.")]

????? public bool iscleartrack

????? {

???????? get

???????? {

??????????? Return m_iscleartrack;

????????}

???????? set

???????? {

??????????? m_iscleartrack = value;

????????}

?????}

????? ///

????? /// Query conditions????? ///

????? [Bindable (True), Category ("Wim"), DEFAULTVALUE (NULL), Description ("Query Conditions when getting or setting data")]

????? public queryconditionCollection DataQueryConditions

????? {

???????? get

???????? {

??????????? if (m_dataqueryconditions == null) ??????????? {

?????????????? m_dataqueryconditions = new queryconditioncollection ();

???????????}

??????????? Return M_DataQueryConditions;

????????}

???????? set

???????? {

??????????? m_dataqueryconditions = value;

????????}

?????}

????? ///

????? /// sort object ????? ///

????? [Bindable (True), Category ("Wim"), DEFAULTVALUE (NULL), DESCRIPTION ("Sampling Objects when getting Data")]]

????? public sortcondition datasortcondition

????? {

???????? set

???????? {

??????????? m_datasortcondition = value;

????????}

???????? get

???????? {

??????????? return m_datasortcondition;

????????}

?????}

????? #endregion

#Region main body

????? ///

????? /// presented this control to the specified output parameter. ????? ///

????? ///

HTML writer to write

????? protected override void render (HTMLTextWriter Output)

????? {

???????? placeholder control = new placeholder ();

???????? control.page = this.page;

???????? this.enableviewState = false

???????? this.initparameter ();

???????? Literal Literal = new literal (); ???????? Literal.Text = this.treehtml (); ???????? control.controls.add (Litral) ;

????????? // Add hidden control ???????? basefunction Basfun = new basefunction (); ???????? HTMLINPUTHIDDEN HVAL = BASFun.creaHid (ID, m_Datavalue);? ??????? control.controls.add (hval); ???????? HTMLINPUTHIDDEN HTXT = BASFUN.CREAHID (ID "Text", ""); ???????? control .Controls.add (htxt);

???????? // Output public script block ????????????????????????????????????????????????????????????????????????????????????????????????????????????; ???????? // Output Private script ???????? Control.page.registerStartupScript (ID "script", this.buildprivatescript ());

???????? control.renderControl (output); ?????}

????? #endregion ????? #Region variable initialization

????? private void initparameter () ????? {???????? {(m_treecodecolumn == null) || (m_treecodecolumn == ")) ???????? {??????????? m_treecodecolumn = "trecode"; ????????} ????????} ((M_TextColumn == Null) || (m_textColumn == " ")) ????????? {??????????? m_textColumn =" name "; ????????} ????????} ((M_ValueColumn) == NULL) || (m_valuecolumn == "")) ???????????? M_ValueColumn = "ID"; ????????}? ??????? f ((m_schemaname == null) || (m_schemaname == "")) ????????????? m_schemaname = "org_organ" ; ????????} ???????? IF (m_imageurl == null) || (m_imageurl == "")) ??????? {????? ?????? m_imageurl = "../ images / organtree /"; ????????} ???????? IF (m_childclick == null) || (m_childclick == " ")) ????????? {???????????? m_childclick =" "; ????????} ????????} ((m_redirecturl = = null) || (m_redirecturl == ")) ????????????? M_redirecturl =" "; ????????} ??? ????? IF ((m_targetframe == null) || (m_targetframe == ")) ???????????? m_targetframe =" Self "; ???????} ???????? IF (this. m_datasource == NULL) ???????????? m_datasource = this.getdataSource (m_schemaname); ????????} ?????}

????? private doc getDataSource (string schecess) ????? {???????? DocManagement DM = New DocManagement (userSessionID);

???????? Doc Result = DM.GETDOC (m_schemaname, "view", m_datasortcondition, m_dataqueryconditions);

???????? Return RESULT; ?????}

????? #endregion

????? #Region main function ????? ///

????? /// get the code of the tree structure ????? ///

????? ///

?????pring treehtml ()

????? {

???????? StringBuilder html = new stringbuilder ();

???????? // Coiled type

???????? String lineestyle

???????? // leaf node type

???????? String Leafstyle

???????? // Current node level

???????? INT level = 0;

???????? // Run the total number of child nodes in the current level

???????? int [] levelsonnumberlist = new int rt [52];

???????? // runtime record the child node count of the current level

???????? int [] levelsoncounterlist = new int [52];

???????? // gacred the EntityTable object of the menu

???????? EntityTable Table = this.m_datasource.entityTable;

???????? // record the number of child points (recalculated results)

???????? int [] sonnumberlist = recalculateparentNumber (Table, this.m_treecodecolumn);

???????? // initialize the value ???????? for (int i = 0; i <52; i ) ??????? {?????? ????? levelsonnumberlist [i] = 0; ??????????? levelsoncounterlist [i] = 0; ????????}

???????? for (int i = 0; i

???????????? // indicate whether the node is displayed ?????????????????????????????? (Item [m_valuecolumn] .Value == m_datavalue) ??????????? {????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?? SELECTED = true; ???????????} ??????????? // determine the line style of the cable ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? "" "; ??????????? for (int J = 1; j levelsoncounterlist [j - 1]) ????????????????????????????????????????????????????????????? ??? // 1 Category Line: The current layer still has a sub-node (vertical line) ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????} ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?????? // 0 cable: The current layer has no child node (blank) ??????????????????????????????????????????????????????????????????????????????????????? ?????????} ???????????}

??????????? // determine the type of directory and leaves ??????????? f (SonnumberList [i] == 0) ?????????? ? {?????????????? // leaf ?????????????? f (LevelsonNumberlist [level - 1] == levelsoncounterlist [level - 1]) ?????????????? {????????????????? // leaf-level node, there is no brothers node (ie the last child node) ??????????????????????????? leafstyle = "2"; ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?? Else ???????????????????????? odor-level node, and after another brother node? ???????????????? leafstyle = "3"; ??????????????} ???????????}? ??????????? Else ??????????? {?????????????? // directory?????? ???? i (Levelsonnumberlist [level - 1] <= levelsoncounterlist [level - 1]) ???????????????????????????????????????????????????????????????????????????????????????????????????????????? ??? // directory node, and have not jumped to the next superior node ????????????????? leafstyle = "41"; ???????? ?????} ?????????????? ELSE ?????????????? {?????????????? ??? // directory node, and have been jumped to the next superior node ????????????????? leafstyle = "51"; ????????? ?????} ???????????}

??????????? // displays a node ??????????? HTML.Append (GetMenuItem (Item, LINESTYLE, Leafstyle, Level, SELECTED, M_VALUECOLUMN, M_TEXTCOLUMN, M_TREECODECOLUMN, M_TREECODECOLUMN, M_IMAGEURL )); ???????????? // If the number of sons of the node is not 0, insert a layer of control the lower-level submenu ??????????? IF (SonNumberList [i ]> 0) ??????????? {?????????????? HTML.APpend ("

");

???????????}

??????????? IF ((Levelsonnumberlist [level - 1] == levelsoncounterlist [level - 1]) && (SonNumberlist [i] == 0)) ??????????????????????? ? {?????????????? INT K; ????????????????????? {? ????????????????????????????????????????????????????????????? {?????? ?????????????? k = Table.Entitys [i 1] [m_treecodecolumn] .value.Length / 4; ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?} ?????????????????????????????? {???????????? ???????? k = 0; ????????????????????????} ????? ?????????????????????????????????????? K = 0; ???? ??????????}

?????????????? for (int J = K; j

");

??????????????}

???????????}

????????}

???????? Return html.tostring (); ?????}

///

????? /// return to the html code of the menu item ????? ///

????? ///

????? ///

????? ///

????? ///

????? ///

????? ///

????? ///

????? ///

????? ///

????? ///

????? private string getmenuitem (Wim.Data.Antity Item, String Linestyle, String Leafstyle, Int Level, Bool Selected, String Valcolumn, String TxtColumn, String Codecolumn, String Imageurl)

????? {

???????? StringBuilder InputML = New StringBuilder ();

???????? INPUTHTML.APPEND ("

???????? INPUTHTML.APpend (item [valcolumn] .value);

???????? INPUTHTML.APpend ("/" treecode = / ");

???????? INPUTHTML.APpend (item [codecolumn] .value);

???????? INPUTHTML.APpend ("/" οnclick = / ""); ???????? INPUTHTML.APpend ("SelectItem (this) /");

???????? f (selected)

???????? {

??????????? INPUTHTML.APpend ("Checked>");

????????}

???????? ELSE

???????? {

??????????? INPUTHTML.APPpend (">");

????????}

???????? INPUTHTML = new system.text.stringbuilder ();

???????? Stringbuilder html = new stringbuilder (); ???????? HTML.APpend ("

???????? // display cable and blank ???????? for (int i = 1; i

???????? Switch (Leafstyle) ???????? {??????????? case "4": ??????????? case " 5 ": ?????????????? HTML.Append ("

???????? ing ((Leafstyle! = "4") && (Leafstyle! = "41") && (Leafstyle! = "5") && (Leafstyle! = "51")) ???? ???? {??????????? IF ((LeafStyle! = "21") && (Leafstyle! = "31")) ??????????? {?? ???????????? // leaf node ?????????????? html.append ("

");

"); ????????????} ??????????????? {??????????? ??? html.append ("

"); ???????????} ????????}

?????????????? HTML.Append (item [codecolumn] .value); ?????????????? HTML.APpend ("style = /" Display : '' / "οnclick = /" javaScript: ClickItem (this, document.all.imgc "); ?????????????? HTML.Append (item [codecolumn] .value);? ????????????? HTML.Append (", Document.all.l"); ?????????????? HTML.Append (item [CodeColumn]. Value); ?????????????? HTML.APpend (") /"> ?????????????? HTML.Append (LeafStyle);??? ??????????? HTML.Append (". gif /"> ?????????????? HTML.APpend (item [codecolumn] .value);??? ??????????? HTML.Append ("style = /" display: 'none' / "οnclick = /" javascript: clickitem (this, document.all.imgo "); ????? ????????? HTML.Append (item [codecolumn] .value); ?????????????? HTML.Append (", Document.all.l");? ????????????? HTML.Append (item [codecolumn] .value); ?????????????? HTML.APpend (") /"> ?? ???????????? HTML.Append (Leafstyle); ?????????????? HTML.Append ("1.gif /");??? ??????????? breaf; ??????????? case "41": ??????????? Case "51": ????? ????????? HTML.APpend ("

?????????????? HTML.Append (item [codecolumn] .value); ?????????????? HTML.APpend ("style = /" Display : 'None' / "οnclick = /" javascript: clickitem (this, document.all.imgc "); ?????????????? HTML.Append (item [codecolumn] .value); ?????????????? HTML.Append (", Document.all.l"); ??????????????? HTML.Append (item [codecolumn] .Value); ?????????????? HTML.APpend (") /"> ?????????????? HTML.Append (Leafstyle.Substring (0 1)); ?????????????? HTML.Append (". Gif /"> ?????????????? HTML.Append (item [CodeColumn ] .Value); ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????. IMGO "); ?????????????? HTML.Append (item [codecolumn] .value); ?????????????? HTML.Append (", Document.all.l "); ?????????????? HTML.APpend (item [codecolumn] .value); ?????????????? HTML. Append (") /"> ?????????????? HTML.Append (LeafStyle); ?????????????? HTML.APpend (". GIF / ">"); ?????????????????????????????????????? case " 31 ": ?????????????? HTML.APpend (" ????????????? HTML.Append (Leafstyle.Substring (0, 1)); ?????????? ???? html.append (". gif /">); ??????????????????? DEFAULT: ???? ?????????? HTML.APpend ("

?????????????? html.append (leafstyle); ?????????????? HTML.APpend (". GIF /"> ");?? ???????????? breaf; ????????}

"); ????????????????? Insert checkbox ?????????????? HTML.Append (InputHtml); ???????? ?????? html.append ("?????????????? HTML.APpend (item [valcolumn] .value); ????????????? HTML.Append ("','" item [txtColumn] .value ");"); ?????????????? HTML.Append (ID "_SETHIGHLIGHT (THIS) / ">"); ?????????????? HTML.APpend (item [txtcolumn] .value); ?????????????? HTML.Append ( "" "); ???????????} ??????????????? {?????????? ????? // does not have a parent node ?????????????? HTML.Append ("); ?????????????? // Insert Checkbox ?????????????? HTML.Append (Inputhtml); ?????????????? HTML.Append (");??? ??????????? html.append (item [txtcolumn] .value); ?????????????? HTML.APpend (""); ???? ??????} ????????} ?????????????????????? / parent node? ?????????? HTML.APpend ("

"); ??????????? // plug box ?????????????????????????????????? HTML.Append ("??????????? HTML.Append (item [valcolumn] .value); ??????????? HTML.Append (" ',' " item [txtColumn] .Value "');"); ??????????? HTML.Append (ID "_SETHIGHLIGHT (this) /"> "); ??????????? HTML .Append (item [txtcolumn] .value); ??????????? HTML.Append ("); ????????} ???????? HTML.APpend ("

");

???????? Return html.tostring (); ?????}

????? ///

????? /// recalculate the number of parent points ????? ///

????? ///

????? ///

????? ///

????? private int [] recalculateparentNumber (Wim.Data.EntityTable Table, String CodeColumn)

????? {

???????? int [] sonnumberlist = new int [table.entitys.count];

???????? int [] levelparentlist = new int [50]; ???????? for (INT i = 0; i

????????? {??????????? levelparentList [i] = 0; ????????}

???????? for (int i = 0; i 0) ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ? SONNUMBERLIST [0] -; ????????} ???????? Return SonnumberList; ?????}

????? #endregion

?

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

New Post(0)