chenluhua1980
2026-01-21 2254c453025136727917601091f14da02af1b548
SourceCode/Bond/Servo/AlarmPopupDlg.cpp
@@ -30,6 +30,8 @@
BEGIN_MESSAGE_MAP(CAlarmPopupDlg, CDialogEx)
   ON_BN_CLICKED(IDC_POPUP_BTN_CLOSE, &CAlarmPopupDlg::OnBnClickedClose)
   ON_BN_CLICKED(IDC_BUTTON_ALARM_OFF, &CAlarmPopupDlg::OnBnClickedAlarmOff)
   ON_BN_CLICKED(IDC_BUTTON_PREV, &CAlarmPopupDlg::OnBnClickedPrev)
   ON_BN_CLICKED(IDC_BUTTON_NEXT, &CAlarmPopupDlg::OnBnClickedNext)
   ON_WM_CTLCOLOR()
   ON_WM_DESTROY()
END_MESSAGE_MAP()
@@ -151,6 +153,7 @@
void CAlarmPopupDlg::ShowAlarmControls(bool bShow)
{
   const int ids[] = {
      IDC_BUTTON_PREV, IDC_BUTTON_NEXT,
      IDC_LABEL_TITLE, IDC_ICON_ALARM, IDC_ICON_TITLE,
      IDC_LABEL_LEVEL, IDC_LABEL_NAME,
      IDC_LINE1, IDC_BUTTON_SOUND_OFF, IDC_BUTTON_ALARM_OFF,
@@ -165,10 +168,65 @@
void CAlarmPopupDlg::RefreshContent()
{
   auto actives = AlarmManager::getInstance().getActiveAlarms();
   if (!actives.empty()) {
      m_activeAlarm = actives.front();
   m_activeAlarms = AlarmManager::getInstance().getActiveAlarms();
   m_activeIndex = 0;
   if (!m_activeAlarms.empty()) {
      m_hasActive = true;
      DisplayActiveAt(m_activeIndex);
      ShowAlarmControls(true);
      ShowNoAlarmControls(false);
   }
   else {
      m_hasActive = false;
      SetDlgItemText(IDC_LABEL_NO_ALARM, _T("当前无报警"));
      SetDlgItemText(IDC_LABEL_NAME, _T(""));
      SetDlgItemText(IDC_LABEL_LEVEL, _T(""));
      SetDlgItemText(IDC_LABEL_DESCRIPTION, _T(""));
      ShowAlarmControls(false);
      ShowNoAlarmControls(true);
   }
}
void CAlarmPopupDlg::OnBnClickedClose()
{
   ShowWindow(SW_HIDE);
}
void CAlarmPopupDlg::OnBnClickedAlarmOff()
{
   if (!m_hasActive) return;
   AlarmManager& alarmManager = AlarmManager::getInstance();
   alarmManager.clearAlarmByAttributes(
      m_activeAlarm.nId,
      m_activeAlarm.nDeviceId,
      m_activeAlarm.nUnitId,
      CToolUnits::getCurrentTimeString());
   RefreshContent();
}
void CAlarmPopupDlg::OnBnClickedPrev()
{
   if (m_activeIndex > 0) {
      --m_activeIndex;
      DisplayActiveAt(m_activeIndex);
   }
}
void CAlarmPopupDlg::OnBnClickedNext()
{
   if (m_activeIndex + 1 < static_cast<int>(m_activeAlarms.size())) {
      ++m_activeIndex;
      DisplayActiveAt(m_activeIndex);
   }
}
void CAlarmPopupDlg::DisplayActiveAt(int idx)
{
   if (idx < 0 || idx >= static_cast<int>(m_activeAlarms.size())) return;
   m_activeAlarm = m_activeAlarms[idx];
      AlarmManager& alarmManager = AlarmManager::getInstance();
      const AlarmInfo* info = alarmManager.getAlarmInfoByID(m_activeAlarm.nId);
@@ -201,37 +259,17 @@
      SetDlgItemText(IDC_LABEL_NAME, name);
      SetDlgItemText(IDC_LABEL_LEVEL, level);
      SetDlgItemText(IDC_LABEL_DESCRIPTION, desc);
      ShowAlarmControls(true);
      ShowNoAlarmControls(false);
   UpdateNavButtons();
      ShowWindow(SW_SHOW);
   }
   else {
      m_hasActive = false;
      SetDlgItemText(IDC_LABEL_NO_ALARM, _T("当前无报警"));
      SetDlgItemText(IDC_LABEL_NAME, _T(""));
      SetDlgItemText(IDC_LABEL_LEVEL, _T(""));
      SetDlgItemText(IDC_LABEL_DESCRIPTION, _T(""));
      ShowAlarmControls(false);
      ShowNoAlarmControls(true);
   }
}
void CAlarmPopupDlg::OnBnClickedClose()
void CAlarmPopupDlg::UpdateNavButtons()
{
   ShowWindow(SW_HIDE);
}
void CAlarmPopupDlg::OnBnClickedAlarmOff()
{
   if (!m_hasActive) return;
   AlarmManager& alarmManager = AlarmManager::getInstance();
   alarmManager.clearAlarmByAttributes(
      m_activeAlarm.nId,
      m_activeAlarm.nDeviceId,
      m_activeAlarm.nUnitId,
      CToolUnits::getCurrentTimeString());
   RefreshContent();
   auto* pPrev = GetDlgItem(IDC_BUTTON_PREV);
   auto* pNext = GetDlgItem(IDC_BUTTON_NEXT);
   if (pPrev) pPrev->EnableWindow(m_activeIndex > 0);
   if (pNext) pNext->EnableWindow(m_activeIndex + 1 < static_cast<int>(m_activeAlarms.size()));
}
HBRUSH CAlarmPopupDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)