www.pudn.com > duanxinfangwei.rar > FormView_ProductList.cpp
// FormView_ProductList.cpp : implementation file // #include "stdafx.h" #include "smspreventforgery.h" #include "FormView_ProductList.h" #include "DbInterface.h" #include#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CFormView_ProductList IMPLEMENT_DYNCREATE(CFormView_ProductList, CListView) CFormView_ProductList::CFormView_ProductList() { } CFormView_ProductList::~CFormView_ProductList() { } BEGIN_MESSAGE_MAP(CFormView_ProductList, CListView) //{{AFX_MSG_MAP(CFormView_ProductList) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFormView_ProductList drawing void CFormView_ProductList::OnDraw(CDC* pDC) { CDocument* pDoc = GetDocument(); // TODO: add draw code here } ///////////////////////////////////////////////////////////////////////////// // CFormView_ProductList diagnostics #ifdef _DEBUG void CFormView_ProductList::AssertValid() const { CListView::AssertValid(); } void CFormView_ProductList::Dump(CDumpContext& dc) const { CListView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CFormView_ProductList message handlers void CFormView_ProductList::OnInitialUpdate() { CListView::OnInitialUpdate(); /* 改变列表风格 */ CListCtrl &listctrl = GetListCtrl(); listctrl.ModifyStyle(0, LVS_REPORT); listctrl.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); /* 设定表头 */ listctrl.InsertColumn(1, "产品ID", LVCFMT_LEFT, 80); listctrl.InsertColumn(2, "产品名", LVCFMT_LEFT, 150); listctrl.InsertColumn(3, "进入系统时间", LVCFMT_LEFT, 150); /* 显示产品信息 */ CDbInterface db; std::list
productList; PRODUCTINFO productinfo; char buff[256]; if(db.GetProductList(productList)) { while(productList.size() > 0) { /* 取得单个产品 */ productinfo = productList.front(); productList.pop_front(); listctrl.InsertItem(LVIF_TEXT | LVIF_STATE, 0, 0, 0, 0, 0, 0); /* 显示产品信息 */ memset(buff, 0, sizeof(buff)); itoa(productinfo.productId, buff, 10); listctrl.SetItemText(0, 0, buff); listctrl.SetItemText(0, 1, productinfo.productName); listctrl.SetItemText(0, 2, productinfo.entertime); } } else { MessageBox("数据库操作错误", "错误", MB_OK | MB_ICONERROR); } return; }