📄 devicenrtdlg.cpp
字号:
// DeviceNRtDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DeviceDBS.h"
#include "DeviceNRtDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDeviceNRtDlg dialog
CDeviceNRtDlg::CDeviceNRtDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDeviceNRtDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDeviceNRtDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDeviceNRtDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDeviceNRtDlg)
DDX_Control(pDX, IDC_LIST_DEVICE, m_listDevice);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDeviceNRtDlg, CDialog)
//{{AFX_MSG_MAP(CDeviceNRtDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDeviceNRtDlg message handlers
BOOL CDeviceNRtDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//设置列表框控件扩展风格
DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES |
LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT;
m_listDevice.SetExtendedStyle(dwExStyle);
//初始化借出信息列表框控件
//添加设备编号列
LV_COLUMN lvColumn;
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvColumn.fmt = LVCFMT_CENTER;
lvColumn.cx = 80;
lvColumn.iSubItem = 0;
lvColumn.pszText = "设备编号";
m_listDevice.InsertColumn(0, &lvColumn);
//添加设备名称列
lvColumn.cx = 80;
lvColumn.iSubItem = 1;
lvColumn.pszText = "设备名称";
m_listDevice.InsertColumn(1, &lvColumn);
//添加借出人列
lvColumn.cx = 140;
lvColumn.iSubItem = 2;
lvColumn.pszText = "借出人";
m_listDevice.InsertColumn(2, &lvColumn);
//添加设备借出时间列
lvColumn.cx = 140;
lvColumn.iSubItem = 3;
lvColumn.pszText = "借出时间";
m_listDevice.InsertColumn(3, &lvColumn);
InitCtrlData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDeviceNRtDlg::InitCtrlData()
{
TRY{
CRecordset rs(m_pDB);
//打开记录.
CString sql = "select a.DEVICE_CODE,b.device_name,a.borrower,a.borrow_date "
"from device_lend_info_tab a,device_info_tab b "
"where a.lend_id = b.lend_id";
rs.Open(CRecordset::dynaset, sql);
while (!rs.IsEOF()) {
CString strCode,strName,strBorrower,strBorrowerDate;
//获取设备编号字段值
rs.GetFieldValue((short)0, strCode);
//获取设备名称字段值
rs.GetFieldValue(1, strName);
//获取设备借出人字段值
rs.GetFieldValue(2, strBorrower);
//获取设备借出时间字段值
rs.GetFieldValue(3, strBorrowerDate);
//获取当前的纪录条数.
int nIndex = m_listDevice.GetItemCount();
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT ;
lvItem.iItem = nIndex;
lvItem.iSubItem = 0;
lvItem.pszText = (char*)(LPCTSTR)strCode;
//在最后一行插入记录值.
m_listDevice.InsertItem(&lvItem);
//设置该行的其他列的值.
m_listDevice.SetItemText(nIndex,1,strName);
m_listDevice.SetItemText(nIndex,2,strBorrower);
m_listDevice.SetItemText(nIndex,3,strBorrowerDate);
rs.MoveNext();
}
rs.Close();
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CMemoryException,pEx)
{
pEx->ReportError();
AfxMessageBox ("memory exception");
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -