// ReaderMDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Library.h"
#include "ReaderMDlg.h"
#include "readset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CReaderMDlg dialog
CReaderMDlg::CReaderMDlg(CWnd* pParent /*=NULL*/)
: CDialog(CReaderMDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CReaderMDlg)
m_strReaderIDQ = _T("");
m_strReaderID = _T("");
m_strReaderName = _T("");
m_strReaderNameQ = _T("");
m_num = 0;
m_numall = 0;
//}}AFX_DATA_INIT
}
void CReaderMDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReaderMDlg)
DDX_Text(pDX, IDC_READER_ID_FOR_Q, m_strReaderIDQ);
DDV_MaxChars(pDX, m_strReaderIDQ, 8);
DDX_Text(pDX, IDC_READER_ID, m_strReaderID);
DDV_MaxChars(pDX, m_strReaderID, 8);
DDX_Text(pDX, IDC_READER_NAME, m_strReaderName);
DDV_MaxChars(pDX, m_strReaderName, 8);
DDX_Text(pDX, IDC_READER_NAME_FOR_Q, m_strReaderNameQ);
DDV_MaxChars(pDX, m_strReaderNameQ, 8);
DDX_Text(pDX, IDC_NUM_NOW, m_num);
DDX_Text(pDX, IDC_NUM_ALL, m_numall);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReaderMDlg, CDialog)
//{{AFX_MSG_MAP(CReaderMDlg)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_FIRST, OnFirst)
ON_BN_CLICKED(IDC_LAST, OnLast)
ON_BN_CLICKED(IDC_NEW, OnNew)
ON_BN_CLICKED(IDC_NEXT, OnNext)
ON_BN_CLICKED(IDC_PRIOR, OnPrior)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_BN_CLICKED(IDC_CANCEL_REC, OnCancelRec)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_EDIT, OnEdit)
ON_BN_CLICKED(IDC_ENQUERY, OnEnquery)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReaderMDlg message handlers
void CReaderMDlg::OnExit()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
void CReaderMDlg::OnFirst()
{
// TODO: Add your control notification handler code here
if(!m_rsDataSet.IsBOF())
{
m_rsDataSet.MoveFirst(); //将记录集光标移到第一条记录
DisplayRecord(); //刷新编辑框
SetButtonState(); //设置按钮状态
}
}
void CReaderMDlg::OnLast()
{
// TODO: Add your control notification handler code here
if(!m_rsDataSet.IsEOF())
{
m_rsDataSet.MoveLast();
DisplayRecord();
SetButtonState();
}
}
void CReaderMDlg::OnNew()
{
// TODO: Add your control notification handler code here
m_strReaderID = "";
m_strReaderName = "";
//m_type ="";
m_num=NULL;
m_numall=NULL;
UpdateData(FALSE); //刷新屏幕
m_bEdit = TRUE;
m_bAdd = TRUE;
SetButtonState(); //设置按钮状态
SetTextState(); //设置文本状态
CWnd *pWnd;
pWnd = GetDlgItem(IDC_READER_ID);
pWnd->SetFocus(); //设置pWnd获得焦点
}
void CReaderMDlg::OnNext()
{
// TODO: Add your control notification handler code here
if(!m_rsDataSet.IsEOF())
{
m_rsDataSet.MoveNext(); //后移一条记录
DisplayRecord();
SetButtonState();
}
}
void CReaderMDlg::OnPrior()
{
// TODO: Add your control notification handler code here
if(!m_rsDataSet.IsBOF())
{
m_rsDataSet.MovePrev(); //前移一条记录
DisplayRecord();
SetButtonState();
}
}
void CReaderMDlg::OnSave()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if ( m_strReaderName.IsEmpty() || m_strReaderID.IsEmpty())
{
AfxMessageBox("请输入完整数据数据!");
return;
}
if (m_bAdd)
{
m_rsDataSet.AddNew();
}
else
{
m_rsDataSet.Edit();
}
m_rsDataSet.m_borrowername = m_strReaderName;
m_rsDataSet.m_borrowernum = m_strReaderID;
m_rsDataSet.m_amountnow=0;
m_rsDataSet.m_amountall=m_numall;
// m_rsDataSet.m_FLAG_BORROW = "Y";
m_rsDataSet.Update();
m_rsDataSet.Requery();
m_bAdd = FALSE;
m_bEdit = FALSE;
DisplayRecord();
SetButtonState();
SetTextState();
}
void CReaderMDlg::OnCancelRec()
{
// TODO: Add your control notification handler code here
m_bAdd = FALSE;
m_bEdit = FALSE;
DisplayRecord();
SetButtonState();
SetTextState();
}
void CReaderMDlg::OnDelete()
{
// TODO: Add your control notification handler code here
m_rsDataSet.Delete();
DisplayRecord();
SetButtonState();
}
void CReaderMDlg::OnEdit()
{
// TODO: Add your control notification handler code here
m_bEdit = TRUE;
SetButtonState();
SetTextState();
CWnd *pWnd;
pWnd = GetDlgItem(IDC_READER_NAME);
pWnd->SetFocus(); //读者姓名编辑框获得焦点
}
void CReaderMDlg::OnEnquery()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_strReaderIDQ.IsEmpty() && m_strReaderNameQ.IsEmpty())
{
m_rsDataSet.m_strFilter = "";
m_rsDataSet.Requery();
DisplayRecord(); //显示当前记录
SetButtonState();
return;
}
BOOL mAll = FALSE;
if (!m_strReaderIDQ.IsEmpty())
{
m_rsDataSet.m_strFilter = "READER_ID='" + m_strReaderIDQ ;
m_rsDataSet.m_strFilter = m_rsDataSet.m_strFilter + "'";
mAll = TRUE;
}
if (!m_strReaderNameQ.IsEmpty())
{
if (mAll)
{
m_rsDataSet.m_strFilter = m_rsDataSet.m_strFilter + " AND NAME='";
m_rsDataSet.m_strFilter = m_rsDataSet.m_strFilter + m_strReaderNameQ;
m_rsDataSet.m_strFilter = m_rsDataSet.m_strFilter + "'";
}
else
{
m_rsDataSet.m_strFilter = "NAME='" + m_strReaderNameQ;
m_rsDataSet.m_strFilter = m_rsDataSet.m_strFilter + "'";
}
}
m_rsDataSet.Requery();
DisplayRecord();
SetButtonState();
}
BOOL CReaderMDlg::DisplayRecord() //定义函数
{
if (m_rsDataSet.IsEOF() && m_rsDataSet.IsBOF()) //如果记录集为空则清空编辑框
{
m_strReaderID = "";
m_strReaderName = "";
m_num=NULL;
m_numall=NULL;
}
else
{
if (m_rsDataSet.IsBOF())
{
m_rsDataSet.MoveNext();
}
else
{
if (m_rsDataSet.IsEOF()) //如果记录集指向末位则记其指向最后一个记录
{
m_rsDataSet.MovePrev();
}
}
m_strReaderID = m_rsDataSet.m_borrowernum;
m_strReaderName = m_rsDataSet.m_borrowername;
m_num=m_rsDataSet.m_amountnow;
m_numall=m_rsDataSet.m_amountall;
}
UpdateData(FALSE);
return TRUE;
}
BOOL CReaderMDlg::SetButtonState()
{
CWnd *pWnd;
if(!m_rsDataSet.IsOpen())
{
pWnd = GetDlgItem(IDC_FIRST);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_NEXT);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_PRIOR);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_LAST);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_NEW);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_EDIT);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_ENQUERY);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_DELETE);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_SAVE);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_CANCEL_REC);
pWnd->EnableWindow(FALSE);
return TRUE;
}
if (m_bEdit)
{
pWnd = GetDlgItem(IDC_FIRST);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_NEXT);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_PRIOR);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_LAST);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_NEW);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_EDIT);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_ENQUERY);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_DELETE);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_SAVE);
pWnd->EnableWindow(TRUE);
pWnd = GetDlgItem(IDC_CANCEL_REC);
pWnd->EnableWindow(TRUE);
return TRUE;
}
if (m_rsDataSet.IsBOF())
{
pWnd = GetDlgItem(IDC_FIRST);
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_PRIOR);
pWnd->EnableWindow(FALSE);
}
else
{
pWnd = GetDlgItem(IDC_FIRST);
pWnd->EnableWindow(TRUE);
pWnd = GetDlgItem(IDC_PRIOR);
pWnd->EnableWindow(TRUE);
}