| | |
| | | #include "afxdialogex.h" |
| | | #include "AlarmDlg.h" |
| | | #include "AlarmManager.h" |
| | | #include "Common.h" |
| | | |
| | | #define PAGE_SIZE 10 |
| | | #define PAGE_BACKGROUND_COLOR RGB(252, 252, 255) |
| | |
| | | // onNext |
| | | pAny->addRef(); |
| | | int code = pAny->getCode(); |
| | | //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); |
| | | // } |
| | | //} |
| | | |
| | | if (RX_CODE_STEP_EVENT_READDATA == code) { |
| | | LOGI("<CAlarmDlg> Accept RX_CODE_STEP_EVENT_READDATA successfully!"); |
| | | // 通知设备状态 |
| | | SERVO::CEqAlarmStep* pStep = nullptr; |
| | | if (pAny->getPtrValue("ptr", (void*&)pStep)) { |
| | | if (pStep != nullptr) { |
| | | // 获取 AlarmManager 单例 |
| | | AlarmManager& alarmManager = AlarmManager::getInstance(); |
| | | |
| | | // 从 pStep 获取需要的参数,假设这些值是从 pStep 中获取的 |
| | | std::string id = std::to_string(pStep->getAlarmId()); |
| | | std::string deviceName = std::to_string(pStep->getUnitId()); |
| | | std::string description = pStep->getText(); |
| | | std::string startTime = "2025-02-25 10:00"; |
| | | std::string endTime = "2025-02-25 12:00"; |
| | | |
| | | // 插入列表控件 |
| | | CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM); |
| | | if (pListCtrl != nullptr) { |
| | | InsertAlarmData(pListCtrl, id.c_str(), deviceName.c_str(), description.c_str(), startTime.c_str(), endTime.c_str()); |
| | | } |
| | | |
| | | // 调用 addAlarm 添加新的 Alarm |
| | | bool result = alarmManager.addAlarm(id, deviceName, description, startTime, endTime); |
| | | if (result) { |
| | | LOGI("<CAlarmDlg> Alarm added successfully!"); |
| | | } |
| | | else { |
| | | LOGI("<CAlarmDlg> Failed to add alarm."); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | pAny->release(); |
| | | }, [&]() -> void { |
| | |
| | | } |
| | | } |
| | | |
| | | void CAlarmDlg::InsertAlarmData(CListCtrl* pListCtrl, const CString& alarmId, const CString& deviceName, const CString& description, const CString& startTime, const CString& endTime) |
| | | { |
| | | int nRowCount = pListCtrl->GetItemCount(); |
| | | if (nRowCount >= PAGE_SIZE) { |
| | | pListCtrl->DeleteItem(nRowCount - 1); |
| | | } |
| | | |
| | | int nNewItem = pListCtrl->InsertItem(0, _T("")); |
| | | pListCtrl->SetItemText(nNewItem, 1, alarmId); // 警告ID |
| | | pListCtrl->SetItemText(nNewItem, 2, deviceName); // 设备名称 |
| | | pListCtrl->SetItemText(nNewItem, 3, description); // 描述 |
| | | pListCtrl->SetItemText(nNewItem, 4, startTime); // 发生时间 |
| | | pListCtrl->SetItemText(nNewItem, 5, endTime); // 解除时间 |
| | | |
| | | // 重新调整列宽 |
| | | pListCtrl->SetColumnWidth(0, LVSCW_AUTOSIZE); |
| | | pListCtrl->SetColumnWidth(1, LVSCW_AUTOSIZE); |
| | | pListCtrl->SetColumnWidth(2, LVSCW_AUTOSIZE); |
| | | pListCtrl->SetColumnWidth(3, LVSCW_AUTOSIZE); |
| | | pListCtrl->SetColumnWidth(4, LVSCW_AUTOSIZE); |
| | | pListCtrl->SetColumnWidth(5, LVSCW_AUTOSIZE); |
| | | } |
| | | |
| | | void CAlarmDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | DDX_Control(pDX, IDC_DATETIMEPICKER_START, m_dateTimeStart); |