// CDefineReportsDlg.cpp: 实现文件 // #include "pch.h" #include "EAPSimulator.h" #include "CDefineReportsDlg.h" #include "afxdialogex.h" #include "CAddIDSDlg.h" // CDefineReportsDlg 对话框 IMPLEMENT_DYNAMIC(CDefineReportsDlg, CDialogEx) CDefineReportsDlg::CDefineReportsDlg(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOG_DEFINE_REPORTS, pParent) { } CDefineReportsDlg::~CDefineReportsDlg() { } void CDefineReportsDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CDefineReportsDlg, CDialogEx) ON_BN_CLICKED(IDC_BUTTON_ADD_RPTID, &CDefineReportsDlg::OnBnClickedButtonAddRptid) ON_LBN_SELCHANGE(IDC_LIST1, &CDefineReportsDlg::OnLbnSelchangeList1) ON_BN_CLICKED(IDC_BUTTON_DEL_REPORT, &CDefineReportsDlg::OnBnClickedButtonDelReport) ON_BN_CLICKED(IDC_BUTTON_ADD_VID, &CDefineReportsDlg::OnBnClickedButtonAddVid) ON_LBN_SELCHANGE(IDC_LIST2, &CDefineReportsDlg::OnLbnSelchangeList2) ON_BN_CLICKED(IDC_BUTTON_DEL_VID, &CDefineReportsDlg::OnBnClickedButtonDelVid) ON_BN_CLICKED(IDC_BUTTON_SEND, &CDefineReportsDlg::OnBnClickedButtonSend) END_MESSAGE_MAP() // CDefineReportsDlg 消息处理程序 void CDefineReportsDlg::OnBnClickedButtonAddRptid() { CAddIDSDlg dlg; dlg.SetTitle("RPTID"); dlg.DoModal(); int PRTID = dlg.GetId(); addReport(PRTID); } void CDefineReportsDlg::OnBnClickedButtonAddVid() { CString strReportId; CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST1); int nSel = pListBox->GetCurSel(); if (nSel >= 0) { pListBox->GetText(nSel, strReportId); int RPTID = atoi(strReportId); CAddIDSDlg dlg; dlg.SetTitle("RPTID"); dlg.DoModal(); unsigned int VID = dlg.GetId();; addVid(RPTID, VID); } } void CDefineReportsDlg::OnLbnSelchangeList1() { CString strReportId; int RPTID = -1; CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST1); int nSel = pListBox->GetCurSel(); if (nSel >= 0) { pListBox->GetText(nSel, strReportId); RPTID = atoi(strReportId); } GetDlgItem(IDC_BUTTON_DEL_REPORT)->EnableWindow(nSel >= 0); GetDlgItem(IDC_BUTTON_ADD_VID)->EnableWindow(nSel >= 0); CListBox* pListBox2 = (CListBox*)GetDlgItem(IDC_LIST2); pListBox2->ResetContent(); auto iter = m_mapReport.find(RPTID); if (iter != m_mapReport.end()) { auto& vids = m_mapReport[RPTID]; for (auto item : vids) { pListBox2->AddString(std::to_string(item).c_str()); } } } void CDefineReportsDlg::OnBnClickedButtonDelReport() { CString strReportId; CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST1); int nSel = pListBox->GetCurSel(); if (nSel >= 0) { pListBox->GetText(nSel, strReportId); int RPTID = atoi(strReportId); delReport(RPTID); pListBox->DeleteString(nSel); ((CListBox*)GetDlgItem(IDC_LIST2))->ResetContent(); } nSel = pListBox->GetCurSel(); GetDlgItem(IDC_BUTTON_DEL_REPORT)->EnableWindow(nSel >= 0); GetDlgItem(IDC_BUTTON_ADD_VID)->EnableWindow(nSel >= 0); } void CDefineReportsDlg::OnLbnSelchangeList2() { CListBox* pListBox2 = (CListBox*)GetDlgItem(IDC_LIST2); int nSel = pListBox2->GetCurSel(); GetDlgItem(IDC_BUTTON_DEL_VID)->EnableWindow(nSel >= 0); } void CDefineReportsDlg::OnBnClickedButtonDelVid() { CString strRPTID, strVID; CListBox* pListBox1 = (CListBox*)GetDlgItem(IDC_LIST1); CListBox* pListBox2 = (CListBox*)GetDlgItem(IDC_LIST2); int nSel1 = pListBox1->GetCurSel(); int nSel2 = pListBox2->GetCurSel(); if (nSel1 >= 0 && nSel2 >= 0) { pListBox1->GetText(nSel1, strRPTID); pListBox2->GetText(nSel2, strVID); int RPTID = atoi(strRPTID); int VID = atoi(strVID); delVid(RPTID, VID); pListBox2->DeleteString(nSel2); } nSel2 = pListBox2->GetCurSel(); GetDlgItem(IDC_BUTTON_DEL_VID)->EnableWindow(nSel2 >= 0); } void CDefineReportsDlg::addReport(int RPTID) { auto iter = m_mapReport.find(RPTID); if (iter == m_mapReport.end()) { std::vector vids; m_mapReport[RPTID] = vids; } CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST1); pListBox->AddString(std::to_string(RPTID).c_str()); } bool CDefineReportsDlg::addVid(unsigned int RPTID, unsigned int vid) { auto iter = m_mapReport.find(RPTID); if (iter == m_mapReport.end()) { return false; } auto& vids = m_mapReport[RPTID]; vids.push_back(vid); CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST2); pListBox->AddString(std::to_string(vid).c_str()); return true; } void CDefineReportsDlg::delReport(int RPTID) { auto iter = m_mapReport.find(RPTID); if (iter != m_mapReport.end()) { m_mapReport.erase(iter); } } void CDefineReportsDlg::delVid(int RPTID, int VID) { auto iter = m_mapReport.find(RPTID); if (iter != m_mapReport.end()) { auto& vids = iter->second; for (auto iter2 = vids.begin(); iter2 != vids.end(); iter2++) { if ((*iter2) == VID) { vids.erase(iter2); break; } } } } void CDefineReportsDlg::OnBnClickedButtonSend() { theApp.m_model.m_pHsmsActive->hsmsDefineReports(m_mapReport); }