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

📄 monitor.cpp

📁 本人工作中的一个软件开发实例。里面包含了数据库
💻 CPP
字号:
// Monitor.cpp: implementation of the CMonitor class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "OIL.h"
#include "Monitor.h"

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


BEGIN_MESSAGE_MAP(CMonitor, CFrameWnd)
	//{{AFX_MSG_MAP(CMonitor)
	ON_WM_TIMER()
	ON_MESSAGE(WM_COMMAND_CORRECT, OnCorrect)
    ON_MESSAGE(WM_COMMAND_TIMEOUT, OnTimeOut)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


BEGIN_EVENTSINK_MAP(CMonitor, CFrameWnd)
    //{{AFX_EVENTSINK_MAP(CMonitor)
	ON_EVENT(CMonitor, 4500, 2, OnESCommEventScommctrl1, VTS_I4 VTS_BSTR VTS_I4)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMonitor::CMonitor()
{
	 //创建窗口
	 Create(NULL,"",WS_OVERLAPPEDWINDOW,CRect(0,0,0,0)); 
	 
	 //创建标题栏
     CreateTitleLine();

     //动态创建轻油鹤位
     for(int i=0;i<theGlobal.nLightOilPickers;i++)
	 {
		 Monitor[i]= new CPickerMonitor(i);
	 }

	 //动态创建重油鹤位
	 for(i=theGlobal.nLightOilPickers;i<theGlobal.nLightOilPickers+theGlobal.nHeavyOilPickers;i++)
	 {
		 Monitor[i]= new CPickerMonitor(i);
	 }

     //每秒发一次
 	 SetTimer(1,1000,NULL);

	 //创建一个收发线程
	 m_pPicker=new CPicker(this,1);

	 //m_SComm.Create(NULL,0,CRect(0,0,0,0),this,4500);
	 //m_SComm.Open();    
}

//析构函数
CMonitor::~CMonitor()
{
     for(int i=0;i<theGlobal.nLightOilPickers+theGlobal.nHeavyOilPickers;i++)
	 {
		 delete Monitor[i];
	 }

	 //m_MyTimer.KillMyTimer();
	 //delete m_pPicker;
}

//创建标题拦
void CMonitor::CreateTitleLine(void)
{
	CRect rect;
	 rect.left = 10;
	 rect.top = 30;
	 rect.right = rect.left + 30;
	 rect.bottom = rect.top + 18;
	 //鹤位ID   10,40
	 m_strPickerID.Create("鹤位",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strPickerID.ShowWindow(SW_SHOW);

	 //总计发油  42,102
	 rect.left=rect.right;
	 rect.right=rect.left+70;
	 m_strTotalOil.Create("总计发油",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strTotalOil.ShowWindow(SW_SHOW);
 
	 //本班发油  104,164
	 rect.left=rect.right;
	 rect.right=rect.left+70;
	 m_strTurnOil.Create("本班发油",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strTurnOil.ShowWindow(SW_SHOW);

	 //空闲
	 rect.left=rect.right;
	 rect.right=rect.left+40;
	 m_strTemp.Create("空闲",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strTemp.ShowWindow(SW_SHOW);

	 //设置量
	 rect.left=rect.right;
	 rect.right=rect.left+75;
	 m_strSet.Create("设置量",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strSet.ShowWindow(SW_SHOW);

	 //已发量
	 rect.left=rect.right;
	 rect.right=rect.left+75;
	 m_strSend.Create("已发量",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strSend.ShowWindow(SW_SHOW);

	 //发油进度条
	 rect.left=rect.right;
	 rect.right=rect.left+90;
	 m_strProgress.Create("发油进度条",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strProgress.ShowWindow(SW_SHOW);

	 //当前量
	 rect.left=rect.right;
	 rect.right=rect.left+70;
	 m_strCurrent.Create("当前量",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strCurrent.ShowWindow(SW_SHOW);

	 //第二量
	 rect.left=rect.right;
	 rect.right=rect.left+65;
	 m_strSecond.Create("第二量",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strSecond.ShowWindow(SW_SHOW);

	 //第三量
	 rect.left=rect.right;
	 rect.right=rect.left+65;
	 m_strThird.Create("第三量",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strThird.ShowWindow(SW_SHOW);

	 //第四量
	 rect.left=rect.right;
	 rect.right=rect.left+65;
	 m_strForth.Create("第四量",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strForth.ShowWindow(SW_SHOW);

	 //第五量
	 rect.left=rect.right;
	 rect.right=rect.left+65;
	 m_strFifth.Create("第五量",WS_EX_CLIENTEDGE|ES_AUTOHSCROLL|ES_LEFT|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE,rect,AfxGetApp()->m_pMainWnd,0xffff);
	 m_strFifth.ShowWindow(SW_SHOW);
}

//显示与隐藏临控窗口
void CMonitor::ShowMonitor(BOOL bDisplay)
{
	if(bDisplay)   //显示
	{
		//显示标题
		m_strPickerID.ShowWindow(SW_SHOW);
		m_strTotalOil.ShowWindow(SW_SHOW);
		m_strTurnOil.ShowWindow(SW_SHOW);
		m_strTemp.ShowWindow(SW_SHOW);
		m_strSet.ShowWindow(SW_SHOW);
		m_strSend.ShowWindow(SW_SHOW);
		m_strProgress.ShowWindow(SW_SHOW);
		m_strCurrent.ShowWindow(SW_SHOW);
		m_strSecond.ShowWindow(SW_SHOW);
		m_strThird.ShowWindow(SW_SHOW);
		m_strForth.ShowWindow(SW_SHOW);
		m_strFifth.ShowWindow(SW_SHOW);

		//显示控件
		for(int i=0;i<theGlobal.nLightOilPickers+theGlobal.nHeavyOilPickers;i++)
		{
			 Monitor[i]->ShowPickerMonitor(true);
		}
	}
	else          //隐藏
	{
		//隐藏标题
		m_strPickerID.ShowWindow(SW_HIDE);
		m_strTotalOil.ShowWindow(SW_HIDE);
		m_strTurnOil.ShowWindow(SW_HIDE);
		m_strTemp.ShowWindow(SW_HIDE);
		m_strSet.ShowWindow(SW_HIDE);
		m_strSend.ShowWindow(SW_HIDE);
		m_strProgress.ShowWindow(SW_HIDE);
		m_strCurrent.ShowWindow(SW_HIDE);
		m_strSecond.ShowWindow(SW_HIDE);
		m_strThird.ShowWindow(SW_HIDE);
		m_strForth.ShowWindow(SW_HIDE);
		m_strFifth.ShowWindow(SW_HIDE);

		//隐藏控件
		for(int i=0;i<theGlobal.nLightOilPickers+theGlobal.nHeavyOilPickers;i++)
		{
			 Monitor[i]->ShowPickerMonitor(false);
		}
	}
}

//设置发油量
//nIndex为要设置发油量的鹤位
//lValue为要设置的发油量
BOOL CMonitor::AddSendOil(int nIndex,long int lValue)
{
   return Monitor[nIndex]->AddSendOil(nIndex,lValue);
}

//删除发油量
//nIndex为要删除发油量的鹤位
//
BOOL CMonitor::DelSendOil(int nIndex,int nSeq)
{
   return true;
}

//发油监控
void CMonitor::Polling()
{   
	//轻油模块监控
    for(int i=0;i<theGlobal.nLightOilPickers;i++)
	{
		char   pszTmp[50];
		itoa(i,pszTmp,10);
		int i=strlen(pszTmp);
        pszTmp[i]='*';
		pszTmp[++i]='\0';
		m_pPicker->SendData(pszTmp);
	}
	//重油模块监控
    for(i=theGlobal.nLightOilPickers;i<=theGlobal.nLightOilPickers+theGlobal.nHeavyOilPickers;i++)
	{
		char   pszTmp[50];
		itoa(i,pszTmp,10);
		int i=strlen(pszTmp);
        pszTmp[i]='*';
		pszTmp[++i]='\0';
		m_pPicker->SendData(pszTmp);
	}	
}

//每秒钟
void CMonitor::OnTimer(UINT nIDEvent) 
{
    Polling();
}

//通过接收数据正确
void CMonitor::OnCorrect(WPARAM strRcv,LPARAM port)
{
	CString strTmp="收到正确数据";
	strTmp+=strRcv;
	AfxMessageBox(strTmp);
}

//接收数据超时
//鹤位错误数加1,如果n次没收到数据定认为机器出问题
//设置鹤位不可用及红色警示
void CMonitor::OnTimeOut(WPARAM strRcv,LPARAM port)
{

	//AfxMessageBox("接收数据超时");
}

//响应事件
void CMonitor::OnESCommEventScommctrl1(long EventID, LPCTSTR DataString, long Flag) 
{
	// TODO: Add your control notification handler code here
	AfxMessageBox("通过事件");	
}

⌨️ 快捷键说明

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