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

📄 addnewusr.cpp

📁 去年暑假帮朋友企业写的仓库管理软件
💻 CPP
字号:
// AddNewUsr.cpp : implementation file
//

#include "stdafx.h"
#include "Material_MIS.h"
#include "AddNewUsr.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAddNewUsr dialog


CAddNewUsr::CAddNewUsr(CWnd* pParent /*=NULL*/)
	: CDialog(CAddNewUsr::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddNewUsr)
	m_user_add = _T("");
	m_user_pwd = _T("");
	m_user_re_pwd = _T("");
	//}}AFX_DATA_INIT
}


void CAddNewUsr::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddNewUsr)
	DDX_Text(pDX, IDC_USER_ADD, m_user_add);
	DDV_MaxChars(pDX, m_user_add, 15);
	DDX_Text(pDX, IDC_USER_PWD, m_user_pwd);
	DDV_MaxChars(pDX, m_user_pwd, 10);
	DDX_Text(pDX, IDC_USER_RE_PWD, m_user_re_pwd);
	DDV_MaxChars(pDX, m_user_re_pwd, 10);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAddNewUsr, CDialog)
	//{{AFX_MSG_MAP(CAddNewUsr)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddNewUsr message handlers

BOOL CAddNewUsr::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	((CEdit*)GetDlgItem(IDC_USER_ADD))->SetFocus();

	return FALSE;	// return TRUE unless you set the focus to a control
					// EXCEPTION: OCX Property Pages should return FALSE
}

void CAddNewUsr::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	
	// Check the data integrality ...
	m_user_add.TrimLeft();
	m_user_add.TrimRight();
	if(m_user_add.GetLength()<=0)
	{
		AfxMessageBox("请输入用户名!",MB_ICONEXCLAMATION);
		((CEdit*)GetDlgItem(IDC_USER_ADD))->SetFocus();
		return;
	}
	m_user_pwd.TrimLeft();
	m_user_pwd.TrimRight();
	if(m_user_pwd.GetLength()<=0)
	{
		AfxMessageBox("请输入密码!",MB_ICONEXCLAMATION);
		((CEdit*)GetDlgItem(IDC_USER_PWD))->SetFocus();
		return;
	}
	m_user_re_pwd.TrimLeft();
	m_user_re_pwd.TrimRight();
	if(m_user_re_pwd.GetLength()<=0)
	{
		AfxMessageBox("请确认密码!",MB_ICONEXCLAMATION);
		((CEdit*)GetDlgItem(IDC_USER_RE_PWD))->SetFocus();
		return;
	}

	// Check the coherence of the password;
	if(m_user_pwd.Compare(m_user_re_pwd)!=0)
	{
		AfxMessageBox("前后密码输入不一致!",MB_ICONEXCLAMATION);
		((CEdit*)GetDlgItem(IDC_USER_PWD))->SetWindowText("");
		((CEdit*)GetDlgItem(IDC_USER_RE_PWD))->SetWindowText("");
		((CEdit*)GetDlgItem(IDC_USER_PWD))->SetFocus();
		return;
	}

	// Check if the database have already exist the user name;
	_variant_t strQuery;
	int count;

	strQuery = "select * from UserInfo where UserID='"+m_user_add+"'";
	theApp.ADOExecute(theApp.m_pADOSet,strQuery);
	count = theApp.m_pADOSet->GetRecordCount();
	if(count != 0)
	{
		AfxMessageBox("改用户名已存在!",MB_ICONEXCLAMATION);
		((CEdit*)GetDlgItem(IDC_USER_ADD))->SetWindowText("");
		((CEdit*)GetDlgItem(IDC_USER_ADD))->SetFocus();
		return;
	}

	// Add the new user and its password to the database;
	strQuery = "insert UserInfo (UserID, UserPwd) \
	         			  values ('"+m_user_add+"', '"+m_user_pwd+"')";
	if ( theApp.ADOExecute(theApp.m_pADOSet, strQuery) ) 
		AfxMessageBox(_T("添加记录成功!"), MB_ICONINFORMATION);
	else
	{
		AfxMessageBox(_T("添加记录失败!"),MB_ICONEXCLAMATION);
		return;
	}
	
	CDialog::OnOK();
}

⌨️ 快捷键说明

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