【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了UserDlg.cpp提供大家参考,希望对大家有所帮助!
// UserDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MyPos.h"
#include "UserDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CUserDlg dialog
extern CMyPosApp theApp;
CUserDlg::CUserDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUserDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUserDlg)
m_Listuser = _T("");
m_datebirth = _T("");
m_duty = _T("");
m_jiguan = _T("");
m_logname = _T("");
m_username = _T("");
m_number = _T("");
m_upwd = _T("");
m_sex = _T("");
//}}AFX_DATA_INIT
}
void CUserDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUserDlg)
DDX_Control(pDX, IDC_CHECK1, m_oCheck1);
DDX_Control(pDX, IDC_CHECK2, m_oCheck2);
DDX_Control(pDX, IDC_CHECK3, m_oCheck3);
DDX_Control(pDX, IDC_CHECK4, m_oCheck4);
DDX_Control(pDX, IDC_CHECK5, m_oCheck5);
DDX_Control(pDX, IDC_CHECK6, m_oCheck6);
DDX_Control(pDX, IDC_CHECK7, m_oCheck7);
DDX_Control(pDX, IDC_CHECK8, m_oCheck8);
DDX_Control(pDX, IDC_CHECK9, m_oCheck9);
DDX_Control(pDX, IDC_EDIT_USERID, m_oUserid);
DDX_Control(pDX, IDC_EDIT_DISCOUNT, m_oDiscount);
DDX_Control(pDX, IDC_EDIT_NUMBER, m_oNumber);
DDX_Control(pDX, IDC_EDIT_LOGNAME, m_oLogname);
DDX_Control(pDX, IDC_EDIT_JIGUAN, m_oJiguan);
DDX_Control(pDX, IDC_EDIT_DUTY, m_oDuty);
DDX_Control(pDX, IDC_EDIT_DATEBIRTH, m_oDatebirth);
DDX_Control(pDX, IDC_EDIT_PWD, m_oPwd);
DDX_Control(pDX, IDC_EDIT_USERNAME, m_oUsername);
DDX_Control(pDX, IDC_COMBO_SEX, m_oSex);
DDX_Control(pDX, IDC_LIST_USER, m_oListuser);
DDX_LBString(pDX, IDC_LIST_USER, m_Listuser);
DDX_Text(pDX, IDC_EDIT_DATEBIRTH, m_datebirth);
DDX_Text(pDX, IDC_EDIT_DUTY, m_duty);
DDX_Text(pDX, IDC_EDIT_JIGUAN, m_jiguan);
DDX_Text(pDX, IDC_EDIT_LOGNAME, m_logname);
DDX_Text(pDX, IDC_EDIT_USERNAME, m_username);
DDX_Text(pDX, IDC_EDIT_NUMBER, m_number);
DDX_Text(pDX, IDC_EDIT_PWD, m_upwd);
DDX_CBString(pDX, IDC_COMBO_SEX, m_sex);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUserDlg, CDialog)
//{{AFX_MSG_MAP(CUserDlg)
ON_BN_CLICKED(IDC_BUTTON_UADD, OnButtonUadd)
ON_BN_CLICKED(IDC_BUTTON_UDEL, OnButtonUdel)
ON_BN_CLICKED(IDC_BUTTON_USAVE, OnButtonUsave)
ON_LBN_SELCHANGE(IDC_LIST_USER, OnSelchangeListUser)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUserDlg message handlers
BOOL CUserDlg::OnInitDialog()
{
CDialog::OnInitDialog();
ReadToListbox();
m_oListuser.SelectString(-1, theApp.name);//设置选中项
OnSelchangeListUser();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CUserDlg::OnButtonUadd()
{
//Clear the edit and combobox content.
m_oDatebirth.SetWindowText("");
m_oDuty.SetWindowText("");
m_oJiguan.SetWindowText("");
m_oLogname.SetWindowText("");
m_oUsername.SetWindowText("");
m_oNumber.SetWindowText("");
m_oPwd.SetWindowText("");
m_oDiscount.SetWindowText("");
m_oSex.SetCurSel(0);
m_oCheck1.SetCheck(0);
m_oCheck2.SetCheck(0);
m_oCheck3.SetCheck(0);
m_oCheck4.SetCheck(0);
m_oCheck5.SetCheck(0);
m_oCheck6.SetCheck(0);
m_oCheck7.SetCheck(0);
m_oCheck8.SetCheck(0);
m_oCheck9.SetCheck(0);
lNewID=GenNewID();
// m_oListuser.SetCurSel(-1);
}
void CUserDlg::OnButtonUdel()
{
CString sql, stemp;
int iOption;
_RecordsetPtr m_pRecordset;
iOption = m_oListuser.GetCurSel();
if(iOption>=0)
{
m_oListuser.GetText(iOption, stemp);//得到选中项的文本
sql="select * from USERS where NAME='"+stemp+"'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(AfxMessageBox("要删除此用户吗?",MB_YESNO)==IDYES)
{
CString slogid=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("LOGINID");
if(slogid=="Admin")
{
MessageBox("不能删除
系统管理员!");
return;
}
m_pRecordset->Delete(adAffectCurrent);///删除当前记录
m_oListuser.DeleteString(iOption);
OnButtonUadd();//Clear