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

📄 trenddoc.cpp

📁 此文件为VC++开发环境下的OPC client trend 源代码
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////
//
//  OPC Trend VC++ Client:	TrendDoc.CPP
//							(Source File)
//
/////////////////////////////////////////////////////////////////////////////
//
//          Author: Raphael Imhof
//    Initial Date: 11/04/98
//       $Workfile: TrendDoc.cpp $
//       $Revision: 1 $
//           $Date: 7/27/99 5:24p $
//   Target System: Microsoft Windows NT 4.0
//     Environment: Visual C++ 5.0 / OPC DataAccess 1.0 / 2.0
//         Remarks: 
//
/////////////////////////////////////////////////////////////////////////////
//
//     Description: implementation of the CTrendDoc class
//					
//
/////////////////////////////////////////////////////////////////////////////
//
//  History of Changes     (Please remove very old comments and blank lines!)
//            $Log: /IDK/OPCServer/clients/VC++/Trend/TrendDoc.cpp $
// 
// 1     7/27/99 5:24p Imhof
// 
// 1     7/27/99 5:20p Imhof
// 
// 6     1/15/99 7:04p Imhof
// Updated legal notice.
// 
// 5     12/15/98 10:30a Imhof
// Modifications for OPC 2.0
// 
// 4     11/06/98 5:53p Imhof
// Added header, comment and made some small code changes.
// 
// 
//  $Nokeywords:$ (To avoid useless search while checking in.)
/////////////////////////////////////////////////////////////////////////////
//  Copyright (C) 1998, Siemens Building Technologies, Inc. Landis Division
//
// SIEMENS BUILDING TECHNOLOGIES, INC. IS PROVIDING THE FOLLOWING
// EXAMPLES OF CODE AS SAMPLE ONLY.
//
// SIEMENS BUILDING TECHNOLOGIES, INC.  MAKES NO REPRESENTATIONS
// OR WARRANTIES OF ANY KIND  WITH RESPECT TO THE VALIDTY OF THE 
// CODES   OR   DESIRED   RESULTS   AND   DISCLAIMS   ALL   SUCH 
// REPRESENTATIONS   AND   WARRANTIES,  INCLUDING  FOR  EXAMPLE, 
// WARRANTIES  OF  MERCHANTABILITY  AND FITNESS FOR A PARTICULAR 
// PURPOSE.    SIEMENS  BUILIDNG  TECHNOLOGIES,  INC.  DOES  NOT 
// REPRESENT  OR  WARRANT  THAT  THE  FOLLOWING CODE SAMPLES ARE 
// ACCURATE, VALID, COMPLETE OR CURRENT.
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Trend.h"
#include "TrendDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTrendDoc

IMPLEMENT_DYNCREATE(CTrendDoc, CDocument)

BEGIN_MESSAGE_MAP(CTrendDoc, CDocument)
	//{{AFX_MSG_MAP(CTrendDoc)
	ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTrendDoc construction/destruction

CTrendDoc::CTrendDoc()
{
	// TODO: add one-time construction code here
	m_pItem = NULL;

}

CTrendDoc::~CTrendDoc()
{
}

BOOL CTrendDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	CArray<CGroup*, CGroup*>*	pGroups;
	unsigned int nGroups = 0;

	CTrendApp* pApp = (CTrendApp*) AfxGetApp();
	nGroups = pApp->GetInfoServer()->GetGroups(&pGroups);
	if(nGroups != 1) return FALSE;

	CItem*	pItem = NULL;
	if((*pGroups)[0]->AddItem(&pItem))
	{
		SetTitle(pItem->GetName());
		m_pItem = pItem;
		return pItem->LoadTrendData();
	}

	return FALSE;
}



/////////////////////////////////////////////////////////////////////////////
// CTrendDoc serialization

void CTrendDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CTrendDoc diagnostics

#ifdef _DEBUG
void CTrendDoc::AssertValid() const
{
	CDocument::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CTrendDoc commands

CItem* CTrendDoc::GetItem()
{
	return m_pItem;
}

void CTrendDoc::OnCloseDocument() 
{
	// TODO: Add your specialized code here and/or call the base class
	CArray<CGroup*, CGroup*>*	pGroups;
	unsigned int nGroups = 0;

	CTrendApp* pApp = (CTrendApp*) AfxGetApp();
	nGroups = pApp->GetInfoServer()->GetGroups(&pGroups);
	if((1 == nGroups) && (NULL != m_pItem))
	{
		(*pGroups)[0]->RemoveItem(&m_pItem);
	}
	
	CDocument::OnCloseDocument();
}

BOOL CTrendDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
		CWaitCursor	wait;
	
	// TODO: Add your specialized creation code here
	CArray<CGroup*, CGroup*>*	pGroups;
	unsigned int nGroups = 0;

	CTrendApp* pApp = (CTrendApp*) AfxGetApp();
	
	if(pApp->GetInfoServer()->IsConnected())
	{
		nGroups = pApp->GetInfoServer()->GetGroups(&pGroups);
		if(nGroups != 1) return FALSE;

		//exclude the item name from the path
		CString sItemName = lpszPathName;
		sItemName = sItemName.Right(sItemName.GetLength() - sItemName.ReverseFind(TCHAR('\\')) - 1);
		
		CItem*	pItem = NULL;
		if((*pGroups)[0]->AddItem(&pItem, sItemName))
		{
			SetTitle(pItem->GetName());
			m_pItem = pItem;
			return pItem->LoadTrendData();
		}
	}
	else
	{
		AfxMessageBox(IDS_CONNECT_OPC_SERVER_FIRST);
	}

	return FALSE;
}

void CTrendDoc::OnViewRefresh() 
{
	// TODO: Add your command handler code here
	CWaitCursor	wait;

	m_pItem->LoadTrendData();

	UpdateAllViews(NULL);
	
}

⌨️ 快捷键说明

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