www.gusucode.com > VC++编写的SQL服务端和客户端源码程序 > VC++编写的SQL服务端和客户端源码程序\code\Server\SelView.cpp

    //Download by http://www.NewXing.com
// SelView.cpp : implementation file
//

#include "stdafx.h"
#include "miniSQL.h"
#include "SelView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSelView

IMPLEMENT_DYNCREATE(CSelView, CListView)

CSelView::CSelView()
{
	ItemIndex = 0;
}

CSelView::~CSelView()
{
}

BOOL CSelView::PreCreateWindow( CREATESTRUCT& cs )
{
	cs.style |= LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS;

	return CListView::PreCreateWindow( cs );
}

BEGIN_MESSAGE_MAP(CSelView, CListView)
	//{{AFX_MSG_MAP(CSelView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSelView drawing

void CSelView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CSelView diagnostics

#ifdef _DEBUG
void CSelView::AssertValid() const
{
	CListView::AssertValid();
}

void CSelView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSelView message handlers

void CSelView::InsertCol( CEntryAttr& attr )
{
	CListCtrl&	theCtrl = GetListCtrl();
	LV_COLUMN	LVColumn;
	int count = attr.num;

	DWORD dwStyle = ListView_GetExtendedListViewStyle( GetListCtrl() );
	dwStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES
			| LVS_EX_HEADERDRAGDROP | LVS_EX_TRACKSELECT;
	ListView_SetExtendedListViewStyle (GetListCtrl(),dwStyle);

	theCtrl.DeleteAllItems();

	LVColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	for ( int column = 0; column < count; column ++ ){
		LVColumn.fmt = LVCFMT_RIGHT;
		LVColumn.cx = GetLength( attr.attr[ column ].type );
		LVColumn.pszText = (LPTSTR) (LPCTSTR) attr.attr[ column ].name;
		LVColumn.iSubItem = column;
		theCtrl.InsertColumn( column, &LVColumn );
	}
}

int CSelView::GetLength( const CItemType& type )
{
	switch( type.id )
	{
	case _INT:
	case _LONG:
		return 40;
	case _FLOAT:
	case _DATE:
		return 80;
	case _STRING:
		return type.size * 7;
	default:
		throw Error( OUT_TYPE_ERROR, (int)type.id, CString("") );
	}
}

void CSelView::InsertItem( CEntry& entry )
{
	CListCtrl&	theCtrl = GetListCtrl();
	char		item[ 1024 ];
	int			count = entry.values();

	entry[0].out( item, 1024 );
	int curItemIndex = theCtrl.InsertItem( LVIF_TEXT | LVIF_PARAM, ItemIndex++, item, 0, 0, 0, 0 );

	for( int SubItemIndex = 1; SubItemIndex < count; SubItemIndex++ )
	{
		entry[ SubItemIndex ].out( item, 1024 );
		theCtrl.SetItem( curItemIndex, SubItemIndex, LVIF_TEXT, item, 0, 0, 0, 0 );
	}
}