📄 readerregdlg.cpp
字号:
// ReaderRegDlg.cpp : implementation file
//
#include "stdafx.h"
#include "LibraryManage.h"
#include "ReaderRegDlg.h"
#include "ReaderTypeSet.h"
#include "BorrowInfoSet.h"
#include "CommonFunc.h"
// CReaderRegDlg dialog
IMPLEMENT_DYNAMIC(CReaderRegDlg, CDialog)
CReaderRegDlg::CReaderRegDlg(CWnd* pParent /*=NULL*/)
: CDialog(CReaderRegDlg::IDD, pParent)
, strReaderID_(_T(""))
, strReaderType_(_T(""))
, strReaderName_(_T(""))
, strSex_(_T(""))
, strDeptName_(_T(""))
, strPhoneNO_(_T(""))
, strTelNO_(_T(""))
, strAddress_(_T(""))
, strDescription_(_T(""))
, strText_(_T(""))
, strCaption_(_T(""))
, strEmail_(_T(""))
, bModify_(FALSE)
, bSignOff_(FALSE)
, bAdd_(TRUE)
, dFine_(0.0)
, ctrlDateTime_(CTime::GetCurrentTime())
{
}
CReaderRegDlg::~CReaderRegDlg()
{
}
void CReaderRegDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReaderRegDlg)
DDX_Text(pDX, IDC_EDIT_READERNO, strReaderID_);
DDV_MaxChars(pDX, strReaderID_, 10);
DDX_CBString(pDX, IDC_COMBO_READERTYPE, strReaderType_);
DDV_MaxChars(pDX, strReaderType_, 10);
DDX_Text(pDX, IDC_EDIT_NAME, strReaderName_);
DDV_MaxChars(pDX, strReaderName_, 10);
DDX_CBString(pDX, IDC_COMBO_SEX, strSex_);
DDV_MaxChars(pDX, strSex_, 2);
DDX_Text(pDX, IDC_EDIT_DEPT, strDeptName_);
DDV_MaxChars(pDX, strDeptName_, 10);
DDX_Text(pDX, IDC_EDIT_PHONE, strPhoneNO_);
DDV_MaxChars(pDX, strPhoneNO_, 20);
DDX_Text(pDX, IDC_EDIT_TELNO, strTelNO_);
DDV_MaxChars(pDX, strTelNO_, 20);
DDX_Text(pDX, IDC_EDIT_ADDRESS, strAddress_);
DDX_Text(pDX, IDC_EDIT_DESCRIPTION, strDescription_);
DDX_Control(pDX, IDC_COMBO_READERTYPE, ctrlReaderType_);
DDX_Control(pDX, IDC_EDIT_READERNO, ctrlReaderID_);
DDX_Text(pDX, IDC_EDIT_FINE, dFine_);
DDX_Text(pDX, IDC_EDIT_EMAIL, strEmail_);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER, ctrlDateTime_);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReaderRegDlg, CDialog)
//{{AFX_MSG_MAP(CReaderRegDlg)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_EN_CHANGE(IDC_EDIT_READERNO, OnEnChangeEditReaderno)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CReaderRegDlg message handlers
BOOL CReaderRegDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CReaderTypeSet rdtRS;
CString strSQL = _T("SELECT * FROM ReaderType");
strText_.LoadString(IDS_OPENDBFAIL);
strCaption_.LoadString(IDS_DBERROR);
if (rdtRS.IsOpen())rdtRS.Close();
if (!rdtRS.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL))
{
MessageBox(strText_, strCaption_);
return FALSE;
}
while(!rdtRS.IsEOF())
{
ctrlReaderType_.AddString(rdtRS.strTypeName_);
rdtRS.MoveNext();
}
rdtRS.Close();
if (bModify_)
{
ctrlReaderID_.SetReadOnly(!strReaderID_.IsEmpty());
GetData();
GetDlgItem(IDOK)->SetWindowText(_T("确定(&C)"));
SetWindowText(_T("修改读者信息"));
}
if (bSignOff_)
{
ctrlReaderID_.SetReadOnly(!strReaderID_.IsEmpty());
GetDlgItem(IDOK)->SetWindowText(_T("注销(&O)"));
SetWindowText(_T("读者注销"));
GetData();
}
HICON hIcon;
hIcon = theApp.LoadIcon(IDI_REGICON);
SetIcon(hIcon, FALSE);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CReaderRegDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (strReaderID_.IsEmpty())
{
MessageBox(_T("请输入用户ID!"), theApp.strSystemName);
ctrlReaderID_.SetFocus();
return ;
}
if (strReaderName_.IsEmpty())
{
MessageBox(_T("请输入姓名!"), theApp.strSystemName);
GetDlgItem(IDC_EDIT_NAME)->SetFocus();
return ;
}
if (strReaderType_.IsEmpty())
{
MessageBox(_T("请选择读者类型!"), theApp.strSystemName);
GetDlgItem(IDC_COMBO_READERTYPE)->SetFocus();
return ;
}
if (strSex_.IsEmpty())
{
MessageBox(_T("请选择性别!"), theApp.strSystemName);
GetDlgItem(IDC_COMBO_SEX)->SetFocus();
return ;
}
if (strAddress_.IsEmpty())
{
MessageBox(_T("请输入地址!"), theApp.strSystemName);
GetDlgItem(IDC_EDIT_ADDRESS)->SetFocus();
return ;
}
CString strSQL;
strSQL.Format(_T("SELECT * FROM ReaderInfo WHERE ReaderID = '%s'"), strReaderID_);
if (rdRS.IsOpen())rdRS.Close();
if (!rdRS.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL))
{
MessageBox(strText_, strCaption_);
return;
}
if (bAdd_)
{
if(rdRS.GetRecordCount() != 0)
{
rdRS.Close();
MessageBox(_T("该用户已经存在,请重新输入!"), theApp.strSystemName);
return;
}
//添加读者记录
rdRS.AddNew();
SetData();
if (!rdRS.Update())
{
DWORD dwErrrorCode = GetLastError();
MessageBox(_T("读者登记失败!"), theApp.strSystemName);
}
else
{
if(IDYES == MessageBox(_T("读者登记成功!是否登记下一个读者?"),
theApp.strSystemName,MB_YESNO))
{
strReaderID_.Empty();
UpdateData(FALSE);
rdRS.Close();
return;
}
}
}
if (bModify_)
{
if(rdRS.GetRecordCount() == 0)
{
rdRS.Close();
MessageBox(_T("该用户不存在,请重新输入!"), theApp.strSystemName);
return;
}
// 修改读者记录
rdRS.Edit();
SetData();
rdRS.Update();
}
if (bSignOff_) //!< 注销读者
{
CBorrowInfoSet biRS;
if(rdRS.GetRecordCount() == 0)
{
rdRS.Close();
MessageBox(_T("该读者不存在,请重新输入!"), theApp.strSystemName);
return;
}
if (DeleteRecord(&biRS, _T("BorrowInfo"), _T("ReaderID"), strReaderID_))
{
rdRS.Delete();
}
else
MessageBox(_T("读者注销失败!"), theApp.strSystemName);
rdRS.Close();
CDialog::OnOK();
}
rdRS.Close();
CDialog::OnOK();
}
void CReaderRegDlg::GetData()
{
CString strSQL;
strSQL.Format(_T("SELECT * FROM ReaderInfo WHERE ReaderID = '%s'"), strReaderID_);
CReaderInfoSet rdRS;
if (rdRS.IsOpen())rdRS.Close();
if (rdRS.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL))
{
if (rdRS.GetRecordCount())
{
strReaderID_ = rdRS.m_ReaderID;
strReaderName_ = rdRS.m_ReaderName;
strSex_ = rdRS.m_Sex;
strReaderType_ = rdRS.m_Type;
strDeptName_ = rdRS.m_Dept;
strPhoneNO_ = rdRS.m_PhoneNO;
strTelNO_ = rdRS.m_TelNO;
strEmail_ = rdRS.m_Email;
ctrlDateTime_ = rdRS.m_RegDate;
strAddress_ = rdRS.m_Address;
dFine_ = rdRS.m_Punish;
strDescription_ = rdRS.m_Description;
}
}
}
void CReaderRegDlg::SetData()
{
rdRS.m_ReaderID = strReaderID_;
rdRS.m_ReaderName = strReaderName_;
rdRS.m_Sex = strSex_;
rdRS.m_Type = strReaderType_;
rdRS.m_Dept = strDeptName_;
rdRS.m_PhoneNO = strPhoneNO_;
rdRS.m_TelNO = strTelNO_;
rdRS.m_Email = strEmail_;
rdRS.m_RegDate = ctrlDateTime_;
rdRS.m_Address = strAddress_;
rdRS.m_Punish = dFine_;
rdRS.m_Description= strDescription_;
}
void CReaderRegDlg::OnEnChangeEditReaderno()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
if(!bModify_ && ! bSignOff_)return;
UpdateData(TRUE);
GetData();
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -