chenluhua1980
2026-01-24 847a34f02bfe00475735fb5bfbefea2db28c8ad6
SourceCode/Bond/Servo/CPageCollectionEvent.cpp
@@ -5,6 +5,7 @@
#include "Servo.h"
#include "CPageCollectionEvent.h"
#include "afxdialogex.h"
#include "CEventEditDlg.h"
// CPageCollectionEvent 对话框
@@ -149,5 +150,84 @@
void CPageCollectionEvent::OnClickedBtn(const char* btnName)
{
   // 暂留:后续实现增删改逻辑
   ASSERT(btnName);
   if (_strcmpi(btnName, "新增") == 0) {
      int rc = UX_CanExecute(L"addEvents");
      if (rc != 1) {
         AfxMessageBox("操作权限不足,请联系管理人员!");
         return;
      }
      unsigned int newId = theApp.m_model.m_hsmsPassive.getMaxCollectionEventId() + 1;
      std::vector<unsigned int> rptIds;
      CEventEditDlg dlg(_T("新增事件"), (int)newId, _T(""), _T(""), rptIds, this);
      if (dlg.DoModal() != IDOK) return;
      int ret = theApp.m_model.m_hsmsPassive.addCollectionEvent(newId, CT2A(dlg.GetNameText()), CT2A(dlg.GetDescText()), dlg.GetSelectedRptIds());
      if (ret == 0) {
         UX_RecordAction(L"addEvents");
         m_listCtrl.DeleteAllItems();
         loadCollectionEvents();
         if (CButton* pDel = GetBtnByName("删除")) pDel->EnableWindow(FALSE);
         if (CButton* pEdit = GetBtnByName("编辑")) pEdit->EnableWindow(FALSE);
      }
      else {
         AfxMessageBox(_T("新增事件失败(可能ID重复或写入失败)"));
      }
   }
   else if (_strcmpi(btnName, "删除") == 0) {
      POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
      if (pos == nullptr) return;
      int nItem = m_listCtrl.GetNextSelectedItem(pos);
      auto pEvent = reinterpret_cast<SERVO::CCollectionEvent*>(m_listCtrl.GetItemData(nItem));
      if (pEvent == nullptr) return;
      int rc = UX_CanExecute(L"delEvents");
      if (rc != 1) {
         AfxMessageBox("操作权限不足,请联系管理人员!");
         return;
      }
      int ret = theApp.m_model.m_hsmsPassive.deleteCollectionEvent((unsigned short)pEvent->getEventId());
      if (ret == 0) {
         UX_RecordAction(L"delEvents");
         m_listCtrl.DeleteAllItems();
         loadCollectionEvents();
         if (CButton* pDel = GetBtnByName("删除")) pDel->EnableWindow(FALSE);
         if (CButton* pEdit = GetBtnByName("编辑")) pEdit->EnableWindow(FALSE);
      }
      else {
         AfxMessageBox(_T("删除事件失败"));
      }
   }
   else if (_strcmpi(btnName, "编辑") == 0) {
      POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
      if (pos == nullptr) return;
      int nItem = m_listCtrl.GetNextSelectedItem(pos);
      auto pEvent = reinterpret_cast<SERVO::CCollectionEvent*>(m_listCtrl.GetItemData(nItem));
      if (pEvent == nullptr) return;
      int rc = UX_CanExecute(L"editEvents");
      if (rc != 1) {
         AfxMessageBox("操作权限不足,请联系管理人员!");
         return;
      }
      CString name = pEvent->getName().c_str();
      CString desc = pEvent->getDescription().c_str();
      auto rptIds = pEvent->getReportIds();
      CEventEditDlg dlg(_T("编辑事件"), (int)pEvent->getEventId(), name, desc, rptIds, this);
      if (dlg.DoModal() != IDOK) return;
      int ret = theApp.m_model.m_hsmsPassive.updateCollectionEvent(pEvent->getEventId(), CT2A(dlg.GetNameText()), CT2A(dlg.GetDescText()), dlg.GetSelectedRptIds());
      if (ret == 0) {
         UX_RecordAction(L"editEvents");
         m_listCtrl.DeleteAllItems();
         loadCollectionEvents();
         if (CButton* pDel = GetBtnByName("删除")) pDel->EnableWindow(FALSE);
         if (CButton* pEdit = GetBtnByName("编辑")) pEdit->EnableWindow(FALSE);
      }
      else {
         AfxMessageBox(_T("编辑事件失败(可能写入失败)"));
      }
   }
}