From 552b0d6e5d9f02c5f50e7407f0b274f4b926a043 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 12 六月 2025 09:53:57 +0800
Subject: [PATCH] Merge branch 'clh'

---
 SourceCode/Bond/Servo/LoginDlg.cpp |  126 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/LoginDlg.cpp b/SourceCode/Bond/Servo/LoginDlg.cpp
new file mode 100644
index 0000000..bd9fef8
--- /dev/null
+++ b/SourceCode/Bond/Servo/LoginDlg.cpp
@@ -0,0 +1,126 @@
+锘�// LoginDlg.cpp: 瀹炵幇鏂囦欢
+//
+
+#include "stdafx.h"
+#include "Servo.h"
+#include "afxdialogex.h"
+#include "LoginDlg.h"
+#include "ChangePasswordDlg.h"
+#include "UserManager.h"
+#include "SystemLogManager.h"
+
+
+// CLoginDlg 瀵硅瘽妗�
+
+IMPLEMENT_DYNAMIC(CLoginDlg, CDialogEx)
+
+CLoginDlg::CLoginDlg(CWnd* pParent /*=nullptr*/)
+	: CDialogEx(IDD_DIALOG_LOGIN, pParent)
+{
+}
+
+CLoginDlg::~CLoginDlg()
+{
+}
+
+void CLoginDlg::DoDataExchange(CDataExchange* pDX)
+{
+    CDialogEx::DoDataExchange(pDX);
+    DDX_Control(pDX, IDC_STATIC_IMAGE, m_staticImage);
+    DDX_Control(pDX, IDC_EDIT_USERNAME, m_editUsername);
+    DDX_Control(pDX, IDC_EDIT_PASSWORD, m_editPassword);
+    DDX_Control(pDX, IDC_CHECK_REMEMBER_PASSWORD, m_checkRememberPassword);
+}
+
+
+BEGIN_MESSAGE_MAP(CLoginDlg, CDialogEx)
+	ON_BN_CLICKED(IDC_BUTTON_LOGIN, &CLoginDlg::OnBnClickedLogin)
+    ON_STN_CLICKED(IDC_STATIC_CHANGE_PASSWORD, &CLoginDlg::OnBnClickedChangePassword)
+END_MESSAGE_MAP()
+
+
+// CLoginDlg 娑堟伅澶勭悊绋嬪簭
+
+
+BOOL CLoginDlg::OnInitDialog()
+{
+    CDialog::OnInitDialog();
+
+    // 璁剧疆绐楀彛鏍囬鍜屽垵濮嬪��
+    SetWindowText(_T("鐧诲綍"));
+
+    CString strIconPath;
+    strIconPath.Format(_T("%s\\Res\\Operator_High_32.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+
+    // 鍔犺浇鍥炬爣
+    HICON hIcon = (HICON)::LoadImage(
+        nullptr,
+        strIconPath,
+        IMAGE_ICON,
+        32, // 鍥炬爣瀹藉害
+        32, // 鍥炬爣楂樺害
+        LR_LOADFROMFILE);
+
+    if (hIcon) {
+        // 璁剧疆 CStatic 鎺т欢涓哄浘鏍囨牱寮�
+        m_staticImage.ModifyStyle(0xF, SS_ICON);
+        m_staticImage.SetIcon(hIcon);
+    }
+
+    // 娣诲姞SS_NOTIFY鏍峰紡
+    CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC_CHANGE_PASSWORD);
+    if (pStatic != nullptr) {
+        pStatic->ModifyStyle(0, SS_NOTIFY);
+    }
+
+    UserManager& userManager = UserManager::getInstance();
+	if (userManager.isLoggedIn()) {
+        if (userManager.isRememberMe()) {
+            m_checkRememberPassword.SetCheck(BST_CHECKED);
+        }
+       
+        userManager.getCurrentUserRole();
+		m_editUsername.SetWindowText(userManager.getCurrentUser().c_str());
+		m_editPassword.SetWindowText(userManager.getCurrentPass().c_str());
+	}
+
+    return TRUE;
+}
+
+void CLoginDlg::OnBnClickedLogin()
+{
+    CString username, password, role;
+    m_editUsername.GetWindowText(username);
+    m_editPassword.GetWindowText(password);
+
+    if (username.IsEmpty() || password.IsEmpty()) {
+        AfxMessageBox(_T("璇疯緭鍏ョ敤鎴峰悕鍜屽瘑鐮併��"));
+        return;
+    }
+
+#ifdef UNICODE
+    std::string strUsername = CStringA(username);
+    std::string strPassword = CStringA(password);
+#else
+    std::string strUsername = username;
+    std::string strPassword = password;
+#endif
+
+    UserManager& userManager = UserManager::getInstance();
+    SystemLogManager& logManager = SystemLogManager::getInstance();
+    if (!userManager.login(strUsername, strPassword, (m_checkRememberPassword.GetCheck() == BST_CHECKED))) {
+        AfxMessageBox(_T("鐧诲綍澶辫触銆�"));
+        return;
+    }
+
+    EndDialog(IDOK);
+    logManager.log(SystemLogManager::LogType::Info, _T("鐧诲綍鎴愬姛..."));
+}
+
+void CLoginDlg::OnBnClickedChangePassword()
+{
+    CChangePasswordDlg changePasswordDlg;
+    if (changePasswordDlg.DoModal() == IDOK) {
+        m_editPassword.SetWindowText("");
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3