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

📄 accessdlg.cpp

📁 美国Solartron测量设备的演示程序,带数据库和图形显示功能
💻 CPP
字号:
// AccessDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Demo.h"
#include "AccessDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAccessDlg dialog


CAccessDlg::CAccessDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAccessDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAccessDlg)
	m_fAverage = 0.0f;
	m_fMax = 0.0f;
	m_fMin = 0.0f;
	//}}AFX_DATA_INIT
}


void CAccessDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAccessDlg)
	DDX_Control(pDX, IDC_Datebase, m_Display);
	DDX_Text(pDX, IDC_Average, m_fAverage);
	DDX_Text(pDX, IDC_Max, m_fMax);
	DDX_Text(pDX, IDC_Min, m_fMin);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAccessDlg, CDialog)
	//{{AFX_MSG_MAP(CAccessDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAccessDlg message handlers

BOOL CAccessDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	DWORD style;
	style=m_Display.GetExtendedStyle();
	m_Display.SetExtendedStyle(style|LVS_EX_GRIDLINES);

	RECT rect;
	m_Display.GetViewRect(&rect);

	LV_COLUMN LVColumn;
	LVColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	LVColumn.iSubItem	= 0;
	LVColumn.cx			= 90;
	LVColumn.fmt		= LVCFMT_LEFT;

	LVColumn.pszText="Sequence";
	m_Display.InsertColumn(0,&LVColumn);
	LVColumn.pszText="TempValue";
	m_Display.InsertColumn(1,&LVColumn);
	LVColumn.pszText="BaseValue";
	m_Display.InsertColumn(2,&LVColumn);
	LVColumn.pszText="RealValue";
	m_Display.InsertColumn(3,&LVColumn);
	LVColumn.pszText="Uplimit";
	m_Display.InsertColumn(4,&LVColumn);
	LVColumn.pszText="Lowlimit";
	m_Display.InsertColumn(5,&LVColumn);
	LVColumn.pszText="Result";
	m_Display.InsertColumn(6,&LVColumn);

	m_Display.DeleteAllItems();	

	ConnectToAccess();
	LoadDataFromAccess();
	DisconnectToAccess();

	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CAccessDlg::LoadDataFromAccess()
{
	_variant_t var;
	CString strSequence,strTempValue,strBaseValue,strRealValue,strUplimit,strLowlimit,strResult;
	strSequence=strTempValue=strBaseValue=strRealValue=strUplimit=strLowlimit=strResult="";

	int i=0;
	try
	{
		if(!m_pRecordset->BOF)
			m_pRecordset->MoveFirst();
		else
		{
			AfxMessageBox("The content is blank");
		}

		while(!m_pRecordset->adoEOF)
		{
			var=m_pRecordset->GetCollect("Sequence");
			if(var.vt==VT_NULL)
				strSequence="";
			else
				strSequence.Format("%d",var.lVal);

			var=m_pRecordset->GetCollect("TempValue");
			if(var.vt==VT_NULL)
				strTempValue="";
			else
				strTempValue.Format("%.4f",var.fltVal);

			var=m_pRecordset->GetCollect("BaseValue");
			if(var.vt==VT_NULL)
				strBaseValue="";
			else
				strBaseValue.Format("%.4f",var.fltVal);

			var=m_pRecordset->GetCollect("RealValue");
			if(var.vt==VT_NULL)
				strRealValue="";
			else
				strRealValue.Format("%.4f",var.fltVal);

			var=m_pRecordset->GetCollect("Uplimit");
			if(var.vt==VT_NULL)
				strUplimit="";
			else
				strUplimit.Format("%.4f",var.fltVal);

			var=m_pRecordset->GetCollect("Lowlimit");
			if(var.vt==VT_NULL)
				strLowlimit="";
			else
				strLowlimit.Format("%.4f",var.fltVal);

			var=m_pRecordset->GetCollect("Result");

			if(var.vt==VT_NULL)
				strResult="";
			else
			{
				CString str;
				str=(const char*)(_bstr_t)var;
				strResult.Format("%s",str);
/*
				COLORREF m_colorRed,m_colorGreen,m_colorBlue;
				m_colorRed=RGB(255,0,0);
				m_colorGreen=RGB(0,255,0);
				m_colorBlue=RGB(0,0,255);

				
				if(str.GetLength()==10)
					m_Display.SetTextColor(m_colorRed);
				else
					if(str.GetLength()==3)
						m_Display.SetTextColor(m_colorGreen);
					else
						if(str.GetLength()==11)
						m_Display.SetTextColor(m_colorBlue);
*/
			}

			m_Display.InsertItem(i,"");

			m_Display.SetItemText(i,0,strSequence);
			m_Display.SetItemText(i,1,strTempValue);
			m_Display.SetItemText(i,2,strBaseValue);
			m_Display.SetItemText(i,3,strRealValue);
			m_Display.SetItemText(i,4,strUplimit);
			m_Display.SetItemText(i,5,strLowlimit);
			m_Display.SetItemText(i,6,strResult);

			i++;			

			m_pRecordset->MoveNext();

		}
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}

	m_pRecordset->Close();
}

void CAccessDlg::ConnectToAccess()
{
	m_pConnection.CreateInstance(__uuidof(Connection));
	try
	{
		m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Solartron.mdb","","",adModeUnknown);
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}


	m_pRecordset.CreateInstance(__uuidof(Recordset));
	try
	{
		m_pRecordset->Open("SELECT * FROM Orbit",_variant_t((IDispatch *)m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
}

void CAccessDlg::DisconnectToAccess()
{
	
	if(m_pRecordset->State)
	{
		m_pRecordset->Close();
		m_pRecordset=NULL;
	}

	if(m_pConnection->State)
	{
		m_pConnection->Close();
		m_pConnection=NULL;
	}
}

⌨️ 快捷键说明

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