?? dutcomputermanagerview.cpp
字號:
// DutComputerManagerView.cpp : implementation of the CDutComputerManagerView class
//
#include "stdafx.h"
#include "DutComputerManager.h"
#include <io.h>
#include <odbcinst.h>
#include <afxdb.h>
#include "DutComputerManagerDoc.h"
#include "DutComputerManagerView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDutComputerManagerView
IMPLEMENT_DYNCREATE(CDutComputerManagerView, CListView)
BEGIN_MESSAGE_MAP(CDutComputerManagerView, CListView)
//{{AFX_MSG_MAP(CDutComputerManagerView)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
ON_COMMAND(ID_FILE_TOEXCEL, OnFileToexcel)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
ON_REGISTERED_MESSAGE(WM_COLLUM_MESSAGE,OnCollumMessage)
ON_REGISTERED_MESSAGE(WM_QUERY_MESSAGE,OnQueryMessage)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDutComputerManagerView construction/destruction
CDutComputerManagerView::CDutComputerManagerView()
{
// TODO: add construction code here
m_plistCtrl=NULL;
m_bChanged=false;
m_pOutBar=NULL;
}
CDutComputerManagerView::~CDutComputerManagerView()
{
if(m_pOutBar!=NULL)
{
delete m_pOutBar;
m_pOutBar=NULL;
}
while(!m_dataList.IsEmpty( ))
{
m_dataList.RemoveHead();
}
}
BOOL CDutComputerManagerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style &= ~LVS_TYPEMASK;
cs.style |= LVS_REPORT;
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDutComputerManagerView drawing
void CDutComputerManagerView::OnDraw(CDC* pDC)
{
CDutComputerManagerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
#include "assert.h"
CString Collum[]={_T("序號"),_T("物品名稱"),_T("物品編號"),_T("狀態"),_T("來源"),_T("使用人"),_T("價格"),
_T("類別"),_T("校區"),_T("房間"),_T("備注"),_T("CPU"),_T("內存"),_T("硬盤"),_T("顯卡"),
_T("網卡"),_T("顯示器")};
int Collumlen[]={0,40,40,30,40,40,40,30,40,40,120,0,0,0,0,0,0,0,0};
void CDutComputerManagerView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
m_plistCtrl=&GetListCtrl();
m_plistCtrl->SetExtendedStyle(m_plistCtrl->GetExtendedStyle() | LVS_EX_FULLROWSELECT |LVS_EX_GRIDLINES);
for(int i=0;i<sizeof(Collum)/sizeof(CString);i++)
{
m_plistCtrl->InsertColumn(i,Collum[i], LVCFMT_CENTER, Collumlen[i]*2);
}
//m_pOutBar=new COutputBar();
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
}
/////////////////////////////////////////////////////////////////////////////
// CDutComputerManagerView printing
BOOL CDutComputerManagerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDutComputerManagerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDutComputerManagerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDutComputerManagerView diagnostics
#ifdef _DEBUG
void CDutComputerManagerView::AssertValid() const
{
CListView::AssertValid();
}
void CDutComputerManagerView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CDutComputerManagerDoc* CDutComputerManagerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDutComputerManagerDoc)));
return (CDutComputerManagerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDutComputerManagerView message handlers
void CDutComputerManagerView::InsertData()
{
CString str="";
m_plistCtrl->DeleteAllItems();
m_dataList.RemoveAll();
if(theApp.m_strSQL=="")return;
if(theApp.m_pConnection!=NULL)
{
CAdoRecordSet *pRecordset=new CAdoRecordSet(theApp.m_pConnection);
pRecordset->Open(theApp.m_strSQL);
_ItemDB dbbean;
CString str;
pRecordset->MoveFirst();
while(!pRecordset->IsEOF())
{
memset(&dbbean,0,sizeof(_dbbean));
pRecordset->GetCollect("id",dbbean.id);
pRecordset->GetCollect("serialnum",str);
strcpy(dbbean.serialnum,(LPCTSTR)str);
pRecordset->GetCollect("wname",str);
strcpy(dbbean.wname,(LPCTSTR)str);
pRecordset->GetCollect("status",str);
strcpy(dbbean.status,(LPCTSTR)str);
pRecordset->GetCollect("source",str);
strcpy(dbbean.source,(LPCTSTR)str);
pRecordset->GetCollect("user",str);
strcpy(dbbean.user,(LPCTSTR)str);
pRecordset->GetCollect("price",dbbean.price);
pRecordset->GetCollect("comment",str);
strcpy(dbbean.comment,(LPCTSTR)str);
pRecordset->GetCollect("cpu",str);
strcpy(dbbean.cpu,(LPCTSTR)str);
pRecordset->GetCollect("mem",str);
strcpy(dbbean.mem,(LPCTSTR)str);
pRecordset->GetCollect("harddisk",str);
strcpy(dbbean.harddisk,(LPCTSTR)str);
pRecordset->GetCollect("videocard",str);
strcpy(dbbean.videocard,(LPCTSTR)str);
pRecordset->GetCollect("netcard",str);
strcpy(dbbean.netcard,(LPCTSTR)str);
pRecordset->GetCollect("monitor",str);
strcpy(dbbean.monitor,(LPCTSTR)str);
pRecordset->GetCollect("type",str);
strcpy(dbbean.type,(LPCTSTR)str);
pRecordset->GetCollect("location",str);
strcpy(dbbean.location,(LPCTSTR)str);
pRecordset->GetCollect("area",str);
strcpy(dbbean.area,(LPCTSTR)str);
m_dataList.AddTail(dbbean);
pRecordset->MoveNext();
}
pRecordset->Close();
}
_dbbean dbbean;
char buf[20];
for(int i=0;i<m_dataList.GetCount();i++)
{
memset(&dbbean,0,sizeof(_dbbean));
POSITION pos=m_dataList.FindIndex(i);
dbbean=m_dataList.GetAt(pos);
// int tt=m_plistCtrl->InsertItem(i,dbbean.wname);
sprintf(buf,"%d",dbbean.id);
int tt=m_plistCtrl->InsertItem(i,buf);
if(tt!=-1)
{
int t=1;
m_plistCtrl->SetItemText(i,t++,dbbean.wname);
m_plistCtrl->SetItemText(i,t++,dbbean.serialnum);
m_plistCtrl->SetItemText(i,t++,dbbean.status);
m_plistCtrl->SetItemText(i,t++,dbbean.source);
m_plistCtrl->SetItemText(i,t++,dbbean.user);
sprintf(buf,"%f",dbbean.price);
m_plistCtrl->SetItemText(i,t++,buf);
m_plistCtrl->SetItemText(i,t++,dbbean.type);
m_plistCtrl->SetItemText(i,t++,dbbean.area);
m_plistCtrl->SetItemText(i,t++,dbbean.location);
m_plistCtrl->SetItemText(i,t++,dbbean.comment);
m_plistCtrl->SetItemText(i,t++,dbbean.cpu);
m_plistCtrl->SetItemText(i,t++,dbbean.mem);
m_plistCtrl->SetItemText(i,t++,dbbean.harddisk);
m_plistCtrl->SetItemText(i,t++,dbbean.videocard);
m_plistCtrl->SetItemText(i,t++,dbbean.netcard);
m_plistCtrl->SetItemText(i,t++,dbbean.monitor);
}
}
CString strMsg;
strMsg.Format(" 共有%d條記錄",m_dataList.GetCount());
strMsg=theApp.m_strSQL+strMsg;
//獲取主窗口指針
CMDIFrameWnd *m_pFrame=((CMDIFrameWnd*)AfxGetApp()->m_pMainWnd);
m_pFrame->SendMessage(WM_OUTLISTINFO_MESSAGE,(WPARAM)(LPCTSTR)strMsg,(LPARAM)0);
}
void CDutComputerManagerView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NMITEMACTIVATE *pItem=(NMITEMACTIVATE *)pNMHDR;
if(pItem!=NULL)
{
CString str;
str.Format("選擇的是 。2k19luwuuo。。%d",pItem->iItem);
MessageBox(str,"33");
}
*pResult = 0;
}
LRESULT CDutComputerManagerView::OnCollumMessage(WPARAM wParam, LPARAM lParam)
{
BOOL *bShowAll=(BOOL *)wParam;
if(m_plistCtrl!=NULL){
if(*bShowAll==TRUE){
for(int i=sizeof(Collum)/sizeof(CString)-6;i<sizeof(Collum)/sizeof(CString);i++)
m_plistCtrl->SetColumnWidth(i,70);
}
if(*bShowAll==FALSE){
for(int i=sizeof(Collum)/sizeof(CString)-6;i<sizeof(Collum)/sizeof(CString);i++)
m_plistCtrl->SetColumnWidth(i,0);
}
}
return 0;
}
LRESULT CDutComputerManagerView::OnQueryMessage(WPARAM wParam, LPARAM lParam)
{
InsertData();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -