?? operate.cpp
字號:
// OPERATE.cpp : implementation file
//
#include "stdafx.h"
#include "圖書館系統.h"
#include "OPERATE.h"
#include "BORROWLIST.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// OPERATE dialog
OPERATE::OPERATE(CWnd* pParent /*=NULL*/)
: CDialog(OPERATE::IDD, pParent)
{
//{{AFX_DATA_INIT(OPERATE)
m_optbid = _T("");
m_optuid = _T("");
//}}AFX_DATA_INIT
}
void OPERATE::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(OPERATE)
DDX_Text(pDX, IDC_OPT_BOOKID, m_optbid);
DDX_Text(pDX, IDC_OPT_USERID, m_optuid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(OPERATE, CDialog)
//{{AFX_MSG_MAP(OPERATE)
ON_BN_CLICKED(IDC_OPT, OnOpt)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// OPERATE message handlers
BOOL OPERATE::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
if(m_option==2)
{
CEdit* pEdit=(CEdit*)GetDlgItem(IDC_OPT_BOOKID);
//當前對話框是否用來編輯,圖書ID不允許編輯
pEdit->EnableWindow(FALSE);
}
if(m_option==3)
{
CEdit* pEdit=(CEdit*)GetDlgItem(IDC_OPT_USERID);
//當前對話框是否用來編輯,圖書ID不允許編輯
pEdit->EnableWindow(FALSE);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void OPERATE::OnOpt()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString strSQL,strql;
mbookname="";
if(m_option==1)
{
strSQL.Format("select * from 圖書信息情況 where 圖書ID='%s' ",m_optbid);
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("沒有成功打開數據表");
return ;
}
if(!m_pRecordset->adoEOF)
{
try
{
mbookname=pLeftView->VariantToCString(m_pRecordset->GetCollect("圖書名稱"));
}
catch(_com_error e)
{
CString strError;
strError.Format("警告:插入信息時發生異常。錯誤信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
}
if(mbookname=="")
{
AfxMessageBox("找不到該圖書數據");
return;
}
strSQL.Format("select * from 借閱人員表 where 借閱ID='%s' ",m_optuid);
//打開記錄集 選擇表名
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("沒有成功打開數據表");
return;
}
if(!m_pRecordset->adoEOF)
{
strSQL="select * from 借閱信息表";
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("沒有成功打開數據表");
return;
}
try
{
//添加數據,姓名只允許添加不允許更改
strSQL="1";
m_pRecordset->AddNew();
m_pRecordset->PutCollect("圖書ID",_variant_t(m_optbid));
m_pRecordset->PutCollect("圖書名稱",_variant_t(mbookname));
m_pRecordset->PutCollect("借閱ID",_variant_t(m_optuid));
m_pRecordset->PutCollect("借閱次數",_variant_t(strSQL));
COleDateTime oleTime;
CDateTimeCtrl* pDtCtrl=(CDateTimeCtrl*)GetDlgItem(IDC_DATETIMEPICKER);
pDtCtrl->GetTime(oleTime);
m_pRecordset->PutCollect("借閱日期",_variant_t(oleTime));
//更新數據庫
m_pRecordset->Update();
m_pRecordset->MoveLast();
//m_pRecordset->Close();
//m_pRecordset=NULL;
}
catch(_com_error e)
{
CString strError;
strError.Format("警告:該圖書可能已經被借閱! 錯誤信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
return;
}
m_pRecordset->Close();
m_pRecordset=NULL;
AfxMessageBox("借閱成功!");
CDialog::OnCancel();
}
else
{
AfxMessageBox("沒有該用戶");
return;
}
}
else if(m_option==2)
{
BORROWLIST dlg;
dlg.m_getblid=m_optuid;
dlg.DoModal();
}
else if(m_option==3)
{
strSQL.Format("delete * from 借閱信息表 where 圖書ID='%s' ",m_optbid);
if (MessageBox("是否歸還該圖書?","確認",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
return;
}
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("沒有成功打開數據表");
return ;
}
AfxMessageBox("歸還操作成功!該圖書可能沒有借閱記錄!");
}
else
AfxMessageBox("Error!");
}
BOOL OPERATE::OpenRecordSet(_RecordsetPtr &recPtr, CString &strSQL)
{
CMyApp* pApp=(CMyApp*)AfxGetApp();
//創建記錄集對象
m_pRecordset.CreateInstance(__uuidof(Recordset));
//在ADO操作中建議語句中要常用try...catch()來捕獲錯誤信息,
//因為它有時會經常出現一些想不到的錯誤
try
{
//從數據庫中打開表
recPtr->Open(strSQL.AllocSysString(),
pApp->m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch (_com_error e)
{
CString strError;
strError.Format("警告:打開數據表時發生異常。 錯誤信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -