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

📄 viewcablealarminfo.cpp

📁 电缆故障监控系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ViewCableAlarmInfo.cpp : implementation file
//

#include "stdafx.h"
#include "remotemonitor.h"
#include "ViewCableAlarmInfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CViewCableAlarmInfo dialog
extern BOOL bRight[];
extern CString strAlarmType[];
extern CString strTitleArray[];

CViewCableAlarmInfo::CViewCableAlarmInfo(CWnd* pParent /*=NULL*/)
	: CDialog(CViewCableAlarmInfo::IDD, pParent)
{
	//{{AFX_DATA_INIT(CViewCableAlarmInfo)
	m_edit1 = _T("");
	m_edit2 = _T("");
	m_edit3 = 0;
	//}}AFX_DATA_INIT
}


void CViewCableAlarmInfo::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CViewCableAlarmInfo)
	DDX_Control(pDX, IDC_COMBO2, m_combo2);
	DDX_Control(pDX, IDC_COMBO1, m_combo1);
	DDX_Control(pDX, IDC_LIST1, m_list1);
	DDX_Text(pDX, IDC_EDIT1, m_edit1);
	DDX_Text(pDX, IDC_EDIT2, m_edit2);
	DDX_Text(pDX, IDC_EDIT3, m_edit3);
	DDV_MinMaxInt(pDX, m_edit3, 0, 999);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CViewCableAlarmInfo, CDialog)
	//{{AFX_MSG_MAP(CViewCableAlarmInfo)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	ON_BN_CLICKED(IDC_EXPORT3, OnExport3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CViewCableAlarmInfo message handlers

BOOL CViewCableAlarmInfo::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CString str;
    int i;
    GetDlgItem(IDC_MYSTATIC)->GetWindowPlacement(&m_mystaticwnd);
    GetDlgItem(IDC_EDIT1)->GetWindowPlacement(&m_editwnd[0]);
    GetDlgItem(IDC_EDIT2)->GetWindowPlacement(&m_editwnd[1]);
    GetDlgItem(IDC_EDIT3)->GetWindowPlacement(&m_editwnd[2]);
    GetDlgItem(IDC_COMBO2)->GetWindowPlacement(&m_combownd);

	WINDOWPLACEMENT wndplace;
	wndplace.rcNormalPosition.left	    = 2000;
	wndplace.rcNormalPosition.right	    = 2000;
	wndplace.rcNormalPosition.top		= 2000;
	wndplace.rcNormalPosition.bottom	= 2000;
	GetDlgItem(IDC_EDIT3)->SetWindowPlacement(&wndplace);
	GetDlgItem(IDC_COMBO2)->SetWindowPlacement(&wndplace);

	m_combo1.AddString("按时间段");
	m_combo1.AddString("按分机号");
	m_combo1.AddString("按报警类型");
    m_combo1.SetCurSel(0);

	for(i=0;i<11;i++)
       m_combo2.AddString(strAlarmType[i]);

    m_combo2.SetCurSel(0);

	CTime time=CTime::GetCurrentTime();
    m_edit1=time.Format("%Y-%m-%d");
    m_edit1+=" 00:00:00";
	m_edit2=time.Format("%Y-%m-%d %H:%M:%S");
	m_list1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	m_list1.InsertColumn( 0, "分机号", LVCFMT_LEFT,80, 0 );
	m_list1.InsertColumn( 1, "分机名", LVCFMT_LEFT,80, 0 );
	m_list1.InsertColumn( 2, "电缆号", LVCFMT_LEFT,80, 0 );
	m_list1.InsertColumn( 3, "报警类型", LVCFMT_LEFT,80, 0 );
    m_list1.InsertColumn( 4, "距  离", LVCFMT_LEFT,55, 0 );
    m_list1.InsertColumn( 5, "报警时间", LVCFMT_LEFT,180, 0 );
//    m_list1.InsertColumn( 6, "恢复时间", LVCFMT_LEFT,160, 0 );
    m_table.m_strSort=_T("[alarmtime]");
//    m_table.m_strFilter=_T("[alarmtime] Between '" + m_edit1 + "' AND '" + m_edit2+"'"); 
    m_table.m_strFilter=_T("[alarmtime] Between #" + m_edit1 + "# AND #" + m_edit2+"#"); 
	if(!m_table.IsOpen())
      m_table.Open();
    Insertlist1();
	if(!bRight[3])
		GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);
    UpdateData(FALSE);		
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CViewCableAlarmInfo::Insertlist1()
{
	int ntotalItem;
	CString str;
    CTime time;
	while(!m_table.IsEOF())
	{
		ntotalItem = m_list1.GetItemCount();
		str.Format("%3.3d",m_table.m_cablenumber/100);
		m_list1.InsertItem(ntotalItem,str);

        str=m_table.m_fenjiname;
		m_list1.SetItem(ntotalItem,1,LVIF_TEXT,_T(str),0,0,0,NULL);

		str.Format("%d",m_table.m_cablenumber%100);
		m_list1.SetItem(ntotalItem,2,LVIF_TEXT,_T(str),0,0,0,NULL);

		str=strAlarmType[m_table.m_alarmtype-1];
		m_list1.SetItem(ntotalItem,3,LVIF_TEXT,_T(str),0,0,0,NULL);

        str.Format("%d",m_table.m_distant);
		m_list1.SetItem(ntotalItem,4,LVIF_TEXT,_T(str),0,0,0,NULL);

		time=m_table.m_alarmtime;
		if(time==0) str="";
//		else str=time.Format("%Y-%m-%d %H:%M:%S");
		else str=time.Format("%Y-%m-%d %H:%M");
		m_list1.SetItem(ntotalItem,5,LVIF_TEXT,_T(str),0,0,0,NULL);
//		time=m_table.m_recovertime;
//		if(time==0) str="";
//		else str=time.Format("%Y-%m-%d %H:%M:%S");
//		else str=time.Format("%Y-%m-%d %H:%M");
//		m_list1.SetItem(ntotalItem,6,LVIF_TEXT,_T(str),0,0,0,NULL);
        m_table.MoveNext();
	}
}
void CViewCableAlarmInfo::OnOK() 
{
	// TODO: Add extra validation here
    if(m_table.IsOpen())
      m_table.Close();
	
	CDialog::OnOK();
}

void CViewCableAlarmInfo::OnButton1() //查询
{
	// TODO: Add your control notification handler code here
	CString str1,str2;
	UpdateData(TRUE);
	int nIndex=m_combo1.GetCurSel();
	if(nIndex==0)//按时间查询
	{
	   if(m_edit1==""||m_edit2=="")
	   {
		   MessageBox("没有正确地输入查询条件!请重新输入","提示信息");
		   return;
	   }
       m_table.m_strSort=_T("[alarmtime]");
//       m_table.m_strFilter=_T("[alarmtime] Between '" + m_edit1 + "' AND '" + m_edit2+"'"); 
       m_table.m_strFilter=_T("[alarmtime] Between #" + m_edit1 + "# AND #" + m_edit2+"#"); 
	   if(m_table.Requery())
	   {
           m_list1.DeleteAllItems();
		   Insertlist1();
	   }
	}
	else  if(nIndex==1)//按分机号查询
	{
		if(m_edit3<0||m_edit3>999)
		{
		   MessageBox("没有正确地输入分机号!请重新输入","提示信息");
		   return;
		}
		m_table.m_strSort=_T("[alarmtime]");
		str1.Format("%d",m_edit3*100);
		str2.Format("%d",m_edit3*100+16);
        m_table.m_strFilter=_T("[cablenumber] Between " + str1 + " AND " + str2); 
		if(m_table.Requery())
		{
			m_list1.DeleteAllItems();
			Insertlist1();
		}
	}
	else//按报警类型查询
	{
		m_table.m_strSort=_T("[alarmtime]");
		str1.Format("%d",m_combo2.GetCurSel()+1);
		m_table.m_strFilter=_T("[alarmtype] = " + str1); 
		if(m_table.Requery())
		{
			m_list1.DeleteAllItems();
			Insertlist1();
		}
	}
}

void CViewCableAlarmInfo::OnButton2() //打印
{
	// TODO: Add your control notification handler code here
    int numPages;
	int nTotalRecord=m_list1.GetItemCount();
    if(nTotalRecord==0)
	{
		MessageBox("当前无可打印的记录","提示信息",MB_OK);
		return;
	}
	CDC dc;
	CPrintDialog printDlg(FALSE);
	//利用CPrintDialog 生成打印机设备环境
	if (printDlg.DoModal() == IDCANCEL) // Get printer settings from user 让用户选择打印纸张等
		return;
	dc.Attach(printDlg.GetPrinterDC()); // Attach a printer DC 让HANDLE连接到dc上
	dc.m_bPrinting = TRUE;
	
	TEXTMETRIC textMetric;
	dc.GetTextMetrics(&textMetric);
    m_perCharHeight=(int)(textMetric.tmHeight*1.2);
	m_perlineHeight=(int)((textMetric.tmHeight+textMetric.tmExternalLeading)*1.2);
	m_paperHeight  =dc.GetDeviceCaps(VERTRES);
	m_paperWidth   =dc.GetDeviceCaps(HORZRES), 
	m_linesPerPage=m_paperHeight/m_perlineHeight;
	
	DOCINFO di; // Initialise print document details DOCINFO中有相关的打印信息
	::ZeroMemory (&di, sizeof (DOCINFO));
	di.cbSize = sizeof (DOCINFO);
	di.lpszDocName = strTitleArray[1];//设置标题
	
	BOOL bPrintingOK = dc.StartDoc(&di); // Begin a new print job 开始打印
	
	// Get the printing extents and store in the m_rectDraw field of a 
	// CPrintInfo object
	CPrintInfo Info;//
	Info.m_rectDraw.SetRect(0,0, m_paperWidth,m_paperHeight);//设置范围
	
	if(nTotalRecord<=m_linesPerPage-11)//上下各留4行,标题2行,标题1行
		numPages=1;
	else
	{
		numPages=(nTotalRecord-(m_linesPerPage-11))/(m_linesPerPage-9)+1;
		if((nTotalRecord-(m_linesPerPage-11))%(m_linesPerPage-9)!=0)
			numPages+=1;
	}
	Info.SetMinPage(1);
	Info.SetMaxPage(numPages);

	for (UINT page = Info.GetMinPage(); page<=Info.GetMaxPage()&& bPrintingOK;page++)
	{
		Info.m_nCurPage = page;
	    Print(&dc, &Info); // Call your "Print page" function
	    bPrintingOK = (dc.EndPage() > 0); // end page
	}
//	OnEndPrinting(&dc, &Info); // 结束打印
	
	if (bPrintingOK)
		dc.EndDoc(); // end a print job
	else
		dc.AbortDoc(); // abort job.
	
	dc.Detach(); // detach the printer DC	
}
void CViewCableAlarmInfo::DrawGrid(CDC* pDC,int nStartY,int nLine)
{
	int i, nX1,nX2,nY1,nY2,nPerItem;

    nX1=m_perlineHeight*3;
	nX2=m_paperWidth-m_perlineHeight*3;
	for(i=0;i<=nLine;i++)
	{
	   nY1=nY2=nStartY+i*m_perlineHeight;
	   pDC->MoveTo(nX1,nY1);
	   pDC->LineTo(nX2,nY2);
	}
	nY1=nStartY;
	nY2=nStartY+nLine*m_perlineHeight;
    nPerItem=(m_paperWidth-m_perlineHeight*6)/10;
	nX1=nX2=m_perlineHeight*3;
	pDC->MoveTo(nX1,nY1);
	pDC->LineTo(nX2,nY2);
	nX1=nX2=m_perlineHeight*3+nPerItem;
	pDC->MoveTo(nX1,nY1);
	pDC->LineTo(nX2,nY2);
	nX1=nX2=m_perlineHeight*3+3*nPerItem;
	pDC->MoveTo(nX1,nY1);
	pDC->LineTo(nX2,nY2);
	nX1=nX2=m_perlineHeight*3+4*nPerItem;
	pDC->MoveTo(nX1,nY1);
	pDC->LineTo(nX2,nY2);
	nX1=nX2=m_perlineHeight*3+6*nPerItem;
	pDC->MoveTo(nX1,nY1);
	pDC->LineTo(nX2,nY2);
	nX1=nX2=m_perlineHeight*3+7*nPerItem;
	pDC->MoveTo(nX1,nY1);
	pDC->LineTo(nX2,nY2);

/*	nX1=nX2=m_perlineHeight*3+10*nPerItem;
	pDC->MoveTo(nX1,nY1);
	pDC->LineTo(nX2,nY2);
	nX1=nX2=m_paperWidth-m_perlineHeight*3;
	pDC->MoveTo(nX1,nY1);
	pDC->LineTo(nX2,nY2);*/	
	nX1=nX2=m_paperWidth-m_perlineHeight*3;
	pDC->MoveTo(nX1,nY1);
	pDC->LineTo(nX2,nY2);

}

void CViewCableAlarmInfo::DrawTexttoGrid(CDC* pDC,int nStartY,int nStartRecord,int nEndRecord)
{
    CString str;
	int i,nPerItem;
    CRect rc;

    nPerItem=(m_paperWidth-m_perlineHeight*6)/10;
    nStartY+=(int)(0.1*m_perlineHeight);

⌨️ 快捷键说明

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