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

📄 adduser.cpp

📁 一个很好的VC源代码
💻 CPP
字号:
// AddUser.cpp : implementation file
//

#include "stdafx.h"
#include "aoManage.h"
#include "AddUser.h"
#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAddUser dialog


CAddUser::CAddUser(CWnd* pParent /*=NULL*/)
	: CParentDlg(CAddUser::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddUser)
	m_strName = _T("");
	m_strPriority = _T("");
	//}}AFX_DATA_INIT
	m_pUser=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
}


void CAddUser::DoDataExchange(CDataExchange* pDX)
{
	CParentDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddUser)
	DDX_Control(pDX, IDC_COMBO1, m_ctlCombo);
	DDX_Text(pDX, IDC_EDIT1, m_strName);
	DDX_CBString(pDX, IDC_COMBO1, m_strPriority);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAddUser, CParentDlg)
	//{{AFX_MSG_MAP(CAddUser)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddUser message handlers

BOOL CAddUser::OnInitDialog() 
{
	CParentDlg::OnInitDialog();
	
	m_ctlCombo.AddString("1");
	m_ctlCombo.AddString("2");
	m_ctlCombo.AddString("3");
	m_pUser->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from user");

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


void CAddUser::OnButton1() 
{
	UpdateData(TRUE);
	if (!m_strName.GetLength()||!m_strPriority.GetLength())
	{
		MessageBox("用户名或权限不能为空");
		return;
	}
	if (m_pUser->FindFirst("name='"+m_strName+"'"))
	{
		MessageBox("此用户已存在,请选择其他的用户名");
		return;
	}
	m_pUser->AddNew();
	m_pUser->SetFieldValue("name",(LPCTSTR)m_strName);
	m_pUser->SetFieldValue("Priority",(LPCTSTR)m_strPriority);
	m_pUser->Update();
	MessageBox("已成功添加");
	m_strName="";
	UpdateData(FALSE);
	//m_strPriority="";
	m_ctlCombo.SetCurSel(-1);
}

void CAddUser::OnButton2() 
{
	OnCancel();	
}

void CAddUser::OnClose() 
{
	if (m_pUser->IsOpen())
		m_pUser->Close();
	CParentDlg::OnClose();
}

⌨️ 快捷键说明

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