login.cpp

来自「用ADO连接数据库,然后有相应图书馆管理的功能」· C++ 代码 · 共 89 行

CPP
89
字号
// Login.cpp : implementation file
//

#include "stdafx.h"
#include "图书管理系统.h"
#include "Login.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLogin dialog


CLogin::CLogin(CWnd* pParent /*=NULL*/)
	: CDialog(CLogin::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLogin)
	m_user = _T("");
	m_password = _T("");
	m_server = _T("");
	//}}AFX_DATA_INIT
}


void CLogin::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLogin)
	DDX_Text(pDX, IDC_EDIT1, m_user);
	DDX_Text(pDX, IDC_EDIT2, m_password);
	DDX_Text(pDX, IDC_EDIT3, m_server);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CLogin message handlers

void CLogin::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();
////////////连接数据库//////////////
	CString strConnection = "Provider=MSDAORA;Data Source=" + m_server + 
							";User ID=" + m_user + "; Password=" + m_password;
	HRESULT hr;
	try
	{
	hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
	if(SUCCEEDED(hr))
	{
	hr = m_pConnection->Open((_bstr_t)strConnection,"","",-1);///连接数据库
	state=1;
	}
	}
	catch(_com_error e)///捕捉异常
	{   state=0;
		CString errormessage;
		errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
		AfxMessageBox(errormessage);///显示错误信息
		
	} 
	





	CDialog::OnOK();
}

void CLogin::OnCancel() 
{
	// TODO: Add extra cleanup here
	state=0;
	CDialog::OnCancel();
	

}

⌨️ 快捷键说明

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