📄 phoneno7dlg.cpp
字号:
// PhoneNo7Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "PhoneNo7.h"
#include "PhoneNo7Dlg.h"
#include "voconnection.h"
#include "vorecordset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPhoneNo7Dlg dialog
extern CPhoneNo7App theApp;
CPhoneNo7Dlg::CPhoneNo7Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CPhoneNo7Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPhoneNo7Dlg)
m_txtname1 = _T("");
m_txtname2 = _T("");
m_txtname3 = _T("");
m_txtname4 = _T("");
m_no1 = _T("");
m_no2 = _T("");
m_no3 = _T("");
m_no4 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
// this->m_txtname1="ddd"; //可以正常显示
//读入数据库中数据,暂时先在这里显示数据
//1.注册DLL
int testreg; //非0表示注册成功
testreg=CreateProcess(_T("\\RegSvrCe"),_T("/s \\Windows\\adoce31.dll"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
testreg=CreateProcess(_T("\\RegSvrCe"),_T("/s \\Windows\\Adoxce31.dll"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
testreg=CreateProcess(_T("\\RegSvrCe"),_T("/s \\Windows\\Adocedb31.dll"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
testreg=CreateProcess(_T("\\RegSvrCe"),_T("/s \\Windows\\Adoceoledb31.dll"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
testreg=CreateProcess(_T("\\RegSvrCe"),_T("/s \\Windows\\Msdaer.dll"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
testreg=CreateProcess(_T("\\RegSvrCe"),_T("/s \\Windows\\Msdaeren.dll"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
testreg=CreateProcess(_T("\\RegSvrCe"),_T("/s \\Windows\\msdadc.dll"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
testreg=CreateProcess(_T("\\RegSvrCe"),_T("/s \\Windows\\msdaosp.dll"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
//2.读入数据库中数据
CString sql;
sql=_T("select * from PhoneNumb");
// con=new CVOConnection(_T("\\My Documents\\个人\\Phone.cdb")); //成功!
con=new CVOConnection(_T("\\My Documents\\Phone.cdb")); //成功!
//con=new CVOConnection(_T("\\Phone.cdb")); //失败,不能读取根目录下的数据
/* //打开对话框读取成功!
TCHAR szFilters[]=_T("Access File (*.cdb)|*.cdb||");
//调用,打开文件对话框,选择Access数据库文件
CString cdbName;
CFileDialog fileDlg (TRUE, _T("cdb"),_T("*.cdb"),OFN_FILEMUSTEXIST,szFilters,this);
if (fileDlg.DoModal() == IDOK)
{
cdbName = fileDlg.GetPathName();
}
else
{
AfxMessageBox(_T("打开文件失败!"));
//theApp.ExitInstance();
}
con=new CVOConnection(cdbName);
*/
CVORecordset* rs;
rs=opentable(sql);
//3.将数据库中数据前几项显示在对话框中
CString name,no;
if(!(rs->IsBOF())&&!(rs->IsEOF()))
{
// try //试着捕捉这个异常
// {
name=rs->GetFieldValueString(0);
no=rs->GetFieldValueString(1);
// }
// catch(CException e)
// {
// ;
// }
this->m_txtname1=name;
this->m_no1=no;
rs->MoveNext();
this->m_txtname2=rs->GetFieldValueString(0);
this->m_no2=rs->GetFieldValueString(1);
rs->MoveNext();
this->m_txtname3=rs->GetFieldValueString(0);
this->m_no3=rs->GetFieldValueString(1);
rs->MoveNext();
this->m_txtname4=rs->GetFieldValueString(0);
this->m_no4=rs->GetFieldValueString(1);
}
delete rs;
delete con;
/**/
//UpdateData(false);
}
void CPhoneNo7Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPhoneNo7Dlg)
DDX_Text(pDX, IDC_NAME1, m_txtname1);
DDX_Text(pDX, IDC_NAME2, m_txtname2);
DDX_Text(pDX, IDC_NAME3, m_txtname3);
DDX_Text(pDX, IDC_NAME4, m_txtname4);
DDX_Text(pDX, IDC_NO1, m_no1);
DDX_Text(pDX, IDC_NO2, m_no2);
DDX_Text(pDX, IDC_NO3, m_no3);
DDX_Text(pDX, IDC_NO4, m_no4);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPhoneNo7Dlg, CDialog)
//{{AFX_MSG_MAP(CPhoneNo7Dlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPhoneNo7Dlg message handlers
BOOL CPhoneNo7Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
// this->m_txtname1=_T("dfff"); //而PhoneNumber则可以。
// UpdateData(false); //从变量到控件的更新数据
return TRUE; // return TRUE unless you set the focus to a control
}
CVORecordset* CPhoneNo7Dlg::opentable(CString sql)
{
//执行语句sql,读取数据库
CVORecordset *rs;
// CVOConnection *con;
rs=new CVORecordset(*con);
rs->Initialize();
rs->Open(sql,adOpenForwardOnly,adLockPessimistic);
boolean a,b;
a=rs->IsBOF();b=rs->IsEOF();
if(a||b) //如果为空
{
AfxMessageBox(_T("数据库为空!"));
rs->Close();
delete rs;
delete con;
return NULL;
}
rs->MoveFirst(); //已指向第一条
return rs;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -