The idea of this algorithm is:
Step 1: cyclically complete treenode Construction
Build the hierarchy in the second cycle
Data storage uses a general Hierarchical Storage Method to call the database at a time to complete all required data. The array index storage tree node and parentsqn avoid the disadvantages of search performance.
Table:
Inclumentid uniqueidentifier,
Departmentsqn int,
Departmentname nvarchar (32 ),
Parentid uniqueidentifier
Stored Procedure:
Create procedure DBO. department_selectcore
As
Set nocount on
Select inclumentid, departmentsqn, departmentname, parentid,
(Select departmentsqn from department parent where (parent. Partition mentid = Department. parentid)
Parentsqn
From Department
Order by departmentsqn
Return
Data Call code:
[Dataobject (true)]
Public class departmentdataobject
{
[Dataobjectmethod (dataobjectmethodtype. Select, true)]
Public static dataset readcore ()
{
Database DB = databasefactory. createdatabase ("workitemtrack ");
String sqlcommand = "department_selectcore"
Dbcommand = dB. getstoredproccommand (sqlcommand );
DB. addreturnvalueparameter (dbcommand );
Return dB. executedataset (dbcommand );
}
}
Data Structure Construction Code:
Protected void buildtree ()
{
_ Departmenttreeview. nodes. Clear ();
Dataset DS = departmentdataobject. readcore ();
Int COUNT = Ds. Tables [0]. Rows. count;
Treenode [] nodes = new treenode [count + 1];
Nullable <int> [] parentsqns = new nullable <int> [count + 1];
Foreach (datarow DR in DS. Tables [0]. Rows)
{
Nodes [(INT) Dr ["departmentsqn"])] = new treenode (string) Dr ["departmentname"], (guid) Dr ["inclumentid"]). tostring ());
Try
{
Parentsqns [(INT) Dr ["departmentsqn"] = (INT) Dr ["parentsqn"];
}
Catch
{
Parentsqns [(INT) Dr ["departmentsqn"] = NULL;
}
}
For (INT I = 1; I <count + 1; I ++)
{
If (parentsqns [I]. hasvalue)
{
Nodes [parentsqns [I]. value]. childnodes. Add (nodes [I]);
}
Else
{
_ Departmenttreeview. nodes. Add (nodes [I]);
}
}
}