【VC开源代码栏目提醒】:网学会员VC开源代码为您提供ADOTest1Dlg.cpp参考,解决您在ADOTest1Dlg.cpp学习中工作中的难题,参考学习。
// ADOTest1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "ADOTest1.h"
#include "ADOTest1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CADOTest1App theApp;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CADOTest1Dlg dialog
CADOTest1Dlg::CADOTest1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CADOTest1Dlg::IDD, pParent)
, m_strAdd(_T(""))
, m_strDev(_T(""))
{
//{{AFX_DATA_INIT(CADOTest1Dlg)
m_nID = 0;
m_nPrice = 0;
m_sName = _T("");
m_tDate = COleDateTime::GetCurrentTime();
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nCurrentSel = -1;
m_bSuccess = FALSE;
m_bAutoSave = TRUE;
}
void CADOTest1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CADOTest1Dlg)
DDX_Control(pDX, IDC_DELITEM, m_cDelItem);
DDX_Control(pDX, IDC_ADDITEM, m_cAddItem);
DDX_Control(pDX, IDC_REALLIST, m_Reallist);
DDX_Text(pDX, IDC_ID, m_nID);
DDX_Text(pDX, IDC_PRICE, m_nPrice);
DDX_Text(pDX, IDC_NAME, m_sName);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_tDate);
//}}AFX_DATA_MAP
DDX_Text(pDX, IDC_ADDRESS, m_strAdd);
DDX_Text(pDX, IDC_DEV, m_strDev);
}
BEGIN_MESSAGE_MAP(CADOTest1Dlg, CDialog)
//{{AFX_MSG_MAP(CADOTest1Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ADDITEM, OnAdditem)
ON_BN_CLICKED(IDC_DELITEM, OnDelitem)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_REALLIST, OnItemchangedUserlist)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CADOTest1Dlg message handlers
BOOL CADOTest1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_cDelItem.EnableWindow(FALSE);
::SendMessage(m_Reallist.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
//////////为列表控件添加列//////////
m_Reallist.InsertColumn(0,"楼盘ID",LVCFMT_LEFT,60);
m_Reallist.InsertColumn(1,"楼盘名称",LVCFMT_LEFT,100);
m_Reallist.InsertColumn(2,"价格",LVCFMT_LEFT,60);
m_Reallist.InsertColumn(3,"开盘日期",LVCFMT_LEFT,100);
m_Reallist.InsertColumn(4,"楼盘地点",LVCFMT_LEFT,150);
m_Reallist.InsertColumn(5,"楼盘开发商",LVCFMT_LEFT,150);
//////////读取数据库中的信息添加到列表控件///////////
int nItem;
_variant_t vName,vDate,vID,vPrice,vAddress,vDev;
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("SELECT * FROM realestate",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
m_bSuccess = TRUE;
while(!m_pRecordset->adoEOF)
{
vID = m_pRecordset->GetCollect("索引");
vName = m_pRecordset->GetCollect("楼盘名称");
vAddress = m_pRecordset->GetCollect("楼盘地点");
vDev = m_pRecordset->GetCollect("楼盘开发商");
vPrice = m_pRecordset->GetCollect("价格");
vDate = m_pRecordset->GetCollect("开盘日期");
nItem=m_Reallist.InsertItem(0xffff,(_bstr_t)vID);
m_Reallist.SetItem(nItem,1,1,(_bstr_t)vName,NULL,0,0,0);
m_Reallist.SetItem(nItem,2,1,(_bstr_t)vPrice,NULL,0,0,0);
m_Reallist.SetItem(nItem,3,1,(_bstr_t)vDate,NULL,0,0,0);
m_Reallist.SetItem(nItem,4,1,(_bstr_t)vAddress,NULL,0,0,0);
m_Reallist.SetItem(nItem,5,1,(_bstr_t)vDev,NULL,0,0,0);
m_pRecordset->MoveNext();
}
}
catch(_com_error e)///捕捉异常
{
AfxMessageBox("读取数据库失败!");///显示错误信息
}
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CADOTest1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CADOTest1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CADOTest1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CADOTest1Dlg::OnOK()
{
if(m_bSuccess)
{
m_pRecordset->Update();
m_pRecordset->Close();
}
CDialog::OnOK();
}
void CADOTest1Dlg::OnAdditem()
{
if(UpdateD
上一篇:
ADOTest1.cpp
下一篇:
法律专业开题报告范文