// RegisterGlg.cpp: 实现文件
//

#include "pch.h"
#include "ZGKJ.h"
#include "afxdialogex.h"
#include "RegisterDlg.h"


// RegisterGlg 对话框

IMPLEMENT_DYNAMIC(RegisterDlg, CDialogEx)

RegisterDlg::RegisterDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_REGISTER, pParent)
	, Phone(_T(""))
	, Name(_T(""))
	, Pass1(_T(""))
	, Pass2(_T(""))
{

}

RegisterDlg::~RegisterDlg()
{
}

const char* RegisterDlg::PassConvet(char* pass, int SecretKey)
{
	const char* pass1;
	for (int i = 0; i < strlen(pass); i++)
	{
		pass[i] ^= SecretKey;
	}
	pass1 = pass;
	return pass1;
}

void RegisterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_PHONE, Phone);
	DDX_Text(pDX, IDC_NAME, Name);
	DDX_Text(pDX, IDC_PASS, Pass1);
	DDX_Text(pDX, IDC_PASS2, Pass2);
}


BEGIN_MESSAGE_MAP(RegisterDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &RegisterDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// RegisterGlg 消息处理程序


void RegisterDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData();
	if (Pass1.IsEmpty() || Pass2.IsEmpty()||Phone.IsEmpty()||Name.IsEmpty())
	{
		AfxMessageBox(_T("信息输入错误，核对后再输入！"));
		return;
	}
	if (Pass1 != Pass2)
	{
		AfxMessageBox(_T("两次密码输入必须一样！！！"));
		GetDlgItem(IDC_PASS)->SetWindowText(_T(""));
		GetDlgItem(IDC_PASS2)->SetWindowText(_T(""));
		return;
	}
	//CString Order;
	char* order = new char[STR_NUM];
	srand(time(NULL));
	int secret_key = rand() % 99 + 37;
	const char* name = CZGKJApp::MyTtoA(Name);
	const char* phone = CZGKJApp::MyTtoA(Phone);
	char* tempPass1 = CZGKJApp::MyTtoA(Pass1);
	const char* pass1 = PassConvet(tempPass1, secret_key);
	sprintf_s(order, STR_NUM-1,"INSERT INTO tb_wait_for_review (phone,pass,name,secret_key)VALUES ('%s','%s','%s',%d)", phone, pass1, name, secret_key);
	if (theApp.sql->ExecutiveCommand(order))
	{
		CString error = CZGKJApp::MyAtoT(theApp.sql->GetErrorInformation());
		//error.Format(_T("%s"),);
		AfxMessageBox(error,MB_OK | MB_ICONERROR);
		return;
	}
	AfxMessageBox(_T("注册成功，请等待人事部审核！"));
	CDialogEx::OnOK();
}
