WEB开发网
开发学院软件开发VC 用VC实现按数据库记录构建树控件 阅读

用VC实现按数据库记录构建树控件

 2008-11-13 19:30:38 来源:WEB开发网   
核心提示: 6.添加一个求当前项子项串的成员函数ReturnTreeChilds(CString strCurItem):此成员函数也是递归函数.//提取当前所选择项的子项文本所组成的字符串CString CTreeDataDlg::ReturnTreeChilds(CString strCurIte

6.添加一个求当前项子项串的成员函数

ReturnTreeChilds(CString strCurItem):
此成员函数也是递归函数.
//----------------提取当前所选择项的子项文本所组成的字符串------------------------
CString CTreeDataDlg::ReturnTreeChilds(CString strCurItem)
{
CString strTreeChildren;//记录子项文本所组成的字符串
if (TreeSumRecordCount(strCurItem) > 0)
{
//--------------------进入递归运算---------------------
_RecordsetPtr m_pTreeRecordset; //用于创建一个查询记录集
_variant_t vCur;
CString strSQL;
//-----------------------------------------------
strSQL="SELECT * FROM TreeItem where ParentItem like ''%" ;
strSQL=strSQL+strCurItem+"%''";
try
{
HRESULT hTRes;
hTRes = m_pTreeRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
//----------------------------------------------------
hTRes = m_pTreeRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
_variant_t((IDispatch *)(((CTreeDataApp*)AfxGetApp())->m_pTreeConn),true),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!n"));
//------------------------------------------
m_pTreeRecordset->MoveFirst();
vCur=(m_pTreeRecordset->GetCollect("Name"));
if (TreeSumRecordCount(VariantToCString(vCur))>=0)
{
while(!m_pTreeRecordset->adoEOF)
{
vCur=(m_pTreeRecordset->GetCollect("Name"));
strTreeChildren+=(",''"+VariantToCString(vCur)+"''");
if (TreeSumRecordCount(VariantToCString(vCur))!=0)
{
strTreeChildren+=ReturnTreeChilds(VariantToCString(vCur));
}
if (!(m_pTreeRecordset->adoEOF))
{
m_pTreeRecordset->MoveNext();
}
}
}
//---------------------------------------
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
AfxMessageBox("创建ChildTree记录集失败!"+strCurItem);
}
}
return strTreeChildren;
}

上一页  1 2 3 4 5  下一页

Tags:VC 实现 数据库

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接