From 0677e1aaead1762fc19c16c82a02926ec6d21b8a Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 13 十二月 2024 11:59:01 +0800
Subject: [PATCH] Merge branch 'liuyang' into clh

---
 SourceCode/Bond/BondEq/CPageAlarm.cpp |   38 ++++++++++++++++++++++++++++++++++----
 1 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/SourceCode/Bond/BondEq/CPageAlarm.cpp b/SourceCode/Bond/BondEq/CPageAlarm.cpp
index 0d76752..ffffedd 100644
--- a/SourceCode/Bond/BondEq/CPageAlarm.cpp
+++ b/SourceCode/Bond/BondEq/CPageAlarm.cpp
@@ -155,9 +155,11 @@
 
 void CPageAlarm::LoadAlarms()
 {
-	CAlarmMonitor* pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("警告信息");
+	CAlarmMonitor* pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
 
 	pMonitor->Lock();
+
+#if 0
 	std::map<int, CAlarm*>& alarmings = pMonitor->getAlarmingMap();
 	std::list< CAlarm*>& alarms = pMonitor->getAlarmRecords();
 
@@ -167,6 +169,20 @@
 	for (auto item : alarms) {
 		AddAlarm(pMonitor, item);
 	}
+#else
+	// 获取报警数据
+	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());
+	}
+#endif // 0
 
 	pMonitor->Unlock();
 }
@@ -174,7 +190,7 @@
 void CPageAlarm::AddAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm)
 {
 	if (pMonitor == nullptr) {
-		pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("警告信息");
+		pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
 	}
 	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
 	pListCtrl->InsertItem(0, _T(""));
@@ -186,18 +202,30 @@
 	if (pAlarm->getOffTime() > 0) {
 		pListCtrl->SetItemText(0, 4, CToolUnits::timeToString2(pAlarm->getOffTime()).c_str());
 	}
+
+	AlarmManager::getInstance().addAlarm(
+		std::to_string(pAlarm->getId()).c_str(), 
+		pMonitor->getAlarmText(pAlarm->getId()),
+		CToolUnits::timeToString2(pAlarm->getOnTime()).c_str(),
+		CToolUnits::timeToString2(pAlarm->getOffTime()).c_str());
 }
 
 void CPageAlarm::UpdateAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm)
 {
 	if (pMonitor == nullptr) {
-		pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("警告信息");
+		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());
+
+				AlarmManager::getInstance().updateAlarmEndTime(
+					std::to_string(pAlarm->getId()).c_str(),
+					pMonitor->getAlarmText(pAlarm->getId()),
+					CToolUnits::timeToString2(pAlarm->getOnTime()).c_str(),
+					CToolUnits::timeToString2(pAlarm->getOffTime()).c_str());
 			}
 		}
 	}
@@ -208,7 +236,9 @@
 	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
 	for (int i = 0; i < pListCtrl->GetItemCount(); i++) {
 		CAlarm* pAlarm = (CAlarm*)pListCtrl->GetItemData(i);
-		pAlarm->release();
+		if (pAlarm != nullptr) {
+			pAlarm->release();
+		}
 	}
 
 	return CDialogEx::DestroyWindow();

--
Gitblit v1.9.3