?? roomtypedlg.cpp
字號:
// RoomTypeDLG.cpp : implementation file
//
#include "stdafx.h"
#include "hotel_mis.h"
#include "RoomTypeDLG.h"
#include "Hotel_MISView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRoomTypeDLG dialog
CRoomTypeDLG::CRoomTypeDLG(CWnd* pParent /*=NULL*/)
: CDialog(CRoomTypeDLG::IDD, pParent)
{
//{{AFX_DATA_INIT(CRoomTypeDLG)
m_sArea = _T("");
m_sBedNo = _T("");
m_sTypeID = _T("");
m_sTypeName = _T("");
m_sPrice = _T("");
//}}AFX_DATA_INIT
}
void CRoomTypeDLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRoomTypeDLG)
DDX_Text(pDX, IDC_ROOMTYPE_AREA, m_sArea);
DDX_Text(pDX, IDC_ROOMTYPE_BEDNO, m_sBedNo);
DDX_Text(pDX, IDC_ROOMTYPE_ID, m_sTypeID);
DDX_Text(pDX, IDC_ROOMTYPE_NAME, m_sTypeName);
DDX_Text(pDX, IDC_ROOMTYPE_PRICE, m_sPrice);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRoomTypeDLG, CDialog)
//{{AFX_MSG_MAP(CRoomTypeDLG)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRoomTypeDLG message handlers
BOOL CRoomTypeDLG::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// Init Edit Text limit
((CEdit*)GetDlgItem(IDC_ROOMTYPE_ID))->SetLimitText(50);
((CEdit*)GetDlgItem(IDC_ROOMTYPE_NAME))->SetLimitText(50);
((CEdit*)GetDlgItem(IDC_ROOMTYPE_AREA))->SetLimitText(5);
((CEdit*)GetDlgItem(IDC_ROOMTYPE_BEDNO))->SetLimitText(2);
((CEdit*)GetDlgItem(IDC_ROOMTYPE_PRICE))->SetLimitText(9);
if (m_bAppend)
{
// Update Dialog Caption
SetWindowText(_T("添加客房標準"));
// Init Combobox
((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISAIRCON))->SetCurSel(1);
((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTEL))->SetCurSel(1);
((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTV))->SetCurSel(1);
((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTOILET))->SetCurSel(1);
}
else
{
// Update Dialog Caption
SetWindowText(_T("修改客房標準"));
// Disable ID and Name Edit
GetDlgItem(IDC_ROOMTYPE_ID)->EnableWindow(false);
GetDlgItem(IDC_ROOMTYPE_NAME)->EnableWindow(false);
// Init Combobox
if (m_bAirCon) ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISAIRCON))->SetCurSel(1);
else ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISAIRCON))->SetCurSel(0);
if (m_bTel) ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTEL))->SetCurSel(1);
else ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTEL))->SetCurSel(0);
if (m_bTV) ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTV))->SetCurSel(1);
else ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTV))->SetCurSel(0);
if (m_bToilet) ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTOILET))->SetCurSel(1);
else ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTOILET))->SetCurSel(0);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CRoomTypeDLG::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
m_sTypeID.TrimRight(" ");
m_sTypeName.TrimRight(" ");
m_sArea.TrimRight(" ");
m_sBedNo.TrimRight(" ");
m_sPrice.TrimRight(" ");
// Make sure all needed info is available
CString sWarning="";
if ( ""==m_sTypeID ) sWarning=_T("標準編號");
else if ( ""==m_sTypeName ) sWarning=_T("標準名稱");
else if ( ""==m_sArea ) sWarning=_T("客房面積");
else if ( ""==m_sBedNo ) sWarning=_T("床位數量");
else if ( ""==m_sPrice ) sWarning=_T("住房單價");
if ( ""!=sWarning )
{
sWarning += _T("不能為空");
AfxMessageBox(sWarning, MB_ICONEXCLAMATION);
return;
}
// Make sure the Number info is valid
float fArea = atof(m_sArea);
if ( 0==fArea )
{
AfxMessageBox(_T("客房面積:請輸入非零數字"), MB_ICONEXCLAMATION);
return;
}
m_sArea.Format("%.2f", fArea);
float fPrice = atof(m_sPrice);
if ( 0==fPrice )
{
AfxMessageBox(_T("住房單價:請輸入非零數字"), MB_ICONEXCLAMATION);
return;
}
m_sPrice.Format("%.2f", fPrice);
if ( atof(m_sPrice)>99999999.99 )
{
AfxMessageBox(_T("住房單價溢出,請不要超過99999999.99"), MB_ICONEXCLAMATION);
return;
}
_variant_t strQuery;
if (m_bAppend)
{
// Judge Room Type is Unique
strQuery = "select * from roomtype where typeid='"+m_sTypeID+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
int iCount = theApp.m_pADOSet->GetRecordCount();
if ( 0!=iCount )
{
AfxMessageBox(_T("已經存在此標準編號的記錄!"), MB_ICONEXCLAMATION);
return;
}
// Judge Room Name is Unique
strQuery = "select * from roomtype where typeid!='"+m_sTypeID+"' and typename='"+m_sTypeName+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
iCount = theApp.m_pADOSet->GetRecordCount();
if ( 0!=iCount )
{
AfxMessageBox(_T("已經存相同客房標準的記錄!"), MB_ICONEXCLAMATION);
return;
}
}
// Get other info
CString sAir("0"), sTel("0"), sTV("0"), sToilet("0");
if ( ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISAIRCON))->GetCurSel() ) sAir="1";
if ( ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTEL))->GetCurSel() ) sTel="1";
if ( ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTV))->GetCurSel() ) sTV="1";
if ( ((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTOILET))->GetCurSel() ) sToilet="1";
if (m_bAppend)// Append Record
{
strQuery = "insert roomtype (typeid, typename, area, bednum, price, haircondition, htelephone, htelevision, htoilet) \
values ('"+m_sTypeID+"', '"+m_sTypeName+"', "+m_sArea+", "+m_sBedNo+", "+m_sPrice+", "+sAir+", "+sTel+","+sTV+", "+sToilet+")";
if ( theApp.ADOExecute(theApp.m_pADOSet, strQuery) )
{
AfxMessageBox(_T("添加記錄成功!"), MB_ICONINFORMATION);
// Clear all input
m_sTypeID=m_sTypeName=m_sArea=m_sBedNo=m_sPrice="";
((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISAIRCON))->SetCurSel(1);
((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTEL))->SetCurSel(1);
((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTV))->SetCurSel(1);
((CComboBox*)GetDlgItem(IDC_ROOMTYPE_ISTOILET))->SetCurSel(1);
UpdateData(false);
}
else AfxMessageBox(_T("添加記錄失敗!"), MB_ICONEXCLAMATION);
}
else// Alter Record
{
strQuery = "Update roomtype set area="+m_sArea+", bednum="+m_sBedNo+", price="+m_sPrice+", haircondition="+sAir+", \
htelephone="+sTel+", htelevision="+sTV+", htoilet="+sToilet+" where typeid='"+m_sTypeID+"'";
if ( theApp.ADOExecute(theApp.m_pADOSet, strQuery) ) AfxMessageBox(_T("修改記錄成功!"), MB_ICONINFORMATION);
else AfxMessageBox(_T("修改記錄失敗!"), MB_ICONEXCLAMATION);
}
// Refresh RoomType List
CHotel_MISView* p = (CHotel_MISView*)(((CMainFrame*)AfxGetMainWnd())->GetActiveView());
p->RefreshRoomType();
if (!m_bAppend) CDialog::OnOK();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -