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

📄 mslview.cpp

📁 用CJ60Lib界面库制作的SQL数据库客户与服务器程序。
💻 CPP
字号:
// MSLView.cpp : implementation file
//

#include "stdafx.h"
#include "miniSQL.h"
#include "MSLView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMSLView

IMPLEMENT_DYNCREATE(CMSLView, CListView)

CMSLView::CMSLView()
{
}

CMSLView::~CMSLView()
{
}

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

	return CListView::PreCreateWindow( cs );
}

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

/////////////////////////////////////////////////////////////////////////////
// CMSLView drawing

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

void CMSLView::OnInitialUpdate()
{
	CListView::OnInitialUpdate();

	CListCtrl&	theCtrl = GetListCtrl();
	CMSLDoc*	pDoc = ( CMSLDoc* )GetDocument();
	LV_COLUMN	LVColumn;
	int count = pDoc->m_pTable->attr.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( pDoc->m_pTable->attr.attr.attr[column].type );
		LVColumn.pszText = (LPTSTR) (LPCTSTR) pDoc->m_pTable->attr.attr.attr[column].name;
		LVColumn.iSubItem = column;
		theCtrl.InsertColumn( column, &LVColumn );
	}

	CEntry		entry( pDoc->m_pTable->attr.attr );	
	char		item[ 1024 ];
	int			i = 0;
	long		rec = pDoc->m_pTable->tableAPI->FirstRec();

	while( rec != -1 )
	{
		pDoc->m_pTable->tableAPI->ReadRec( rec, &entry );
		entry[0].out( item, 1024 );
		int ItemIndex = theCtrl.InsertItem( LVIF_TEXT | LVIF_PARAM, i, item, 0, 0, 0, 0);

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

		rec = pDoc->m_pTable->tableAPI->NextRec( rec );
	}

	Message( "Successful : Select all from table.\n" );
}

/////////////////////////////////////////////////////////////////////////////
// CMSLView diagnostics

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

void CMSLView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}

/*CMSLDoc* CMSLView::GetDocument()
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMSLDoc)));
	return (CMSLDoc*)m_pDocument;
}*/
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMSLView message handlers
/*
void CMSLView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	CListCtrl&	theCtrl = GetListCtrl();
	CMSLDoc*	pDoc = GetDocument();
	CEntry		entry( pDoc->m_pTable->attr.attr );

	theCtrl.DeleteAllItems();
	
	char		item[ 1024 ];
	int			i = 0;
	int			count = pDoc->m_pTable->attr.attr.num;
	long		rec = pDoc->m_pTable->tableAPI->FirstRec();

	while( rec != -1 )
	{
		pDoc->m_pTable->tableAPI->ReadRec( rec, &entry );
		entry[0].out( item, 1024 );
		int ItemIndex = theCtrl.InsertItem( LVIF_TEXT | LVIF_PARAM, i++, item, 0, 0, 0, 0);

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

		rec = pDoc->m_pTable->tableAPI->NextRec( rec );
	}
}*/

int CMSLView::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("") );
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -