【VC开源代码栏目提醒】:本文主要为网学会员提供UserEditDlg.cpp,希望对需要UserEditDlg.cpp网友有所帮助,学习一下!
// UserEditDlg.cpp : implementation file
//
#include "stdafx.h"
#include "HrSys.h"
#include "UserEditDlg.h"
#include "Users.h"
#include "EmpSelDlg.h"
extern CUsers curUser;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CUserEditDlg dialog
CUserEditDlg::CUserEditDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUserEditDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUserEditDlg)
m_UserName = _T("");
m_DepName = _T("");
m_EmpName = _T("");
//}}AFX_DATA_INIT
}
void CUserEditDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUserEditDlg)
DDX_Control(pDX, IDC_TYPE_COMBO, m_UserType);
DDX_Text(pDX, IDC_USERNAME_EDIT, m_UserName);
DDX_Text(pDX, IDC_DEPNAME_STATIC, m_DepName);
DDX_Text(pDX, IDC_EMPNAME_STATIC, m_EmpName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUserEditDlg, CDialog)
//{{AFX_MSG_MAP(CUserEditDlg)
ON_BN_CLICKED(IDC_SELEMP_BUTTON, OnSelempButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUserEditDlg message handlers
void CUserEditDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
//域校验
if(m_UserName=="")
{
MessageBox("请输入用户名");
return;
}
if(lEmpId<=0)
{
MessageBox("请选择员工");
return;
}
//定义用户对象
CUsers usr;
usr.UserName = m_UserName;
usr.EmpId = lEmpId;
if(m_UserType.GetCurSel() == 0)
usr.UserType = "
系统管理员";
else
usr.UserType = "普通用户";
if (cUserName=="")//插入用户记录
{
//判断用户名是否已存在
if (usr.HaveRecord(m_UserName))
{
MessageBox("当前用户名已存在");
return;
}
usr.sql_insert();
}
else
usr.
sql_update(cUserName);//更新用户信息
CDialog::OnOK();
}
//打开选择员工对话框
void CUserEditDlg::OnSelempButton()
{
// TODO: Add your control notification handler code here
CEmpSelDlg dlg;
if(dlg.DoModal()==IDOK)
{
//根据用户选择设置员工信息
lEmpId = dlg.EmpId;
m_EmpName = dlg.EmpName;
m_DepName = dlg.DepName;
UpdateData(FALSE);
}
}
BOOL CUserEditDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_UserType.SetCurSel(iUserType - 1);
if (curUser.UserName != "Admin")
GetDlgItem(IDC_TYPE_COMBO)->EnableWindow(FALSE);
if (lEmpId>0)
GetDlgItem(IDC_USERNAME_EDIT)->EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}