📄 dop.cpp
字号:
// DOp.cpp : implementation file
//
#include "stdafx.h"
#include "Rsglxt.h"
#include "DOp.h"
#include "DBaseQuery.h"
#include "externdllHeader.h"
//#include "RxGrid.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDOp dialog
extern CRsglxtApp theApp;
CDOp::CDOp(CWnd* pParent /*=NULL*/)
: CDialog(CDOp::IDD, pParent)
{
//{{AFX_DATA_INIT(CDOp)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDOp::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDOp)
DDX_Control(pDX, IDC_COMBO_PUR, m_ComPur);
DDX_Control(pDX, IDC_Group1, m_Group1);
DDX_Control(pDX, IDC_Group, m_Group);
DDX_Control(pDX, IDC_EDITSTNAME, m_EdtStname);
DDX_Control(pDX, IDC_BUTADD, m_ButAdd);
DDX_Control(pDX, IDC_BUTCHANGE1, m_ButChange);
DDX_Control(pDX, IDC_BUTDELE, m_ButDele);
DDX_Control(pDX, IDC_BUTEXIT, m_ButExit);
DDX_Control(pDX, IDC_BUTSAVE, m_ButSave);
DDX_Control(pDX, IDC_BUTUNDO, m_ButUndo);
DDX_Control(pDX, IDC_EDTSPWD, m_EdtSpwd);
DDX_Control(pDX, IDC_EDTPWD, m_EdtPwd);
// DDX_Control(pDX, IDC_EDTPUR, m_EdtPur);
DDX_Control(pDX, IDC_EDTNAME, m_EdtName);
DDX_Control(pDX, IDC_EDTID, m_EdtID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDOp, CDialog)
//{{AFX_MSG_MAP(CDOp)
ON_BN_CLICKED(IDC_BUTEXIT, OnButexit)
ON_BN_CLICKED(IDC_BUTADD, OnButadd)
ON_BN_CLICKED(IDC_BUTCHANGE1, OnButchange1)
ON_BN_CLICKED(IDC_BUTDELE, OnButdele)
ON_BN_CLICKED(IDC_BUTSAVE, OnButsave)
ON_BN_CLICKED(IDC_BUTUNDO, OnButundo)
ON_WM_PAINT()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDOp message handlers
BOOL CDOp::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CDBaseQuery* ParentWnd=(CDBaseQuery*)FindWindow(NULL,"用户信息查询");
m_sID=ParentWnd->m_Grid.GetItemText(ParentWnd->m_Grid.GetRow(),0);
//m_ComPur.SelectString(0,"普通管理员");
this->Display(m_sID);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDOp::Enabled(bool bEnabled)
{
m_EdtSpwd.EnableWindow(bEnabled);
m_EdtPwd.EnableWindow(bEnabled);
m_EdtName.EnableWindow(bEnabled);
m_EdtStname.EnableWindow(bEnabled);
m_ComPur.EnableWindow(bEnabled);
m_ButUndo.EnableWindow(bEnabled);
m_ButSave.EnableWindow(bEnabled);
m_ButExit.EnableWindow(!bEnabled);
m_ButDele.EnableWindow(!bEnabled);
m_ButChange.EnableWindow(!bEnabled);
m_ButAdd.EnableWindow(!bEnabled);
}
void CDOp::Display(CString sID)
{
if(sID.IsEmpty())
return;
CString sSQL;
RxRecordset drst;
sSQL.Format("SELECT * FROM 用户视图 WHERE 编号='%s'",sID);
drst.Open(sSQL,adCmdText);
if(drst.GetRecordCount()<1)
return;
CString sName,sPwd,sStname,sPur;
sStname=drst.GetFieldValue("员工姓名");
sName=drst.GetFieldValue("用户名");
sPwd=drst.GetFieldValue("密码");
sPur=drst.GetFieldValue("权限");
m_EdtID.SetWindowText(sID);
m_EdtStname.SetWindowText(sStname);
m_EdtName.SetWindowText(sName);
m_EdtPwd.SetWindowText(sPwd);
m_EdtSpwd.SetWindowText(sPwd);
m_ComPur.SetWindowText(sPur);///
m_EdtID.SetColour(RGB(0,0,0));//设置编辑框边框颜色
m_EdtStname.SetColour(RGB(0,0,0));
m_EdtName.SetColour(RGB(0,0,0));
m_EdtPwd.SetColour(RGB(0,0,0));
m_EdtSpwd.SetColour(RGB(0,0,0));
}
void CDOp::Clear()
{
m_EdtSpwd.SetWindowText("");
m_EdtPwd.SetWindowText("");
m_EdtStname.SetWindowText("");
m_EdtName.SetWindowText("");
m_EdtID.SetWindowText("");
}
void CDOp::OnButexit()
{
// TODO: Add your control notification handler code here
this->OnCancel();
}
void CDOp::OnButadd()
{
// TODO: Add your control notification handler code here
AddOrChange=1;
this->Enabled(true);
this->Clear();
CString NewID=ado.AutoNumber("UserInfo","User_ID","",1);
m_EdtID.SetWindowText(NewID);
m_EdtStname.SetFocus();
}
void CDOp::OnButchange1()
{
// TODO: Add your control notification handler code here
AddOrChange=2;
this->Enabled(true);
m_EdtStname.SetFocus();
}
void CDOp::OnButdele()
{
// TODO: Add your control notification handler code here
if(MessageBox("确定要删除此条记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
return;
CString sSQL;
sSQL.Format("DELETE FROM UserInfo WHERE User_ID=%s",m_sID);
RxRecordset Drst;
Drst.Open(sSQL,adCmdText);
this->OnCancel();
}
void CDOp::OnButsave()
{
// TODO: Add your control notification handler code here
if(MessageBox("确定要保存记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
return;
CString sSQL,sID,sStname,sName,sPwd,sSpwd,sPur;
m_EdtID.GetWindowText(sID);
m_EdtStname.GetWindowText(sStname);
m_EdtName.GetWindowText(sName);
m_EdtPwd.GetWindowText(sPwd);
m_EdtSpwd.GetWindowText(sSpwd);
m_ComPur.GetWindowText(sPur);
RxRecordset namest;
CString namesql;
namesql.Format("SELECT * FROM StaffInfo WHERE Staff_name='%s'",sStname);
namest.Open(namesql,adCmdText);
if(sName.IsEmpty())
{
MessageBox("用户名不能为空,请输入用户名。","系统提示",MB_OKCANCEL|MB_ICONQUESTION!=1);
m_EdtName.SetFocus();
return;
}
if(namest.GetRecordCount()<1)
{
MessageBox("您输入的用户名不存在!请重新输入!","系统提示",MB_OK|MB_ICONSTOP);
m_EdtStname.SetWindowText("");
m_EdtStname.SetFocus();
return;
}
if(sPwd.IsEmpty())
{
MessageBox("密码不能为空,请输入密码。","系统提示",MB_OKCANCEL|MB_ICONQUESTION!=1);
m_EdtPwd.SetFocus();
return;
}
else
{
int len;
len=sPwd.GetLength();
if(len>15)
{
MessageBox("密码不能超过15位,请重新输入。","系统提示",MB_OKCANCEL|MB_ICONQUESTION!=1);
m_EdtPwd.SetFocus();
return;
}
char ch;
int i;
for(i=1;i<len;i++)
{
ch = sPwd.GetAt(i);
if(ch==32||ch==8)//||((ch<65||ch>90)&&(ch<97||ch>122))||(ch>47 && ch<58))//32是空格,8是退格键,65_90,97_122是大小写字母,47_58是数字
{
MessageBox("输入密码无效,请输入新的密码。","系统提示",MB_OKCANCEL|MB_ICONQUESTION!=1);
m_EdtPwd.SetFocus();
return;
}
if((ch<48 || ch>57)&&(ch<65||ch>90)&&(ch<97||ch>122))
{
MessageBox("输入密码无效,请输入新的密码。","系统提示",MB_OKCANCEL|MB_ICONQUESTION!=1);
m_EdtPwd.SetFocus();
return;
}
}
}
if (sPwd!=sSpwd)
{
MessageBox("您两次输入的密码不一致,请确认后重新输入!","系统提示",MB_OK|MB_ICONSTOP);
m_EdtSpwd.SetWindowText("");
m_EdtSpwd.SetFocus();
return;
}
if(sPur.IsEmpty())
{
MessageBox("权限不能为空,请输入权限。","系统提示",MB_OKCANCEL|MB_ICONQUESTION!=1);
m_ComPur.SetFocus();
return;
}
else if(sPur!="普通管理员"&&sPur!="超级管理员")
{
MessageBox("输入的权限无效,请重新输入权限。","系统提示",MB_OKCANCEL|MB_ICONQUESTION!=1);
m_ComPur.SetFocus();
return;
}
if(sStname.IsEmpty())
{
MessageBox("姓名不能为空,请输入姓名。","系统提示",MB_OKCANCEL|MB_ICONQUESTION!=1);
m_EdtStname.SetFocus();
return;
}
if(AddOrChange==1)//添加操作
sSQL.Format("Insert Into UserInfo Values(%s,'%s','%s','%s','%s')",sID,sStname,sName,sPwd,sPur);
else
sSQL.Format("Update UserInfo set User_Stname='%s',User_name='%s',Password='%s',Purview='%s' WHERE User_ID=%s",sStname,sName,sPwd,sPur,sID);
RxRecordset arst;
arst.Open(sSQL,adCmdText);
this->Enabled(false);
this->m_ButAdd.SetFocus();
}
void CDOp::OnButundo()
{
// TODO: Add your control notification handler code here
if(MessageBox("确定要撤消操作吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
return;
this->Enabled(false);
this->Clear();
this->Display(m_sID);
this->m_ButAdd.SetFocus();
}
void CDOp::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;
CBitmap bit;
CDC memDC;
this->GetClientRect(&rect);
bit.LoadBitmap(IDB_BIT_BJ);
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(&bit);
dc.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
memDC.DeleteDC();
::DeleteObject(&bit);
CDialog::OnPaint();
// Do not call CDialog::OnPaint() for painting messages
}
HBRUSH CDOp::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor==CTLCOLOR_STATIC)
{
pDC->SetBkColor(RGB(255,255,255));
pDC->SetTextColor(RGB(0,0,0));
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -