📄 alarminfo.cpp
字号:
// AlarmInfo.cpp : implementation file
//
#include "stdafx.h"
#include "gtmpeg.h"
#include "AlarmInfo.h"
#include "gtmpegWnd.h"
#include "GridCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
TCHAR *sReportTitle[]={"","日期","位置","状态"};
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(CAlarmInfo, CPropertyPage)
CAlarmInfo::CAlarmInfo() : CPropertyPage(CAlarmInfo::IDD)
{
//{{AFX_DATA_INIT(CAlarmInfo)
m_EndDate = COleDateTime::GetCurrentTime();
m_StartDate = COleDateTime::GetCurrentTime();
//}}AFX_DATA_INIT
m_pGridCtrl=NULL;
m_EndDate.SetDateTime(m_EndDate.GetYear(),m_EndDate.GetMonth(),m_EndDate.GetDay(),23,59,59);
m_StartDate.SetDateTime(m_StartDate.GetYear(),m_StartDate.GetMonth(),m_StartDate.GetDay(),0,0,0);
}
CAlarmInfo::~CAlarmInfo()
{
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CAlarmInfo::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAlarmInfo)
DDX_Control(pDX, IDC_END_DATET, m_cEndDate);
DDX_Control(pDX, IDC_START_DATET, m_cStartDate);
DDX_Control(pDX, IDC_REPORT_POS, m_cReportPos);
DDX_DateTimeCtrl(pDX, IDC_END_DATET, m_EndDate);
DDX_DateTimeCtrl(pDX, IDC_START_DATET, m_StartDate);
//}}AFX_DATA_MAP
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CAlarmInfo, CPropertyPage)
//{{AFX_MSG_MAP(CAlarmInfo)
ON_BN_CLICKED(IDC_RESET, OnReset)
ON_NOTIFY(DTN_CLOSEUP, IDC_START_DATET, OnCloseupStartDatet)
ON_NOTIFY(DTN_CLOSEUP, IDC_END_DATET, OnCloseupEndDatet)
ON_BN_CLICKED(IDC_PRINT, OnPrint)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CAlarmInfo::OnInitDialog()
{
CPropertyPage::OnInitDialog();
CRect rect;
m_cReportPos.GetWindowRect(rect);
ScreenToClient(rect);
rect.bottom=rect.bottom-16;
m_pGridCtrl=new CGridCtrl;
m_pGridCtrl->SetRowResize(FALSE);
m_pGridCtrl->SetColumnResize(FALSE);
m_pGridCtrl->Create(rect,this,100);
m_pGridCtrl->SetFixedRowCount();
m_pGridCtrl->SetFixedColumnCount();
m_pGridCtrl->SetColumnCount(4);
int nColWidth[]={40,130,120,100};
m_pGridCtrl->SetRowHeight(0,15);
for (int col = 0; col < m_pGridCtrl->GetColumnCount(); col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = 0;
Item.col = col;
Item.nFormat = DT_CENTER|DT_VCENTER|DT_WORDBREAK;
Item.szText=sReportTitle[col];
m_pGridCtrl->SetItem(&Item);
m_pGridCtrl->SetColumnWidth(col,nColWidth[col]);
}
OnReset();
return TRUE;
}
////////////////////////////
//
/////////////////////////////
void CAlarmInfo::OnReset()
{
UpdateGrid();
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CAlarmInfo::UpdateGrid()
{
m_pGridCtrl->DeleteNonFixedRows();
CFileStatus Status;
CString sInfoFile=GetAppPath()+"AlarmInfo.hdb";
if (!CFile::GetStatus (sInfoFile, Status))
{
MessageBox("没有发现"+sInfoFile);
return;
}
CFile Info;
if(!Info.Open(sInfoFile,CFile::modeRead))
return;
int nRow=1;
GV_ITEM Item;
DWORD dwPos=Info.GetPosition();
DWORD dwLen=Info.GetLength();
int nIndex=0;
CGtMpegWnd *pWnd=(CGtMpegWnd *)theApp.m_pMainWnd;
while(dwPos!=dwLen)
{
ALARMINFO AlarmInfo;
COleDateTime InfoDate;
CString sCol[4];
sCol[0].Format("%d",nRow);
Info.Read(&AlarmInfo,sizeof(ALARMINFO));
CString sTmp;
InfoDate.SetDateTime(AlarmInfo.m_nYear,AlarmInfo.m_nMonth,AlarmInfo.m_nDay,AlarmInfo.m_nHour,AlarmInfo.m_nMin,AlarmInfo.m_nSec);
sCol[1]=InfoDate.Format("%Y/%m/%d/%H:%M:%S");
//
CChunnel *pChunnel=pWnd->GetChunnel(AlarmInfo.m_nChunnel);
CZone *pZone=pChunnel->GetZone(AlarmInfo.m_nZone);
sCol[2]=pZone->GetZoneTxt();
switch(AlarmInfo.m_nStates)
{
case 0:
sTmp="准备布防";
break;
case 1:
sTmp="布防时解除警报";
break;
case 2:
sTmp=pZone->m_sTouchTxt;
break;
case 3:
sTmp="准备撤防";
break;
case 4:
sTmp="撤防时解除警报";
break;
case 5:
sTmp="布防";
break;
case 6:
sTmp="撤防";
break;
default:
sTmp="未知事件";
break;
}
sCol[3]=sTmp;
dwPos=Info.GetPosition();
nIndex++;
if(InfoDate<=m_EndDate&&InfoDate>=m_StartDate)
{
m_pGridCtrl->InsertRow("", -1);
m_pGridCtrl->SetRowHeight(nRow,15);
for(int j=0;j<m_pGridCtrl->GetColumnCount();j++)
{
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = nRow;
Item.col = j;
Item.nFormat = DT_LEFT|DT_VCENTER|DT_WORDBREAK;
Item.nEditFormat=0;
Item.szText.Format("%s",sCol[j]);
m_pGridCtrl->SetItem(&Item);
}
nRow++;
}
}
Info.Close();
m_pGridCtrl->SetEditable(FALSE);
m_pGridCtrl->Invalidate();
}
////////////////////////////////////////////
//
////////////////////////////////////////////
void CAlarmInfo::OnCloseupStartDatet(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
m_cStartDate.GetTime(m_StartDate);
}
////////////////////////////////////////////
//
////////////////////////////////////////////
void CAlarmInfo::OnCloseupEndDatet(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
m_cEndDate.GetTime(m_EndDate);
}
////////////////////////////////////////////
//
////////////////////////////////////////////
void CAlarmInfo::OnPrint()
{
m_pGridCtrl->m_nHeaderHeight=90;
//m_pGridCtrl->m_nFootHeight=;
m_pGridCtrl->m_nLeft=40;
m_pGridCtrl->m_nRight=5;
m_pGridCtrl->m_nTop=5;
m_pGridCtrl->m_nBottom=5;
m_pGridCtrl->m_nHeaderGap=3;
m_pGridCtrl->Print();
}
///////////////////////////////////////
//
///////////////////////////////////////
void CAlarmInfo::OnPrintHeader(WPARAM wParam, LPARAM lParam)
{
NM_GRIDVIEW *pGV=(NM_GRIDVIEW *)lParam;
CDC *pDC=pGV->pDC;
CPrintInfo *pInfo=pGV->pInfo;
CRect rc(pInfo->m_rectDraw);
CRect rect=rc;
int TotlaWidth=0;
for(int i=1;i<m_pGridCtrl->GetColumnCount();i++)
{
TotlaWidth+=m_pGridCtrl->GetColumnWidth(i);
}
CString sTitle="警情信息";
rect.right=TotlaWidth;
rect.bottom=rect.top+80;
CSize PaperPixelsPerInch(pDC->GetDeviceCaps(LOGPIXELSX), pDC->GetDeviceCaps(LOGPIXELSY));
CFont *pFont=SetFontType(24,0,600,"楷体");
CFont *pOldFont=pDC->SelectObject(pFont);
int nLen=pDC->GetTextExtent(sTitle).cx+5;
pDC->DrawText(sTitle,-1,rect, DT_CENTER| DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
int nStartx=rect.left+(rect.Width()-nLen)/2-5;
int nStarty=rect.top+(rect.Height()-pDC->GetTextExtent(sTitle).cy)/2+pDC->GetTextExtent(sTitle).cy+5;
::LineWidth(nStartx,nStarty,nStartx+nLen+5,nStarty,2,COLOR_BLACK,pDC);
delete pFont;
pFont=SetFontType(9,0,400,"宋体");
pDC->SelectObject(pFont);
//m_sUserName
rect.top=rect.bottom;
rect.bottom=rect.top+16;
pDC->DrawText(theApp.GetProfileString("系统参数","建设单位",""),-1,rect, DT_LEFT| DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
CString sTime=m_StartDate.Format("%Y年%m月%d日")+"-"+m_EndDate.Format("%Y年%m月%d日");
pDC->DrawText("查询时期:"+sTime,-1,rect, DT_RIGHT| DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
delete pFont;
pDC->SelectObject(pOldFont);
}
///////////////////////////////////////
//
///////////////////////////////////////
void CAlarmInfo::OnPrintFoot(WPARAM wParam, LPARAM lParam)
{
NM_GRIDVIEW *pGV=(NM_GRIDVIEW *)lParam;
CDC *pDC=pGV->pDC;
CPrintInfo *pInfo=pGV->pInfo;
CRect rc(pInfo->m_rectDraw);
int TotlaWidth=0;
CSize PaperPixelsPerInch(pDC->GetDeviceCaps(LOGPIXELSX), pDC->GetDeviceCaps(LOGPIXELSY));
CFont *pFont=SetFontType(9,0,400,"宋体");
CFont *pOldFont=pDC->SelectObject(pFont);
for(int i=1;i<m_pGridCtrl->GetColumnCount();i++)
{
TotlaWidth+=m_pGridCtrl->GetColumnWidth(i);
}
rc.right=TotlaWidth;
pDC->MoveTo(rc.left, rc.top);
pDC->LineTo(rc.right, rc.top);
int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
CString sTemp ;
rc.OffsetRect(0, 2);
sTemp.Format(_T("第%d页共%d页"), pInfo->m_nCurPage, pInfo->GetMaxPage());
pDC->DrawText(sTemp,-1,rc, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
pDC->SetBkMode(nPrevBkMode);
pDC->SelectObject(pOldFont);
}
BOOL CAlarmInfo::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
if(m_pGridCtrl->GetSafeHwnd())
{
NM_GRIDVIEW *pGV=(NM_GRIDVIEW *)lParam;
if(pGV->hdr.idFrom==(UINT)m_pGridCtrl->GetDlgCtrlID())
{
switch(pGV->hdr.code)
{
case GVN_PRINT_HEADER:OnPrintHeader(wParam,lParam);
break;
case GVN_PRINT_FOOT:OnPrintFoot(wParam,lParam);
break;
}
return TRUE;
}
}
return CPropertyPage::OnNotify(wParam, lParam, pResult);
}
//////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////
CFont * CAlarmInfo::SetFontType(long nHeight,long nWidth,long nWeight,CString sFontName)
{
LOGFONT LogFont;
CFont *pRetFont=new CFont;
CString FontName=sFontName;
if(FontName=="楷体"||FontName=="@楷体"||FontName=="仿宋"||FontName=="@仿宋"
||FontName=="宋体"||FontName=="隶书"||FontName=="幼圆"||FontName=="黑体"
||FontName=="@宋体"||FontName=="@隶书"||FontName=="@幼圆"||FontName=="@黑体")
{
LogFont.lfCharSet=GB2312_CHARSET;
if(FontName=="楷体"||FontName=="@楷体"||FontName=="仿宋"||FontName=="@仿宋")
FontName+="_GB2312";
}
else
LogFont.lfCharSet=DEFAULT_CHARSET;
LogFont.lfHeight=nHeight;
LogFont.lfWidth=nWidth;
for(int i=0;i<32;i++)
LogFont.lfFaceName[i]=0;
for(i=0;i<FontName.GetLength();i++)
LogFont.lfFaceName[i]=(CHAR)FontName.GetAt(i);
LogFont.lfEscapement=0;
LogFont.lfOrientation=0;
LogFont.lfWeight=nWeight;
LogFont.lfItalic=0;
LogFont.lfUnderline=0;
LogFont.lfStrikeOut=0;
LogFont.lfOutPrecision=3;//OUT_CHARACTER_PRECIS;
LogFont.lfClipPrecision=2;//CLIP_MASK;
LogFont.lfQuality=1;//PROOF_QUALITY;
LogFont.lfPitchAndFamily=FF_MODERN|FIXED_PITCH;
pRetFont->CreateFontIndirect(&LogFont);
return pRetFont;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -