📄 personsystemdlg.cpp
字号:
// PersonSystemDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MarketManager.h"
#include "PersonSystemDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////
//peter statements
extern CMarketManagerApp theApp;
//peter statements
////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CPersonSystemDlg dialog
CPersonSystemDlg::CPersonSystemDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPersonSystemDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPersonSystemDlg)
m_no = _T("");
m_name = _T("");
m_code = _T("");
m_limit = 0;
//}}AFX_DATA_INIT
//////////////////////////////////////////////////////
//peter statements
m_pRdset.CreateInstance(__uuidof(Recordset));
//peter statements
//////////////////////////////////////////////////////
}
void CPersonSystemDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPersonSystemDlg)
DDX_Text(pDX, ID_PERSON_NO, m_no);
DDV_MaxChars(pDX, m_no, 10);
DDX_Text(pDX, ID_PERSON_NAME, m_name);
DDV_MaxChars(pDX, m_name, 20);
DDX_Text(pDX, ID_PERSON_CODE, m_code);
DDV_MaxChars(pDX, m_code, 10);
DDX_Text(pDX, ID_PERSON_LIMIT, m_limit);
DDV_MinMaxInt(pDX, m_limit, 0, 1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPersonSystemDlg, CDialog)
//{{AFX_MSG_MAP(CPersonSystemDlg)
ON_BN_CLICKED(ID_PERSON_NEXT, OnPersonNext)
ON_BN_CLICKED(ID_PERSON_LAST, OnPersonLast)
ON_BN_CLICKED(ID_PERSON_ADD, OnPersonAdd)
ON_BN_CLICKED(ID_PERSON_DELETE, OnPersonDelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPersonSystemDlg message handlers
//DEL void CPersonSystemDlg::OnPersonNext()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL
//DEL }
//DEL void CPersonSystemDlg::OnPersonNext(_RecordsetPtr pRdset)
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL
//DEL }
void CPersonSystemDlg::OnPersonNext()
{
// TODO: Add your control notification handler code here
CString str;
_variant_t var;
bool isexist=false;
UpdateData();
str.Format("select * from Person");
try
{
m_pRdset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRdset->BOF)
{//find the record displayed
m_pRdset->MoveFirst();
while(!isexist&&!m_pRdset->adoEOF)
{
var=m_pRdset->GetCollect("person_no");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
if(str==m_no)
isexist=true;
else
m_pRdset->MoveNext();
}
if(isexist==true)
{//移动到下一个记录并显示
m_pRdset->MoveNext();
if(m_pRdset->adoEOF)
m_pRdset->MoveFirst();
var=m_pRdset->GetCollect("person_no");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
m_no=str;
var=m_pRdset->GetCollect("person_name");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
m_name=str;
var=m_pRdset->GetCollect("person_code");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
m_code=str;
var=m_pRdset->GetCollect("person_limit");
m_limit=var.intVal;
UpdateData(FALSE);
}
else
{
MessageBox("当前人事纪录不存在\n请确认编号","系统提示",MB_OK|MB_ICONWARNING);
}
}
else
{
MessageBox("人事纪录已被清空","系统提示",MB_OK|MB_ICONWARNING);
}
m_pRdset->Close();
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}
void CPersonSystemDlg::OnPersonLast()
{
CString str;
_variant_t var;
bool isexist=false;
UpdateData();
str.Format("select * from Person");
try
{
//打开人事纪录表
m_pRdset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRdset->BOF)
{
//循环遍历Datebase,查找当前显示的纪录
m_pRdset->MoveFirst();
while(!isexist&&!m_pRdset->adoEOF)
{
var=m_pRdset->GetCollect("person_no");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
if(str==m_no)
isexist=true;
else
m_pRdset->MoveNext();
}
if(isexist==true)
{
//移动到上一个记录并显示
m_pRdset->MovePrevious();
if(m_pRdset->BOF)
m_pRdset->MoveLast();
var=m_pRdset->GetCollect("person_no");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
m_no=str;
var=m_pRdset->GetCollect("person_name");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
m_name=str;
var=m_pRdset->GetCollect("person_code");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
m_code=str;
var=m_pRdset->GetCollect("person_limit");
m_limit=var.intVal;
UpdateData(FALSE);
}
else
{
MessageBox("当前人事纪录不存在\n请确认编号","系统提示",MB_OK|MB_ICONWARNING);
}
}
else
{
MessageBox("人事纪录已被清空","系统提示",MB_OK|MB_ICONWARNING);
}
m_pRdset->Close();
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}
void CPersonSystemDlg::OnPersonAdd()
{
_variant_t var;
bool isexist=false;
CString str;
UpdateData();
str.Format("select * from Person");
try
{
//打开人事纪录表
m_pRdset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRdset->BOF)
{
//循环遍历Datebase,确保输入编码唯一
m_pRdset->MoveFirst();
while(!isexist&&!m_pRdset->adoEOF)
{
var=m_pRdset->GetCollect("person_no");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
if(str==m_no)
isexist=true;
else
m_pRdset->MoveNext();
}
if(isexist==false)
{//添加新的纪录
m_pRdset->AddNew();
m_pRdset->PutCollect("person_no",_variant_t(m_no));
m_pRdset->PutCollect("person_name",_variant_t(m_name));
m_pRdset->PutCollect("person_code",_variant_t(m_code));
var.iVal=m_limit;
m_pRdset->PutCollect("person_limit",var.iVal);
m_pRdset->Update();
MessageBox("新人事纪录添加成功","系统提出",MB_OK|MB_ICONINFORMATION);
}
else
{
MessageBox("身份编码已存在\n添加失败","系统提示",MB_OK|MB_ICONINFORMATION);
}
}
else
{
MessageBox("人事纪录已被清空","系统提示",MB_OK|MB_ICONWARNING);
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
m_pRdset->Close();
}
void CPersonSystemDlg::OnPersonDelete()
{
_variant_t var;
bool isexist=false;
CString str="0";
UpdateData();
if(m_no==str)
{
MessageBox("非法删除编号为零的管理员","系统提示",MB_OK|MB_ICONSTOP);
return;
}
str.Format("select * from Person");
try
{
//打开人事纪录表
m_pRdset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRdset->BOF)
{
//循环遍历Datebase,查找指定纪录
m_pRdset->MoveFirst();
while(!isexist&&!m_pRdset->adoEOF)
{
var=m_pRdset->GetCollect("person_no");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
if(str==m_no)
isexist=true;
else
m_pRdset->MoveNext();
}
if(isexist==true)
{//确认删除操作
str.Format("编号为 ");
str+=m_no;
str+=" 的人员将被删除\n点击OK确认删除!\n点击Cancel撤销操作!";
if(MessageBox(str,"系统确认",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
{
m_pRdset->Delete(adAffectCurrent);
m_pRdset->MoveNext();
if(m_pRdset->adoEOF)
m_pRdset->MoveFirst();
var=m_pRdset->GetCollect("person_no");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
m_no=str;
var=m_pRdset->GetCollect("person_name");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
m_name=str;
var=m_pRdset->GetCollect("person_code");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
m_code=str;
var=m_pRdset->GetCollect("person_limit");
m_limit=var.intVal;
UpdateData(FALSE);
MessageBox("人员纪录删除成功","系统提示",MB_OK|MB_ICONINFORMATION);
}
}
else
{
MessageBox("人事纪录不存在\n确认输入编号","系统提示",MB_OK|MB_ICONINFORMATION);
}
}
else
{
MessageBox("人事纪录已被清空","系统提示",MB_OK|MB_ICONWARNING);
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
m_pRdset->Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -