📄 regdlg.cpp
字号:
/*****************************************
注册用户模块
作者:颜永华
******************************************/
// RegDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "BankClient.h"
#include "RegDlg.h"
#include ".\regdlg.h"
#include "OPCODE.H"
#include "md5.h"
#include "sock.h"
// CRegDlg 对话框
extern int connFlag;
extern CSock sock;
extern CLIENT_STATUS clientStatus;
IMPLEMENT_DYNAMIC(CRegDlg, CDialog)
CRegDlg::CRegDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRegDlg::IDD, pParent)
{
}
CRegDlg::~CRegDlg()
{
}
void CRegDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT8, m_EditUserName);
DDX_Control(pDX, IDC_EDIT1, m_EditUserPwd);
DDX_Control(pDX, IDC_EDIT6, m_EditAccountId);
DDX_Control(pDX, IDC_EDIT7, m_EditAccountPwd);
DDX_Control(pDX, IDC_EDIT2, m_EditRealName);
DDX_Control(pDX, IDC_EDIT3, m_EditPhone);
DDX_Control(pDX, IDC_EDIT4, m_EditAddr);
DDX_Control(pDX, IDC_EDIT5, m_EditEmail);
//DDX_Control(pDX, IDC_LIST1, m_ListSign);
}
BEGIN_MESSAGE_MAP(CRegDlg, CDialog)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_EN_CHANGE(IDC_EDIT8, OnEnChangeEdit8)
END_MESSAGE_MAP()
// CRegDlg 消息处理程序
BOOL CRegDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_EditAccountId.SetLimitText(18);
m_EditAccountPwd.SetLimitText(16);
m_EditAddr.SetLimitText(20);
m_EditEmail.SetLimitText(20);
m_EditPhone.SetLimitText(15);
m_EditRealName.SetLimitText(10);
m_EditUserName.SetLimitText(10);
m_EditUserPwd.SetLimitText(16);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CRegDlg::OnBnClickedOk()
{//注册
int errNum=0;
CString showStr;
int strlen=m_EditUserName.GetWindowTextLength();
if(strlen==0)
showStr.Format("%d:用户名不能为空\n",++errNum);
strlen=m_EditAccountId.GetWindowTextLength();
if(strlen!=18)
showStr.Format("%s%d:账号只能为18位\n",showStr,++errNum);
strlen=m_EditRealName.GetWindowTextLength();
if(strlen==0)
showStr.Format("%s%d:姓名不能为空\n",showStr,++errNum);
strlen=this->m_EditPhone.GetWindowTextLength();
if(strlen==0)
showStr.Format("%s%d:电话不能为空\n",showStr,++errNum);
strlen=this->m_EditAddr.GetWindowTextLength();
if(strlen==0)
showStr.Format("%s%d:地址不能为空\n",showStr,++errNum);
strlen=this->m_EditEmail.GetWindowTextLength();
if(strlen==0)
showStr.Format("%s%d:EMAIL不能为空\n",showStr,++errNum);
if(errNum)
GetDlgItem(IDC_SIGN)->SetWindowText(showStr);
else
{//组包
FIRST_REG_PACKET firstRegPack;
memset(&firstRegPack,0,sizeof(FIRST_REG_PACKET));
firstRegPack.wCode=CLIENT_FIRST_REG;
firstRegPack.wLen=sizeof(FIRST_REG_PACKET);
m_EditAccountId.GetWindowText(firstRegPack.accountId,18);
m_EditAccountPwd.GetWindowText(firstRegPack.accountPwd,16);
m_EditAddr.GetWindowText(firstRegPack.customerAddr,20);
m_EditEmail.GetWindowText(firstRegPack.customerEmail,20);
m_EditRealName.GetWindowText(firstRegPack.customerRealName,10);
m_EditUserName.GetWindowText(firstRegPack.customerName,10);
m_EditUserPwd.GetWindowText(firstRegPack.customerPwd,16);
m_EditPhone.GetWindowText(firstRegPack.customerPhone,15);
//保持状态
strcpy(clientStatus.cUserName,firstRegPack.customerName);
strcpy(clientStatus.cUserPwd,firstRegPack.customerPwd);
//加密密码
CMD5 md5;
md5.MD5Update((BYTE*)&firstRegPack.accountPwd[0],16);
md5.MD5Final((BYTE*)&firstRegPack.accountPwd[0]);
md5.MD5Update((BYTE*)&firstRegPack.customerPwd[0],16);
md5.MD5Final((BYTE*)&firstRegPack.customerPwd[0]);
if(!connFlag)
connFlag=sock.connectServer();
if(connFlag)
{
if(sock.sendPacket((BYTE*)&firstRegPack,sizeof(FIRST_REG_PACKET)))
{
int i=sock.RetFlag();
switch(i)
{case FLAG_NOBANK:
MessageBox("你当前登陆的银行有误!");
break;
case FLAG_YESUSER:
{MessageBox("用户名已经被注册!");
m_EditUserName.SetWindowText("");
m_EditUserName.SetFocus();
}
break;
case FLAG_YESACC:
{MessageBox("账号已经被注册!");
m_EditAccountId.SetWindowText("");
m_EditAccountId.SetFocus();
}
break;
case FLAG_FAILED:
MessageBox("操作失败!");
break;
case FLAG_SUCCEED:
{MessageBox("注册成功");
m_EditAccountId.SetWindowText("");
m_EditAccountPwd.SetWindowText("");
m_EditAddr.SetWindowText("");
m_EditEmail.SetWindowText("");
m_EditRealName.SetWindowText("");
m_EditUserName.SetWindowText("");
m_EditUserPwd.SetWindowText("");
m_EditPhone.SetWindowText("");
CString str;
str.Format("你注册信息为:\n用户名:%s\n用户密码: %s",clientStatus.cUserName,clientStatus.cUserPwd);
GetDlgItem(IDC_SIGN)->SetWindowText(str);
}break;
default:
MessageBox("系统出错!");
}
}
}
}// OnOK();
}
void CRegDlg::OnEnChangeEdit8()
{
int i=m_EditUserName.GetWindowTextLength();
if(i)
{ CString str;
m_EditUserName.GetWindowText(str);
char curCh=str.GetAt(i-1);
if(!(curCh>='a' && curCh<='z'||curCh>='A'&&curCh<='Z'))
{
m_EditUserName.SetWindowText("");
//MessageBox("只能输入英文");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -