| | |
| | | #include "Log.h" |
| | | #include "Common.h" |
| | | #include "HorizontalLine.h" |
| | | #include "ServoDlg.h" |
| | | |
| | | |
| | | IMPLEMENT_DYNAMIC(CAlarmPopupDlg, CDialogEx) |
| | |
| | | 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() |
| | |
| | | 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, |
| | |
| | | |
| | | 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; |
| | | |
| | | AlarmManager& alarmManager = AlarmManager::getInstance(); |
| | | const AlarmInfo* info = alarmManager.getAlarmInfoByID(m_activeAlarm.nId); |
| | | |
| | | CString title, level, name, desc; |
| | | level.Format(_T("等级: %d"), m_activeAlarm.nSeverityLevel); |
| | | |
| | | if (info != nullptr && !info->strAlarmText.empty()) { |
| | | name = CString(info->strAlarmText.c_str()); |
| | | } |
| | | else { |
| | | name.Format(_T("ID:%d (%s)"), m_activeAlarm.nId, CString(m_activeAlarm.strDeviceName.c_str())); |
| | | } |
| | | |
| | | if (!m_activeAlarm.strDescription.empty()) { |
| | | desc = CString(m_activeAlarm.strDescription.c_str()); |
| | | } |
| | | else if (info != nullptr && !info->strDescription.empty()) { |
| | | desc = CString(info->strDescription.c_str()); |
| | | } |
| | | else { |
| | | desc = _T("暂无描述"); |
| | | } |
| | | |
| | | title.Format(_T("设备:%s 单元:%s"), |
| | | CString(m_activeAlarm.strDeviceName.c_str()), |
| | | CString(m_activeAlarm.strUnitName.c_str())); |
| | | |
| | | SetDlgItemText(IDC_LABEL_TITLE, title); |
| | | SetDlgItemText(IDC_LABEL_NAME, name); |
| | | SetDlgItemText(IDC_LABEL_LEVEL, level); |
| | | SetDlgItemText(IDC_LABEL_DESCRIPTION, desc); |
| | | DisplayActiveAt(m_activeIndex); |
| | | ShowAlarmControls(true); |
| | | ShowNoAlarmControls(false); |
| | | ShowWindow(SW_SHOW); |
| | | } |
| | | else { |
| | | m_hasActive = false; |
| | |
| | | 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]; |
| | | |
| | | // 标记已读 |
| | | if (auto* pParent = dynamic_cast<CServoDlg*>(GetParent())) { |
| | | pParent->AckAlarm(m_activeAlarm.nId); |
| | | } |
| | | |
| | | AlarmManager& alarmManager = AlarmManager::getInstance(); |
| | | const AlarmInfo* info = alarmManager.getAlarmInfoByID(m_activeAlarm.nId); |
| | | |
| | | CString title, level, name, desc; |
| | | level.Format(_T("等级: %d"), m_activeAlarm.nSeverityLevel); |
| | | |
| | | if (info != nullptr && !info->strAlarmText.empty()) { |
| | | name = CString(info->strAlarmText.c_str()); |
| | | } |
| | | else { |
| | | name.Format(_T("ID:%d (%s)"), m_activeAlarm.nId, CString(m_activeAlarm.strDeviceName.c_str())); |
| | | } |
| | | |
| | | if (!m_activeAlarm.strDescription.empty()) { |
| | | desc = CString(m_activeAlarm.strDescription.c_str()); |
| | | } |
| | | else if (info != nullptr && !info->strDescription.empty()) { |
| | | desc = CString(info->strDescription.c_str()); |
| | | } |
| | | else { |
| | | desc = _T("暂无描述"); |
| | | } |
| | | |
| | | title.Format(_T("设备:%s 单元:%s"), |
| | | CString(m_activeAlarm.strDeviceName.c_str()), |
| | | CString(m_activeAlarm.strUnitName.c_str())); |
| | | |
| | | SetDlgItemText(IDC_LABEL_TITLE, title); |
| | | SetDlgItemText(IDC_LABEL_NAME, name); |
| | | SetDlgItemText(IDC_LABEL_LEVEL, level); |
| | | SetDlgItemText(IDC_LABEL_DESCRIPTION, desc); |
| | | |
| | | UpdateNavButtons(); |
| | | ShowWindow(SW_SHOW); |
| | | } |
| | | |
| | | void CAlarmPopupDlg::UpdateNavButtons() |
| | | { |
| | | 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) |
| | | { |
| | | HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); |