📄 modifydeleteuser.cpp
字号:
// ModifyDeleteUser.cpp : implementation file
//
#include "stdafx.h"
#include "sms.h"
#include "ModifyDeleteUser.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CModifyDeleteUser dialog
CModifyDeleteUser::CModifyDeleteUser(CWnd* pParent /*=NULL*/)
: CDialog(CModifyDeleteUser::IDD, pParent)
{
//{{AFX_DATA_INIT(CModifyDeleteUser)
m_UserName = _T("");
m_Password = _T("");
//}}AFX_DATA_INIT
}
void CModifyDeleteUser::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CModifyDeleteUser)
DDX_Control(pDX, IDC_AUTHORITY, m_Authority);
DDX_Text(pDX, IDC_USER_NAME, m_UserName);
DDX_Text(pDX, IDC_PASSWORD, m_Password);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CModifyDeleteUser, CDialog)
//{{AFX_MSG_MAP(CModifyDeleteUser)
ON_BN_CLICKED(IDC_MODIFY_USER, OnModifyUser)
ON_BN_CLICKED(IDC_DELETE_USER, OnDeleteUser)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CModifyDeleteUser message handlers
BOOL CModifyDeleteUser::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_Authority.InsertString(0,"管理员");
m_Authority.InsertString(1,"普通员工");
m_Authority.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CModifyDeleteUser::OnModifyUser()
{
// TODO: Add your control notification handler code here
UpdateData();
if(m_UserName.IsEmpty())
{
MessageBox("请选择一下要删除的用户");
return;
}
if(m_Password.IsEmpty())
{
MessageBox("密码不能为空");
return;
}
if(m_Password.GetLength()>12 && CValidate::IsDigitAndAlpha(m_Password))
{
MessageBox("密码的长度不能超过12位,并且只能是字母或数字");
return;
}
//////////////////////////////////////////////////////////////////////////
///数据库操作
CSMSApp * pCSMSApp=(CSMSApp *)AfxGetApp();//取得App类对象的指针
CSMSADO &Ado=pCSMSApp->m_SMSAdo;
//这里判断数据连接是否连接成功
if(!Ado.IsConnection())
{
MessageBox("连接数据库出错\n请重新设置Oracle相关信息");
return;
}
int authority=m_Authority.GetCurSel();
CString sql;
int isSuccess;
sql.Format("UPDATE users SET PASSWD='%s',AUTHORITY=%d WHERE username='%s'",m_Password,authority,m_UserName);
//判断是否查询到记录 查找到就返回真 没查找到就返回假
isSuccess=Ado.ExecuteWithoutRecordset(sql);
//SQLRECORDSET rs=Ado.ExecuteWithRecordset(sql);
//int authority=Ado.GetIntegerFieldVal(rs,"authority");
if(!isSuccess)
{
MessageBox("插入数据出错,请查看是否以连接数据库");
return;
}
((CUserManager *)(GetParent()->GetParent()))->ShowUsers();
m_UserName.Empty();
m_Password.Empty();
m_Authority.SetCurSel(0);
UpdateData(FALSE);//将变量的内容更新到于之关加的窗口上
}
void CModifyDeleteUser::OnDeleteUser()
{
// TODO: Add your control notification handler code here
UpdateData();
if(m_UserName.IsEmpty())
{
MessageBox("请选择一下要删除的用户");
return;
}
//判断删除的用户是不是当前登入用户,如果是就不让他删除
if(m_UserName==((CSMSApp *)AfxGetApp())->m_UserName)
{
MessageBox("不能删除当前正在使用的用户");
return;
}
//////////////////////////////////////////////////////////////////////////
///数据库操作
CSMSApp * pCSMSApp=(CSMSApp *)AfxGetApp();//取得App类对象的指针
CSMSADO &Ado=pCSMSApp->m_SMSAdo;
//这里判断数据连接是否连接成功
if(!Ado.IsConnection())
{
MessageBox("连接数据库出错\n请重新设置Oracle相关信息");
return;
}
CString sql;
int isSuccess;
sql.Format("DELETE users WHERE username='%s'",m_UserName);
//判断是否查询到记录 查找到就返回真 没查找到就返回假
isSuccess=Ado.ExecuteWithoutRecordset(sql);
//SQLRECORDSET rs=Ado.ExecuteWithRecordset(sql);
//int authority=Ado.GetIntegerFieldVal(rs,"authority");
if(!isSuccess)
{
MessageBox("删除数据出错,请查看是否以连接数据库");
return;
}
((CUserManager *)(GetParent()->GetParent()))->ShowUsers();
m_UserName.Empty();
m_Password.Empty();
m_Authority.SetCurSel(0);
UpdateData(FALSE);//将变量的内容更新到于之关加的窗口上
}
BOOL CModifyDeleteUser::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_RETURN) return TRUE;
if (pMsg->wParam == VK_ESCAPE) return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -