📄 dep.cpp
字号:
// Dep.cpp : implementation file
//
#include "stdafx.h"
#include "Rsglxt.h"
#include "Dep.h"
#include "DBaseQuery.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDep dialog
CDep::CDep(CWnd* pParent /*=NULL*/)
: CDialog(CDep::IDD, pParent)
{
//{{AFX_DATA_INIT(CDep)
//}}AFX_DATA_INIT
}
void CDep::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDep)
DDX_Control(pDX, IDC_Group1, m_Group1);
DDX_Control(pDX, IDC_Group, m_Group);
DDX_Control(pDX, IDC_EDITMAN, m_EdtMan);
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_EDITFUC, m_EdtFuc);
DDX_Control(pDX, IDC_EDITNAME, m_EdtName);
DDX_Control(pDX, IDC_EDITNUM, m_EdtNum);
DDX_Control(pDX, IDC_EDITTEL, m_EdtTel);
DDX_Control(pDX, IDC_EDTID, m_EdtID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDep, CDialog)
//{{AFX_MSG_MAP(CDep)
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_BN_CLICKED(IDC_BUTEXIT, OnButexit)
ON_WM_PAINT()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDep message handlers
void CDep::Clear()
{
m_EdtID.SetWindowText("");
m_EdtTel.SetWindowText("");
m_EdtNum.SetWindowText("");
m_EdtName.SetWindowText("");
m_EdtFuc.SetWindowText("");
m_EdtMan.SetWindowText("");
}
void CDep::Enabled(bool bEnabled)
{
m_EdtTel.EnableWindow(bEnabled);
m_EdtMan.EnableWindow(bEnabled);
m_EdtNum.EnableWindow(bEnabled);
m_EdtName.EnableWindow(bEnabled);
m_EdtFuc.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 CDep::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,sPrincipal,sTel,sMem,sNum;
sName=drst.GetFieldValue("部门名称");
sPrincipal=drst.GetFieldValue("部门主管");
sTel=drst.GetFieldValue("部门电话");
sMem=drst.GetFieldValue("部门职责");
sNum=drst.GetFieldValue("编制人数");
m_EdtID.SetWindowText(sID);
m_EdtNum.SetWindowText(sNum);
m_EdtName.SetWindowText(sName);
m_EdtFuc.SetWindowText(sMem);
m_EdtTel.SetWindowText(sTel);
m_EdtMan.SetWindowText(sPrincipal);
m_EdtID.SetColour(RGB(0,0,0));//设置编辑框边框颜色
m_EdtNum.SetColour(RGB(0,0,0));
m_EdtName.SetColour(RGB(0,0,0));
m_EdtFuc.SetColour(RGB(0,0,0));
m_EdtTel.SetColour(RGB(0,0,0));
m_EdtMan.SetColour(RGB(0,0,0));
}
void CDep::OnButadd()
{
// TODO: Add your control notification handler code here
AddOrChange=1;
this->Enabled(true);
this->Clear();
CString NewID=ado.AutoNumber("DepInfo","Dep_ID","",1);
m_EdtID.SetWindowText(NewID);
m_EdtName.SetFocus();
}
void CDep::OnButchange1()
{
// TODO: Add your control notification handler code here
AddOrChange=2;
this->Enabled(true);
m_EdtName.SetFocus();
}
void CDep::OnButdele()
{
// TODO: Add your control notification handler code here
if(MessageBox("确定要删除此条记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
return;
CString sSQL;
sSQL.Format("DELETE FROM DepInfo WHERE Dep_ID=%s",m_sID);
RxRecordset Drst;
Drst.Open(sSQL,adCmdText);
this->OnCancel();
}
void CDep::OnButsave()
{
// TODO: Add your control notification handler code here
if(MessageBox("确定要保存记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
return;
CString sSQL,sSQL1,sID,sName,sMan,sTel,sNum,sFuc,tSql;
m_EdtID.GetWindowText(sID);
m_EdtFuc.GetWindowText(sFuc);
m_EdtTel.GetWindowText(sTel);
m_EdtNum.GetWindowText(sNum);
m_EdtName.GetWindowText(sName);
m_EdtMan.GetWindowText(sMan);
if(sName.IsEmpty())
{
MessageBox("部门名称不能为空,请输入部门名称。","系统提示",MB_OK|MB_ICONSTOP);
m_EdtName.SetFocus();
return;
}else if(sName.GetLength()>15)
{
MessageBox("部门名称字数不能过长,请重新输入部门名称。","系统提示",MB_OK|MB_ICONSTOP);
m_EdtName.SetFocus();
return;
}
if(sTel.IsEmpty())
{
MessageBox("部门联系电话不能为空,请重新输入部门联系电话。","系统提示",MB_OK|MB_ICONSTOP);
m_EdtTel.SetFocus();
return;
}else
{
int len;
len=atoi(sTel);
if(len>12)
{
MessageBox("部门联系电话无效,请重新输入部门联系电话。","系统提示",MB_OK|MB_ICONSTOP);
m_EdtTel.SetFocus();
return;
}
}
if(sMan.IsEmpty())
{
MessageBox("部门主管不能为空,请输入部门主管。","系统提示",MB_OK|MB_ICONSTOP);
m_EdtMan.SetFocus();
return;
}
int num1;
num1=atoi(sNum);
if(num1>1000)
{
MessageBox("部门编制人数不能大于1000人,请重新输入编制人数。","系统提示",MB_OK|MB_ICONSTOP);
m_EdtNum.SetFocus();
return;
}
RxRecordset namest,dutyst;
CString namesql,dutysql,man1;
namesql.Format("SELECT * FROM StaffInfo WHERE Staff_name='%s'",sMan);
// dutysql.Format("SELECT * FROM StaffInfo WHERE Duty='部门主管'");
namest.Open(namesql,adCmdText);
// dutyst.Open(dutysql,adCmdText);
if(namest.GetRecordCount()<1)
{
MessageBox("您输入的用户名不存在!请重新输入!","系统提示",MB_OK|MB_ICONSTOP);
m_EdtMan.SetWindowText("");
m_EdtMan.SetFocus();
return;
}
// man1=dutyst.GetFieldValue("Duty");
// if(man1!=sMan)
// {
// MessageBox("您输入的用户的职务不是部门主管!请重新输入!","系统提示",MB_OK|MB_ICONSTOP);
// m_EdtMan.SetWindowText("");
// m_EdtMan.SetFocus();
// return;
// }
if(sFuc.GetLength()>50)
{
MessageBox("您输入的部门职责字数过长!请重新输入!","系统提示",MB_OK|MB_ICONSTOP);
m_EdtFuc.SetFocus();
return;
}
CString bu="部门主管";
if(AddOrChange==1)//添加操作
{
sSQL.Format("Insert Into DepInfo Values(%s,'%s','%s','%s','%s','%s')",sID,sName,sNum,sMan,sTel,sFuc);
tSql.Format("Update StaffInfo set Duty='%s',Dep='%s' where Staff_name='%s'",bu,sName,sMan);
}
else
{
sSQL.Format("Update DepInfo set Dep_name='%s',Weave_num='%s',Dep_manage='%s',Dep_tel='%s',Dep_function='%s' WHERE Dep_ID=%s",sName,sNum,sMan,sTel,sFuc,sID);
tSql.Format("Update StaffInfo set Duty='%s',Dep='%s' where Staff_name='%s'",bu,sName,sMan);
}
RxRecordset arst,trst;
arst.Open(sSQL,adCmdText);
trst.Open(tSql,adCmdText);
this->Enabled(false);
this->m_ButAdd.SetFocus();
}
void CDep::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 CDep::OnButexit()
{
// TODO: Add your control notification handler code here
this->OnCancel();
}
BOOL CDep::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
RxGrid grid;
CDBaseQuery* ParentWnd=(CDBaseQuery*)FindWindow(NULL,"部门信息查询");
m_sID=ParentWnd->m_Grid.GetItemText(ParentWnd->m_Grid.GetRow(),0);
if(m_sID.IsEmpty())
{
this->m_ButChange.EnableWindow(false);
this->m_ButDele.EnableWindow(false);
}
this->Display(m_sID);
// m_ButAdd.LoadPic(IDB_BIT_Add,IDB_BIT_Add,IDB_BIT_Add);
// m_ButChange.LoadPic(IDB_BIT_Change,IDB_BIT_Change,IDB_BIT_Change);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDep::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 CDep::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 + -