Binding Treeview to data instances in the database

Source: Internet
Author: User

Today is depressing. It took a long time to complete the Treeview data binding function in the database, but it felt that the method was weak and the efficiency was very low. Read the database multiple times.
The following is a brief introduction. Anyone who wants to know the simple method can give me some inspiration.
Effect


The nodes are in the Data military database.
The following code: (many loops)

Private   Void Initthetree ()
{
String M_nodename; // Root node name
Testmanagerrules temprules =   New Testmanagerrules ();
Projectdata. testmanager_selectprojectlistdatatable temptable =   New Projectdata. testmanager_selectprojectlistdatatable ();
Temptable = Temprules. selectprojectlist ();
For ( Int I =   0 ; I < Temptable. Count; I ++ )
{
// Control Word Length
String Tempstring = Convert. tostring (temptable [I]. projectname );
If (Tempstring. Length >   15 )
{< br> tempstring = tempstring. substring ( 0 , 15 ) + " " ;
m_nodename = tempstring;
}
Else
{
M_nodename=Temptable [I]. projectname. tostring ();
}
Treenode newnode =   New Treenode (m_nodename, temptable [I]. projectid. tostring ());
Newnode. navigateurl = Temprules. getmodulepage (m_moduleid, modulepageenum. projectmanagement) +   " ? Id = "   + Newnode. value;
Newnode. Expanded =   False ;
This . Categorytree. nodes. Add (newnode );
// Bind Root Node
}



For ( Int A =   0 ; < Categorytree. nodes. Count; ++ )
{
Treenode modulenode =   New Treenode ( " Module " , Temptable [A]. projectid. tostring ());
Modulenode. navigateurl = Temprules. getmodulepage (m_moduleid, modulepageenum. moduleaddandedit) +   " ? Id = "   + Modulenode. value;
Treenode testcombinationnode =   New Treenode ( " Test " , Temptable [A]. projectid. tostring ());
Testcombinationnode. navigateurl = Temprules. getmodulepage (m_moduleid, modulepageenum. testcombinationlist) +   " ? Id = "   + Testcombinationnode. value;
This . Categorytree. nodes [A]. childnodes. Add (modulenode );
This . Categorytree. nodes [A]. childnodes. Add (testcombinationnode );

String M_modulename;
Projectdata. testmanager_getmoduleinfobyprojectiddatatable table =   New Projectdata. testmanager_getmoduleinfobyprojectiddatatable ();
Table = Temprules. getmoduleinfobyprojectid (convert. toint32 (temptable [A]. projectid. tostring ()));
If (Table. Count >   0 )
{
For ( Int X =   0 ; X < Table. Count; x ++ )
{
String Tempmodule = Table [X]. modulename. tostring ();
// Control Data Length
If (Tempmodule. Length >   15 )
{< br> m_modulename = tempmodule. substring ( 0 , 15 ) + " " ;< BR >}
Else
{
M_modulename=Table [X]. modulename. tostring ();
}
Treenode newchildnode =   New Treenode (m_modulename, table [X]. Mid. tostring ());
Moduledata. testmanager_getprojectidbymoduleiddatatable projecttable;
Testmanagerrules rule =   New Testmanagerrules ();
Projecttable = Rule. getprojectidbymid (convert. toint32 (newchildnode. Value ));
Newchildnode. navigateurl = Temprules. getmodulepage (m_moduleid, modulepageenum. testdemandlist) +   " ? Id = "   + Newchildnode. Value +   " & Pid = "   + Projecttable [ 0 ]. Projectid. tostring ();
Newchildnode. Expanded =   False ;
This . Categorytree. nodes [A]. childnodes [ 0 ]. Childnodes. Add (newchildnode );
}
}
}
// Cyclically bound test combination data
For ( Int B =   0 ; B < Categorytree. nodes. Count; B ++ )
{
String M_testcombinationname;
Projectdata. testmanager_gettestcombinationinfobyprojectiddatatable tables =   New Projectdata. testmanager_gettestcombinationinfobyprojectiddatatable ();
Tables = Temprules. gettestcombinationinfobyprojectid (convert. toint32 (temptable [B]. projectid. tostring ()));
Projectdata. testmanager_getprojectidbytestiddatatable projecttable;
For ( Int Y =   0 ; Y < Tables. Count; y ++ )
{
String Tempcombination = Tables [Y]. testname. tostring ();
// Control Data Length
If (Tempcombination. Length >   15 )
{< br> m_testcombinationname = tempcombination. substring ( 0 , 15 ) + " " ;
}
Else
{
M_testcombinationname=Tables [Y]. testname. tostring ();
}
Treenode newchildnode1 =   New Treenode (m_testcombinationname, tables [Y]. testid. tostring ());
Projecttable = Temprules. getprojectidbytestid (convert. toint32 (newchildnode1.value ));
PID = Projecttable [ 0 ]. Projectid;
Newchildnode1.navigateurl = Temprules. getmodulepage (m_moduleid, modulepageenum. testcombinationdetail) +   " ? Id = "   + PID. tostring () +   " & Testid = "   + Newchildnode1.value;
Newchildnode1.expanded =   False ;
This . Categorytree. nodes [B]. childnodes [ 1 ]. Childnodes. Add (newchildnode1 );
}
}
}

Very troublesome. Sorry, haha! Hope everyone can help me!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.