| | |
| | | #include "CPageAlarm.h" |
| | | #include "afxdialogex.h" |
| | | #include "Common.h" |
| | | #include "ToolUnits.h" |
| | | |
| | | |
| | | // CPageAlarm 对话框 |
| | |
| | | // 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(); |
| | |
| | | { |
| | | 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 |
| | |
| | | return m_hbrBkgnd; |
| | | } |
| | | |
| | | |
| | | void CPageAlarm::OnDestroy() |
| | | { |
| | | CDialogEx::OnDestroy(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | 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(); |
| | | } |