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

📄 demodbview.cpp

📁 一个完备的组态软件源代码
💻 CPP
字号:
// DemoDBView.cpp : implementation of the CDemoDBView class
//

#include "stdafx.h"
#include "DemoDB.h"

#include "DemoDBDoc.h"
#include "DemoDBView.h"

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

IMPLEMENT_DYNCREATE(CDemoDBView, CListView)

BEGIN_MESSAGE_MAP(CDemoDBView, CListView)
	//{{AFX_MSG_MAP(CDemoDBView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}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)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDemoDBView construction/destruction

CDemoDBView::CDemoDBView()
{
	// TODO: add construction code here

}

CDemoDBView::~CDemoDBView()
{
}

BOOL CDemoDBView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	cs.lpszName = WC_LISTVIEW;
	cs.style |= LVS_SHOWSELALWAYS | LVS_REPORT ;

	return CListView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDemoDBView drawing

void CDemoDBView::OnDraw(CDC* pDC)
{
	CDemoDBDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

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


	// TODO: You may populate your ListView with items by directly accessing
	//  its list control through a call to GetListCtrl().

	DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | 
							LVS_EX_HEADERDRAGDROP | LVS_EX_TRACKSELECT;
	GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LPARAM(dwExStyle));	

    int cols=8;
	LV_COLUMN lvColumn;
	lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvColumn.fmt = LVCFMT_LEFT;	
	lvColumn.cx = 70;
 
	for(int i = 0; i < cols; i++) // set up columns
	{
		char temp[20] ;
		if (i==0) strcpy(temp,"年");
		if (i==1) strcpy(temp, "月");
		if (i==2) strcpy(temp, "日");
		if (i==3) strcpy(temp, "时");
		if (i==4) strcpy(temp, "分");
		if (i==5) strcpy(temp, "终端");
		if (i==6) strcpy(temp, "参数");
		if (i==7) strcpy(temp, "数值");

 		int len = strlen(temp);
		lvColumn.iSubItem = i;
 		lvColumn.pszText = temp;
		GetListCtrl().InsertColumn(i, &lvColumn);//insert column
	}
	
	RETCODE rcode;
	HENV    henv;
	HDBC	hdbc;
	HSTMT	hstmt;

	char	szBuf[50];
	SDWORD	sdODataLength;
	unsigned char conStringOut[256];

	rcode=::SQLAllocEnv(&henv);
	if (rcode==SQL_SUCCESS)
	{
		rcode=::SQLAllocConnect(henv,&hdbc);
		if (rcode==SQL_SUCCESS)
		{
			rcode=::SQLDriverConnect(hdbc,0,
				    (unsigned char*)"DSN=Rms2000",
					SQL_NTS,conStringOut,256,NULL,
					SQL_DRIVER_NOPROMPT);
			if (rcode==SQL_SUCCESS)
			{
				rcode=::SQLAllocStmt(hdbc,&hstmt);
				if (rcode==SQL_SUCCESS)
				{
					rcode=::SQLExecDirect(hstmt,
						(unsigned char*)"SELECT * FROM 历史数据",
						SQL_NTS);
					if (rcode==SQL_SUCCESS)
					{
						int row=0;
						for (rcode=::SQLFetch(hstmt);
						     rcode==SQL_SUCCESS;
							 rcode=::SQLFetch(hstmt))
						{
							LV_ITEM lvi; 
							lvi.iItem = row;
							lvi.mask = LVIF_TEXT;
							lvi.iSubItem = 0;
							lvi.pszText = "";
 							GetListCtrl().InsertItem(&lvi);
							for (int i=0;i<8;i++)
							{
								::SQLGetData(hstmt,i+1,SQL_C_CHAR,szBuf,50,&sdODataLength);
					  			GetListCtrl().SetItemText(row,i,szBuf);
							}
							row++;
 						}	

					}

					::SQLFreeStmt(hstmt,SQL_DROP);
				}

				::SQLDisconnect(hdbc);
			}
			::SQLFreeConnect(hdbc);
		}
		::SQLFreeEnv(henv);
	}

}

/////////////////////////////////////////////////////////////////////////////
// CDemoDBView printing

BOOL CDemoDBView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CDemoDBView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CDemoDBView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CDemoDBView diagnostics

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

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

CDemoDBDoc* CDemoDBView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDemoDBDoc)));
	return (CDemoDBDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDemoDBView message handlers

⌨️ 快捷键说明

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