📄 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 + -