📄 roomprebookdlg.cpp
字号:
// Roomprebookdlg.cpp : implementation file
//
#include "stdafx.h"
#include "Myhotel.h"
#include "Roomprebookdlg.h"
#include <stdlib.h>
#include <stdio.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CString loguserid;
extern CMyhotelApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CRoomprebookdlg dialog
CRoomprebookdlg::CRoomprebookdlg(CWnd* pParent /*=NULL*/)
: CDialog(CRoomprebookdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRoomprebookdlg)
m_prebookidkind = _T("");
m_prebookroomkind = _T("");
m_prebookcheckindate = 0;
m_prebookaddr = _T("");
m_prebookdays = _T("");
m_prebookhandinmoney = _T("");
m_prebookidnumber = _T("");
m_prebookname = _T("");
m_prebooktelnumber = _T("");
m_prebookworkcompany = _T("");
m_prebookroommoney = _T("");
m_showuser = _T("");
//}}AFX_DATA_INIT
}
void CRoomprebookdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRoomprebookdlg)
DDX_CBString(pDX, IDC_COMBOprebookidkind, m_prebookidkind);
DDX_CBString(pDX, IDC_COMBOroomkind, m_prebookroomkind);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKERprecheckindate, m_prebookcheckindate);
DDX_Text(pDX, IDC_prebookaddr, m_prebookaddr);
DDX_Text(pDX, IDC_prebookdays, m_prebookdays);
DDX_Text(pDX, IDC_prebookhandinmoney, m_prebookhandinmoney);
DDX_Text(pDX, IDC_prebookidnumber, m_prebookidnumber);
DDX_Text(pDX, IDC_prebookname, m_prebookname);
DDX_Text(pDX, IDC_prebooktelnumber, m_prebooktelnumber);
DDX_Text(pDX, IDC_prebookworkcompany, m_prebookworkcompany);
DDX_Text(pDX, IDC_roommoney, m_prebookroommoney);
DDX_Text(pDX, IDC_STATICshowuser, m_showuser);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRoomprebookdlg, CDialog)
//{{AFX_MSG_MAP(CRoomprebookdlg)
ON_CBN_CLOSEUP(IDC_COMBOroomkind, OnCloseupCOMBOroomkind)
ON_BN_CLICKED(IDcancelprebookroom, Oncancelprebookroom)
ON_BN_CLICKED(IDC_Btnroomyuding, OnBtnroomyuding)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRoomprebookdlg message handlers
void CRoomprebookdlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
//////////////////////////////////////////////////////////////////////////
/*
* 检查身份证的号码是否为15位或者为18位
*/
CString strCertifyCode;//证件号码
//获得证件号码
int nCertifyCodeLength=m_prebookidnumber.GetLength();//获得证件的长度
if(nCertifyCodeLength!=15&&nCertifyCodeLength!=18)
{
if(m_prebookidkind=="身份证")
{//若选择的是身份证
MessageBox("你的身份证的号码的位数不正确!\n应该为15位或者18位!",
"身份证错误",MB_OK);
return ;
}
}
//////////////////////////////////////////////////////////////////////////
m_pRecordset.CreateInstance(__uuidof(Recordset));
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
//
try
{//打开数据表
m_pRecordset->Open("SELECT * FROM kfyd", // 查询表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)//捕获异常情况
{
AfxMessageBox(e->ErrorMessage());
}
//////////////////////////////////////////////////////////////
try
{
// 写入各字段值
m_pRecordset->AddNew();
// 向数据表姓名字段写入数据
m_pRecordset->PutCollect("姓名",_variant_t(m_prebookname));
// 向数据表身份证号字段写入数据
m_pRecordset->PutCollect("身份证号", _variant_t(m_prebookidnumber));
// 向数据表联系电话字段写入数据
m_pRecordset->PutCollect("联系电话", _variant_t(m_prebooktelnumber));
// 向数据表详细地址字段写入数据
m_pRecordset->PutCollect("详细地址", _variant_t(m_prebookaddr));
// 向数据表工作单位字段写入数据
m_pRecordset->PutCollect("工作单位", _variant_t(m_prebookworkcompany));
// 向数据表客房类型字段写入数据
m_pRecordset->PutCollect("客房类型", _variant_t(m_prebookroomkind));
// 向数据表房间价格字段写入数据
m_pRecordset->PutCollect("房间价格", _variant_t(m_prebookroommoney));
CString checkindate;
int nYear,nDay,nMonth;
int nhour,nmin,nsecond;
CString sYear,sDay,sMonth;
nYear=m_prebookcheckindate.GetYear();//提取年份
nDay=m_prebookcheckindate.GetDay();//提取日
nMonth=m_prebookcheckindate.GetMonth();//提取月份
sYear.Format("%d",nYear);//转换为字符串
sDay.Format("%d",nDay);//转换为字符串
sMonth.Format("%d",nMonth);//转换为字符串
//格式化时间
checkindate.Format("%s-%s-%s",sYear,sMonth,sDay);
// 向数据表预住日期字段写入数据
m_pRecordset->PutCollect("预住日期",_variant_t(checkindate));
// 向数据表预住天数字段写入数据
m_pRecordset->PutCollect("预住天数", _variant_t(m_prebookdays));
// 向数据表预付金额字段写入数据
m_pRecordset->PutCollect("预付金额", _variant_t(m_prebookhandinmoney));
CString nowdate,nowtime;
CTime tTime;
tTime=tTime.GetCurrentTime();
nYear=tTime.GetYear();//提取年份
nDay=tTime.GetDay();//提取日
nMonth=tTime.GetMonth();//提取月份
sYear.Format("%d",nYear);//转换为字符串
sDay.Format("%d",nDay);//转换为字符串
sMonth.Format("%d",nMonth);//转换为字符串
//格式化时间
nowdate.Format("%s-%s-%s",sYear,sMonth,sDay);
CString shour,smin,ssecond;
nhour=tTime.GetHour();//提取小时
nmin=tTime.GetMinute();//提取分钟
nsecond=tTime.GetSecond();//提取秒
shour.Format("%d",nhour);//转换为字符串
smin.Format("%d",nmin);//转换为字符串
ssecond.Format("%d",nsecond);//转换为字符串
//格式化时间
nowtime.Format("%s:%s:%s",shour,smin,ssecond);
m_pRecordset->PutCollect("日期", _variant_t(nowdate));
m_pRecordset->PutCollect("时间", _variant_t(nowtime));
// 向数据表证件名称字段写入数据
m_pRecordset->PutCollect("证件名称", _variant_t(m_prebookidkind));
//更新数据表
m_pRecordset->Update();
MessageBox("预定成功!","客房管理系统");
}
catch(_com_error *e)//抛出异常情况,并显示
{
AfxMessageBox(e->ErrorMessage());
}
//关闭记录集
m_pRecordset->Close();
m_pRecordset = NULL;
// CDialog::OnOK();
}
void CRoomprebookdlg::OnCloseupCOMBOroomkind()
{
// TODO: Add your control notification handler code here
CString roomkind;//
//获得输入值
UpdateData(true);
roomkind=m_prebookroomkind;
//如果客房类型使标房
if(m_prebookroomkind=="标房")
{
m_prebookroommoney="138";
}
//如果客房类型使普房
if(m_prebookroomkind=="普房")
{
m_prebookroommoney="98";
}
//如果客房类型使双人间
if(m_prebookroomkind=="双人间")
{
m_prebookroommoney="168";
}
//如果客房类型使套房
if(m_prebookroomkind=="套房")
{
m_prebookroommoney="268";
}
//更新显示
UpdateData(false);
}
void CRoomprebookdlg::Oncancelprebookroom()
{
// TODO: Add your control notification handler code here
//输入变量初始化
m_prebookidkind = _T("");
m_prebookroomkind = _T("");
m_prebookcheckindate = 0;
m_prebookaddr = _T("");
m_prebookdays = _T("");
m_prebookhandinmoney = _T("");
m_prebookidnumber = _T("");
m_prebookname = _T("");
m_prebooktelnumber = _T("");
m_prebookworkcompany = _T("");
m_prebookroommoney = _T("");
CTime tTime;
tTime=tTime.GetCurrentTime();
//设置登记的默认时间
m_prebookcheckindate=tTime;
//更新显示
UpdateData(false);
}
BOOL CRoomprebookdlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_showuser=loguserid;
enable(0);//
//更新输入框状态
CTime tTime;
tTime=tTime.GetCurrentTime();
//设置登记的默认时间
m_prebookcheckindate=tTime;
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CRoomprebookdlg::OnBtnroomyuding()
{
// TODO: Add your control notification handler code here
enable(1);//
//更新输入框状态
}
void CRoomprebookdlg::enable(bool bEnabled)
{
// m_ComYSFS.EnableWindow(bEnabled);
//更改输入框等控件状态,方便使用,防止错误操作
GetDlgItem(IDC_COMBOprebookidkind)->EnableWindow(bEnabled);
GetDlgItem(IDC_COMBOroomkind)->EnableWindow(bEnabled);
GetDlgItem(IDC_DATETIMEPICKERprecheckindate)->EnableWindow(bEnabled);
GetDlgItem(IDC_prebookaddr)->EnableWindow(bEnabled);
GetDlgItem(IDC_prebookdays)->EnableWindow(bEnabled);
GetDlgItem(IDC_prebookhandinmoney)->EnableWindow(bEnabled);
GetDlgItem(IDC_prebookidnumber)->EnableWindow(bEnabled);
GetDlgItem(IDC_prebookname)->EnableWindow(bEnabled);
GetDlgItem(IDC_prebooktelnumber)->EnableWindow(bEnabled);
GetDlgItem(IDC_prebookworkcompany)->EnableWindow(bEnabled);
GetDlgItem(IDC_roommoney)->EnableWindow(bEnabled);
GetDlgItem(IDOK)->EnableWindow(bEnabled);
GetDlgItem(IDcancelprebookroom)->EnableWindow(bEnabled);
}
BOOL CRoomprebookdlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_RETURN)
{
pMsg->wParam=VK_TAB;//重载回车键盘消息为table键盘消息,ok!2006.4.18
}
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -