📄 booklostdlg.cpp
字号:
// BookLostDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Library.h"
#include "BookLostDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBookLostDlg dialog
CBookLostDlg::CBookLostDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBookLostDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBookLostDlg)
m_strCode = _T("");
//}}AFX_DATA_INIT
}
void CBookLostDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBookLostDlg)
DDX_Control(pDX, IDC_LIST1, m_ctrList);
DDX_Text(pDX, IDC_EDIT_BOOK_CODE, m_strCode);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBookLostDlg, CDialog)
//{{AFX_MSG_MAP(CBookLostDlg)
ON_BN_CLICKED(IDC_BUTTON_LOST, OnButtonLost)
ON_BN_CLICKED(IDC_BUTTON_ALL, OnButtonAll)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBookLostDlg message handlers
BOOL CBookLostDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//设置列表
m_ctrList.InsertColumn(0,"图书编号");
m_ctrList.InsertColumn(1,"图书名称");
m_ctrList.InsertColumn(2,"图书类别");
m_ctrList.InsertColumn(3,"作者");
m_ctrList.InsertColumn(4,"出版社");
m_ctrList.InsertColumn(5,"图书价格");
m_ctrList.InsertColumn(6,"登记日期");
m_ctrList.InsertColumn(7,"备注说明");
m_ctrList.SetColumnWidth(0,60);
m_ctrList.SetColumnWidth(1,120);
m_ctrList.SetColumnWidth(2,80);
m_ctrList.SetColumnWidth(3,80);
m_ctrList.SetColumnWidth(4,80);
m_ctrList.SetColumnWidth(5,80);
m_ctrList.SetColumnWidth(6,80);
m_ctrList.SetColumnWidth(7,80);
m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBookLostDlg::OnButtonLost()
{
// TODO: Add your control notification handler code here
UpdateData();
if(m_strCode.IsEmpty())
{
AfxMessageBox("请输入待挂失的图书编号!");
return;
}
CString strSQL;
strSQL.Format("select * from bookInfo where code = '%s' ",m_strCode);
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
AfxMessageBox("打开数据库失败!");
return ;
}
if(m_recordset.GetRecordCount()==0)
{
AfxMessageBox("没有找到该图书!");
m_recordset.Close();
return;
}
m_recordset.Delete();
m_recordset.Close();
AfxMessageBox("图书挂失成功!",MB_ICONINFORMATION );
m_ctrList.DeleteAllItems();
//更新界面显示
m_strCode = _T("");
UpdateData(FALSE);
}
void CBookLostDlg::OnButtonAll()
{
// TODO: Add your control notification handler code here
CString strSQL;
strSQL.Format( "select * from bookInfo ");
RefreshData( strSQL);
}
void CBookLostDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int i = m_ctrList.GetSelectionMark();
m_strCode = m_ctrList.GetItemText(i,0);
UpdateData(FALSE);
*pResult = 0;
}
void CBookLostDlg::RefreshData(CString strSQL)
{
m_ctrList.DeleteAllItems();
m_ctrList.SetRedraw(FALSE);
UpdateData(TRUE);
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据库失败!","数据库错误",MB_OK);
return ;
}
int i=0;
CString strTime;
while(!m_recordset.IsEOF())
{
m_ctrList.InsertItem(i,m_recordset.m_code);
m_ctrList.SetItemText(i,1,m_recordset.m_name);
m_ctrList.SetItemText(i,2,m_recordset.m_type);
m_ctrList.SetItemText(i,3,m_recordset.m_writer);
m_ctrList.SetItemText(i,4,m_recordset.m_press);
m_ctrList.SetItemText(i,5,m_recordset.m_price);
strTime.Format("%d-%d-%d",m_recordset.m_in_date.GetYear(),m_recordset.m_in_date.GetMonth(),m_recordset.m_in_date.GetDay());
m_ctrList.SetItemText(i,6,strTime);
m_ctrList.SetItemText(i,7,m_recordset.m_brief);
i++;
m_recordset.MoveNext();
}
m_recordset.Close();
m_ctrList.SetRedraw(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -