chenluhua1980
8 天以前 6c92ade0aeb6a505f2ab8108dcbdab20e37a9fac
SourceCode/Bond/Servo/CPageReport.cpp
@@ -5,6 +5,8 @@
#include "Servo.h"
#include "CPageReport.h"
#include "afxdialogex.h"
#include "CReportEditDlg.h"
#include <algorithm>
// CPageReport 对话框
@@ -32,6 +34,7 @@
   ON_WM_CTLCOLOR()
   ON_WM_DESTROY()
   ON_WM_SIZE()
   ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &CPageReport::OnLvnItemchangedList1)
END_MESSAGE_MAP()
@@ -123,3 +126,112 @@
      m_listCtrl.SetItemText(index, 2, item->getVariablesIdsText().c_str());
   }
}
void CPageReport::OnCreateBtns()
{
   const int BTN_W = 80;
   const int BTN_H = 28;
   CreateBtn(_T("新增"), BTN_W, BTN_H, 2001);
   CreateBtn(_T("删除"), BTN_W, BTN_H, 2002)->EnableWindow(FALSE);
   CreateBtn(_T("编辑"), BTN_W, BTN_H, 2003)->EnableWindow(FALSE);
}
void CPageReport::OnLvnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
{
   LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
   int nSelCount = m_listCtrl.GetSelectedCount();
   if (CButton* pDel = GetBtnByName("删除")) {
      pDel->EnableWindow(nSelCount > 0);
   }
   if (CButton* pEdit = GetBtnByName("编辑")) {
      pEdit->EnableWindow(nSelCount > 0);
   }
   *pResult = 0;
}
void CPageReport::OnClickedBtn(const char* btnName)
{
   ASSERT(btnName);
   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);
      auto pRpt = reinterpret_cast<SERVO::CReport*>(m_listCtrl.GetItemData(nItem));
      if (pRpt == nullptr) return;
      int rc = UX_CanExecute(L"delReports");
      if (rc != 1) {
         AfxMessageBox("操作权限不足,请联系管理人员!");
         return;
      }
      int ret = theApp.m_model.m_hsmsPassive.deleteReport((int)pRpt->getReportId());
      if (ret == 0) {
         UX_RecordAction(L"delReports");
         m_listCtrl.DeleteAllItems();
         loadReports();
         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 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("编辑报告失败(可能文件写入失败)"));
      }
   }
}