搜档网
当前位置:搜档网 › C源码_307

C源码_307

C源码_307
C源码_307

C++编程=>Source Part Three

Changeroomdlg.cpp : implementation file

#include "stdafx.h"

#include "Myhotel.h"

#include "Changeroomdlg.h"

#ifdef _fxDEBUG

#define new DEBUG_fxNEW

#undef THIS_fxFILE

static char THIS_fxFILE[] = _fxFILE_fx;

#endif

extern CMyhotelApp theApp;

extern CString loguserid;

CChangeroomdlg dialog

CChangeroomdlg::CChangeroomdlg(CWnd pParent =NULL)

: CDialog(CChangeroomdlg::IDD, pParent)

{

{{AFX_fxDATA_fxINIT(CChangeroomdlg)

m_fxsourceroom = _fxT("");

m_fxdestroom = _fxT("");

m_fxchangeroom_fxbeizhu = _fxT("");

m_fxchangeroom_fxidkind = _fxT("");

m_fxchangeroom_fxidnumber = _fxT("");

m_fxchangeroom_fxname = _fxT("");

m_fxchangeroom_fxroommoney = _fxT("");

m_fxchangeroom_fxregnumber = _fxT("");

m_fxshowuser = _fxT("");

}}AFX_fxDATA_fxINIT

}

void CChangeroomdlg::DoDataExchange(CDataExchange pDX)

{

CDialog::DoDataExchange(pDX);

{{AFX_fxDATA_fxMAP(CChangeroomdlg)

DDX_fxControl(pDX, IDC_fxCOMBO_fxdestroom, m_fxdestroomctr);

DDX_fxControl(pDX, IDC_fxCOMBO_fxsourceroom, m_fxsourceroomctr);

DDX_fxCBString(pDX, IDC_fxCOMBO_fxsourceroom, m_fxsourceroom);

DDX_fxCBString(pDX, IDC_fxCOMBO_fxdestroom, m_fxdestroom);

DDX_fxText(pDX, IDC_fxchangeroom_fxbeizhu, m_fxchangeroom_fxbeizhu);

DDX_fxCBString(pDX, IDC_fxchangeroom_fxidkind, m_fxchangeroom_fxidkind);

DDX_fxText(pDX, IDC_fxchangeroom_fxidnumber, m_fxchangeroom_fxidnumber); DDX_fxText(pDX, IDC_fxchangeroom_fxname, m_fxchangeroom_fxname);

DDX_fxText(pDX, IDC_fxchangeroom_fxroommoney, m_fxchangeroom_fxroommoney); DDX_fxText(pDX, IDC_fxchangeroomdlg_fxregnumber, m_fxchangeroom_fxregnumber); DDX_fxText(pDX, IDC_fxSTA TICshowuser, m_fxshowuser);

}}AFX_fxDATA_fxMAP

}

BEGIN_fxMESSAGE_fxMAP(CChangeroomdlg, CDialog)

{{AFX_fxMSG_fxMAP(CChangeroomdlg)

ON_fxBN_fxCLICKED(ID_fxBTN_fxchangeroomreg, OnBTNchangeroomreg)

ON_fxCBN_fxCLOSEUP(IDC_fxCOMBO_fxsourceroom, OnCloseupCOMBOsourceroom) ON_fxCBN_fxCLOSEUP(IDC_fxCOMBO_fxdestroom, OnCloseupCOMBOdestroom)

ON_fxBN_fxCLICKED(IDCANCEL_fxchangeroom, Onchangeroom)

}}AFX_fxMSG_fxMAP

END_fxMESSAGE_fxMAP()

CChangeroomdlg message handlers

BOOL CChangeroomdlg::OnInitDialog()

{

CDialog::OnInitDialog();

TODO: Add extra initialization here

使用ADO创建数据库记录集

m_fxpRecordset.CreateInstance(_fxuuidof(Recordset));

_fxvariant_fxt var;

CString strroomnumber;

在ADO操作中建议语句中要常用try...catch()来捕获错误信息,

try

{

m_fxpRecordset->Open("SELECT FROM roomsetting",

查询表中所有字段

theApp.m_fxpConnection.GetInterfacePtr(), 获取库接库的IDispatch指针adOpenDynamic,

adLockOptimistic,

adCmdText);

}

catch(_fxcom_fxerror e)捕获连接数据库异常

{

AfxMessageBox(e->ErrorMessage());

}

try

{

if(!m_fxpRecordset->BOF)判断指针是否在数据集最后

m_fxpRecordset->MoveFirst();

else

{

AfxMessageBox("表内数据为空");

return false;

}

read data from the database table

while(!m_fxpRecordset->adoEOF)

{读取房间号

var = m_fxpRecordset->GetCollect("房间号");

if(var.vt != VT_fxNULL)

strroomnumber = (LPCSTR)_fxbstr_fxt(var);

m_fxsourceroomctr.AddString(strroomnumber);添加到列表

m_fxdestroomctr.AddString(strroomnumber);

m_fxpRecordset->MoveNext();移动记录集指针

}

}

catch(_fxcom_fxerror e)捕获异常

{

AfxMessageBox(e->ErrorMessage());

}

关闭记录集

m_fxpRecordset->Close();

m_fxpRecordset = NULL;

获得操作员ID

m_fxshowuser=loguserid;

显示更新

UpdateData(false);

enable(0);

return TRUE;

//return TRUE unless you set the focus to a control

EXCEPTION: OCX Property Pages should return FALSE

}

void CChangeroomdlg::enable(bool bEnabled)

{

m_fxComYSFS.EnableWindow(bEnabled);

更改输入框状态

GetDlgItem(IDC_fxCOMBO_fxdestroom)->EnableWindow(bEnabled); GetDlgItem(IDC_fxCOMBO_fxsourceroom)->EnableWindow(bEnabled); GetDlgItem(IDC_fxCOMBO_fxdestroom)->EnableWindow(bEnabled); GetDlgItem(IDC_fxchangeroom_fxbeizhu)->EnableWindow(bEnabled); GetDlgItem(IDC_fxchangeroom_fxidkind)->EnableWindow(bEnabled); GetDlgItem(IDC_fxchangeroom_fxidnumber)->EnableWindow(bEnabled); GetDlgItem(IDC_fxchangeroom_fxname)->EnableWindow(bEnabled); GetDlgItem(IDC_fxchangeroom_fxroommoney)->EnableWindow(bEnabled); GetDlgItem(IDC_fxchangeroomdlg_fxregnumber)->EnableWindow(bEnabled); GetDlgItem(IDOK)->EnableWindow(bEnabled);

更改输入框状态完毕

}

void CChangeroomdlg::OnBTNchangeroomreg()

{

TODO: Add your control notification handler code here

enable(1);

}

void CChangeroomdlg::OnCloseupCOMBOsourceroom()

{

TODO: Add your control notification handler code here

_fxvariant_fxt var;

使用ADO创建数据库记录集

m_fxpRecordset.CreateInstance(_fxuuidof(Recordset));

在ADO操作中建议语句中要常用try...catch()来捕获错误信息,

获取输入框内容

UpdateData(true);

CString strsql;

strsql.Format("SELECT FROM checkinregtable where 房间号='%s'",m_fxsourceroom); try

{打开数据库

m_fxpRecordset->Open(_fxvariant_fxt(strsql),

//查询表中所有字段

theApp.m_fxpConnection.GetInterfacePtr(), 获取库接库的IDispatch指针adOpenDynamic,

adLockOptimistic,

adCmdText);

}

catch(_fxcom_fxerror e)

{捕获异常

AfxMessageBox(e->ErrorMessage());

}

try

{

if(!m_fxpRecordset->BOF)判断指针是否在数据集最后

m_fxpRecordset->MoveFirst();

else

{

AfxMessageBox("表内数据为空");

return ;

}

read data from the database table

从数据表中读取姓名字段

var = m_fxpRecordset->GetCollect("姓名");

if(var.vt != VT_fxNULL)

m_fxchangeroom_fxname= (LPCSTR)_fxbstr_fxt(var);

//从数据表中读取凭证号码字段

var = m_fxpRecordset->GetCollect("凭证号码");

if(var.vt != VT_fxNULL)

m_fxchangeroom_fxregnumber= (LPCSTR)_fxbstr_fxt(var);

//从数据表中读取证件名称字段

var = m_fxpRecordset->GetCollect("证件名称");

if(var.vt != VT_fxNULL)

m_fxchangeroom_fxidkind = (LPCSTR)_fxbstr_fxt(var);

//从数据表中读取证件号码字段

var = m_fxpRecordset->GetCollect("证件号码");

if(var.vt != VT_fxNULL)

m_fxchangeroom_fxidnumber = (LPCSTR)_fxbstr_fxt(var);

//从数据表中读取备注字段

var = m_fxpRecordset->GetCollect("备注");

if(var.vt != VT_fxNULL)

m_fxchangeroom_fxbeizhu = (LPCSTR)_fxbstr_fxt(var);

UpdateData(false);

//更新显示

}

catch(_fxcom_fxerror e)

//捕获异常

{

AfxMessageBox(e->ErrorMessage());

}

//关闭记录集

m_fxpRecordset->Close();

m_fxpRecordset = NULL;

更新显示

UpdateData(false);

}

void CChangeroomdlg::OnCloseupCOMBOdestroom()

{

TODO: Add your control notification handler code here

_fxvariant_fxt var;

使用ADO创建数据库记录集

m_fxpRecordset.CreateInstance(_fxuuidof(Recordset));

// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,

UpdateData(true);

CString strsql;

strsql.Format("SELECT FROM checkinregtable where 房间号='%s'",m_fxdestroom); try打开数据库

{

m_fxpRecordset->Open(_fxvariant_fxt(strsql),

//查询表中所有字段

theApp.m_fxpConnection.GetInterfacePtr(), 获取库接库的IDispatch指针adOpenDynamic,

adLockOptimistic,

adCmdText);

}

catch(_fxcom_fxerror e)

{ 捕获打开数据库时候可能发生的异常情况

AfxMessageBox(e->ErrorMessage());

}

try

{

if(!m_fxpRecordset->BOF)判断指针是否在数据集最后

m_fxpRecordset->MoveFirst();

else

{

AfxMessageBox("表内数据为空");

return ;

}

read data from the database table

从数据表中读取客房价格字段

var = m_fxpRecordset->GetCollect("客房价格");

if(var.vt != VT_fxNULL)

m_fxchangeroom_fxroommoney = (LPCSTR)_fxbstr_fxt(var);

从数据表中读取客房类型字段

var = m_fxpRecordset->GetCollect("客房类型");

if(var.vt != VT_fxNULL)

destroomlevel = (LPCSTR)_fxbstr_fxt(var);

读取数据完毕,然后更新显示

UpdateData(false);

更新显示完毕

}

catch(_fxcom_fxerror e) 捕获异常

{

AfxMessageBox(e->ErrorMessage());

}

相关主题