PAGE2.CPP
上传用户:sanlisteel
上传日期:2008-06-19
资源大小:98k
文件大小:3k
- // Page2.cpp : implementation file
- //
- #include "stdafx.h"
- #include "tbvc.h"
- #include "Page2.h"
- #include "mdbfield.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CPage2 property page
- IMPLEMENT_DYNCREATE(CPage2, CPropertyPage)
- CPage2::CPage2() : CPropertyPage(CPage2::IDD)
- {
- m_pSet=NULL;
- //{{AFX_DATA_INIT(CPage2)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- CPage2::~CPage2()
- {
- if(m_pSet!=NULL)
- {
- m_pSet->Close();
- m_database->Close();
- delete m_pSet;
- delete m_database;
- }
- }
- void CPage2::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPage2)
- DDX_Control(pDX, IDC_LIST2, m_listctrl);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPage2, CPropertyPage)
- //{{AFX_MSG_MAP(CPage2)
- ON_WM_CTLCOLOR()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPage2 message handlers
- BOOL CPage2::OnInitDialog()
- {
-
- CPropertyPage::OnInitDialog();
- m_brush.CreateSolidBrush(RGB(0,170,170));
- try
- {
- CString sDSN="ODBC;DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=telbook.mdb";
- m_database = new CDatabase;
- if(!m_database->Open(NULL,FALSE,FALSE,sDSN,FALSE))
- {
- CDialog::EndDialog(0);
- return FALSE;
- }
- CString strSQL="select * from personlist";
- m_pSet = new CRecordset(m_database);
- m_pSet->Open(CRecordset::dynaset,strSQL);
- m_listctrl.SetBkColor(RGB(0xFF,0xFF,0xFF));
- m_listctrl.SetTextBkColor(RGB(0xFF,0xFF,0xFF));
- for(int i=0;i<12;i++)
- {
- m_listctrl.InsertColumn(i,dbFields[i].label,LVCFMT_LEFT,-1,-1);
- m_listctrl.SetColumnWidth(i,dbFields[i].len);
- }
-
- }
- catch(CDBException* pEx)
- {
- pEx->ReportError();
- }
- return TRUE;
-
- }
- HBRUSH CPage2::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr =(HBRUSH)m_brush;
-
- return hbr;
- }
- void CPage2::AddDataIntoCtrl()
- {
- CWaitCursor wc;
- CString temp;
- char *buf;
- int j=0;
- if(!m_pSet->Requery()) AfxMessageBox("can not requery");
- if(m_pSet->IsBOF() && m_pSet->IsEOF()) return;
- //m_pSet->MoveFirst();
- while( !m_pSet->IsEOF() )
- {
- for(int i=0;i<MAX_LEN;i++)
- {
- m_pSet->GetFieldValue(dbFields[i].name,temp);
- buf=temp.GetBuffer(temp.GetLength());
- strcpy(dbFields[i].m_name,buf);
- }
- m_listctrl.InsertItem(j,(LPCTSTR)dbFields[0].m_name,0);
- for(i=1;i<MAX_LEN;i++)
- {
- m_listctrl.SetItemText(j,i,dbFields[i].m_name);
- }
- j++;
- m_pSet->MoveNext();
- }
- }
- BOOL CPage2::OnSetActive()
- {
- EmptyListCtrl();
- AddDataIntoCtrl();
- return CPropertyPage::OnSetActive();
- }
- void CPage2::EmptyListCtrl()
- {
- m_listctrl.DeleteAllItems();
- }