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

📄 logindlg.cpp

📁 图书管理系统,数据结构思想,用 C++编写,经测试,可用
💻 CPP
字号:
// LoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "library.h"
#include "LoginDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog

CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLoginDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLoginDlg)
	m_Password = _T("");
	m_ManagerID = _T("");
	//}}AFX_DATA_INIT
}


void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoginDlg)
	DDX_Text(pDX, IDC_PASSWORD, m_Password);
	DDX_Text(pDX, IDC_MANAGERID, m_ManagerID);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
	//{{AFX_MSG_MAP(CLoginDlg)
	ON_BN_CLICKED(ID_LOGIN, OnLogin)
	ON_BN_CLICKED(ID_EXIT, OnExit)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

void CLoginDlg::OnLogin() 
{
	// TODO: Add your control notification handler code here
	//完成管理员的登陆
	CWnd *m_pMainWnd;

	if(!CheckValid())
		return;

	SaveLoginTime();
	CDialog::OnOK();
	m_pMainWnd=AfxGetMainWnd();
	if(m_pMainWnd!=NULL)
	{
		m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
		m_pMainWnd->UpdateWindow();
	}				

}

void CLoginDlg::OnExit() 
{
	// TODO: Add your control notification handler code here
	//退出主程序
	CDialog::OnCancel();
	//如果主窗口存在,销毁主窗口
	CFrameWnd *mainFrame;
	mainFrame=GetParentFrame();
	if(mainFrame!=NULL)
		mainFrame->DestroyWindow();

}

void CLoginDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	//初始化光标设置
	GetDlgItem(IDC_MANAGERID)->SetFocus();

	// Do not call CDialog::OnPaint() for painting messages
}

void CLoginDlg::SaveLoginTime()
{
	//纪录管理员的登陆时间
	CTime m_LoginTime;

	m_LoginTime=CTime::GetCurrentTime();
	m_ManagerSet.Edit();
	m_ManagerSet.m_logintime=m_LoginTime;
	m_ManagerSet.Update();
	m_ManagerName=m_ManagerSet.m_managername;
	m_ManagerSet.Close();

}

BOOL CLoginDlg::CheckValid()
{
	//检查用户输入的合法性
	UpdateData();

	if(m_ManagerID.IsEmpty() || m_Password.IsEmpty())
	{
		AfxMessageBox("请输入用户名和密码!");	
		GetDlgItem(IDC_MANAGERID)->SetFocus();
		return false;
	}

	m_ManagerSet.Open();
	m_ManagerSet.m_strFilter="managerid='"+m_ManagerID+"'";
	m_ManagerSet.Requery();

	if(m_ManagerSet.GetRecordCount()==0)
	{
		AfxMessageBox("您输入的用户名有误,请重新输入!");	
		GetDlgItem(IDC_MANAGERID)->SetFocus();
		m_ManagerSet.Close();
		return false;
	}

	if(m_ManagerSet.m_password!=m_Password)
	{
		AfxMessageBox("您输入的密码有误,请重新输入!");	
		GetDlgItem(IDC_PASSWORD)->SetFocus();
		m_ManagerSet.Close();
		return false;
	}

	return true;
}

⌨️ 快捷键说明

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