?? dlgregist.cpp
字號:
// DlgRegist.cpp : implementation file
//
#include "stdafx.h"
#include "Student.h"
#include "DlgRegist.h"
#include "DlgLoggin.h"
#include "StudentDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgRegist dialog
CDlgRegist::CDlgRegist(CWnd* pParent /*=NULL*/)
: CDialog(CDlgRegist::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgRegist)
m_rname = _T("");
m_ruserid = _T("");
m_rpsw = _T("");
//}}AFX_DATA_INIT
}
void CDlgRegist::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgRegist)
DDX_Text(pDX, IDC_EDIT_RNAME, m_rname);
DDV_MaxChars(pDX, m_rname, 10);
DDX_Text(pDX, IDC_EDIT_RUSERID, m_ruserid);
DDV_MaxChars(pDX, m_ruserid, 14);
DDX_Text(pDX, IDC_EDIT_RPSW, m_rpsw);
DDV_MaxChars(pDX, m_rpsw, 14);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgRegist, CDialog)
//{{AFX_MSG_MAP(CDlgRegist)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgRegist message handlers
void CDlgRegist::OnOK()
{
// TODO: Add extra validation here
CString strSQL1,strSQL2;
CString ruserid,rpsw,rname;
CString str;
CDlgLoggin DlgLog;
UpdateData(true);
if(m_rpsw.GetLength()==0||m_ruserid.GetLength()==0||m_rname.GetLength()==0)
{
AfxMessageBox("請輸入用戶名、密碼和姓名");
return;
}
for( int n = 0 ; n< m_ruserid.GetLength(); n++)
{
if(!((m_ruserid[n]>='a' && m_ruserid[n]<='z')||(m_ruserid[n]>='A' && m_ruserid[n]<='Z')|| (m_ruserid[n]>='0' && m_ruserid[n]<='9')))
{
AfxMessageBox("用戶名只能是字母或數字!");
return;
}
}
for( int i = 0 ; i< m_rpsw.GetLength(); i++)
{
if(!((m_rpsw[i]>='a' && m_rpsw[i]<='z')||(m_rpsw[i]>='A' && m_rpsw[i]<='Z')|| (m_rpsw[i]>='0' && m_rpsw[i]<='9')))
{
AfxMessageBox("密碼只能是字母或數字!");
return;
}
}
ruserid=m_ruserid;
rpsw=m_rpsw;
rname=m_rname;
_variant_t nTemp;
UpdateData(false);
strSQL1="INSERT INTO 用戶信息(用戶名ID,密碼ID,姓名) VALUES('"+ruserid+"','"+rpsw+"','"+rname+"')";
strSQL2="SELECT 用戶信息.用戶名ID, 用戶信息.密碼ID FROM 用戶信息";
try
{
m_pRecordset_Std->Open(_bstr_t(strSQL2), 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();
while(!m_pRecordset_Std->adoEOF)
{
nTemp=m_pRecordset_Std->GetCollect("用戶名ID");
str=(LPCSTR)_bstr_t(nTemp);
if (str==m_ruserid)
{
ExistID=true;
break;
}
else
m_pRecordset_Std->MoveNext();
}
if(ExistID==true)
{
AfxMessageBox("用戶名已存在,請重新輸入!");
return;
}
else
{
try
{
m_pConnection_Std->Execute((_bstr_t)strSQL1,&nTemp,ADODB::adCmdText);
}
catch (_com_error e)
{
CString strError;
strError.Format("警告:打開數據表時發生異常。錯誤信息:%s",e.ErrorMessage());
}
AfxMessageBox("注冊成功!");
}
CDialog::OnOK();
DlgLog.DoModal();
}
BOOL CDlgRegist::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 CDlgRegist::OnCancel()
{
// TODO: Add extra cleanup here
CDlgLoggin DlgLog;
m_database.Close();
CDialog::OnOK();
DlgLog.DoModal();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -