基于c++ builder的课件导航知识点实现
问题描述:利用Treeview控件实现知识点章节树状导航,利用Query组建,结合SQL语言,自动从数据库中选取数据。
希望提供思路和程序示范。
[解决办法]
TTreeView *tree;
//------初始化树型列表---------------
String year;
int index,k;
Word Year, Month, Day;
TDateTime dtPresent =Now();
DecodeDate(dtPresent, Year, Month, Day);
year=IntToStr(Year);
Month1=Month;
Month2=Month1;
TTreeNode *root,*node[10],*node1;
root=tree->Items->AddChild(NULL,"车辆监控信息");
root->SelectedIndex=0;
for(index=2002;index<=year;index++)
{
k=index-2002;
node[k]=tree->Items->AddChild(root,index);
node[k]->SelectedIndex=1;
}
int tablenum,n;
String tname,ta,tyear,tmonth,tm;
TStringList* List=new TStringList;
UserMod->Session1->GetTableNames(UserMod->Plocal->DatabaseName,"*.*",true,false,List);
for(tablenum=0;tablenum<List->Count;tablenum++)
{
tname=List->Strings[tablenum];
ta=tname.SubString(1,1);
if(ta=='V')
{
tyear=tname.SubString(5,4);
n=StrToInt(tyear)-2002;
tmonth=tname.SubString(9,2);
if(StrToInt(tmonth)==1)
tm="一月";
if(StrToInt(tmonth)==2)
tm="二月";
if(StrToInt(tmonth)==3)
tm="三月";
if(StrToInt(tmonth)==4)
tm="四月";
if(StrToInt(tmonth)==5)
tm="五月";
if(StrToInt(tmonth)==6)
tm="六月";
if(StrToInt(tmonth)==7)
tm="七月";
if(StrToInt(tmonth)==8)
tm="八月";
if(StrToInt(tmonth)==9)
tm="九月";
if(StrToInt(tmonth)==10)
tm="十月";
if(StrToInt(tmonth)==11)
tm="十一月";
if(StrToInt(tmonth)==12)
tm="十二月";
node1=tree->Items->AddChild(node[n],tm);
node1->SelectedIndex=2;
}
}
[解决办法]
TTreeNode *rNode1,*rNode2, *mNode ; AnsiString TableSQL =" SELECT code,cname FROM CodeModule where Clevel = 1 "; TableSQL += " order BY code "; ADOQueryDB->Close(); ADOQueryDB->SQL->Clear(); ADOQueryDB->SQL->Add(TableSQL); ADOQueryDB->Open(); TreeViewCode->Items->Clear(); mNode= TreeViewCode->Items->Add(TreeViewCode->Selected,"资料 "); while(!ADOQueryDB->Eof) { AnsiString nodeStr = ADOQueryDB->FieldByName("cname")->AsString ; AnsiString nodeNum = ADOQueryDB->FieldByName("code")->AsString ; rNode1=TreeViewCode->Items->AddChild(mNode, nodeStr ); TableSQL =" SELECT code,cname FROM CodeModule where Clevel = 2 "; TableSQL += " and UpCode='"+nodeNum+"' order BY code "; ADOQueryDB2->Close(); ADOQueryDB2->SQL->Clear(); ADOQueryDB2->SQL->Add(TableSQL); ADOQueryDB2->Open(); while(!ADOQueryDB2->Eof) { rNode2=TreeViewCode->Items->AddChild(rNode1, ADOQueryDB2->FieldByName("cname")->AsString ); ADOQueryDB2->Next(); } ADOQueryDB->Next(); } TreeViewCode->FullExpand() ; TreeViewCode->OnDblClick = treeProcSub;// 设置树 事件