LAPTOP-SNT8I5JK\Boounion
2025-09-15 c3aa662297c2182de2e7a53d7bf63f4ab6b1adbd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// 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<unsigned int> 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);
}