⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dutcomputermanagerview.cpp

📁 利用CJ60库创建界面
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 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 + -