📄 register.cpp
字号:
// Register.cpp : implementation file
//
#include "stdafx.h"
#include "TotalPay.h"
#include "Register.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRegister dialog
extern CTotalPayApp theApp;
CRegister::CRegister(CWnd* pParent /*=NULL*/)
: CDialog(CRegister::IDD, pParent)
{
//{{AFX_DATA_INIT(CRegister)
m_user = _T("");
m_code = _T("");
m_code1 = _T("");
//}}AFX_DATA_INIT
}
void CRegister::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRegister)
DDX_Control(pDX, IDOK, m_ok);
DDX_Control(pDX, IDCANCEL, m_cancel);
DDX_Text(pDX, IDC_USER, m_user);
DDV_MaxChars(pDX, m_user, 14);
DDX_Text(pDX, IDC_CODE, m_code);
DDV_MaxChars(pDX, m_code, 14);
DDX_Text(pDX, IDC_CODE1, m_code1);
DDV_MaxChars(pDX, m_code1, 14);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRegister, CDialog)
//{{AFX_MSG_MAP(CRegister)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRegister message handlers
void CRegister::OnOK()
{
// TODO: Add extra validation here
UpdateData();
//如果用户名和密码不为空则执行以下操作
if(!m_user.IsEmpty()&&!m_code.IsEmpty()&&!m_code1.IsEmpty())
{
//成生sql语句
CString sql="SELECT * FROM alluser where name='"+m_user+"'";
try
{
//查询数据库,看是否有此用户和密码
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
//theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
//如果没有此用户和密码,再查询是否有此用户
if(!m_pRecordset->adoEOF)
{
AfxMessageBox("用户名已存在,请更换!");
return;
}
m_pRecordset->Close();
if(m_code1!=m_code)
{
AfxMessageBox("您两次输入的密码不同,请重新输入!");
}
//用户名和密码存在,登录成功
else
{
sql="insert into alluser values('" + m_user +"','" + m_code+"')";
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
AfxMessageBox("欢迎你 "+m_user +" 你已经注册成功,请返回重新登录!");
}
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
//反之则
else
AfxMessageBox("请输入用户名,密码以及密码确认!");
CDialog::OnOK();
}
BOOL CRegister::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_cancel.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_cancel.SetBkColor(RGB(162,189,252));
m_cancel.SetRounded(TRUE);
m_ok.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_ok.SetBkColor(RGB(162,189,252));
m_ok.SetRounded(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -