chenluhua1980
2025-12-17 2aff4ac73e77d803ba3656057187956258713dbd
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
194
195
196
197
198
199
200
201
202
203
204
205
// CLinkReportDlg.cpp: 实现文件
//
 
#include "pch.h"
#include "EAPSimulator.h"
#include "CLinkReportDlg.h"
#include "afxdialogex.h"
#include <string.h>  
#include <regex>
#include "CLinkReportDetailDlg.h"
 
 
// CLinkReportDlg 对话框
 
IMPLEMENT_DYNAMIC(CLinkReportDlg, CDialogEx)
 
CLinkReportDlg::CLinkReportDlg(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_DIALOG_LINK_REPORT, pParent)
{
 
}
 
CLinkReportDlg::~CLinkReportDlg()
{
}
 
void CLinkReportDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
 
 
BEGIN_MESSAGE_MAP(CLinkReportDlg, CDialogEx)
    ON_NOTIFY(NM_DBLCLK, IDC_LIST1, &CLinkReportDlg::OnListCtrlDoubleClick)
    ON_BN_CLICKED(IDC_BUTTON_SEND, &CLinkReportDlg::OnBnClickedButtonSend)
    ON_WM_DESTROY()
END_MESSAGE_MAP()
 
 
// CLinkReportDlg 消息处理程序
BOOL CLinkReportDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
    CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST1);
    DWORD dwStyle = pListCtrl->GetExtendedStyle();
    dwStyle |= LVS_EX_FULLROWSELECT;
    dwStyle |= LVS_EX_GRIDLINES;
    pListCtrl->SetExtendedStyle(dwStyle);
    pListCtrl->ModifyStyle(0, LVS_SHOWSELALWAYS);
 
    HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
    ListView_SetImageList(pListCtrl->GetSafeHwnd(), imageList, LVSIL_SMALL);
    pListCtrl->InsertColumn(0, _T(""), LVCFMT_RIGHT, 0);
    pListCtrl->InsertColumn(1, _T("CEID"), LVCFMT_LEFT, 120);
    pListCtrl->InsertColumn(2, _T("CD Name"), LVCFMT_LEFT, 120);
    pListCtrl->InsertColumn(3, _T("Descriptions"), LVCFMT_LEFT, 180);
    pListCtrl->InsertColumn(4, _T("Attached RPTID"), LVCFMT_LEFT, 120);
    pListCtrl->SetColumnWidth(4, LVSCW_AUTOSIZE_USEHEADER);
 
 
    CString strFile;
    strFile.Format(_T("%s\\CollectionEventList.txt"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
    loadCollectionEvents((LPTSTR)(LPCTSTR)strFile);
 
    for (auto item : m_collectionEvents) {
        int index = pListCtrl->InsertItem(pListCtrl->GetItemCount(), _T(""));
        pListCtrl->SetItemData(index, (DWORD_PTR)item);
        pListCtrl->SetItemText(index, 1, std::to_string(item->getEventId()).c_str());
        pListCtrl->SetItemText(index, 2, item->getName().c_str());
        pListCtrl->SetItemText(index, 3, item->getDescription().c_str());
        pListCtrl->SetItemText(index, 4, item->getReportIdsText().c_str());
    }
 
 
    return TRUE;  // return TRUE unless you set the focus to a control
                  // 异常: OCX 属性页应返回 FALSE
}
 
int CLinkReportDlg::loadCollectionEvents(const char* pszFilepath)
{
    CStdioFile file;
    if (!file.Open(pszFilepath, CFile::modeRead)) {
        return -1;
    }
 
    std::regex pattern("^\\d+,[^,]*,[^,]*,\\(\\d+(,\\d+)*\\).*");  // 匹配以数字+逗号开头的字符串
    std::vector<SERVO::CCollectionEvent*> events;
    int index, last;
    CString strLine, strRPTIDs;
    CString strId, strName, strDescription;
    while (file.ReadString(strLine)) {
        if (!std::regex_match((LPTSTR)(LPCTSTR)strLine, pattern)) {
            continue;
        }
 
        last = 0;
        index = strLine.Find(",", last);
        if (index < 0) continue;
        strId = strLine.Left(index);
        last = index + 1;
 
        index = strLine.Find(",", last);
        if (index < 0) continue;
        strName = strLine.Mid(last, index - last);
        last = index + 1;
 
        index = strLine.Find(",", last);
        if (index < 0) continue;
        strDescription = strLine.Mid(last, index - last);
        strRPTIDs = strLine.Right(strLine.GetLength() - index - 1);
        strRPTIDs.Delete(0);
        strRPTIDs.Delete(strRPTIDs.GetLength() - 1);
        auto prtids = parseVidList(strRPTIDs);
 
        SERVO::CCollectionEvent* pEvent = new SERVO::CCollectionEvent(
            atoi(strId), (LPTSTR)(LPCTSTR)strName, (LPTSTR)(LPCTSTR)strDescription, prtids);
        events.push_back(pEvent);
    }
 
    if (!events.empty()) {
        clearAllCollectionEvent();
        for (auto item : events) {
            m_collectionEvents.push_back(item);
        }
    }
 
 
    file.Close();
    return 0;
}
 
std::vector<unsigned int> CLinkReportDlg::parseVidList(CString& strNums)
{
    // 1. 先去掉可能出现的空白符(空格、制表符等)
    strNums.Trim();
 
    // 2️.
    std::vector<unsigned int> result;
    int i = 0;
    CString strVid;
    while (1) {
        if (!AfxExtractSubString(strVid, (LPCTSTR)strNums, i, ',')) {
            break;
        }
        if (!strVid.IsEmpty())                 // 防御性检查
            result.push_back(std::stoi((LPTSTR)(LPCTSTR)strVid));
        i++;
 
    }
 
    return result;
}
 
void CLinkReportDlg::clearAllCollectionEvent()
{
    for (auto item : m_collectionEvents) {
        delete item;
    }
    m_collectionEvents.clear();
}
 
void CLinkReportDlg::OnListCtrlDoubleClick(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMITEMACTIVATE pNMItem = (LPNMITEMACTIVATE)pNMHDR;
    int nItem = pNMItem->iItem;
    if (nItem >= 0) {
        CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST1);
        SERVO::CCollectionEvent* pEvent = (SERVO::CCollectionEvent*)pListCtrl->GetItemData(nItem);
        CLinkReportDetailDlg dlg;
        dlg.SetCollectionEvent(pEvent);
        if (IDOK == dlg.DoModal()) {
            pListCtrl->SetItemText(nItem, 4, pEvent->getReportIdsText().c_str());
        }
    }
 
    *pResult = 0;
}
 
void CLinkReportDlg::OnBnClickedButtonSend()
{
    std::vector<SERVO::CCollectionEvent*> events;
    CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST1);
    POSITION pos = pListCtrl->GetFirstSelectedItemPosition();
    while (pos) {
        int nItem = pListCtrl->GetNextSelectedItem(pos);
        SERVO::CCollectionEvent* pEvent = (SERVO::CCollectionEvent*)pListCtrl->GetItemData(nItem);
        events.push_back(pEvent);
    }
 
    std::map<unsigned int, std::vector<unsigned int>> mapEvent;
    for (auto item : events) {
        std::vector<unsigned int> RPTIDs = item->getReportIds();
        mapEvent[item->getEventId()] = RPTIDs;
    }
 
 
    theApp.m_model.m_pHsmsActive->hsmsLinkEventReport(mapEvent);
}
 
void CLinkReportDlg::OnDestroy()
{
    CDialogEx::OnDestroy();
    clearAllCollectionEvent();
}