chenluhua1980
2025-12-11 33f080ddc32f3545b685b2e0a7a5df3c35894270
SourceCode/Bond/Servo/PageAlarm.cpp
@@ -48,7 +48,7 @@
   }
}
void CPageAlarm::InitRxWindow()
void CPageAlarm::InitRxWindows()
{
   /* code */
   // 订阅数据
@@ -82,12 +82,52 @@
void CPageAlarm::Resize()
{
   CWnd* pItem;
   CRect rcClient;
   GetClientRect(&rcClient);
   pItem = GetDlgItem(IDC_LIST_ALARM);
   pItem->MoveWindow(12, 58, rcClient.Width() - 24, rcClient.Height() - 64);
   // ===== 常量定义 =====
   const int nLeft = 12;
   const int nRight = 12;
   const int nTop = 58;
   const int nButtonHeight = 28;
   const int nButtonMarginBottom = 12;
   const int nSpacing = 8;
   const int nButtonWidth = 80;
   const int nLabelWidth = 100;
   // ===== 分页控件布局 =====
   int yBottom = rcClient.bottom - nButtonMarginBottom - nButtonHeight;
   int xRight = rcClient.Width() - nRight;
   CWnd* pBtnNext = GetDlgItem(IDC_BUTTON_NEXT_PAGE);
   CWnd* pBtnPrev = GetDlgItem(IDC_BUTTON_PREV_PAGE);
   CWnd* pLabelPage = GetDlgItem(IDC_LABEL_PAGE_NUMBER);
   if (pBtnNext && pBtnPrev && pLabelPage) {
      // 获取分页文本宽度估算
      //CString strLabel;
      //GetDlgItemText(IDC_LABEL_PAGE_NUMBER, strLabel);
      //if (strLabel.IsEmpty()) {
      //   strLabel = _T("第 1 / 1 页");
      //}
      //int nCharWidth = 8;
      //int nLabelWidth = strLabel.GetLength() * nCharWidth + 20;
      // 设置按钮和标签位置
      pBtnNext->MoveWindow(xRight - nButtonWidth, yBottom, nButtonWidth, nButtonHeight);
      xRight -= nButtonWidth + nSpacing;
      pLabelPage->MoveWindow(xRight - nLabelWidth, yBottom, nLabelWidth, nButtonHeight);
      xRight -= nLabelWidth + nSpacing;
      pBtnPrev->MoveWindow(xRight - nButtonWidth, yBottom, nButtonWidth, nButtonHeight);
   }
   // ===== 表格区域布局 =====
   if (nullptr != m_listCtrl.m_hWnd) {
      int listHeight = yBottom - nTop - nSpacing;
      m_listCtrl.MoveWindow(nLeft, nTop, rcClient.Width() - nLeft - nRight, listHeight);
   }
}
void CPageAlarm::LoadAlarms()
@@ -100,7 +140,7 @@
void CPageAlarm::UpdatePageData()
{
   // 根据过滤条件加载数据,提供描述和时间范围查询
   auto vecData = AlarmManager::getInstance().getFilteredAlarms("", "", m_strDeviceName, m_strUnitName, m_strKeyword, m_szTimeStart, m_szTimeEnd, m_nCurPage, PAGE_SIZE);
   auto vecData = AlarmManager::getInstance().getFilteredAlarms(m_strKeyword, m_szTimeStart, m_szTimeEnd, m_nCurPage, PAGE_SIZE);
   // 填充数据到控件
   CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
@@ -114,12 +154,15 @@
{
   // 更新分页信息
   CString strPage;
   strPage.Format(_T("第 %d 页"), m_nCurPage);
   strPage.Format(_T("第 %d / %d 页"), m_nCurPage, m_nTotalPages);
   SetDlgItemText(IDC_LABEL_PAGE_NUMBER, strPage);
   // 启用/禁用翻页按钮
   GetDlgItem(IDC_BUTTON_PREV_PAGE)->EnableWindow(m_nCurPage > 1);
   GetDlgItem(IDC_BUTTON_NEXT_PAGE)->EnableWindow(m_nCurPage < m_nTotalPages);
   // 调整控件大小
   // Resize();
}
void CPageAlarm::FillDataToListCtrl(CListCtrl* pListCtrl, const std::vector<AlarmData>& vecData)
@@ -153,7 +196,7 @@
      pListCtrl->DeleteItem(nRowCount - 1);
   }
   int nNewItem = pListCtrl->InsertItem(0, _T(""));
   int nNewItem = pListCtrl->InsertItem(pListCtrl->GetItemCount(), _T(""));
   // 设置每一列的数据
   CString str;
@@ -206,6 +249,7 @@
BOOL CPageAlarm::OnInitDialog()
{
   CDialogEx::OnInitDialog();
   InitRxWindows();
   SetTimer(1, 3000, nullptr);
   // 下拉框控件
@@ -254,7 +298,7 @@
   // 计算总页数
   int totalRecords = AlarmManager::getInstance().getTotalAlarmCount("", "", m_strDeviceName, m_strUnitName, m_strKeyword, m_szTimeStart, m_szTimeEnd);
   int totalRecords = AlarmManager::getInstance().getTotalAlarmCount(m_strKeyword, m_szTimeStart, m_szTimeEnd);
   m_nTotalPages = (totalRecords + PAGE_SIZE - 1) / PAGE_SIZE;
   m_nCurPage = 1;
@@ -383,7 +427,7 @@
   }
   // 计算总页数
   int totalRecords = AlarmManager::getInstance().getTotalAlarmCount("", "", m_strDeviceName, m_strUnitName, m_strKeyword, m_szTimeStart, m_szTimeEnd);
   int totalRecords = AlarmManager::getInstance().getTotalAlarmCount(m_strKeyword, m_szTimeStart, m_szTimeEnd);
   m_nTotalPages = (totalRecords + PAGE_SIZE - 1) / PAGE_SIZE;
   m_nCurPage = 1;
@@ -463,3 +507,12 @@
   m_nCurPage++;
   UpdatePageData();  // 调用分页更新函数
}
BOOL CPageAlarm::PreTranslateMessage(MSG* pMsg)
{
   if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE) {
      return TRUE;
   }
   return CDialogEx::PreTranslateMessage(pMsg);
}