基本信息
源码名称:c++ 客房管理系统完整源码(含数据库)
源码大小:9.78M
文件格式:.rar
开发语言:C/C++
更新时间:2019-05-07
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

系统将动态实时的住宿登记、客房调整、销售报表、追加押金等有机地联系在一起,对宾馆客房进行全方位的管理











// 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);
}