📄 mainfrm.cpp
字号:
// MainFrm.cpp : CMainFrame 类的实现
//
#include "stdafx.h"
#include "QueryTerminal.h"
#include "QueryTerminalView.h"
#include "MainFrm.h"
#include ".\mainfrm.h"
#include <iostream>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//using namespace std;
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_BN_CLICKED(IDC_BTN_OPENFILE, OnBnClickedBtnOpenfile)
ON_BN_CLICKED(IDC_BTN_QUERY, OnBnClickedBtnQuery)
ON_COMMAND(ID_MENU_SHOW_STATUS, OnMenuShowStatus)
ON_UPDATE_COMMAND_UI(ID_MENU_SHOW_STATUS, OnUpdateMenuShowStatus)
ON_BN_CLICKED(IDC_BTN_RTN_SHOW, OnBnClickedBtnRtnShow)
ON_WM_TIMER()
ON_COMMAND(ID_PRINT_QUERYDATA, OnPrintQuerydata)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // 状态行指示器
ID_INDICATOR_MSG,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
// CMainFrame 构造/析构
CMainFrame::CMainFrame()
{
// TODO: 在此添加成员初始化代码
theApp.ClearAllWxccData();
}
CMainFrame::~CMainFrame()
{
theApp.ClearAllWxccData();
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("未能创建状态栏\n");
return -1; // 未能创建
}
if (!m_wndQueryCtlBar.Create(this, IDD_DLG_QUERY_CTL, CBRS_ALIGN_TOP | CBRS_FLYBY, 100) /*||!m_wndReplay.Init()*/)
{
TRACE0("未能创建查询控制条\n");
return -1;
}
// TODO: 如果不需要可停靠,则删除这三行
/*m_wndQueryCtlBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndQueryCtlBar);*/
m_DlgRevStus.Create(IDD_DLG_REVMSG_STUS,this);
m_DlgRevStus.ShowWindow(SW_HIDE);
UpdateCtlBarComboData();
IniRevStusListctrlData();
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
// 样式
return TRUE;
}
// CMainFrame 诊断
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
// CMainFrame 消息处理程序
void CMainFrame::OnBnClickedBtnOpenfile()
{
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"配置文件 (*.MZN)|*.MZN|所有文件 (*.*)|*.*||");
if (dlg.DoModal()!=IDOK)
{
Invalidate(FALSE);
return;
}
CStdioFile pfile;
if(!pfile.Open(dlg.GetPathName(),CFile::modeRead | CFile::typeText))
{
MessageBox("打开文件错误!","告警");
return;
}
theApp.ClearAllWxccData();
SetPaneText(ID_INDICATOR_MSG,"正在解析数据文件,请稍候……");
CString str,strTmp;
while(pfile.ReadString(str))
{
if(str.Find("82 00 01") == -1)
{
continue;
}
else
{
pfile.ReadString(strTmp);
if(!strTmp.IsEmpty())
{
int nBegin = strTmp.Find("时间:");
int nEnd = strTmp.Find(",版本号");
strTmp = strTmp.Mid(nBegin + 6,nEnd - nBegin - 6);
}
DealstrData(str,strTmp);
}
}
CQueryTerminalView *pView = (CQueryTerminalView *)GetActiveView();
pView->RefreshViewData(0);
CString strPanel;
int nCount = theApp.m_WxccMsgList.GetSize();
strPanel.Format("共有 %d 条记录",nCount);
this->SetPaneText(ID_INDICATOR_MSG,strPanel);
theApp.m_DisplayDataSort = FILE_ALL_DATA;
m_wndQueryCtlBar.SetRetBtnVisible(false);
}
void CMainFrame::OnBnClickedBtnQuery()
{
// TODO: 在此添加控件通知处理程序代码
int nSum = theApp.m_WxccMsgList.GetSize();
if(nSum <= 0)
{
MessageBox("没有可供查询的数据,请打开一个数据文件","提示");
return;
}
bool bStnFlag = m_wndQueryCtlBar.GetStnCheckStatus();
bool bTrainFlag = m_wndQueryCtlBar.GetTrainCheckStatus();
CString strStnNm,strTrain;
strStnNm = strTrain = "";
if(bTrainFlag) m_wndQueryCtlBar.GetEditBoxText(strTrain);
if(bStnFlag) strStnNm = m_wndQueryCtlBar.GetComboCurSelText();
if(!bStnFlag && !bTrainFlag)
{
MessageBox("请选择查询条件","提示");
return;
}
if(bTrainFlag && strTrain.IsEmpty())
{
MessageBox("请选择查询条件中,车次信息不能为空","提示");
return;
}
theApp.ClearAllWxccData(false);
SetPaneText(ID_INDICATOR_MSG,"正在搜索符合条件的数据,请稍候……");
CQueryTerminalView *pView = (CQueryTerminalView *)GetActiveView();
//查询数据
if(!GatherDataofAccordQuery(strStnNm,strTrain))
{
pView->RefreshViewData(1);
MessageBox("没有符合查询条件的数据","提示");
SetPaneText(ID_INDICATOR_MSG,"没有符合查询条件的数据");
m_wndQueryCtlBar.SetRetBtnVisible(true);
return;
}
pView->RefreshViewData(1);
CString strPanel;
int nCount = theApp.m_QueryMsgList.GetSize();
strPanel.Format("查询结果:共有 %d 条记录",nCount);
this->SetPaneText(ID_INDICATOR_MSG,strPanel);
//
theApp.m_DisplayDataSort = FILE_QUERY_DATA;
m_wndQueryCtlBar.SetRetBtnVisible(true);
}
void CMainFrame::OnMenuShowStatus()
{
if(!m_DlgRevStus.IsWindowVisible())
{
m_DlgRevStus.ShowWindow(SW_SHOW);
m_DlgRevStus.CenterWindow();
m_DlgRevStus.UpdateWindow();
}
else
{
m_DlgRevStus.ShowWindow(SW_HIDE);
}
}
void CMainFrame::OnUpdateMenuShowStatus(CCmdUI *pCmdUI)
{
if(m_DlgRevStus.IsWindowVisible())
{
pCmdUI->SetText("隐藏信息接收状况");
}
else
{
pCmdUI->SetText("显示信息接收状况");
}
}
// 更新查询控制栏组合框内容
void CMainFrame::UpdateCtlBarComboData(void)
{
int nSum = theApp.m_StnRelaMsgList.GetSize();
if(nSum <= 0) return;
this->m_wndQueryCtlBar.RemoveAllComboData();
STATUS_STN_REVWWCC *pStus = NULL;
for(int i=0 ;i< nSum; i++)
{
pStus = (STATUS_STN_REVWWCC *)theApp.m_StnRelaMsgList.GetAt(i);
if(pStus == NULL) continue;
if(pStus->strStnNm.IsEmpty()) continue;
this->m_wndQueryCtlBar.AddComboData(pStus->strStnNm);
}
m_wndQueryCtlBar.SetComboCursel(0);
}
void CMainFrame::DealstrData(CString strOrg,CString strRevTime)
{
if(strOrg.IsEmpty())
return;
strOrg.Remove(' ');
strOrg.MakeLower();
int nCount = strOrg.GetLength();
if(nCount%2 != 0) return;
BYTE *pbyteArray = new BYTE[nCount/2];
HexStrConvertToBytes(strOrg,nCount,pbyteArray);
CheckDataAndParse(pbyteArray,nCount/2,strRevTime);
delete[] pbyteArray;
}
void CMainFrame::CheckDataAndParse(BYTE* pData,int nLen,CString strRevTime)
{
if(pData == NULL || nLen < 15) return;
if(pData[0] != 0x82) return;
WORD ndatalen = *(WORD *)&pData[7];
if(nLen != ndatalen + 9) return;
ndatalen = *(WORD *)&pData[13];
if(nLen != ndatalen + 15) return;
BYTE nMsgId = pData[12];
WORD nStnCode = *(WORD *)&pData[10];
switch(nMsgId)
{
case 0x08:
TransformWxccDataV1(nStnCode,&pData[15],ndatalen,strRevTime);
break;
case 0x18:
TransformWxccDataV2(nStnCode,&pData[15],ndatalen,strRevTime);
break;
default:
TRACE("\n未知类型的数据!");
break;
}
}
void CMainFrame::TransformWxccDataV1(WORD StnCode,BYTE *pData,int nlen,CString strRevTime)
{
if(pData == NULL || nlen != 33)
{
return;
}
WXCC_RELAMSG* pMsg = new WXCC_RELAMSG();
pMsg->nMsgVer = 2;
pMsg->strTime = strRevTime;
theApp.m_WxccMsgList.Add(pMsg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -