?? borrowinfo.cpp
字號:
// BORROWINFO.cpp : implementation file
//
#include "stdafx.h"
#include "圖書館系統(tǒng).h"
#include "BORROWINFO.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBORROWINFO dialog
CBORROWINFO::CBORROWINFO(CWnd* pParent /*=NULL*/)
: CDialog(CBORROWINFO::IDD, pParent)
{
//{{AFX_DATA_INIT(CBORROWINFO)
m_borid = _T("");
m_bordate = _T("");
m_bordays = _T("");
m_borjid = _T("");
m_bortime = _T("");
m_datatime = COleDateTime::GetCurrentTime();
m_overdays = _T("");
//}}AFX_DATA_INIT
}
void CBORROWINFO::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBORROWINFO)
DDX_Text(pDX, IDC_BOR_BID, m_borid);
DDX_Text(pDX, IDC_BOR_DATE, m_bordate);
DDX_Text(pDX, IDC_BOR_DAYS, m_bordays);
DDX_Text(pDX, IDC_BOR_JID, m_borjid);
DDX_Text(pDX, IDC_BOR_TIME, m_bortime);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_datatime);
DDX_Text(pDX, IDC_EDIT_OVERDAY, m_overdays);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBORROWINFO, CDialog)
//{{AFX_MSG_MAP(CBORROWINFO)
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
ON_BN_CLICKED(IDC_SET_UP, OnSetUp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBORROWINFO message handlers
BOOL CBORROWINFO::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CEdit* pEdit=(CEdit*)GetDlgItem(IDC_BOR_BID);
//當(dāng)前對話框是否用來編輯,圖書ID不允許編輯
pEdit->EnableWindow(FALSE);
pEdit=(CEdit*)GetDlgItem(IDC_BOR_DAYS);
pEdit->EnableWindow(FALSE);
pEdit=(CEdit*)GetDlgItem(IDC_BOR_JID);
pEdit->EnableWindow(FALSE);
pEdit=(CEdit*)GetDlgItem(IDC_BOR_DATE);
pEdit->EnableWindow(FALSE);
pEdit=(CEdit*)GetDlgItem(IDC_BOR_TIME);
pEdit->EnableWindow(FALSE);
pEdit=(CEdit*)GetDlgItem(IDC_EDIT_OVERDAY);
pEdit->EnableWindow(FALSE);
//設(shè)置查詢語句
CString strSQL;
strSQL.Format("select * from 借閱信息表 where 圖書ID='%s'",m_getid);
//打開記錄集 選擇表名
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("沒有成功打開數(shù)據(jù)表");
return FALSE;
}
//應(yīng)該只有一條記錄
long int m_today,m_ytoday;
if(m_pRecordset->adoEOF)
{
AfxMessageBox("該圖書沒有借出或不存在!");
CDialog::OnCancel();
return FALSE;
}
m_pRecordset->MoveFirst();
m_borid=pLeftView->VariantToCString(m_pRecordset->GetCollect("圖書ID"));
m_borjid=pLeftView->VariantToCString(m_pRecordset->GetCollect("借閱ID"));
m_bortime=pLeftView->VariantToCString(m_pRecordset->GetCollect("借閱次數(shù)"));
m_bordate=pLeftView->VariantToCString(m_pRecordset->GetCollect("借閱日期"));
m_today=(long)m_datatime;
m_datatime=m_pRecordset->GetCollect("借閱日期");
m_ytoday=(long)m_datatime;//計算借閱天數(shù)
m_bordays.Format("%d",m_today-m_ytoday);
if(m_today-m_ytoday-60>0)//判斷逾期天數(shù)
m_overdays.Format("%d",m_today-m_ytoday-60);
else
m_overdays.Format("0");
UpdateData(FALSE);
//關(guān)閉
m_pRecordset->Close();
m_pRecordset=NULL;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CBORROWINFO::OpenRecordSet(_RecordsetPtr &recPtr, CString &strSQL)
{
CMyApp* pApp=(CMyApp*)AfxGetApp();
//創(chuàng)建記錄集對象
m_pRecordset.CreateInstance(__uuidof(Recordset));
//在ADO操作中建議語句中要常用try...catch()來捕獲錯誤信息,
//因為它有時會經(jīng)常出現(xiàn)一些想不到的錯誤
try
{
//從數(shù)據(jù)庫中打開表
recPtr->Open(strSQL.AllocSysString(),
pApp->m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch (_com_error e)
{
CString strError;
strError.Format("警告:打開數(shù)據(jù)表時發(fā)生異常。 錯誤信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
return TRUE;
}
void CBORROWINFO::OnButtonDelete()
{
// TODO: Add your control notification handler code here
if (MessageBox("你確定要刪除這條借閱信息嗎?","刪除確認(rèn)",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
return;
}
CString strSQL;
strSQL.Format("delete * from 借閱信息表 where 圖書ID='%s'",m_borid);
//打開記錄集 選擇表名
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("沒有成功打開數(shù)據(jù)表");
return ;
}
AfxMessageBox("刪除成功!");
}
void CBORROWINFO::OnButtonEdit()
{
// TODO: Add your control notification handler code here
//更新控件變量的值
UpdateData(TRUE);
//姓名、類別為空時返回
//刪除空格
m_borid.Remove(' ');
m_borjid.Remove(' ');
m_bordate.Remove(' ');
if(m_borid.IsEmpty()||m_borjid.IsEmpty()||m_bordate.IsEmpty())
{
AfxMessageBox("圖書名稱和類別不能為空");
return;
}
//打開記錄集 選擇表名
CString strSQL;
strSQL.Format("select * from 借閱信息表 where 圖書ID='%s' ",m_getid);
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("沒有成功打開數(shù)據(jù)表");
return;
}
if(!m_pRecordset->BOF)
{
m_pRecordset->MoveFirst();
}
//上述準(zhǔn)備完畢,下面開始插入內(nèi)容
try
{
m_pRecordset->PutCollect("圖書ID",_variant_t(m_borid));
m_pRecordset->PutCollect("借閱ID",_variant_t(m_borjid));
m_pRecordset->PutCollect("借閱次數(shù)",_variant_t(m_bortime));
m_pRecordset->PutCollect("借閱日期",_variant_t(m_bordate));
//更新數(shù)據(jù)庫
m_pRecordset->Update();
//當(dāng)前記錄移動到最后
m_pRecordset->MoveLast();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告:插入信息時發(fā)生異常。錯誤信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
AfxMessageBox("修改成功!");
CDialog::OnOK();
}
void CBORROWINFO::OnSetUp()
{
// TODO: Add your control notification handler code here
CEdit* pEdit=(CEdit*)GetDlgItem(IDC_BOR_BID);
//當(dāng)前對話框是否用來編輯,圖書ID不允許編輯
pEdit->EnableWindow(TRUE);
pEdit=(CEdit*)GetDlgItem(IDC_BOR_DAYS);
pEdit->EnableWindow(TRUE);
pEdit=(CEdit*)GetDlgItem(IDC_BOR_JID);
pEdit->EnableWindow(TRUE);
pEdit=(CEdit*)GetDlgItem(IDC_BOR_DATE);
pEdit->EnableWindow(TRUE);
pEdit=(CEdit*)GetDlgItem(IDC_BOR_TIME);
pEdit->EnableWindow(TRUE);
pEdit=(CEdit*)GetDlgItem(IDC_EDIT_OVERDAY);
pEdit->EnableWindow(TRUE);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -