⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logindlg.cpp

📁 数据库开发的工资管理系统
💻 CPP
字号:
// LoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SalaryManagement.h"
#include "LoginDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
BOOL CLoginDlg::OnInitDialog(){  //重载初始化对话框的虚函数
	//初始化用户名的组合框
	CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_USERNAME_COMBO);  //建立一个指向 用户名的组合框 的CComboBox指针
	pCombo->ResetContent();  //重置下拉列表的所有内容
	pCombo->AddString("A部门");  //添加A部门选项
	pCombo->AddString("B部门");  //添加B部门选项
	pCombo->AddString("C部门");  //添加C部门选项,用这些用户登录只能访问相关部门
	pCombo->AddString("Root");  //Root是管理员可以访问所有部门
	//
	CDialog::OnInitDialog();  //CDialog基类的初始化对话框函数
	return TRUE;
}
CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/):CDialog(CLoginDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLoginDlg)
	m_password = _T("");
	//}}AFX_DATA_INIT
}


void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoginDlg)
	DDX_Control(pDX, IDC_USERNAME_COMBO, m_username);
	DDX_Text(pDX, IDC_PASSWORD_EDIT, m_password);
	DDV_MaxChars(pDX, m_password, 8);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
	//{{AFX_MSG_MAP(CLoginDlg)
	ON_BN_CLICKED(IDC_LOGIN_BUTTON, OnLoginButton)
	ON_BN_CLICKED(IDC_CANCEL_BUTTON, OnCancelButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers

void CLoginDlg::OnLoginButton(){  //确认键按下的消息处理函数
	bool success=false;  //用户名 密码输入正确
	_bstr_t psw;  //用来保存从Recordset里得来的密码
	CString username;  //用来保存下拉菜单里的用户名

	UpdateData(TRUE);  //将对话框中的数据读到数据成员中去
	m_username.GetWindowText(username);
	if(username==""){  //判断用户名是否为空
		MessageBox("请输入用户名");
		return;
	}
	else if(m_password==""){  //判断密码是否为空
		MessageBox("请输入密码");
		return;
	}
	//建立要查询的SQL语句
	CString SQL="select * from Login where 用户名='"+username+"' and 密码='"+m_password+"'";
	database.GetRecordset(SQL);  //得到查询的记录集
	try{
		if(database.m_pRecordset->adoEOF==0)
			success=true;  //如果输入正确就允许登陆
	}
	catch(_com_error e){  //捕捉登陆时的错误
		MessageBox(e.Description());  //给出错误信息
	}
	if(success){
		if(username=="A部门"){
			pDepartment=&A_Department;  //指针指向A部门的对象
			Initial="A";  //首字母为A
		}
		else if(username=="B部门"){
			pDepartment=&B_Department;  //指针指向B部门的对象
			Initial="B";  //首字母为B
		}
		else if(username=="C部门"){
			pDepartment=&C_Department;  //指针指向C部门的对象
			Initial="C";  //首字母为C
		}
		else
			pDepartment=&NULL_Department;  //Root登陆时现指向A部门的对象
		EndDialog(IDOK);
	}
	else
		MessageBox("您输入的用户名或密码不正确,请重新输入");
}

void CLoginDlg::OnCancelButton(){  //取消键被按下
	EndDialog(IDCANCEL);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -