【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了FreqListDlg.cpp提供大家参考,希望对大家有所帮助!
// FreqListDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DeviceDBS.h"
#include "FreqListDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFreqListDlg dialog
CFreqListDlg::CFreqListDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFreqListDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFreqListDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CFreqListDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFreqListDlg)
DDX_Control(pDX, IDC_LIST_LEND, m_listLend);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFreqListDlg, CDialog)
//{{AFX_MSG_MAP(CFreqListDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFreqListDlg message handlers
BOOL CFreqListDlg::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_listLend.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_listLend.InsertColumn(0, &lvColumn);
//添加设备名称列
lvColumn.cx = 80;
lvColumn.iSubItem = 1;
lvColumn.pszText = "设备名称";
m_listLend.InsertColumn(1, &lvColumn);
//添加使用次数列
lvColumn.cx = 140;
lvColumn.iSubItem = 2;
lvColumn.pszText = "使用次数";
m_listLend.InsertColumn(2, &lvColumn);
InitCtrlData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CFreqListDlg::InitCtrlData()
{
TRY{
CRecordset rs(m_pDB);
//打开记录.
CString sql = "select a.DEVICE_CODE,b.device_name,count(a.DEVICE_CODE) "
"from DEVICE_LEND_INFO_TAB a,device_info_tab b "
"where a.device_code = b.device_code "
"group by a.DEVICE_CODE,b.device_name";
rs.Open(CRecordset::dynaset, sql);
while (!rs.IsEOF()) {
int nCount;
CString strCode,strName;
//获取设备编号字段值
rs.GetFieldValue((short)0, strCode);
//获取设备名称字段值
rs.GetFieldValue(1, strName);
CDBVariant var;
//获取统计信息字段值
rs.GetFieldValue(2, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
nCount = var.m_iVal;
//获取当前的纪录条数.
int nIndex = m_listLend.GetItemCount();
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT ;
lvItem.iItem = nIndex; //行数
lvItem.iSubItem = 0;
lvItem.pszText = (char*)(LPCTSTR)strCode; //第一列
//在最后一行插入记录值.
m_listLend.InsertItem(&lvItem);
//设置该行的其他列的值.
m_listLend.SetItemText(nIndex,1,strName);
CString temp;
temp.Format("%d",nCount);
m_listLend.SetItemText(nIndex,2,temp);
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
}
上一篇:
FreightOrderForm.cpp
下一篇:
如何当一个轻松的班主任