From b67e16869a5bfbbde3896a4e5a13f1301f1b978d Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 13 十二月 2024 14:55:55 +0800
Subject: [PATCH] 1.调整保存警告到数据库的位置; 2.CAlarmMonitor组件不再保存已完成的警告的数据;

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

diff --git a/SourceCode/Bond/BondEq/CPageAlarm.cpp b/SourceCode/Bond/BondEq/CPageAlarm.cpp
index 5533d1e..f03c56b 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,92 @@
 	}
 }
 
-
 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(ALARM_MONITOR);
+
+
+	// 当前正在发生的报警
+	pMonitor->Lock();
+	std::map<int, CAlarm*>& alarmings = pMonitor->getAlarmingMap();
+	for (auto item : alarmings) {
+		AddAlarm(pMonitor, item.second);
+	}
+	pMonitor->Unlock();
+
+
+	// 获取历史报警数据
+	auto vecData = AlarmManager::getInstance().getAllAlarms();
+
+	// 填充数据
+	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
+	for (auto item : vecData) {
+		pListCtrl->InsertItem(0, _T(""));
+		pListCtrl->SetItemText(0, 1, item[0].c_str());
+		pListCtrl->SetItemText(0, 2, item[1].c_str());
+		pListCtrl->SetItemText(0, 3, item[2].c_str());
+		pListCtrl->SetItemText(0, 4, item[3].c_str());
+	}
+}
+
+void CPageAlarm::AddAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm)
+{
+	if (pMonitor == nullptr) {
+		pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
+	}
+	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(ALARM_MONITOR);
+	}
+	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);
+		if (pAlarm != nullptr) {
+			pAlarm->release();
+		}
+	}
+
+	return CDialogEx::DestroyWindow();
 }

--
Gitblit v1.9.3