📄 dlglog.cpp
字号:
// DlgLog.cpp : implementation file
//
#include "stdafx.h"
#include "pcm120.h"
#include "DlgLog.h"
#include "DlgAllStaSet.h"
#include "PrintListCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgLog dialog
CDlgLog::CDlgLog(CWnd* pParent /*=NULL*/)
: CDialog(CDlgLog::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgLog)
m_PickDateTimer = COleDateTime::GetCurrentTime();
m_iMonth =1 ;
m_iYear = 2006;
//}}AFX_DATA_INIT
}
void CDlgLog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgLog)
DDX_Control(pDX, IDC_LIST1, m_ListWarn);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_PickDateTimer);
DDX_Text(pDX, IDC_EDIT_YANDM, m_iMonth);
DDV_MinMaxUInt(pDX, m_iMonth, 1, 12);
DDX_Text(pDX, IDC_EDIT_YEAR, m_iYear);
DDV_MinMaxUInt(pDX, m_iYear, 1999, 2038);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgLog, CDialog)
//{{AFX_MSG_MAP(CDlgLog)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER2, OnDatetimechangeDatetimepicker2)
ON_BN_CLICKED(IDC_BTN_DAILY, OnBtnDaily)
ON_BN_CLICKED(IDC_BTN_MONTH, OnBtnMonth)
ON_BN_CLICKED(IDC_BTN_YEAR, OnBtnYear)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgLog message handlers
CDlgAllStaSet dlgalstaset;
void CDlgLog::OnOK()
{
// PrintListCtrl(m_ListWarn);
CPrintListCtrl printlist;
printlist.SetListCtrl(m_ListWarn.GetSafeHwnd());
printlist.PrintLineSeparator(true);
printlist.Print(GetSafeHwnd(),"报表",false);
}
BOOL CDlgLog::OnInitDialog()
{
CDialog::OnInitDialog();
/////////////////得到应用程序的路径/////////////////////////////////////////////////////////
dlgalstaset.GetModulePath(strProPath,NULL);
//////////////////初始化title////////////////////////////////////////////////////////
GetAllID();
///////////////////得到系统时间///////////////////////////////////////////////////////
SYSTEMTIME systime;
GetSystemTime(&systime);
DWORD dYear=systime.wYear;
DWORD dMonth=systime.wMonth;
m_iYear=(UINT)dYear;
m_iMonth=(UINT)dMonth;
iCntDev=staDevID.GetSize();
// TODO: Add extra initialization here
//////////////////////////////////////////////////////////////////////////
/*
DWORD dwStyle =m_ListWarn.GetExtendedStyle();
m_ListWarn.SetExtendedStyle(dwStyle|LVS_EX_GRIDLINES|LVS_EX_TRACKSELECT|LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS);
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_CENTER;
lvc.cx = 50;
lvc.iSubItem = 0;
lvc.pszText = "设备\n告警\\时间";
m_ListWarn.InsertColumn(0,&lvc);
*/
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgLog::GetAllID()
{
char GetStaCnt[255];
char GetDevCnt[255];
char GetDevID[255];
CString strDevConPath;
strDevConPath=strProPath+"PCM120networksetup.ini";
GetPrivateProfileString("general","StationCnt","0",GetStaCnt,255,strDevConPath);
int iCntSta =atoi(GetStaCnt);
for(int i=0;i<iCntSta;i++)
{
CString strSection;
strSection.Format("station%d",i+1);
GetPrivateProfileString(strSection,"DevCnt","0",GetDevCnt,255,strDevConPath);
int iCntDevOne =atoi(GetDevCnt);
for(int j=0;j<iCntDevOne;j++)
{
CString strSeach;
strSeach.Format("第%d个设备ID",j+1);
GetPrivateProfileString(strSection,strSeach,"",GetDevID,255,strDevConPath);
staDevID.Add(GetDevID);
}
}
}
void CDlgLog::OnDatetimechangeDatetimepicker2(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CDlgLog::OnBtnDaily()
{
// TODO: Add your control notification handler code here
// char Get[255];
UpdateData(true);
int iCountRecord=m_ListWarn.GetItemCount();
for (int iRecord=0;iRecord < 255;iRecord++)
{
m_ListWarn.DeleteColumn(0);
}
m_ListWarn.DeleteAllItems();
UpdateData(false);
//////////////////////////////////////////////////////////////////////////
DWORD dwStyle =m_ListWarn.GetExtendedStyle();
m_ListWarn.SetExtendedStyle(dwStyle|LVS_EX_GRIDLINES|LVS_EX_TRACKSELECT|LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS);
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_CENTER;
lvc.cx = 80;
lvc.iSubItem = 0;
lvc.pszText = "设备告\n警\\时间";
m_ListWarn.InsertColumn(0,&lvc);
//////////////////////////////////////////////////////////////////////////
iYear =m_PickDateTimer.GetYear();
iMonth =m_PickDateTimer.GetMonth();
iDay=m_PickDateTimer.GetDay();
CString strTime;
CString strLogFilename;
strTime.Format("%d-%d-%d",iYear,iMonth,iDay);
strLogFilename=strProPath+"log\\"+strTime+".ini";
CStdioFile stFile;
CString strReadLine;
CStringArray staSection;
if(!stFile.Open(strLogFilename,CFile::modeRead))
{
return;
}
else
{
while(stFile.ReadString(strReadLine))
{
if(strReadLine.Find("[")!=-1 && strReadLine.Find("[default]")==-1)//不记default里的日志;
{
strReadLine.Replace("[","");
strReadLine.Replace("]","");
staSection.Add(strReadLine);
}
}
stFile.Close();
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
for(int q=iCntDev-1;q>=0;q--)
{
m_ListWarn.InsertItem(0,"ID|1E1|LOS");
m_ListWarn.InsertItem(1,staDevID.GetAt(q)+"| |AIS");
m_ListWarn.InsertItem(2," | |SYN");
m_ListWarn.InsertItem(3," | |D_N");
m_ListWarn.InsertItem(4," | |MSYN");
m_ListWarn.InsertItem(5," | |CRC_FL");
m_ListWarn.InsertItem(6," | |ER_CRC");
m_ListWarn.InsertItem(7," |2E1|LOS");
m_ListWarn.InsertItem(8," | |AIS");
m_ListWarn.InsertItem(9," | |SYN");
m_ListWarn.InsertItem(10," | |D_N");
m_ListWarn.InsertItem(11," | |MSYN");
m_ListWarn.InsertItem(12," | |CRC_FL");
m_ListWarn.InsertItem(13," | |ER_CRC");
m_ListWarn.InsertItem(14," |3E1|LOS");
m_ListWarn.InsertItem(15," | |AIS");
m_ListWarn.InsertItem(16," | |SYN");
m_ListWarn.InsertItem(17," | |D_N");
m_ListWarn.InsertItem(18," | |MSYN");
m_ListWarn.InsertItem(19," | |CRC_FL");
m_ListWarn.InsertItem(20," | |ER_CRC");
m_ListWarn.InsertItem(21," |4E1|LOS");
m_ListWarn.InsertItem(22," | |AIS");
m_ListWarn.InsertItem(23," | |SYN");
m_ListWarn.InsertItem(24," | |D_N");
m_ListWarn.InsertItem(25," | |MSYN");
m_ListWarn.InsertItem(26," | |CRC_FL");
m_ListWarn.InsertItem(27," | |ER_CRC");
}
for(int i=0;i<staSection.GetSize();i++)
{
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_CENTER;
lvc.cx = 25;
lvc.iSubItem =i+1;
CString strTemp,strHeader;
strTemp=staSection.GetAt(i);
int iPos1=strTemp.Find(":");
int iPos2=strTemp.Find(":",iPos1+1);
if(iPos1>=0 &&iPos2>=0)
{
CString strTim,strMin,strSec;
strTim=strTemp.Left(iPos1);
strMin=strTemp.Mid(iPos1+1,iPos2-iPos1-1);
strSec=strTemp.Right(strTemp.GetLength()-iPos2-1);
strHeader=strTemp.Left(iPos1)+":\n"+strTemp.Mid(iPos1+1,iPos2-iPos1-1)+":\n"+strTemp.Right(strTemp.GetLength()-iPos2-1);
}
lvc.pszText = (char*)((LPCTSTR)strHeader);
int m=m_ListWarn.InsertColumn(i+1,&lvc);
for(int q=iCntDev-1;q>=0;q--)
{
char GetValueWarn[255];
CString strWarn;
GetPrivateProfileString(staSection.GetAt(i),staDevID.GetAt(q),"",GetValueWarn,255,strLogFilename);
strWarn=GetValueWarn;
if(strWarn!="")
{
if(strWarn.GetLength()==11)
{
CString strTempBin;
XstrtoBin(strWarn,strTempBin);
WarnSetListCtrl(strTempBin,q,i+1);
}
}
}
//////////////////////////////////////////////////////////////////////////
}
/////////////////make the header multiline/////////////////////////////////////////////////////////
m_NewHeaderFontDay.CreatePointFont(250,"MS Serif");
CHeaderCtrl* pHeaderDay = NULL;
pHeaderDay=m_ListWarn.GetHeaderCtrl();
if(pHeaderDay==NULL)
return ;
if(m_HeaderCtrl.GetSafeHwnd()==NULL)
VERIFY(m_HeaderCtrl.SubclassWindow(pHeaderDay->m_hWnd));
//A BIGGER FONT MAKES THE CONTROL BIGGER
m_HeaderCtrl.SetFont(&m_NewHeaderFontDay);
HDITEM hdItem;
hdItem.mask = HDI_FORMAT;
for( i=0; i<m_HeaderCtrl.GetItemCount(); i++)
{
m_HeaderCtrl.GetItem(i,&hdItem);
hdItem.fmt|= HDF_OWNERDRAW;
m_HeaderCtrl.SetItem(i,&hdItem);
}
m_NewHeaderFontDay.DeleteObject();
}
void CDlgLog::OnBtnMonth()
{
// TODO: Add your control notification handler code here
UpdateData(true);
int iCountRecord=m_ListWarn.GetItemCount();
for (int iRecord=0;iRecord < 255;iRecord++)
{
m_ListWarn.DeleteColumn(0);
}
m_ListWarn.DeleteAllItems();
UpdateData(false);
//////////////////////////////////////////////////////////////////////////
DWORD dwStyle =m_ListWarn.GetExtendedStyle();
m_ListWarn.SetExtendedStyle(dwStyle|LVS_EX_GRIDLINES|LVS_EX_TRACKSELECT|LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS);
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_CENTER;
lvc.cx = 80;
lvc.iSubItem = 0;
lvc.pszText = "设备告\n警\\时间";
m_ListWarn.InsertColumn(0,&lvc);
//////////////////////////////////////////////////////////////////////////
char Get[255];
CString strFindTime;
CString strFindName;
for(int q=iCntDev-1;q>=0;q--)
{
m_ListWarn.InsertItem(0,"ID|1E1|LOS");
m_ListWarn.InsertItem(1,staDevID.GetAt(q)+"| |AIS");
m_ListWarn.InsertItem(2," | |SYN");
m_ListWarn.InsertItem(3," | |D_N");
m_ListWarn.InsertItem(4," | |MSYN");
m_ListWarn.InsertItem(5," | |CRC_FL");
m_ListWarn.InsertItem(6," | |ER_CRC");
m_ListWarn.InsertItem(7," |2E1|LOS");
m_ListWarn.InsertItem(8," | |AIS");
m_ListWarn.InsertItem(9," | |SYN");
m_ListWarn.InsertItem(10," | |D_N");
m_ListWarn.InsertItem(11," | |MSYN");
m_ListWarn.InsertItem(12," | |CRC_FL");
m_ListWarn.InsertItem(13," | |ER_CRC");
m_ListWarn.InsertItem(14," |3E1|LOS");
m_ListWarn.InsertItem(15," | |AIS");
m_ListWarn.InsertItem(16," | |SYN");
m_ListWarn.InsertItem(17," | |D_N");
m_ListWarn.InsertItem(18," | |MSYN");
m_ListWarn.InsertItem(19," | |CRC_FL");
m_ListWarn.InsertItem(20," | |ER_CRC");
m_ListWarn.InsertItem(21," |4E1|LOS");
m_ListWarn.InsertItem(22," | |AIS");
m_ListWarn.InsertItem(23," | |SYN");
m_ListWarn.InsertItem(24," | |D_N");
m_ListWarn.InsertItem(25," | |MSYN");
m_ListWarn.InsertItem(26," | |CRC_FL");
m_ListWarn.InsertItem(27," | |ER_CRC");
}
int iCol=1;
for(int itoday=1;itoday<32;itoday++)
{
strFindTime.Format("%d-%d-%d",m_iYear,m_iMonth,itoday);
strFindName=strProPath+"\\log\\"+strFindTime+".ini";
CStdioFile stFile;
CString strReadLine;
CStringArray staSection;
if(stFile.Open(strFindName,CFile::modeRead))
{
while(stFile.ReadString(strReadLine))
{
if(strReadLine.Find("[")!=-1 && strReadLine.Find("[default]")==-1)//不记default里的日志;
{
strReadLine.Replace("[","");
strReadLine.Replace("]","");
staSection.Add(strReadLine);
}
}
stFile.Close();
}
for(int i=0;i<staSection.GetSize();i++)
{
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_CENTER;
lvc.cx = 30;
lvc.iSubItem = iCol;
iCol++;
CString strTemMD,strHM,strTemSec,strTem;
strTemMD.Format("%d-%d",m_iMonth,itoday);
strTemSec=staSection.GetAt(i);
int ipos1=strTemSec.Find(":");
int ipos2=strTemSec.Find(":",ipos1+1);
strHM=strTemSec.Left(ipos2);
strTem =strTemMD+"\n"+strHM;
lvc.pszText = (char*)(LPCTSTR)strTem;
int m=m_ListWarn.InsertColumn(i+1,&lvc);
for(int q=iCntDev-1;q>=0;q--)
{
char GetValueWarn[255];
CString strWarn;
GetPrivateProfileString(staSection.GetAt(i),staDevID.GetAt(q),"",GetValueWarn,255,strFindName);
strWarn=GetValueWarn;
if(strWarn!="")
{
if(strWarn.GetLength()==11)
{
CString strTempBin;
XstrtoBin(strWarn,strTempBin);
WarnSetListCtrl(strTempBin,q,i+1);
}
}
}
//////////////////////////////////////////////////////////////////////////
}
//////////////////////////////////////////////////////////////////////////
}
/////////////////make the header multiline/////////////////////////////////////////////////////////
m_NewHeaderFontMonth.CreatePointFont(250,"MS Serif");
CHeaderCtrl* pHeaderDay = NULL;
pHeaderDay=m_ListWarn.GetHeaderCtrl();
if(pHeaderDay==NULL)
return ;
if(m_HeaderCtrl.GetSafeHwnd()==NULL)
VERIFY(m_HeaderCtrl.SubclassWindow(pHeaderDay->m_hWnd));
//A BIGGER FONT MAKES THE CONTROL BIGGER
m_HeaderCtrl.SetFont(&m_NewHeaderFontMonth);
HDITEM hdItem;
hdItem.mask = HDI_FORMAT;
for(int i=0; i<m_HeaderCtrl.GetItemCount(); i++)
{
m_HeaderCtrl.GetItem(i,&hdItem);
hdItem.fmt|= HDF_OWNERDRAW;
m_HeaderCtrl.SetItem(i,&hdItem);
}
m_NewHeaderFontMonth.DeleteObject();
}
void CDlgLog::OnBtnYear()
{
// TODO: Add your control notification handler code here
UpdateData(true);
int iCountRecord=m_ListWarn.GetItemCount();
for (int iRecord=0;iRecord < iCountRecord;iRecord++)
{
m_ListWarn.DeleteColumn(1);
}
m_ListWarn.DeleteAllItems();
UpdateData(false);
//////////////////////////////////////////////////////////////////////////
DWORD dwStyle =m_ListWarn.GetExtendedStyle();
m_ListWarn.SetExtendedStyle(dwStyle|LVS_EX_GRIDLINES|LVS_EX_TRACKSELECT|LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS);
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_CENTER;
lvc.cx = 80;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -