MainFrm.cpp
资源名称:PasRTDat.rar [点击查看]
上传用户:shtiemo
上传日期:2017-12-29
资源大小:163k
文件大小:7k
源码类别:
能源行业(电力石油煤炭)
开发平台:
Visual C++
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "PasRTDat.h"
- #include "MainFrm.h"
- #include "RTDatOpr.h"
- #include "TimeDlg.h"
- #include "PerDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_COMMAND(ID_RTDAT_AUTOREAD, OnRtdatAutoread)
- ON_COMMAND(ID_RTDAT_AUTOSAVE, OnRtdatAutosave)
- ON_COMMAND(ID_RTDAT_GETRTDAT, OnRtdatGetrtdat)
- ON_COMMAND(ID_RTDAT_READRTDAT, OnRtdatReadrtdat)
- ON_COMMAND(ID_RTDAT_SAVERTDAT, OnRtdatSavertdat)
- ON_COMMAND(ID_RTDAT_SENDRTDAT, OnRtdatSendrtdat)
- ON_COMMAND(ID_RTDAT_SETPERIOD, OnRtdatSetperiod)
- ON_COMMAND(ID_RTDAT_SETTIME, OnRtdatSettime)
- ON_UPDATE_COMMAND_UI(ID_RTDAT_AUTOREAD, OnUpdateRtdatAutoread)
- ON_UPDATE_COMMAND_UI(ID_RTDAT_AUTOSAVE, OnUpdateRtdatAutosave)
- ON_WM_TIMER()
- ON_WM_DESTROY()
- ON_WM_CLOSE()
- ON_COMMAND(ID_RTDAT_RTUMEA, OnRtdatRtumea)
- ON_UPDATE_COMMAND_UI(ID_RTDAT_RTUMEA, OnUpdateRtdatRtumea)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- #define RTDAT_TIMERID 1000 // Timer ID
- #define RTDAT_TIMEER_TIME 1000 // 定时时间间隔
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- if (!m_wndToolBar.Create(this) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- // TODO: Remove this if you don't want tool tips or a resizeable toolbar
- m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- SetTimer (RTDAT_TIMERID, RTDAT_TIMEER_TIME, NULL);
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CMDIFrameWnd::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CMDIFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CMDIFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- void CMainFrame::OnRtdatAutoread()
- {
- // TODO: Add your command handler code here
- if (bAutoSave)
- {
- AfxMessageBox("请先停止自动保存操作!", MB_OK);
- return ;
- }
- if (!bAutoRead)
- {
- if (AfxMessageBox("确定要自动发送数据到ADM?", MB_OKCANCEL||MB_ICONEXCLAMATION) == IDOK)
- bAutoRead = !bAutoRead;
- }
- else
- bAutoRead = !bAutoRead;
- }
- void CMainFrame::OnRtdatAutosave()
- {
- // TODO: Add your command handler code here
- if (bAutoRead)
- {
- AfxMessageBox("请先停止自动读取操作!", MB_OK);
- return ;
- }
- bAutoSave = !bAutoSave;
- }
- void CMainFrame::OnRtdatGetrtdat()
- {
- // TODO: Add your command handler code here
- if (bAutoRead || bAutoSave)
- {
- AfxMessageBox("请先停止自动操作再进行!", MB_OK);
- return ;
- }
- GetAllRTData();
- }
- void CMainFrame::OnRtdatReadrtdat()
- {
- // TODO: Add your command handler code here
- if (bAutoRead || bAutoSave)
- {
- AfxMessageBox("请先停止自动操作再进行!", MB_OK);
- return ;
- }
- CFileDialog Dlg(TRUE, NULL, "C:\IES500\PARAM\实时数据\*.DAT");
- if (Dlg.DoModal() == IDOK)
- {
- CString strFile = Dlg.GetPathName();
- if (!LoadRTDataFromFile(strFile))
- AfxMessageBox("读数据文件失败!");
- else
- Ary2ToAry1();
- }
- }
- void CMainFrame::OnRtdatSavertdat()
- {
- // TODO: Add your command handler code here
- if (bAutoRead || bAutoSave)
- {
- AfxMessageBox("请先停止自动操作再进行!", MB_OK);
- return ;
- }
- saveAllRTDataToFile();
- }
- void CMainFrame::OnRtdatSendrtdat()
- {
- // TODO: Add your command handler code here
- if (bAutoRead || bAutoSave)
- {
- AfxMessageBox("请先停止自动操作再进行!", MB_OK);
- return ;
- }
- if (AfxMessageBox("确定要发送数据到ADM?", MB_OKCANCEL||MB_ICONEXCLAMATION) == IDOK)
- SendAllDataToADM();
- }
- void CMainFrame::OnRtdatSetperiod()
- {
- // TODO: Add your command handler code here
- CPerDlg PerDlg;
- PerDlg.m_nSeconds = nSeconds;
- if (PerDlg.DoModal() == IDOK) nSeconds = PerDlg.m_nSeconds;
- }
- void CMainFrame::OnRtdatSettime()
- {
- // TODO: Add your command handler code here
- CTimeDlg TimeDlg;
- CTime Time = CTime::GetCurrentTime();
- TimeDlg.m_nDay = Time.GetDay();
- TimeDlg.m_nHour = Time.GetHour();
- TimeDlg.m_nMinute = Time.GetMinute();
- if (TimeDlg.DoModal() == IDOK)
- {
- DatStartTime = CTime(Time.GetYear(), Time.GetMonth(), TimeDlg.m_nDay
- ,TimeDlg.m_nHour, TimeDlg.m_nMinute, Time.GetSecond());
- StartTime = CTime::GetCurrentTime();
- }
- }
- void CMainFrame::OnUpdateRtdatAutoread(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- if (bAutoRead) pCmdUI->SetCheck(TRUE);
- else pCmdUI->SetCheck(FALSE);
- }
- void CMainFrame::OnUpdateRtdatAutosave(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- if (bAutoSave) pCmdUI->SetCheck(TRUE);
- else pCmdUI->SetCheck(FALSE);
- }
- void CMainFrame::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- // 事件触发处理
- if (BeSCADAEventProcess())
- nSecond = nSeconds;
- else
- nSecond++;
- if (bAutoSave && nSecond >= nSeconds)
- {
- GetAllRTData();
- saveAllRTDataToFile();
- }
- if (nSecond >= nSeconds) nSecond = 0; // 不保存也同样清0!!!
- if (bAutoRead)
- {
- CString strFile;
- CTime Time = CTime::GetCurrentTime();
- CTime DatTime = DatStartTime + (Time - StartTime);
- strFile.Format("C:\IES500\PARAM\实时数据\实时数据%02d%02d%02d%02d.dat", DatTime.GetDay(), DatTime.GetHour(),
- DatTime.GetMinute(), DatTime.GetSecond());
- if (LoadRTDataFromFile(strFile))
- {
- Ary2ToAry1();
- SendAllDataToADM();
- }
- }
- CMDIFrameWnd::OnTimer(nIDEvent);
- }
- void CMainFrame::OnDestroy()
- {
- CMDIFrameWnd::OnDestroy();
- // TODO: Add your message handler code here
- KillTimer(RTDAT_TIMERID);
- }
- void CMainFrame::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
- if (AfxMessageBox("确定要退出?", MB_OKCANCEL) == IDOK)
- CMDIFrameWnd::OnClose();
- }
- void CMainFrame::OnRtdatRtumea()
- {
- // TODO: Add your command handler code here
- bRTUMea = !bRTUMea;
- }
- void CMainFrame::OnUpdateRtdatRtumea(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- if (bRTUMea) pCmdUI->SetCheck(1);
- else pCmdUI->SetCheck(0);
- }