记录:树形控件的一些使用方法(和sql server 结合显示)
来源:互联网 发布:图图软件 编辑:程序博客网 时间:2024/06/14 18:21
void CTFromViewView::OnInitialUpdate()
{
//框架生成代码
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
//ua
m_tree.DeleteAllItems(); // Clear the tree item
//改变树形控件的样式
m_tree.ModifyStyle(0,TVS_HASLINES|TVS_HASBUTTONS|TVS_SHOWSELALWAYS|TVS_LINESATROOT);
TV_INSERTSTRUCT tvinsert;
//指定是根节点
tvinsert.hParent=NULL;
tvinsert.hInsertAfter=TVI_LAST;
tvinsert.item.mask=TVIF_TEXT;
tvinsert.item.pszText="郑州市";
//插入一个根节点
HTREEITEM hRoot=m_tree.InsertItem(&tvinsert);
//分别对路口,分组,车道信息指定那个啥
_RecordsetPtr pAcrossRs,pGroupRs,pDrivewayRs;
//临时变量
_variant_t vTemp;
TCHAR buffer[30];
//树节点
HTREEITEM hAcrossItem,hGroupItem,hDrivewayItem;
//少用了几个try块。直接 CreatInstance()
m_pCommand.CreateInstance(__uuidof(Command));
pAcrossRs.CreateInstance(__uuidof(Recordset));
pGroupRs.CreateInstance(__uuidof(Recordset));
pDrivewayRs.CreateInstance(__uuidof(Recordset));
//查询所有的路口
m_strSQL="SELECT DISTINCT acrossname FROM cnet_view_preview";
try
{
pAcrossRs->Open("SELECT DISTINCT acrossname FROM cnetstar_view_preview",
_variant_t((IDispatch *)theApp.m_pConnection,true), // Get IDispatch pointer
adOpenStatic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
CString strErrorMsg;
strErrorMsg.Format("Error message:%s",e.ErrorMessage());
AfxMessageBox(strErrorMsg);
}
while(!pAcrossRs->adoEOF)
{
// 获取字段信息 :路口名称
//
vTemp=pAcrossRs->GetCollect("acrossname");
if(vTemp.vt!=VT_NULL)
m_acrossName=(LPCTSTR)_bstr_t(vTemp);
tvinsert.hParent=hRoot;
tvinsert.hInsertAfter=TVI_LAST;
wsprintf(buffer,"%s",m_acrossName);
tvinsert.item.pszText=buffer;
//把路口信息插入树中
hAcrossItem=m_tree.InsertItem(&tvinsert);
//根据路口信息 查询 分组信息 的 sql 语句
m_strSQL="SELECT DISTINCT groupname FROM cnetstar_view_preview WHERE acrossname='"+m_acrossName+"'";
pGroupRs->Open((_variant_t)m_strSQL,
_variant_t((IDispatch*)theApp.m_pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
while(!pGroupRs->adoEOF)
{
//获取所有关联该路口 的 分组信息
vTemp=pGroupRs->GetCollect("groupname");
if(vTemp.vt!=VT_NULL)
m_groupName=(LPCTSTR)_bstr_t(vTemp);
tvinsert.hInsertAfter=TVI_LAST;
tvinsert.hParent=hAcrossItem;
wsprintf(buffer,"%s",m_groupName);
tvinsert.item.pszText=buffer;
//插入分组信息
hGroupItem=m_tree.InsertItem(&tvinsert);
//产生根据分组信息查询 该分组 车道信息 的查询语句(可扩充车道摄像机信息)
m_strSQL="SELECT DISTINCT drivewayname FROM cnetstar_view_preview WHERE groupname='"+m_groupName+"'";
pDrivewayRs->Open(_variant_t(m_strSQL),
_variant_t((IDispatch*)theApp.m_pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
//为每个分组插入一个全景节点
CString strPanarama(_T("全景摄像机"));
tvinsert.hParent=hGroupItem;
wsprintf(buffer,"%s",strPanarama);
tvinsert.item.pszText=buffer;
m_tree.InsertItem(&tvinsert);
while(!pDrivewayRs->adoEOF)
{
//获取车道名称
vTemp=pDrivewayRs->GetCollect("drivewayname");
if(vTemp.vt!=VT_NULL)
m_drivewayName=(LPCTSTR)_bstr_t(vTemp);
wsprintf(buffer,"%s",m_drivewayName);
tvinsert.item.pszText=buffer;
tvinsert.hParent=hGroupItem;
tvinsert.hInsertAfter=TVI_LAST;
//插入车道信息
hDrivewayItem=m_tree.InsertItem(&tvinsert);
pDrivewayRs->MoveNext();
}
m_tree.Expand(hGroupItem,TVE_EXPAND);
//关闭车道记录集
pDrivewayRs->Close();
pGroupRs->MoveNext();
}
m_tree.Expand(hAcrossItem,TVE_EXPAND);
//关闭分组记录集
pGroupRs->Close();
pAcrossRs->MoveNext();
}
//关闭路口记录集
pAcrossRs->Close();
//释放资源
pDrivewayRs=NULL;
pGroupRs=NULL;
pAcrossRs=NULL;
// 展开节点
m_tree.Expand(hRoot,TVE_EXPAND);
//在区域内显示全景 ---该为大恒卡显示全景 yyk 08/05/20
//ShowDSPPanorama(m_rectDsp);
ShowPanorama();
}
要用 ado 的方式连接 sql server ,那么步骤在第一篇里面有,只贴部分代码:
//ua
if(!AfxOleInit()) // Initialize COM library
{
AfxMessageBox("初始化COM库失败");
}
HRESULT hr;
try
{
hr=m_pConnection.CreateInstance("ADODB.Connection"); // Create Connection object
if(SUCCEEDED(hr))
{
// Connection String ;DataSource=local
CString strConncetion=_T("Provider=SQLOLEDB;"
"Server=192.168.16.110;"
"database=tITS;"
//"InitialCatalog=tITS.mdf;"
"User ID=sa;Password=123;");
// Open
hr=m_pConnection->Open((_bstr_t)strConncetion,"","",adModeUnknown);
if(FAILED(hr))
{
AfxMessageBox("Failed to open database");
return FALSE;
}
}
}
catch(_com_error e)
{
CString strErrorMessage;
strErrorMessage.Format("链接数据库错误,错误信息:/r/t%s",e.ErrorMessage());
AfxMessageBox(strErrorMessage);
return FALSE;
}
- 记录:树形控件的一些使用方法(和sql server 结合显示)
- sql server 树形表的一些操作
- SQL Server COUNT() 和SUM()的使用方法
- SQL Server COUNT() 和SUM()的使用方法
- 关于树形弹出框选择JS和sql的记录
- 记录一些Jquery操作控件使用方法
- Android打造一个高性能无限层级显示的树形控件(Android树形控件)
- MFC中利用树形控件和列表控件来显示显示系统的资源列表
- 结合aspnetpager控件和三层的sql语句的分页
- 记录git 的一些使用方法
- 记录一些UIScrollView的使用方法
- MFC树形控件和静态切分视图结合程序
- MFC树形控件和静态切分视图结合程序
- 记录下, sql server下面语句的一些简单用法
- JFinal中树形显示(ztree)和弹层(layer)结合事例
- Sql Server数据库事务介绍(二)---Sql语句,SqlTransaction和TransactionScope的使用方法 (转载)
- 关于树形控件的一些问题
- 树形控件创建的一些基础知识
- js前台创建cookies后台取该cookies的值
- TCP传输与流式套接字
- 如何在北京购车外地上牌
- C#中接口与类的区别
- 在linux下,如何在C语言中使用正则表达式(整理)
- 记录:树形控件的一些使用方法(和sql server 结合显示)
- glutWireTeapot()尝鲜
- 书写是为了更好的思考
- WINCE程序设计之串口通信
- window对象的学习(二)
- Compiler技术研究(1)
- linux 常用c函数
- linux 硬盘分区方式
- oninput和onpropertychange测试