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

📄 login.cpp

📁 简单的图书图书管理系统 (具有增添 删除 查找 功能) 适合初学者
💻 CPP
字号:
// login.cpp : implementation file
//

#include "stdafx.h"
#include "MYpro.h"
#include "login.h"
#include "Access1.h"

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

/////////////////////////////////////////////////////////////////////////////
// login dialog


login::login(CWnd* pParent /*=NULL*/)
	: CDialog(login::IDD, pParent)
{
	//{{AFX_DATA_INIT(login)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void login::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(login)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// login message handlers

void login::OnOK() 
{
	// TODO: Add extra validation here
    CString strText;
	CString cmd;
	CString username;
	CString password;

	GetDlgItem(IDC_USERNAME1)->GetWindowText(username);//获取输入框中的用户名
	GetDlgItem(IDC_PASSWORD1)->GetWindowText(password);//获取输入框中的密码

	if(username==""||password=="")   //用户密码任一为空返回
	{
		AfxMessageBox("用户名和密码不能为空");
		return;
	}

	cmd="SELECT * FROM admin  WHERE username='"+username+"'";//SQL语句
	
	Access* ac=new Access();	//创建Access对象
	CoInitialize(NULL);			//初始化库环境
	_RecordsetPtr _pRecordset;//数据集指针
	
	try{
		_pRecordset=ac->connect(cmd);//调用connect()取得数据集指针
		_variant_t var= _pRecordset->GetCollect(((_variant_t)(long)1)); //取得数据集中第2项
		strText=(LPCTSTR)(_bstr_t)var; 
		//ac->delcon();	//释放连接时的资源
		//_pRecordset->Release();//释放数据集资源
		CoUninitialize();//释放占用的COM资源
	}
	catch(_com_error e){
		AfxMessageBox("用户不存在");
		GetDlgItem(IDC_USERNAME1)->SetWindowText("");
		GetDlgItem(IDC_PASSWORD1)->SetWindowText("");
		//ac->delcon();
		return;
	}
	if(password==strText)	{
			valid=1;	//密码正确,设置valid=1
		}
	else{
		AfxMessageBox("密码错误");
		GetDlgItem(IDC_PASSWORD1)->SetWindowText("");
		return;
	}
	CDialog::OnOK();
}

void login::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}



int login::isvalid()
return valid;
}

⌨️ 快捷键说明

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