?? returnbookdlg.cpp
字號:
// ReturnBookDlg.cpp : implementation file
//
#include "stdafx.h"
#include "librarym.h"
#include "ReturnBookDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CReturnBookDlg dialog
CReturnBookDlg::CReturnBookDlg(CWnd* pParent /*=NULL*/)
: CDialog(CReturnBookDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CReturnBookDlg)
m_ReturnReaderID = _T("");
m_ReturnBookID = _T("");
//}}AFX_DATA_INIT
}
void CReturnBookDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReturnBookDlg)
DDX_Text(pDX, IDC_EDIT_RETURNREADERID, m_ReturnReaderID);
DDX_Text(pDX, IDC_EDIT_RETURNBOOKID, m_ReturnBookID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReturnBookDlg, CDialog)
//{{AFX_MSG_MAP(CReturnBookDlg)
ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
ON_BN_CLICKED(IDC_BUTTON_RETURN, OnButtonReturn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReturnBookDlg message handlers
BOOL CReturnBookDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//初始化數據庫連接
HRESULT result;
try
{
//實例化連接對象
result=m_pConnection.CreateInstance(_uuidof(Connection));
if(SUCCEEDED(result))
{
//設置連接屬性為UDL文件
m_pConnection->ConnectionString="File Name=LIBRARYM.udl";
//設置等待連接打開的時間為20s
m_pConnection->ConnectionTimeout=20;
result=m_pConnection->Open("","","",adConnectUnspecified);
if(FAILED(result))
{
AfxMessageBox("open failed");
return TRUE;
}
}
else
{
AfxMessageBox("createinstance of connection failed!");
return TRUE;
}
}
catch(_com_error e)
{
//輸出異常信息
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
AfxMessageBox(bstrSource+bstrDescription);
return TRUE;
}
return TRUE;
}
void CReturnBookDlg::OnButtonCancel()
{
CDialog::OnCancel();
}
void CReturnBookDlg::OnButtonReturn()
{
UpdateData(TRUE);
CString strSql="delete from BorrowRelation where ";
CString addsql="select * from BookInfo where ";
CString temp;
CString temp1;
if(m_ReturnBookID.IsEmpty())
{
AfxMessageBox("book ID can't ne empty!",MB_OK);
return;
}
temp.Format("BookID='%s'",m_ReturnBookID);
temp1.Format("BookID='%s'",m_ReturnBookID);
strSql+=temp;
addsql+=temp1;
temp="";
if(m_ReturnReaderID.IsEmpty())
{
AfxMessageBox("Reader ID can't ne empty!",MB_OK);
return;
}
temp.Format("and ReaderID='%s'",m_ReturnReaderID);
strSql+=temp;
_RecordsetPtr pset;
pset.CreateInstance(_uuidof(Recordset));
int curItem=0;
_variant_t var;
CString addvalue; //還書后庫存+1
try
{
pset->Open(_variant_t(strSql),m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
pset->Open(_variant_t(addsql),m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
var=pset->GetCollect("Available");
addvalue=(LPCSTR)_bstr_t(var);
//把字符轉化為整型
int add=atoi(addvalue);
add++; //庫存里增加一本剛還的書
addvalue.Format("%d",add);
//把數據放回表BookInfo里,更新保存
pset->PutCollect("Available",_variant_t(addvalue));
pset->Update();
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return;
}
pset->Close();
pset=NULL;
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -