📄 dclime.cpp
字号:
// DClime.cpp : implementation file
//
#include "stdafx.h"
#include "商品库存管理系统.h"
#include "DClime.h"
#include "DClime_AddDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr cnn;
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDClime dialog
CDClime::CDClime(CWnd* pParent /*=NULL*/)
: CDialog(CDClime::IDD, pParent)
{
//{{AFX_DATA_INIT(CDClime)
//}}AFX_DATA_INIT
}
void CDClime::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDClime)
DDX_Control(pDX, IDC_TREE1, m_Tree);
DDX_Control(pDX, IDC_BUTDele, m_ButDele);
DDX_Control(pDX, IDC_BUTAdd, m_ButAdd);
DDX_Control(pDX, IDC_BUTExit, m_ButExit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDClime, CDialog)
//{{AFX_MSG_MAP(CDClime)
ON_BN_CLICKED(IDC_BUTAdd, OnBUTAdd)
ON_BN_CLICKED(IDC_BUTDele, OnBUTDele)
ON_BN_CLICKED(IDC_BUTExit, OnBUTExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDClime message handlers
void CDClime::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CDClime::OnBUTAdd()
{
HTREEITEM Node,SelectNode;
CDClime_AddDlg dlg;
CString NodeText,ParentNodeText,sSQL;
int ID;
Node=m_Tree.GetSelectedItem();
dlg.SetNode(&m_Tree,Node);
dlg.DoModal();
NodeText=m_Tree.GetItemText(Node);
ParentNodeText=m_Tree.GetItemText(m_Tree.GetParentItem(Node));
if(dlg.IsOK==false)
return;
else
{
if(dlg.Connection==1) //确定关系
{
ID=theApp.NumberTOName("地域信息表","名称",NodeText);
SelectNode=Node;
}
else
{
ID=theApp.NumberTOName("地域信息表","名称",ParentNodeText);
SelectNode=m_Tree.GetParentItem(Node);
}
CString LatterText=theApp.CharToLetterCode(dlg.Name);
int NewID=theApp.AutoNumber(0,"地域信息表");
sSQL.Format("INSERT into 地域信息表 VALUES(%d,'%s','%s',%d,%d)",NewID,dlg.Name,LatterText,dlg.IconStyle,ID);
cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
m_Tree.InsertItem(dlg.Name,dlg.IconStyle,dlg.IconStyle,SelectNode,TVI_LAST);
}
}
void CDClime::OnBUTDele()
{
_RecordsetPtr rst;
rst.CreateInstance(__uuidof(Recordset));
CString NodeText,sSQL;
HTREEITEM DeleteItem;
int a=MessageBox("确定删除指定节点吗?","系统提示",MB_ICONQUESTION|MB_OKCANCEL);
if(a==1)
{
//判断是否包含子节点
DeleteItem=m_Tree.GetSelectedItem();
NodeText=m_Tree.GetItemText(DeleteItem);
int ID=theApp.NumberTOName("地域信息表","名称",NodeText);
sSQL.Format("SELECT * FROM 地域信息表 WHERE 上级编号=%d",ID);
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(theApp.GetRecordCount(rst)!=0)
{
MessageBox("此节点包含子节点,请先删除子节点!","系统提示",MB_ICONSTOP|MB_OK);
rst->Close();
}
else
{
rst->Close();
sSQL.Format("DELETE * FROM 地域信息表 WHERE 编号=%d",ID);
cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
m_Tree.DeleteItem(DeleteItem);
}
}
}
void CDClime::OnBUTExit()
{
this->OnCancel();
}
BOOL CDClime::OnInitDialog()
{
CDialog::OnInitDialog();
//设置图标
m_hIcon=::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2));
this->SetIcon(m_hIcon,true);
_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_ICON11;i<=IDI_ICON14;i++)
{
m_Imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(i)));
}
m_Tree.EnableAutomation();
m_Tree.SetImageList(&m_Imagelist,TVSIL_NORMAL);
item=m_Tree.InsertItem("中华人民共和国",0,0,TVI_ROOT,TVI_LAST);
sSQL.Format("SELECT * FROM 地域信息表 WHERE 上级编号=0");
RstProvince=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(theApp.GetRecordCount(RstProvince)<=0)
return false;
else
{
RstProvince->MoveFirst();
for(int Province=0;Province<theApp.GetRecordCount(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),atoi(ItemStyle),item,TVI_LAST);
sSQL.Format("SELECT * FROM 地域信息表 WHERE 上级编号=%s",ItemID);
RstCity=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(theApp.GetRecordCount(RstCity)>0)
{
for(int City=0;City<theApp.GetRecordCount(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),atoi(ItemStyle),itemProvince,TVI_LAST);
sSQL.Format("SELECT * FROM 地域信息表 WHERE 上级编号=%s",ItemID);
RstTown=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(theApp.GetRecordCount(RstTown)>0)
{
for(int Town=0;Town<theApp.GetRecordCount(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),atoi(ItemStyle),itemCity,TVI_LAST);
}
}
}
}
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -