mrDarker
2025-06-17 58b5bb07de4bcbf670db5ad79ff8b9bd7afc1e28
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
// UserManagerDlg.cpp: 实现文件
//
 
#include "stdafx.h"
#include "Servo.h"
#include "afxdialogex.h"
#include "UserManagerDlg.h"
#include "InputDialog.h"
#include "UserManager.h"
#include "SystemLogManager.h"
#include "NewCellTypes/GridCellCombo.h"
#include "NewCellTypes/GridCellNumeric.h"
#include <set>
 
const COLORREF CURR_USER_BK_COLOR = RGB(0, 255, 0);
 
// CUserManagerDlg 对话框
 
IMPLEMENT_DYNAMIC(CUserManagerDlg, CBaseDlg)
 
CUserManagerDlg::CUserManagerDlg(CWnd* pParent /*=nullptr*/)
    : CBaseDlg(IDD_DIALOG_USER_MANAGER, pParent)
{
}
 
CUserManagerDlg::~CUserManagerDlg()
{
}
 
void CUserManagerDlg::DoDataExchange(CDataExchange* pDX)
{
    DDX_Control(pDX, IDC_CUSTOM_USER, m_gridUserManager);
    CBaseDlg::DoDataExchange(pDX);
}
 
void CUserManagerDlg::InitUserManager()
{
    if (m_gridUserManager.GetSafeHwnd() == NULL)
        return;
 
    int nRows = 1;
    int nCols = 8;
 
    int nFixRows = 1;
    int nFixCols = 0;
    int nRowIdx = 0;
    int nColIdx = 0;
 
    m_gridUserManager.DeleteAllItems();
    m_gridUserManager.SetVirtualMode(FALSE);
    m_gridUserManager.GetDefaultCell(TRUE, FALSE)->SetBackClr(g_nGridFixCellColor); // 设置固定行背景色
    m_gridUserManager.GetDefaultCell(FALSE, TRUE)->SetBackClr(g_nGridFixCellColor); // 设置固定列背景色
    m_gridUserManager.GetDefaultCell(FALSE, FALSE)->SetBackClr(g_nGridCellColor);    // 设置单元格背景色
    m_gridUserManager.SetFixedTextColor(g_nGridFixFontColor); // 设置固定行列字体颜色
 
    m_gridUserManager.SetRowCount(nRows);
    m_gridUserManager.SetColumnCount(nCols);
    m_gridUserManager.SetFixedRowCount(nFixRows);
    m_gridUserManager.SetFixedColumnCount(nFixCols);
 
    // Col
    m_gridUserManager.SetColumnWidth(nColIdx, 20);
    m_gridUserManager.SetItemText(nRowIdx, nColIdx++, _T("No."));
    m_gridUserManager.SetColumnWidth(nColIdx, 70);
    m_gridUserManager.SetItemText(nRowIdx, nColIdx++, _T("用户名"));
    m_gridUserManager.SetColumnWidth(nColIdx, 70);
    m_gridUserManager.SetItemText(nRowIdx, nColIdx++, _T("密码"));
    m_gridUserManager.SetColumnWidth(nColIdx, 70);
    m_gridUserManager.SetItemText(nRowIdx, nColIdx++, _T("权限"));
    m_gridUserManager.SetColumnWidth(nColIdx, 70);
    m_gridUserManager.SetItemText(nRowIdx, nColIdx++, _T("会话超时(分钟)"));
    m_gridUserManager.SetColumnWidth(nColIdx, 70);
    m_gridUserManager.SetItemText(nRowIdx, nColIdx++, _T("会话过期(小时)"));
    m_gridUserManager.SetColumnWidth(nColIdx, 70);
    m_gridUserManager.SetItemText(nRowIdx, nColIdx++, _T("最后一次登录时间"));
    m_gridUserManager.SetColumnWidth(nColIdx, 100);
    m_gridUserManager.SetItemText(nRowIdx, nColIdx++, _T("角色描述"));
 
    m_gridUserManager.SetFixedRowSelection(FALSE);
    m_gridUserManager.SetFixedColumnSelection(FALSE);
    m_gridUserManager.SetEditable(TRUE);
    m_gridUserManager.SetRowResize(FALSE);
    m_gridUserManager.SetColumnResize(TRUE);
    m_gridUserManager.ExpandColumnsToFit(TRUE);
    m_gridUserManager.SetListMode(TRUE);                // 启用列表模式
    m_gridUserManager.EnableSelection(TRUE);            // 启用选择
    m_gridUserManager.SetSingleRowSelection(TRUE);        // 自动整行高亮(限制为单行选择)
    m_gridUserManager.ExpandLastColumn();                // 最后一列填充网格
 
    m_mapRoleDescriptions.clear();
    m_mapRoleDescriptions.emplace(_T("管理员"), _T("管理所有用户,分配权限"));
    m_mapRoleDescriptions.emplace(_T("工程师"), _T("维护系统,解决技术问题"));
    m_mapRoleDescriptions.emplace(_T("操作员"), _T("执行日常操作任务"));
 
    FillUserManager();
}
 
void CUserManagerDlg::FillUserManager()
{
    UserManager& userManager = UserManager::getInstance();
    if (!userManager.isLoggedIn()) {
        AfxMessageBox(_T("未登录"));
        return;
    }
 
    if (userManager.getCurrentUserRole() != UserRole::SuperAdmin) {
        AfxMessageBox(_T("非管理员用户"));
        return;
    }
 
    int nCurrNameRow = -1;
    std::vector<std::vector<std::string>> usersData = userManager.getUsers();
    if (!usersData.empty()) {
        m_gridUserManager.SetRowCount((int)usersData.size() + 1);
 
        for (int i = 0; i < usersData.size(); i++) {
            int nRowIdx = i + 1;
            int nColIdx = 0;
 
            m_gridUserManager.SetItemText(nRowIdx, nColIdx++, std::to_string(i + 1).c_str());
            for (int j = 0; j < usersData[i].size(); j++) {
                if (usersData[i][1].empty()) {
                    continue;
                }
                m_gridUserManager.SetItemText(nRowIdx, nColIdx++, usersData[i][j].c_str());
            }
 
            // 当前登录用户高亮
            if (nCurrNameRow == -1 && usersData[i][0] == userManager.getCurrentUser()) {
                nCurrNameRow = nRowIdx;
            }
        }
    }
 
    CStringArray permissions;
    permissions.Add(_T("管理员"));
    permissions.Add(_T("工程师"));
    permissions.Add(_T("操作员"));
 
    int nCols = m_gridUserManager.GetColumnCount();
    for (int i = 1; i < m_gridUserManager.GetRowCount(); ++i) {
        m_gridUserManager.SetItemState(i, 0, GVIS_READONLY); // 第一列只读
        m_gridUserManager.SetItemState(i, nCols - 2, GVIS_READONLY); // 倒数第二列只读
        m_gridUserManager.SetItemState(i, nCols - 1, GVIS_READONLY); // 最后一列只读
 
        // 第四列设置权限列为下拉框
        if (m_gridUserManager.SetCellType(i, 3, RUNTIME_CLASS(CGridCellCombo))) {
            CGridCellCombo* pCell = static_cast<CGridCellCombo*>(m_gridUserManager.GetCell(i, 3));
            pCell->SetOptions(permissions);
            pCell->SetStyle(CBS_DROPDOWNLIST);
 
            CString cstrRole = m_gridUserManager.GetItemText(i, 3);
            int nRole = _ttoi(cstrRole);
            if (nRole < 0 || nRole > 2) {
                CString cstrMessage;
                cstrMessage.Format(_T("用户 [%s],权限异常!将设置成操作员!"), m_gridUserManager.GetItemText(i, 1));
                AfxMessageBox(cstrMessage);
                nRole = 2;
            }
 
            m_gridUserManager.SetItemText(i, 3, permissions.GetAt(nRole));
 
            auto it = m_mapRoleDescriptions.find(permissions.GetAt(nRole));
            if (it != m_mapRoleDescriptions.end()) {
                m_gridUserManager.SetItemText(i, 7, it->second);
            }
        }
 
        // 第五、六列(会话超时)设置为Numeric
        //m_gridUserManager.SetCellType(i, 4, RUNTIME_CLASS(CGridCellNumeric));
        //m_gridUserManager.SetCellType(i, 5, RUNTIME_CLASS(CGridCellNumeric));
        m_gridUserManager.SetItemState(i, 4, GVIS_READONLY); // 第五列只读
        m_gridUserManager.SetItemState(i, 5, GVIS_READONLY); // 第六列只读
 
        m_gridUserManager.ExpandColumnsToFit(FALSE);
        m_gridUserManager.ExpandLastColumn();
    }
 
    for (int i = 0; i < nCols; i++) {
        m_gridUserManager.SetItemBkColour(nCurrNameRow, i, CURR_USER_BK_COLOR);
    }
    m_gridUserManager.SetItemState(nCurrNameRow, 3, GVIS_READONLY);
 
    m_gridUserManager.Invalidate();
    m_gridUserManager.UpdateWindow();
}
 
void CUserManagerDlg::AddRow(CGridCtrl* pGridCtrl)
{
    if (!pGridCtrl) return;
 
    if (pGridCtrl->GetRowCount() <= 0 || pGridCtrl->GetColumnCount() <= 0) {
        AfxMessageBox(_T("网格控件未正确初始化,请检查初始化逻辑!"));
        return;
    }
 
    CInputDialog inputDialog(_T("添加用户"), _T("请输入用户名:"));
    if (inputDialog.DoModal() != IDOK) {
        return;
    }
 
    CString inputText = inputDialog.GetInputText();
    if (inputText.IsEmpty()) {
        AfxMessageBox(_T("用户名不能为空!"));
        return;
    }
 
    if (IsUsernameDuplicate(inputText)) {
        AfxMessageBox(_T("用户名重复!"));
        return;
    }
 
    int nRowCount = pGridCtrl->GetRowCount();
    pGridCtrl->SetRowCount(nRowCount + 1);
    int newRowIndex = nRowCount;
 
    CString strText;
    strText.Format(_T("%d"), newRowIndex);
    pGridCtrl->SetItemText(newRowIndex, 0, strText);
    pGridCtrl->SetItemText(newRowIndex, 1, inputText);
    pGridCtrl->SetItemText(newRowIndex, 2, _T("123456"));
    pGridCtrl->SetItemText(newRowIndex, 3, _T("操作员"));
    pGridCtrl->SetItemText(newRowIndex, 4, _T("30"));
    pGridCtrl->SetItemText(newRowIndex, 5, _T("72"));
    pGridCtrl->SetItemText(newRowIndex, 6, _T("2024-01-01 00:00:00"));
 
    auto it = m_mapRoleDescriptions.find(_T("操作员"));
    if (it != m_mapRoleDescriptions.end()) {
        pGridCtrl->SetItemText(newRowIndex, 7, it->second);
    }
 
    int nCols = pGridCtrl->GetColumnCount();
    pGridCtrl->SetItemState(newRowIndex, 0, GVIS_READONLY); // 第一列只读
    pGridCtrl->SetItemState(newRowIndex, nCols - 2, GVIS_READONLY); // 倒数第二列只读
    pGridCtrl->SetItemState(newRowIndex, nCols - 1, GVIS_READONLY); // 最后一列只读
 
    // 第四列设置(权限列)为下拉框
    CStringArray permissions;
    permissions.Add(_T("管理员"));
    permissions.Add(_T("工程师"));
    permissions.Add(_T("操作员"));
 
    if (pGridCtrl->SetCellType(newRowIndex, 3, RUNTIME_CLASS(CGridCellCombo))) {
        CGridCellCombo* pCell = static_cast<CGridCellCombo*>(pGridCtrl->GetCell(newRowIndex, 3));
        pCell->SetOptions(permissions);
        pCell->SetStyle(CBS_DROPDOWNLIST);
 
        pGridCtrl->SetItemText(newRowIndex, 3, permissions.GetAt(2));
    }
 
    // 第五、六列(会话超时)设置为Numeric
    //pGridCtrl->SetCellType(newRowIndex, 4, RUNTIME_CLASS(CGridCellNumeric));
    //pGridCtrl->SetCellType(newRowIndex, 5, RUNTIME_CLASS(CGridCellNumeric));
    pGridCtrl->SetItemState(newRowIndex, 4, GVIS_READONLY); // 第五列只读
    pGridCtrl->SetItemState(newRowIndex, 5, GVIS_READONLY); // 第六列只读
 
    pGridCtrl->ExpandColumnsToFit(FALSE);
    pGridCtrl->ExpandLastColumn();
    pGridCtrl->Invalidate();
    pGridCtrl->UpdateWindow();
 
    CString cstrMessage;
    cstrMessage.Format(_T("预添加用户 [%s]!"), inputText);
    std::string strMessage = CT2A(cstrMessage);
    SystemLogManager::getInstance().log(SystemLogManager::LogType::Operation, strMessage);
}
 
void CUserManagerDlg::DeleteSelectedRow(CGridCtrl* pGridCtrl)
{
    if (!pGridCtrl) return;
    CCellRange selectedRange = pGridCtrl->GetSelectedCellRange();
    if (selectedRange.IsValid()) {
        CString currentUser = UserManager::getInstance().getCurrentUser().c_str();
        std::vector<int> rowsToDelete;
 
        for (int row = selectedRange.GetMinRow(); row <= selectedRange.GetMaxRow(); ++row) {
            BOOL isRowSelected = FALSE;
            for (int col = selectedRange.GetMinCol(); col <= selectedRange.GetMaxCol(); ++col) {
                if (pGridCtrl->IsCellSelected(row, col)) {
                    isRowSelected = TRUE;
                    break;
                }
            }
 
            if (!isRowSelected) {
                continue;
            }
 
            CString selectedUser = pGridCtrl->GetItemText(row, 1);
            if (selectedUser == currentUser) {
                CString message;
                message.Format(_T("用户 [%s] 是当前登录用户,不能删除!"), currentUser);
                AfxMessageBox(message);
                return;
            }
 
            rowsToDelete.push_back(row);
        }
 
        if (rowsToDelete.empty()) {
            AfxMessageBox(_T("请先选择要删除的行!"));
            return;
        }
 
        CString message;
        if (rowsToDelete.size() == 1) {
            CString selectedUser = pGridCtrl->GetItemText(rowsToDelete[0], 1);
            message.Format(_T("确定要删除选中用户 [%s] 吗?"), selectedUser);
 
            CString cstrMessage;
            cstrMessage.Format(_T("预删除用户 [%s]!"), selectedUser);
            std::string strMessage = CT2A(cstrMessage);
            SystemLogManager::getInstance().log(SystemLogManager::LogType::Operation, strMessage);
        }
        else {
            message.Format(_T("确定要删除选中的 %d 个用户吗?"), rowsToDelete.size());
        }
 
        if (AfxMessageBox(message, MB_YESNO | MB_ICONQUESTION) == IDYES) {
            for (auto it = rowsToDelete.rbegin(); it != rowsToDelete.rend(); ++it) {
                pGridCtrl->DeleteRow(*it);
            }
 
            pGridCtrl->ExpandColumnsToFit(FALSE);
            pGridCtrl->ExpandLastColumn();
            pGridCtrl->Invalidate();
            pGridCtrl->UpdateWindow();
        }
    }
    else {
        AfxMessageBox(_T("请先选择要删除的用户!"));
    }
}
 
bool CUserManagerDlg::IsUsernameDuplicate(const CString& username)
{
    for (int row = 1; row < m_gridUserManager.GetRowCount(); ++row) {
        if (m_gridUserManager.GetItemText(row, 1) == username) {
            return true;
        }
    }
    return false;
}
 
BEGIN_MESSAGE_MAP(CUserManagerDlg, CBaseDlg)
    ON_NOTIFY(GVN_COMBOSELCHANGE, IDC_CUSTOM_USER, &CUserManagerDlg::OnGridComboSelChange)
    ON_BN_CLICKED(IDC_BUTTON_ADD, &CUserManagerDlg::OnBnClickedButtonAdd)
    ON_BN_CLICKED(IDC_BUTTON_DEL, &CUserManagerDlg::OnBnClickedButtonDel)
    ON_BN_CLICKED(IDOK, &CUserManagerDlg::OnBnClickedOk)
    ON_BN_CLICKED(IDC_BUTTON_INSERT, &CUserManagerDlg::OnBnClickedButtonInsert)
END_MESSAGE_MAP()
 
 
// CUserManagerDlg 消息处理程序
 
 
BOOL CUserManagerDlg::OnInitDialog()
{
    CBaseDlg::OnInitDialog();
 
    // TODO:  在此添加额外的初始化
    SetWindowText(_T("用户管理"));
 
    // 初始化用户管理表格
    InitUserManager();
 
    return TRUE;  // return TRUE unless you set the focus to a control
    // 异常: OCX 属性页应返回 FALSE
}
 
void CUserManagerDlg::OnGridComboSelChange(NMHDR* pNMHDR, LRESULT* pResult)
{
    NM_GRIDVIEW* pItem = (NM_GRIDVIEW*)pNMHDR;
 
    int nRow = pItem->iRow;
    int nCol = pItem->iColumn;
 
    // 第4列为权限列, 第8列为角色描述列, 从映射中查找对应描述
    if (nCol == 3) {
        if (m_gridUserManager.GetItemBkColour(nRow, nCol) == CURR_USER_BK_COLOR) {
            AfxMessageBox(_T("当前登录用户权限不能修改!"));
        }
        else {
            CString selectedRole = m_gridUserManager.GetItemText(nRow, nCol);
            auto it = m_mapRoleDescriptions.find(selectedRole);
            if (it != m_mapRoleDescriptions.end()) {
                m_gridUserManager.SetItemText(nRow, 7, it->second);
                m_gridUserManager.RedrawCell(nRow, 7);
            }
            else {
                m_gridUserManager.SetItemText(nRow, 7, _T(""));
                m_gridUserManager.RedrawCell(nRow, 7);
            }
        }
    }
 
    *pResult = 0;
}
 
 
void CUserManagerDlg::OnBnClickedButtonAdd()
{
    // TODO: 在此添加控件通知处理程序代码
    AddRow(&m_gridUserManager);
}
 
 
void CUserManagerDlg::OnBnClickedButtonInsert()
{
    // TODO: 在此添加控件通知处理程序代码
    if (!m_gridUserManager.GetSafeHwnd()) return;
 
    CCellRange selectedRange = m_gridUserManager.GetSelectedCellRange();
    if (!selectedRange.IsValid()) {
        AfxMessageBox(_T("请先选择要插入的位置!"));
        return;
    }
 
    int minRow = selectedRange.GetMinRow();
    int maxRow = selectedRange.GetMaxRow();
    if (minRow < 1) {
        AfxMessageBox(_T("请选择有效的行!"));
        return;
    }
 
    for (int row = maxRow; row >= minRow; --row) {
        std::vector<CString> rowData;
        for (int col = 0; col < m_gridUserManager.GetColumnCount(); ++col) {
            rowData.push_back(m_gridUserManager.GetItemText(row, col));
        }
 
        m_gridUserManager.InsertRow(_T("新用户"), row);
        CString newUsername = rowData[1];
        int suffix = 1;
        while (IsUsernameDuplicate(newUsername)) {
            newUsername.Format(_T("%s_%d"), rowData[1], suffix++);
        }
        rowData[1] = newUsername;
 
        for (int col = 0; col < m_gridUserManager.GetColumnCount(); ++col) {
            m_gridUserManager.SetItemText(row, col, rowData[col]);
        }
 
        CStringArray permissions;
        permissions.Add(_T("管理员"));
        permissions.Add(_T("工程师"));
        permissions.Add(_T("操作员"));
 
        if (m_gridUserManager.SetCellType(row, 3, RUNTIME_CLASS(CGridCellCombo))) {
            CGridCellCombo* pCell = static_cast<CGridCellCombo*>(m_gridUserManager.GetCell(row, 3));
            pCell->SetOptions(permissions);
            pCell->SetStyle(CBS_DROPDOWNLIST);
 
            m_gridUserManager.SetItemText(row, 3, rowData[3]);
        }
 
        m_gridUserManager.SetCellType(row, 4, RUNTIME_CLASS(CGridCellNumeric));
        m_gridUserManager.SetCellType(row, 5, RUNTIME_CLASS(CGridCellNumeric));
    }
 
    for (int row = 1; row < m_gridUserManager.GetRowCount(); ++row) {
        CString strIndex;
        strIndex.Format(_T("%d"), row);
        m_gridUserManager.SetItemText(row, 0, strIndex);
    }
 
    m_gridUserManager.Invalidate();
    m_gridUserManager.UpdateWindow();
}
 
 
void CUserManagerDlg::OnBnClickedButtonDel()
{
    // TODO: 在此添加控件通知处理程序代码
    DeleteSelectedRow(&m_gridUserManager);
}
 
 
void CUserManagerDlg::OnBnClickedOk()
{
    // TODO: 在此添加控件通知处理程序代码
    std::vector<std::vector<std::string>> vecData;
    std::set<std::string> usernameSet; // 用于存储用户名,检查是否重复
 
    int nCurrUserRow = -1;
    UserManager& userManager = UserManager::getInstance();
    for (int i = 1; i < m_gridUserManager.GetRowCount(); ++i) {
        std::vector<std::string> rowData;
        CString cellText = m_gridUserManager.GetItemText(i, 1);
        std::string username = CT2A(cellText.GetString());
 
        cellText = m_gridUserManager.GetItemText(i, 2);
        std::string userpass = CT2A(cellText.GetString());
 
        if (username.empty() || userpass.empty()) {
            AfxMessageBox(_T("用户名和密码不能为空!")); 
            return;
        }
 
        if (usernameSet.find(username) != usernameSet.end()) {
            CString message;
            message.Format(_T("用户名 [%s] 重复,请修改后保存!"), cellText);
            AfxMessageBox(message, MB_ICONEXCLAMATION);
            return;
        }
        usernameSet.insert(username);
 
        if (nCurrUserRow == -1 && m_gridUserManager.GetItemBkColour(i, 0) == CURR_USER_BK_COLOR){
            nCurrUserRow = i;
            if (username.compare(userManager.getCurrentUser()) != 0) {
                userManager.setCurrentUser(username);
            }
 
            if (userpass.compare(userManager.getCurrentPass()) != 0) {
                userManager.setCurrentPass(userpass);
            }
 
            userManager.clearSession();
            userManager.saveSession();
        }
 
        for (int j = 1; j < m_gridUserManager.GetColumnCount() - 1; ++j) {
            CString cellText = m_gridUserManager.GetItemText(i, j);
            std::string cellString = CT2A(cellText.GetString());
 
            // 第4列是权限,转换为数字字符串
            if (j == 3) {
                if (cellText == _T("管理员"))
                    cellString = "0";
                else if (cellText == _T("工程师"))
                    cellString = "1";
                else if (cellText == _T("操作员"))
                    cellString = "2";
                else
                    cellString = "2";
            }
 
            rowData.push_back(cellString);
        }
 
        vecData.push_back(rowData);
    }
 
    userManager.setUsers(vecData);
    CBaseDlg::OnOK();
}