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

📄 logindlg.cpp

📁 VC+Access图书管理系统
💻 CPP
字号:
// LoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "libmis.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_strName = _T("");
	m_strPsw = _T("");
	//}}AFX_DATA_INIT
}


void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoginDlg)
	DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
	DDX_Text(pDX, IDC_EDIT_PSW, m_strPsw);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
	//{{AFX_MSG_MAP(CLoginDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

BOOL CLoginDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	// TODO: Add extra initialization here
	m_bLogin=FALSE;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLoginDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData ();
	m_strName.TrimRight ();
	m_strPsw.TrimRight ();	
	_ConnectionPtr  pConnection;
	_RecordsetPtr  pRecordset,pRecordset2;	
	CString strSql;
	strSql="SELECT * FROM admin WHERE name='"+m_strName+"' AND password='"+m_strPsw+"'";
	try
	{
		if (!pConnection.CreateInstance(__uuidof(Connection)))
			pConnection->Open("Provider=Microsoft.JET.OLEDB.4.0;Data Source=lib.mdb","","",adModeUnknown);
	}

	catch (_com_error e)
	{
		CString errormessage;
		errormessage.Format ("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage ());
		AfxMessageBox (errormessage);
		return ;
	}
	try
	{
		pRecordset.CreateInstance(__uuidof(Recordset));
		pRecordset2.CreateInstance(__uuidof(Recordset));
	
		pRecordset->Open (_variant_t(strSql),_variant_t((IDispatch*)pConnection,true),
			adOpenStatic,adLockOptimistic,adCmdText);
		if (pRecordset->adoEOF)
		{
			MessageBox ("用户名或密码错误!","",MB_ICONERROR);
			return;
		}
		pRecordset->Close ();
		m_bLogin=TRUE;	
	}
	catch (_com_error e)
	{
		CString errormessage;
		errormessage.Format ("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage ());
		AfxMessageBox (errormessage);
		return ;
	}	
	////以下为检查读者有效性
	try
	{
		strSql="SELECT * FROM borrow";
		pRecordset->Open (_variant_t(strSql),_variant_t((IDispatch*)pConnection,true),
			adOpenStatic,adLockOptimistic,adCmdText);
		COleDateTime ot,curT;
		COleDateTimeSpan ts;
		_variant_t vId;
		while (!pRecordset->adoEOF)
		{
			ot=pRecordset->GetCollect ("date");
			curT=curT.GetCurrentTime ();
			ts=curT-ot;
			if (ts.GetDays ()>30)	//超期图书,将读者置为无效
			{
				vId=pRecordset->GetCollect ("readerid");
				vId.ChangeType(VT_BSTR);
				strSql="SELECT * FROM reader WHERE id='"+(CString)vId.bstrVal+"'";
				pRecordset2->Open (_variant_t(strSql),_variant_t((IDispatch*)pConnection,true),
					adOpenStatic,adLockOptimistic,adCmdText);
				pRecordset2->PutCollect ("valid","无效");
				pRecordset2->Update ();
				pRecordset2->Close ();
			}
			pRecordset->MoveNext ();
		}
		pRecordset->Close ();
		m_bLogin=TRUE;	
	}
	catch (_com_error e)
	{
		CString errormessage;
		errormessage.Format ("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage ());
		AfxMessageBox (errormessage);
		return ;
	}	
	pConnection->Close();
	CDialog::OnOK();
}

⌨️ 快捷键说明

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