?? studquery.cpp
字號:
// STUDQUERY.cpp : implementation file
//
#include "stdafx.h"
#include "圖書館系統.h"
#include "STUDQUERY.h"
#include "STUDINFO.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// STUDQUERY dialog
STUDQUERY::STUDQUERY(CWnd* pParent /*=NULL*/)
: CDialog(STUDQUERY::IDD, pParent)
{
//{{AFX_DATA_INIT(STUDQUERY)
m_studbno = _T("");
//}}AFX_DATA_INIT
}
void STUDQUERY::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(STUDQUERY)
DDX_Text(pDX, IDC_STUD_BNO, m_studbno);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(STUDQUERY, CDialog)
//{{AFX_MSG_MAP(STUDQUERY)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////"ZASDA"
// STUDQUERY message handlers
BOOL STUDQUERY::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
SetWindowText(m_strTitle);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void STUDQUERY::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
m_studbno.Remove(' ');
if(m_studbno.IsEmpty())
{
AfxMessageBox("借閱ID不能為空");
return;
}
if(bdelete)
{
if (MessageBox("你確定要刪除該用戶信息嗎?","刪除確認",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
return;
}
CString strSQL;
strSQL.Format("delete * from 借閱人員表 where 借閱ID='%s'",m_studbno);
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("沒有成功打開數據表");
return;
}
strSQL.Format("delete * from 借閱信息表 where 借閱ID='%s'",m_studbno);
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("沒有成功打開數據表");
return;
}
AfxMessageBox("刪除成功!");
}
else
{
CString strSQL;
strSQL.Format("select * from 借閱人員表 where 借閱ID='%s'",m_studbno);
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("沒有成功打開數據表");
return;
}
if(m_pRecordset->adoEOF)
{
AfxMessageBox("該用戶不存在!");
return ;
}
STUDINFO pST;
pST.bookborno=m_studbno;
pST.DoModal();
}
CDialog::OnOK();
}
BOOL STUDQUERY::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 + -