📄 borrowinfo.cpp
字号:
// BORROWINFO.cpp : implementation file
//
#include "stdafx.h"
#include "图书馆系统.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);
//当前对话框是否用来编辑,图书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);
//设置查询语句
CString strSQL;
strSQL.Format("select * from 借阅信息表 where 图书ID='%s'",m_getid);
//打开记录集 选择表名
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("没有成功打开数据表");
return FALSE;
}
//应该只有一条记录
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("借阅次数"));
m_bordate=pLeftView->VariantToCString(m_pRecordset->GetCollect("借阅日期"));
m_today=(long)m_datatime;
m_datatime=m_pRecordset->GetCollect("借阅日期");
m_ytoday=(long)m_datatime;//计算借阅天数
m_bordays.Format("%d",m_today-m_ytoday);
if(m_today-m_ytoday-60>0)//判断逾期天数
m_overdays.Format("%d",m_today-m_ytoday-60);
else
m_overdays.Format("0");
UpdateData(FALSE);
//关闭
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();
//创建记录集对象
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;
}
void CBORROWINFO::OnButtonDelete()
{
// TODO: Add your control notification handler code here
if (MessageBox("你确定要删除这条借阅信息吗?","删除确认",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
return;
}
CString strSQL;
strSQL.Format("delete * from 借阅信息表 where 图书ID='%s'",m_borid);
//打开记录集 选择表名
if(!OpenRecordSet(m_pRecordset,strSQL))
{
AfxMessageBox("没有成功打开数据表");
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("没有成功打开数据表");
return;
}
if(!m_pRecordset->BOF)
{
m_pRecordset->MoveFirst();
}
//上述准备完毕,下面开始插入内容
try
{
m_pRecordset->PutCollect("图书ID",_variant_t(m_borid));
m_pRecordset->PutCollect("借阅ID",_variant_t(m_borjid));
m_pRecordset->PutCollect("借阅次数",_variant_t(m_bortime));
m_pRecordset->PutCollect("借阅日期",_variant_t(m_bordate));
//更新数据库
m_pRecordset->Update();
//当前记录移动到最后
m_pRecordset->MoveLast();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告:插入信息时发生异常。错误信息: %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);
//当前对话框是否用来编辑,图书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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -