⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgadduser.cpp

📁 简易火车售票系统
💻 CPP
字号:
// DlgAdduser.cpp : implementation file
//

#include "stdafx.h"
#include "afxdb.h"
#include "Train.h"
#include "DlgAdduser.h"
#include "UserSet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgAdduser dialog


CDlgAdduser::CDlgAdduser(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgAdduser::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgAdduser)
	m_adduserkey1 = _T("");
	m_adduserkey2 = _T("");
	m_addusername = _T("");
	m_addusert = _T("");
	m_addusertype = _T("");
	//}}AFX_DATA_INIT
}


void CDlgAdduser::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgAdduser)
	DDX_Text(pDX, IDC_ADD_USER_KEY1, m_adduserkey1);
	DDX_Text(pDX, IDC_ADD_USER_KEY2, m_adduserkey2);
	DDX_Text(pDX, IDC_ADD_USER_NAME, m_addusername);
	DDX_Text(pDX, IDC_ADD_USER_T, m_addusert);
	DDX_Text(pDX, IDC_ADD_USER_TYPE, m_addusertype);
	DDV_MaxChars(pDX, m_addusertype, 1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgAdduser, CDialog)
	//{{AFX_MSG_MAP(CDlgAdduser)
	ON_BN_CLICKED(IDC_ADD_USER_CANCEL, OnAddUserCancel)
	ON_BN_CLICKED(IDC_ADD_USER_OK, OnAddUserOk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgAdduser message handlers

void CDlgAdduser::OnAddUserCancel() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
	
}

void CDlgAdduser::OnAddUserOk() 
{
	// TODO: Add your control notification handler code here
	CUserSet set;
	UpdateData();
	//判断用户名长度是否为0
	if(m_addusername.GetLength()<=0)
	{
		AfxMessageBox("用户名不能为空!");
		return;
	}
	//判断密码位数是否合格
	if(m_adduserkey1.GetLength()<3)
	{
		AfxMessageBox("密码长度不能小于3位!");
		return;
	}
	//判断两次密码是否相同
	if(m_adduserkey1!=m_adduserkey2)
	{
		AfxMessageBox("两次密码输入不相同!");
		return;
	}

	try
	{
		if(set.IsOpen())
			set.Close();
		set.m_strFilter.Format("username='%s'",m_addusername);
		set.Open(CRecordset::snapshot,NULL,CRecordset::none);
		if(!set.IsEOF())
		{
			set.Close();
			AfxMessageBox("该用户已经存在!");
			return;
		}

		set.AddNew();
		set.m_username=m_addusername;
		set.m_userkey=m_adduserkey2;
		set.m_usertype=m_addusertype;
		set.m_creatT=m_addusert;

		if(set.CanUpdate())
		{
			set.Update();
		}
		if(set.IsOpen())
		{
			set.Close();
		}
		AfxMessageBox("用户添加成功!");
	}
	catch(CDBException* pe)
	{
		pe->ReportError();
		return;
	}

	CDialog::OnOK();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -