From 829fe6c6bc33d53fda9c31fd45a37e1df87befff Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 30 一月 2026 11:16:24 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/Servo/CUserEdit2Dlg.cpp | 125 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 125 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/CUserEdit2Dlg.cpp b/SourceCode/Bond/Servo/CUserEdit2Dlg.cpp
new file mode 100644
index 0000000..7237f5d
--- /dev/null
+++ b/SourceCode/Bond/Servo/CUserEdit2Dlg.cpp
@@ -0,0 +1,125 @@
+锘�#include "stdafx.h"
+#include "CUserEdit2Dlg.h"
+#include "CUserManager2.h"
+#include "resource.h"
+
+IMPLEMENT_DYNAMIC(CUserEdit2Dlg, CDialogEx)
+
+CUserEdit2Dlg::CUserEdit2Dlg(bool editMode, CWnd* pParent /*=nullptr*/)
+ : CDialogEx(IDD_DIALOG_USER_EDIT2, pParent)
+{
+ m_bEditMode = editMode;
+}
+
+CUserEdit2Dlg::~CUserEdit2Dlg()
+{
+}
+
+void CUserEdit2Dlg::DoDataExchange(CDataExchange* pDX)
+{
+ CDialogEx::DoDataExchange(pDX);
+ DDX_Text(pDX, IDC_EDIT_USER_ACCOUNT, m_strUsername);
+ DDX_Text(pDX, IDC_EDIT_USER_DISPLAY, m_strDisplayName);
+ DDX_Text(pDX, IDC_EDIT_USER_PASSWORD, m_strPassword);
+ DDX_CBString(pDX, IDC_COMBO_USER_ROLE, m_strRole);
+ DDX_Check(pDX, IDC_CHECK_USER_ENABLED, m_bEnabled);
+}
+
+BEGIN_MESSAGE_MAP(CUserEdit2Dlg, CDialogEx)
+END_MESSAGE_MAP()
+
+BOOL CUserEdit2Dlg::OnInitDialog()
+{
+ CDialogEx::OnInitDialog();
+
+ if (m_bEditMode) {
+ if (auto pEdit = GetDlgItem(IDC_EDIT_USER_ACCOUNT)) {
+ pEdit->EnableWindow(FALSE);
+ }
+ }
+
+ UpdateData(FALSE);
+
+ auto roles = CUserManager2::getInstance().getRoles();
+ CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO_USER_ROLE);
+ if (pCombo) {
+ int selected = -1;
+ for (const auto& role : roles) {
+ CString text(role.name.c_str());
+ int idx = pCombo->AddString(text);
+ if (selected == -1 && m_strRole.CompareNoCase(text) == 0) {
+ selected = idx;
+ }
+ }
+
+ if (selected >= 0) {
+ pCombo->SetCurSel(selected);
+ }
+ else if (pCombo->GetCount() > 0) {
+ pCombo->SetCurSel(0);
+ CString text;
+ pCombo->GetLBText(0, text);
+ if (m_strRole.IsEmpty()) {
+ m_strRole = text;
+ }
+ }
+ }
+
+ if (auto pPwd = GetDlgItem(IDC_EDIT_USER_PASSWORD)) {
+ pPwd->EnableWindow(!m_bEditMode);
+ if (m_bEditMode) {
+ pPwd->SetWindowText(_T(""));
+ }
+ }
+
+ return TRUE;
+}
+
+void CUserEdit2Dlg::OnOK()
+{
+ UpdateData(TRUE);
+
+ CString user = m_strUsername;
+ user.Trim();
+ CString role = m_strRole;
+ role.Trim();
+
+ CString password = m_strPassword;
+ password.Trim();
+
+ if (m_bEditMode) {
+ password.Empty();
+ }
+
+ if (!m_bEditMode) {
+ if (user.IsEmpty()) {
+ AfxMessageBox(_T("璇疯緭鍏ヨ处鍙�"));
+ return;
+ }
+
+ if (password.IsEmpty()) {
+ AfxMessageBox(_T("璇疯緭鍏ュ瘑鐮�"));
+ return;
+ }
+ }
+
+ if (role.IsEmpty()) {
+ AfxMessageBox(_T("璇烽�夋嫨瑙掕壊"));
+ return;
+ }
+
+ if (auto pCombo = (CComboBox*)GetDlgItem(IDC_COMBO_USER_ROLE)) {
+ int sel = pCombo->GetCurSel();
+ if (sel != CB_ERR) {
+ CString text;
+ pCombo->GetLBText(sel, text);
+ if (!text.IsEmpty()) {
+ m_strRole = text;
+ }
+ }
+ }
+
+ m_strUsername = user;
+ m_strPassword = password;
+ CDialogEx::OnOK();
+}
--
Gitblit v1.9.3