实例介绍
系统将动态实时的住宿登记、客房调整、销售报表、追加押金等有机地联系在一起,对宾馆客房进行全方位的管理
【实例截图】
【核心代码】
// LoginDlg.cpp : implementation file // #include "stdafx.h" #include "Myhotel.h" #include "LoginDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CString loguserid; extern CMyhotelApp theApp; ///////////////////////////////////////////////////////////////////////////// // CLoginDlg dialog CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/) : CDialog(CLoginDlg::IDD, pParent) { //{{AFX_DATA_INIT(CLoginDlg) m_username = _T(""); m_password = _T(""); //}}AFX_DATA_INIT } void CLoginDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CLoginDlg) DDX_Control(pDX, IDC_COMBO_username, m_usernamectr); DDX_CBString(pDX, IDC_COMBO_username, m_username); DDX_Text(pDX, IDC_password, m_password); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CLoginDlg, CDialog) //{{AFX_MSG_MAP(CLoginDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLoginDlg message handlers void CLoginDlg::OnOK() { // TODO: Add extra validation here CString sqlStr; UpdateData(true); if(m_username.IsEmpty())//判断用户名是否为空 { MessageBox("请输入用户名!","客房管理系统"); return; } //construct the sql string //创建查询语句 sqlStr="SELECT * FROM usertalbe WHERE user_name='"; sqlStr =m_username; sqlStr ="'"; sqlStr ="AND user_pwd='"; sqlStr =m_password; sqlStr ="'"; // MessageBox(sqlStr); //打开数据库 if(!myuserset.Open(AFX_DB_USE_DEFAULT_TYPE,sqlStr)) { MessageBox("user表打开失败!","客房管理系统"); return; } loguserid=m_username;//保存操作员ID,其他窗口要用 if(!myuserset.IsEOF())//关闭数据库连接 { myuserset.Close(); CDialog::OnOK(); } else { //给出错误提示 MessageBox("登陆失败!","客房管理系统"); m_username=_T(""); m_password=_T(""); UpdateData(false);//更新显示 myuserset.Close();//关闭数据库连接 return; } } BOOL CLoginDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here // 使用ADO创建数据库记录集 m_pRecordset.CreateInstance(__uuidof(Recordset)); _variant_t var; CString struser; // 在ADO操作中建议语句中要常用try...catch()来捕获错误信息, // try {//打开数据库 m_pRecordset->Open("SELECT * FROM usertalbe", // 查询 表中所有字段 theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针 adOpenDynamic, adLockOptimistic, adCmdText); } catch(_com_error *e)//捕获打开数据库可能发生的异常情况并实时显示提示 { AfxMessageBox(e->ErrorMessage()); } try { if(!m_pRecordset->BOF)//判断指针是否在数据集最后 m_pRecordset->MoveFirst(); // else // {//提示错误,无数据 // AfxMessageBox("表内数据为空"); // return false; // } // read data from the database table while(!m_pRecordset->adoEOF) { var = m_pRecordset->GetCollect("user_name"); if(var.vt != VT_NULL) struser = (LPCSTR)_bstr_t(var); m_usernamectr.AddString(struser);//从数据库获得 //的内容给变量赋值 m_pRecordset->MoveNext();//移动数据指针 } // } catch(_com_error *e)//捕获异常 { AfxMessageBox(e->ErrorMessage()); } // 关闭记录集 m_pRecordset->Close(); m_pRecordset = NULL; //更新显示 // UpdateData(false); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } BOOL CLoginDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_RETURN) { DWORD def_id=GetDefID(); if(def_id!=0) { //MSG消息的结构中的hwnd存储的是接收该消息的窗口句柄 CWnd *wnd=FromHandle(pMsg->hwnd); char class_name[16]; if(GetClassName(wnd->GetSafeHwnd(),class_name,sizeof(class_name))!=0) { DWORD style=::GetWindowLong(pMsg->hwnd,GWL_STYLE); if((style&ES_MULTILINE)==0) { if(strnicmp(class_name,"edit",5)==0) { //将焦点设置到默认按钮上面 GetDlgItem(LOWORD(def_id))->SetFocus(); pMsg->wParam=VK_TAB;//重载回车键盘消息为table键盘消息,ok!2006.4.18 } } } } } return CDialog::PreTranslateMessage(pMsg); }
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论