?? dlgloggin.cpp
字號:
// DlgLoggin.cpp : implementation file
//
#include "stdafx.h"
#include "Student.h"
#include "DlgLoggin.h"
#include "DlgRegist.h"
#include "StudentDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgLoggin dialog
CDlgLoggin::CDlgLoggin(CWnd* pParent /*=NULL*/)
: CDialog(CDlgLoggin::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgLoggin)
m_psw = _T("");
m_userid = _T("");
//}}AFX_DATA_INIT
}
void CDlgLoggin::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgLoggin)
DDX_Text(pDX, IDC_EDIT_PSW, m_psw);
DDV_MaxChars(pDX, m_psw, 14);
DDX_Text(pDX, IDC_EDIT_USERID, m_userid);
DDV_MaxChars(pDX, m_userid, 14);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgLoggin, CDialog)
//{{AFX_MSG_MAP(CDlgLoggin)
ON_BN_CLICKED(IDC_BUTTON_REGIST, OnButtonRegist)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgLoggin message handlers
void CDlgLoggin::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
if(m_psw.GetLength()==0||m_userid.GetLength()==0)
{
AfxMessageBox("請輸入用戶名或密碼");
return;
}
for( int i = 0 ; i< m_psw.GetLength(); i++)
{
if(!((m_psw[i]>='a' && m_psw[i]<='z')||(m_psw[i]>='A' && m_psw[i]<='Z')|| (m_psw[i]>='0' && m_psw[i]<='9')))
{
// GetDlgItem(IDC_EDIT_PSW)->SetWindowText("");
// GetDlgItem(IDC_EDIT_USERID)->SetWindowText("");
AfxMessageBox("不接受特殊字符!");
return;
}
}
for( int n = 0 ; n< m_userid.GetLength(); n++)
{
if(!((m_userid[n]>='a' && m_userid[n]<='z')||(m_userid[n]>='A' && m_userid[n]<='Z')|| (m_userid[n]>='0' && m_userid[n]<='9')))
{
//GetDlgItem(IDC_EDIT_PSW)->SetWindowText("");
//GetDlgItem(IDC_EDIT_USERID)->SetWindowText("");
AfxMessageBox("不接受特殊字符!");
return;
}
}
CString strSQL; // 聲明MFC之字符串類的對象,存放用于數據庫查詢的SQL語句
CString str;
// m_pRecordset_Std.CreateInstance(__uuidof(ADODB::Recordset));//創建記錄集對象
strSQL="SELECT 用戶信息.用戶名ID, 用戶信息.密碼ID,姓名 FROM 用戶信息";
try
{
m_pRecordset_Std->Open(_bstr_t(strSQL), m_pConnection_Std.GetInterfacePtr(),ADODB::adOpenDynamic,ADODB::adLockOptimistic,ADODB::adCmdText);
}
catch (_com_error e)
{
CString strError;
strError.Format("警告:打開數據表時發生異常。錯誤信息:%s",e.ErrorMessage());
}
m_pRecordset_Std->MoveFirst();
i=0;
while(!m_pRecordset_Std->adoEOF)
{
m_pRecordset_Std->MoveNext();
i++;
}
n = i;
if (n > 0)
{
m_pRecordset_Std->MoveFirst();
for(i=0;i<n;i++)
{
_variant_t nTemp;
nTemp=m_pRecordset_Std->GetCollect("用戶名ID");
str=(LPCSTR)_bstr_t(nTemp);
userid=str;
nTemp=m_pRecordset_Std->GetCollect("密碼ID");
str=(LPCSTR)_bstr_t(nTemp);
psw=str;
nTemp=m_pRecordset_Std->GetCollect("姓名");
str=(LPCSTR)_bstr_t(nTemp);
username=str;
if (m_userid==userid && m_psw==psw)
{
SuccessLog=1;
m_pRecordset_Std->Close();
break;
}
else
{
m_pRecordset_Std->MoveNext();
}
}
}
UpdateData(false);
if (SuccessLog!=1)
{
m_pRecordset_Std->Close();
AfxMessageBox("無此用戶或密碼錯誤!");
return;
}
CDialog::OnOK();
}
void CDlgLoggin::OnCancel()
{
// TODO: Add extra cleanup here
m_pConnection_Std->Close();
exit(1);
}
BOOL CDlgLoggin::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// CString strSQL;
HRESULT hr;
m_pRecordset_Std.CreateInstance(__uuidof(ADODB::Recordset));
try
{
hr = m_pConnection_Std.CreateInstance("ADODB.Connection");//創建Connection對象
if(SUCCEEDED(hr))
{
hr = m_pConnection_Std->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Student.mdb","","",ADODB::adModeUnknown);///連接數據庫
}
}
catch(_com_error e)///捕捉異常
{
CString errormessage;
errormessage.Format("連接數據庫失敗!\r\n錯誤信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///顯示錯誤信息
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgLoggin::OnButtonRegist()
{
// TODO: Add your control notification handler code here
CDlgRegist DlgReg;
CDialog::OnOK();
DlgReg.DoModal();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -