📄 manage.cpp
字号:
//该类是抄表管理员增加、删除抄表员,以及
//修改自己的密码。
//创建时间:2004.02.26
//创建人:苟艳
/////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "抄表系统.h"
#include "Manage.h"
#include "AddMember.h"
#include "Update.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//抄表人员记录的字段
#define prop_10 L"抄表员编号"
#define prop_11 L"抄表员名称"
#define prop_12 L"抄表员密码"
///////////////////////////////////////////////////////////////////////
#include "CreateDB.h"
#include "rapi.h"
/////////////////////////////////////////////////////////////////////////////
extern CCreateDB database;
////////////////////////////////////////////////////////////////////////////////
// CManage dialog
CManage::CManage(CWnd* pParent /*=NULL*/)
: CDialog(CManage::IDD, pParent)
{
//
//{{AFX_DATA_INIT(CManage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CManage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CManage)
DDX_Control(pDX, IDC_LIST1, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CManage, CDialog)
//{{AFX_MSG_MAP(CManage)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_WM_DESTROY()
ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CManage message handlers
void CManage::OnButton1() //增加抄表员
{
CloseHandle(operDBhandle);
CAddMember dlg1;
dlg1.DoModal();
// //按抄表员编号排序打开
if(database.CreateOperDB())
operDBhandle=database.operhandle;
ListOperDB();
}
void CManage::DelRecord()
{
int cursel=m_list.GetCurSel();
int len=m_list.GetTextLen (cursel);
LPWSTR data=new TCHAR[len];
LPWSTR indexname;
m_list.GetText(cursel,data);
TCHAR *seldata;
seldata=wcschr(data,':');
int length=wcslen(data)-wcslen(seldata);
indexname=new TCHAR[length];
for(int i=0;i<length;i++)
indexname[i]=data[i]; //存储了数据的字段名
wcscpy(data,seldata+1); //这个数据库数据
CEOID record;
record=FindDelRecord(indexname,data);
if(record!=0)
{
int answer=::MessageBox (this->m_hWnd ,message,L"确定删除",MB_YESNO);
if(answer==IDYES)
{
if(operDBhandle!=INVALID_HANDLE_VALUE)
CeDeleteRecord(operDBhandle,record);
else
return;
}
}
}
void CManage::OnButton2() //删除抄表员
{
DelRecord();
ListOperDB();
}
///////////////////
CEOID CManage::FindDelRecord(LPWSTR Parname,LPWSTR DATA)
{
CEOID findceoid;
WORD propnumber;
PCEPROPVAL pRecord=0;
DWORD cbBuff;
DWORD index;
CEPROPVAL Property;
CString field1="抄表员名称",field2="抄表员密码";
TCHAR rec1[50],rec2[50],rec3[50];
int operflag;
//
if(field1.Compare(Parname)==0)
{
CloseHandle(operDBhandle);
if(database.openOperator())
{
operDBhandle=database.operhandle;
operflag=1;
}
}
if(field2.Compare(Parname)==0)
{
::AfxMessageBox(L"请选择要删除人员的编号或者名称!");
return 0;
}
findceoid=CeSeekDatabase(operDBhandle,CEDB_SEEK_BEGINNING,0,&index);
if(operflag==1)
Property.propid=MAKELONG(CEVT_LPWSTR,prop_11);
else
Property.propid=MAKELONG(CEVT_LPWSTR,prop_10);
Property.wFlags =0;
Property.val .lpwstr =DATA;
findceoid=CeSeekDatabase(operDBhandle,CEDB_SEEK_VALUEFIRSTEQUAL,(DWORD)&Property ,&index); //找到
if(findceoid==0)
{
int error;
TCHAR text[64];
error=GetLastError();
wsprintf(text,L"Db handle.error=%d(%x)",error,error);
::AfxMessageBox(text);
::AfxMessageBox (L"抄表员记录中无该抄表员的档案");
return 0;
}
findceoid=CeReadRecordProps(operDBhandle,CEDB_ALLOWREALLOC,&propnumber,NULL,(LPBYTE*)&pRecord,&cbBuff);//读出记录的内容
if(findceoid==0)
return 0;
for(int i=0;i<propnumber;i++)//从数据库中读出要删除记录
{
if(pRecord->propid==MAKELONG(CEVT_LPWSTR,prop_10))
lstrcpy(rec1,pRecord->val .lpwstr );
if(pRecord->propid==MAKELONG(CEVT_LPWSTR,prop_11))
lstrcpy(rec2,pRecord->val .lpwstr );
if(pRecord->propid==MAKELONG(CEVT_LPWSTR,prop_12))
lstrcpy(rec3,pRecord->val .lpwstr );
pRecord++;
}
message.Format(L"删除信息:\n该抄表员的编号:%s,他(她)的名字:%s,密码为:%s",rec1,rec2,rec3);
return findceoid;
}
///////
void CManage::OnButton3() //修改抄表管理员的密码
{
CloseHandle(operDBhandle);
CUpdate dlg2;
dlg2.DoModal();
// //按抄表员编号排序打开
if(database.CreateOperDB())
operDBhandle=database.operhandle;
ListOperDB();
}
BOOL CManage::OnInitDialog() //界面初试化
{
CDialog::OnInitDialog();
// //按抄表员编号排序打开
if(database.CreateOperDB())
operDBhandle=database.operhandle;
//
ListOperDB();
//m_nTimer1=SetTimer(1, 2000, 0); //定时刷新界面
//
return TRUE;
}
void CManage::OnDestroy()
{
CloseHandle(operDBhandle);
CDialog::OnDestroy();
}
////////显示抄表员记录中的数据
void CManage::ListOperDB()
{
CEOID findceoid;
WORD propnumber;
PCEPROPVAL pRecord=0;
DWORD cbBuff;
DWORD index;
TCHAR temp[50];
CString message1="";
int k=0;
//清除列表框的内容
m_list.ResetContent();
//
findceoid=CeSeekDatabase(operDBhandle,CEDB_SEEK_BEGINNING,0,&index);
if(findceoid==0)
{
message1="目前抄表员记录中无数据!";
m_list.InsertString(0,message1);
return;
}
findceoid=CeReadRecordProps(operDBhandle,CEDB_ALLOWREALLOC,&propnumber,NULL,(LPBYTE*)&pRecord,&cbBuff);//读出记录的内容
while(findceoid!=0)
{
for(int i=0;i<propnumber;i++)
{
if(pRecord->propid==MAKELONG(CEVT_LPWSTR,prop_10))
{
lstrcpy(temp,pRecord->val .lpwstr );
message1="抄表员编号:";
}
if(pRecord->propid==MAKELONG(CEVT_LPWSTR,prop_11))
{
lstrcpy(temp,pRecord->val .lpwstr );
message1="抄表员名称:";
}
if(pRecord->propid==MAKELONG(CEVT_LPWSTR,prop_12))
{
lstrcpy(temp,pRecord->val .lpwstr );
message1="抄表员密码:";
}
pRecord++;
m_list.InsertString(k++,message1+temp);
}
message1="*****************************";
m_list.InsertString(k++,message1);
pRecord=0;
findceoid=CeReadRecordProps(operDBhandle,CEDB_ALLOWREALLOC,&propnumber,NULL,(LPBYTE*)&pRecord,&cbBuff);//读出记录的内容
}
}
/*void CManage::OnTimer(UINT nIDEvent)
{
ListOperDB();
}*/
void CManage::OnDblclkList1() //双击后也能删除记录
{
DelRecord();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -