From 02fb493f0903013e5258c2ff5e2cb27de873378a Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 12 十二月 2024 10:51:43 +0800
Subject: [PATCH] 1.警告性息弹窗; 2.警告性息列表;

---
 SourceCode/Bond/BondEq/CPageAlarm.cpp |  109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 104 insertions(+), 5 deletions(-)

diff --git a/SourceCode/Bond/BondEq/CPageAlarm.cpp b/SourceCode/Bond/BondEq/CPageAlarm.cpp
index 5533d1e..0d76752 100644
--- a/SourceCode/Bond/BondEq/CPageAlarm.cpp
+++ b/SourceCode/Bond/BondEq/CPageAlarm.cpp
@@ -6,6 +6,7 @@
 #include "CPageAlarm.h"
 #include "afxdialogex.h"
 #include "Common.h"
+#include "ToolUnits.h"
 
 
 // CPageAlarm 对话框
@@ -50,8 +51,17 @@
 			// onNext
 			pAny->addRef();
 			int code = pAny->getCode();
-			if (RX_CODE_LOG == code && ::IsWindow(m_hWnd)) {
-
+			if (RX_CODE_ALARM_ON == code) {
+				CAlarm* pAlarm;
+				if (pAny->getObject("obj", (IRxObject*&)pAlarm)) {
+					AddAlarm(nullptr, pAlarm);
+				}
+			}
+			else if (RX_CODE_ALARM_OFF == code) {
+				CAlarm* pAlarm;
+				if (pAny->getObject("obj", (IRxObject*&)pAlarm)) {
+					UpdateAlarm(nullptr, pAlarm);
+				}
 			}
 
 			pAny->release();
@@ -71,6 +81,26 @@
 {
 	CDialogEx::OnInitDialog();
 	InitRxWindow();
+
+
+	// 报表控件
+	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
+	DWORD dwStyle = pListCtrl->GetExtendedStyle();
+	dwStyle |= LVS_EX_FULLROWSELECT;
+	dwStyle |= LVS_EX_GRIDLINES;
+	pListCtrl->SetExtendedStyle(dwStyle);
+
+	HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
+	ListView_SetImageList(pListCtrl->GetSafeHwnd(), imageList, LVSIL_SMALL);
+	pListCtrl->InsertColumn(0, _T(""), LVCFMT_RIGHT, 0);
+	pListCtrl->InsertColumn(2, _T("警告ID"), LVCFMT_LEFT, 100);
+	pListCtrl->InsertColumn(3, _T("描述"), LVCFMT_LEFT, 580);
+	pListCtrl->InsertColumn(4, _T("发生时间"), LVCFMT_LEFT, 180);
+	pListCtrl->InsertColumn(5, _T("解除时间"), LVCFMT_LEFT, 180);
+
+
+	Resize();
+	LoadAlarms();
 
 	return TRUE;  // return TRUE unless you set the focus to a control
 				  // 异常: OCX 属性页应返回 FALSE
@@ -92,7 +122,6 @@
 	return m_hbrBkgnd;
 }
 
-
 void CPageAlarm::OnDestroy()
 {
 	CDialogEx::OnDestroy();
@@ -107,10 +136,80 @@
 	}
 }
 
-
 void CPageAlarm::OnSize(UINT nType, int cx, int cy)
 {
 	CDialogEx::OnSize(nType, cx, cy);
+	if (GetDlgItem(IDC_LIST_ALARM) == nullptr) return;
+	Resize();
+}
 
-	// TODO: 在此处添加消息处理程序代码
+void CPageAlarm::Resize()
+{
+	CWnd* pItem;
+	CRect rcClient;
+	GetClientRect(&rcClient);
+
+	pItem = GetDlgItem(IDC_LIST_ALARM);
+	pItem->MoveWindow(12, 12, rcClient.Width() - 24, rcClient.Height() - 24);
+}
+
+void CPageAlarm::LoadAlarms()
+{
+	CAlarmMonitor* pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("警告信息");
+
+	pMonitor->Lock();
+	std::map<int, CAlarm*>& alarmings = pMonitor->getAlarmingMap();
+	std::list< CAlarm*>& alarms = pMonitor->getAlarmRecords();
+
+	for (auto item : alarmings) {
+		AddAlarm(pMonitor, item.second);
+	}
+	for (auto item : alarms) {
+		AddAlarm(pMonitor, item);
+	}
+
+	pMonitor->Unlock();
+}
+
+void CPageAlarm::AddAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm)
+{
+	if (pMonitor == nullptr) {
+		pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("警告信息");
+	}
+	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
+	pListCtrl->InsertItem(0, _T(""));
+	pListCtrl->SetItemData(0, (DWORD_PTR)pAlarm);
+	pAlarm->addRef();
+	pListCtrl->SetItemText(0, 1, std::to_string(pAlarm->getId()).c_str());
+	pListCtrl->SetItemText(0, 2, pMonitor->getAlarmText(pAlarm->getId()));
+	pListCtrl->SetItemText(0, 3, CToolUnits::timeToString2(pAlarm->getOnTime()).c_str());
+	if (pAlarm->getOffTime() > 0) {
+		pListCtrl->SetItemText(0, 4, CToolUnits::timeToString2(pAlarm->getOffTime()).c_str());
+	}
+}
+
+void CPageAlarm::UpdateAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm)
+{
+	if (pMonitor == nullptr) {
+		pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("警告信息");
+	}
+	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
+	for (int i = 0; i < pListCtrl->GetItemCount(); i++) {
+		if (pListCtrl->GetItemData(i) == (DWORD_PTR)pAlarm) {
+			if (pAlarm->getOffTime() > 0) {
+				pListCtrl->SetItemText(i, 4, CToolUnits::timeToString2(pAlarm->getOffTime()).c_str());
+			}
+		}
+	}
+}
+
+BOOL CPageAlarm::DestroyWindow()
+{
+	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
+	for (int i = 0; i < pListCtrl->GetItemCount(); i++) {
+		CAlarm* pAlarm = (CAlarm*)pListCtrl->GetItemData(i);
+		pAlarm->release();
+	}
+
+	return CDialogEx::DestroyWindow();
 }

--
Gitblit v1.9.3