📄 dperson.cpp
字号:
// DPerson.cpp : implementation file
//
#include "stdafx.h"
#include "商品销售管理系统.h"
#include "DPerson.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "ExternDllHeader.h"
#include "RxRecordset.h"
/////////////////////////////////////////////////////////////////////////////
// CDPerson dialog
CDPerson::CDPerson(CWnd* pParent /*=NULL*/)
: CDialog(CDPerson::IDD, pParent)
{
//{{AFX_DATA_INIT(CDPerson)
//}}AFX_DATA_INIT
}
void CDPerson::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDPerson)
DDX_Control(pDX, IDC_EDTMONEY, m_EdtMoney);
DDX_Control(pDX, IDC_EDTName, m_EdtName);
DDX_Control(pDX, IDC_EDTLNAME, m_EdtLName);
DDX_Control(pDX, IDC_EDTID, m_EdtID);
DDX_Control(pDX, IDC_EDTBUSIESS, m_EdtBusiess);
DDX_Control(pDX, IDC_DTDATE, m_DtDate);
DDX_Control(pDX, IDC_BUTUndo, m_ButUndo);
DDX_Control(pDX, IDC_BUTSave, m_ButSave);
DDX_Control(pDX, IDC_BUTDELE, m_ButDele);
DDX_Control(pDX, IDC_BUTChange, m_ButChange);
DDX_Control(pDX, IDC_BUTADD, m_ButAdd);
DDX_Control(pDX, ID_BUTEXIT, m_ButExit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDPerson, CDialog)
//{{AFX_MSG_MAP(CDPerson)
ON_BN_CLICKED(IDC_BUTADD, OnButadd)
ON_BN_CLICKED(IDC_BUTChange, OnBUTChange)
ON_BN_CLICKED(IDC_BUTDELE, OnButdele)
ON_BN_CLICKED(IDC_BUTUndo, OnBUTUndo)
ON_BN_CLICKED(ID_BUTEXIT, OnButexit)
ON_BN_CLICKED(IDC_BUTSave, OnBUTSave)
ON_EN_CHANGE(IDC_EDTName, OnChangeEDTName)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDPerson message handlers
void CDPerson::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CDPerson::OnButadd()
{
CString cID;
this->Enabled(true);
m_EdtID.GetWindowText(cID);
if(cID.IsEmpty())
cID="1";
else
cID=ado.AutoNumber("员工信息表","编号","",1);
this->m_EdtID.SetWindowText(cID);
this->clear();
m_EdtName.SetFocus();
this->AddOrChange=1;
CTime time;
time=time.GetCurrentTime();
this->m_DtDate.SetTime(&time);
}
void CDPerson::clear()
{
m_EdtLName.SetWindowText("");
m_EdtName.SetWindowText("");
m_EdtBusiess.SetWindowText("");
m_EdtMoney.SetWindowText("");
}
void CDPerson::Enabled(bool bEnabled)
{
m_EdtLName.EnableWindow(bEnabled);
m_EdtName.EnableWindow(bEnabled);
m_EdtBusiess.EnableWindow(bEnabled);
m_EdtMoney.EnableWindow(bEnabled);
m_DtDate.EnableWindow(bEnabled);
m_ButDele.EnableWindow(!bEnabled);
m_ButChange.EnableWindow(!bEnabled);
m_ButAdd.EnableWindow(!bEnabled);
m_ButUndo.EnableWindow(bEnabled);
m_ButSave.EnableWindow(bEnabled);
m_ButExit.EnableWindow(!bEnabled);
}
void CDPerson::Display(CString sField, CString sValue)
{
RxRecordset disRst;
CString sSQL;
sSQL.Format("SELECT * FROM 员工信息表 WHERE %s='%s'",sField,sValue);
disRst.Open(sSQL,adCmdText);
disRst.MoveFirst();
CString sID,sName,sLName,sBusiess,sMoney,sDate;
sID=disRst.GetFieldValue("编号");
sName=disRst.GetFieldValue("名称");
sLName=disRst.GetFieldValue("简称");
sBusiess=disRst.GetFieldValue("职务");
sMoney=disRst.GetFieldValue("薪金");
sDate=disRst.GetFieldValue("聘用日期");
m_EdtID.SetWindowText(sID);
m_EdtName.SetWindowText(sName);
m_EdtLName.SetWindowText(sLName);
this->m_EdtBusiess.SetWindowText(sBusiess);
this->m_EdtMoney.SetWindowText(sMoney);
CTime tDate;
tDate=CStringTOCTime(sDate);
this->m_DtDate.SetTime(&tDate);
disRst.Close();
}
void CDPerson::OnBUTChange()
{
CString cID;
this->Enabled(true);
m_EdtName.SetFocus();
this->AddOrChange=2;
}
void CDPerson::OnButdele()
{
if(MessageBox("删除后无法恢复 ,确定删除此条记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)==1)
{
CString sSQL,sID;
this->m_EdtID.GetWindowText(sID);
sSQL.Format("DELETE FROM 员工信息表 WHERE 编号='%s'",sID);
RxRecordset DeleRst;
DeleRst.Open(sSQL,adCmdText);
this->OnCancel();
}
}
void CDPerson::OnBUTUndo()
{
if(MessageBox("确定要撤消操作吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)==1)
{
Enabled(false);
Display("编号",m_sID);
this->AddOrChange=0;
this->m_ButAdd.SetFocus();
}
}
void CDPerson::OnButexit()
{
this->OnCancel();
}
void CDPerson::OnBUTSave()
{
if(MessageBox("确定要保存记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)==1)
{
CString sID,sName,sLName,sBusiess,sMoney,sDate;
m_EdtID.GetWindowText(sID);
m_EdtName.GetWindowText(sName);
m_EdtLName.GetWindowText(sLName);
m_EdtBusiess.GetWindowText(sBusiess);
m_EdtMoney.GetWindowText(sMoney);
CTime tDate;
m_DtDate.GetTime(tDate);
sDate=CTimeToCString(tDate);
RxRecordset AddRst;
CString sSQL;
if(this->AddOrChange==1) //添加
sSQL.Format("INSERT INTO 员工信息表 VALUES(%s,'%s','%s','%s','%s',%s)",sID,sName,sLName,sBusiess,sDate,sMoney);
if(this->AddOrChange==2) //修改
sSQL.Format("UPDATE 员工信息表 SET 名称='%s',简称='%s',职务='%s',聘用日期='%s',薪金=%s WHERE 编号=%s",sName,sLName,sBusiess,sDate,sMoney,sID);
AddRst.Open(sSQL,adCmdText);
this->AddOrChange=0;
this->Enabled(false);
this->m_ButExit.SetFocus();
}
}
void CDPerson::SetID(CString sID)
{
m_sID=sID;
}
BOOL CDPerson::OnInitDialog()
{
CDialog::OnInitDialog();
rst.Open("员工信息表");
if(m_sID!="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 CDPerson::OnChangeEDTName()
{
CString sName,sSName;
this->m_EdtName.GetWindowText(sName);
sSName=CharToLetterCode(sName);
this->m_EdtLName.SetWindowText(sSName);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -