SourceCode/Bond/Servo/CPageReport.cpp
@@ -5,6 +5,8 @@
#include "Servo.h"
#include "CPageReport.h"
#include "afxdialogex.h"
#include "CReportEditDlg.h"
#include <algorithm>
// CPageReport 对话框
@@ -152,7 +154,32 @@
void CPageReport::OnClickedBtn(const char* btnName)
{
   ASSERT(btnName);
   if (_strcmpi(btnName, "删除") == 0) {
   if (_strcmpi(btnName, "新增") == 0) {
      int rc = UX_CanExecute(L"addReports");
      if (rc != 1) {
         AfxMessageBox("操作权限不足,请联系管理人员!");
         return;
      }
      unsigned int newId = theApp.m_model.m_hsmsPassive.getMaxReportId() + 1;
      std::vector<unsigned int> initVids;
      CReportEditDlg dlg(_T("新增报告"), static_cast<int>(newId), initVids, this);
      if (dlg.DoModal() != IDOK) return;
      const auto& vids = dlg.GetSelectedVids();
      int ret = theApp.m_model.m_hsmsPassive.addReport(static_cast<int>(newId), vids);
      if (ret == 0) {
         UX_RecordAction(L"addReports");
         m_listCtrl.DeleteAllItems();
         loadReports();
         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);
@@ -177,4 +204,34 @@
         AfxMessageBox(_T("删除报告失败"));
      }
   }
   else if (_strcmpi(btnName, "编辑") == 0) {
      POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
      if (pos == nullptr) return;
      int nItem = m_listCtrl.GetNextSelectedItem(pos);
      auto pRpt = reinterpret_cast<SERVO::CReport*>(m_listCtrl.GetItemData(nItem));
      if (pRpt == nullptr) return;
      int rc = UX_CanExecute(L"editReports");
      if (rc != 1) {
         AfxMessageBox("操作权限不足,请联系管理人员!");
         return;
      }
      std::vector<unsigned int> vidsExisting = pRpt->getVids();
      CReportEditDlg dlg(_T("编辑报告"), (int)pRpt->getReportId(), vidsExisting, this);
      if (dlg.DoModal() != IDOK) return;
      const auto& vids = dlg.GetSelectedVids();
      int ret = theApp.m_model.m_hsmsPassive.updateReport((int)pRpt->getReportId(), vids);
      if (ret == 0) {
         UX_RecordAction(L"editReports");
         m_listCtrl.DeleteAllItems();
         loadReports();
         if (CButton* pDel = GetBtnByName("删除")) pDel->EnableWindow(FALSE);
         if (CButton* pEdit = GetBtnByName("编辑")) pEdit->EnableWindow(FALSE);
      }
      else {
         AfxMessageBox(_T("编辑报告失败(可能文件写入失败)"));
      }
   }
}