📄 clime.cpp
字号:
// Clime.cpp : implementation file
//
#include "stdafx.h"
#include "源程序.h"
#include "Clime.h"
#include "AddRoot.h"
#include "RainFunction.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr cnn;
/////////////////////////////////////////////////////////////////////////////
// CClime dialog
CClime::CClime(CWnd* pParent /*=NULL*/)
: CDialog(CClime::IDD, pParent)
{
//{{AFX_DATA_INIT(CClime)
//}}AFX_DATA_INIT
}
void CClime::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClime)
DDX_Control(pDX, IDC_BUTEXIT, m_ButExit);
DDX_Control(pDX, IDC_BUTDELETE, m_ButDel);
DDX_Control(pDX, IDC_BUTADD, m_ButAdd);
DDX_Control(pDX, IDC_TREE1, m_tree);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CClime, CDialog)
//{{AFX_MSG_MAP(CClime)
ON_BN_CLICKED(IDC_BUTADD, OnButadd)
ON_BN_CLICKED(IDC_BUTEXIT, OnButexit)
ON_BN_CLICKED(IDC_BUTDELETE, OnButdelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClime message handlers
void CClime::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
BOOL CClime::OnInitDialog()
{
CDialog::OnInitDialog();
_RecordsetPtr Rst,RstProvince,RstCity,RstTown;
HTREEITEM item,itemProvince,itemCity,itemTown;
CString sSQL,ItemText,ItemStyle,ItemID;
//初始化数据集
::CoInitialize(NULL);
Rst.CreateInstance(__uuidof(Recordset));
RstProvince.CreateInstance(__uuidof(Recordset));
RstCity.CreateInstance(__uuidof(Recordset));
RstTown.CreateInstance(__uuidof(Recordset));
//建立并初始化图像列表控件
m_Imagelist.Create(16,16,ILC_COLOR32|ILC_MASK,0,0);
for(int i=IDI_ICON1;i<=IDI_ICON4;i++)
{
m_Imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(i)));
}
m_tree.EnableAutomation();
m_tree.SetImageList(&m_Imagelist,TVSIL_NORMAL);
item=m_tree.InsertItem("中华人民共和国",3,3,TVI_ROOT,TVI_LAST);
sSQL.Format("SELECT * FROM 地域信息表 WHERE 上级编号=0");
RstProvince=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(m_function.RecordCount(RstProvince)<=0)
return false;
else
{
RstProvince->MoveFirst();
for(int Province=0;Province<m_function.RecordCount(RstProvince);Province++)
{
RstProvince->MoveFirst();
RstProvince->Move(Province);
ItemText=(char*)(_bstr_t)RstProvince->GetCollect("名称");
ItemStyle=(char*)(_bstr_t)RstProvince->GetCollect("类型");
ItemID=(char*)(_bstr_t)RstProvince->GetCollect("编号");
itemProvince=m_tree.InsertItem(ItemText,atoi(ItemStyle)-1,atoi(ItemStyle)-1,item,TVI_LAST);
sSQL.Format("SELECT * FROM 地域信息表 WHERE 上级编号=%s",ItemID);
RstCity=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(m_function.RecordCount(RstCity)<=0)
continue;
else
{
for(int City=0;City<m_function.RecordCount(RstCity);City++)
{
RstCity->MoveFirst();
RstCity->Move(City);
ItemText=(char*)(_bstr_t)RstCity->GetCollect("名称");
ItemStyle=(char*)(_bstr_t)RstCity->GetCollect("类型");
ItemID=(char*)(_bstr_t)RstCity->GetCollect("编号");
itemCity=m_tree.InsertItem(ItemText,atoi(ItemStyle)-1,atoi(ItemStyle)-1,itemProvince,TVI_LAST);
sSQL.Format("SELECT * FROM 地域信息表 WHERE 上级编号=%s",ItemID);
RstTown=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(m_function.RecordCount(RstTown)<=0)
continue;
else
{
for(int Town=0;Town<m_function.RecordCount(RstTown);Town++)
{
RstTown->MoveFirst();
RstTown->Move(Town);
ItemText=(char*)(_bstr_t)RstTown->GetCollect("名称");
ItemStyle=(char*)(_bstr_t)RstTown->GetCollect("类型");
itemTown=m_tree.InsertItem(ItemText,atoi(ItemStyle)-1,atoi(ItemStyle)-1,itemCity,TVI_LAST);
}
}
}
}
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CClime::OnButadd()
{
HTREEITEM Item,SelectItem,ParentItem;
int ID,Style,NewID;
CString Text,LatterText,sSQL,ItemText;
CAddRoot dlg;
SelectItem=m_tree.GetSelectedItem();
dlg.Root=SelectItem;
ItemText=m_tree.GetItemText(SelectItem);
dlg.m_StaItem=ItemText;
ParentItem=m_tree.GetParentItem(m_tree.GetSelectedItem());
dlg.ParentRoot=ParentItem;
dlg.m_tree=&m_tree;
dlg.DoModal();
if(dlg.Rady==false)
return;
else
{
if(dlg.Connection==0) //确定关系
{
ID=dlg.RootStyle(SelectItem,"编号");
Item=SelectItem;
}
else
{
ID=dlg.RootStyle(ParentItem,"编号");
Item=ParentItem;
}
Style=dlg.Style;
Text=dlg.EdtNameText;
LatterText=m_function.CharToLetterCode(Text);
char* bb=LatterText.GetBuffer(LatterText.GetLength());
NewID=m_function.AutoNumber(0,"地域信息表");
sSQL.Format("INSERT into 地域信息表 VALUES(%d,'%s','%s',%d,%d)",NewID,Text,LatterText,Style,ID);
cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
m_tree.InsertItem(Text,Style-1,Style-1,Item,TVI_LAST);
}
}
void CClime::OnButexit()
{
this->OnCancel();
}
void CClime::OnButdelete()
{
_RecordsetPtr rst;
rst.CreateInstance(__uuidof(Recordset));
CString sSQL;
HTREEITEM DeleteItem;
CRainFunction function;
int a=MessageBox("确定删除指定节点吗?","系统提示",MB_ICONQUESTION|MB_OKCANCEL);
if(a==1)
{
CAddRoot dlg;
//判断是否包含子节点
DeleteItem=m_tree.GetSelectedItem();
dlg.m_tree=&m_tree;
int ID=dlg.RootStyle(DeleteItem,"编号");
sSQL.Format("SELECT * FROM 地域信息表 WHERE 上级编号=%d",ID);
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(m_function.RecordCount(rst)!=0)
{
MessageBox("此节点包含子节点,请先删除子节点!","系统提示",MB_ICONSTOP|MB_OK);
}
else
{
rst->Close();
sSQL.Format("DELETE * FROM 地域信息表 WHERE 编号=%d",ID);
try{
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
}
catch(...)
{
function.ADOError(rst);
return;
}
m_tree.DeleteItem(DeleteItem);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -