From 8dbd14952aa622587a92866dc01943869ea4f9dc Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期三, 20 十一月 2024 11:28:02 +0800
Subject: [PATCH] 1. 添加系统运行记录表 2. 完善用户管理的部分细节

---
 SourceCode/Bond/BondEq/UserManagerDlg.cpp |   91 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 77 insertions(+), 14 deletions(-)

diff --git a/SourceCode/Bond/BondEq/UserManagerDlg.cpp b/SourceCode/Bond/BondEq/UserManagerDlg.cpp
index 993edb9..f58d1e6 100644
--- a/SourceCode/Bond/BondEq/UserManagerDlg.cpp
+++ b/SourceCode/Bond/BondEq/UserManagerDlg.cpp
@@ -5,10 +5,14 @@
 #include "BondEq.h"
 #include "afxdialogex.h"
 #include "UserManagerDlg.h"
+#include "InputDialog.h"
 #include "UserManager.h"
 #include "NewCellTypes/GridCellCombo.h"
 #include "NewCellTypes/GridCellNumeric.h"
 
+#include <set>
+
+const COLORREF CURR_USER_BK_COLOR = RGB(0, 255, 0);
 
 // CUserManagerDlg 瀵硅瘽妗�
 
@@ -110,12 +114,12 @@
 	if (!usersData.empty()) {
 		m_gridUserManager.SetRowCount(usersData.size() + 1);
 
-		for (size_t i = 0; i < usersData.size(); i++) {
+		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 (size_t j = 0; j < usersData[i].size(); j++) {
+			for (int j = 0; j < usersData[i].size(); j++) {
 				if (usersData[i][1].empty()) {
 					continue;
 				}
@@ -174,8 +178,9 @@
 	}
 
 	for (int i = 0; i < nCols; i++) {
-		bool ret = m_gridUserManager.SetItemBkColour(nCurrNameRow, i, RGB(0, 255, 0));
+		m_gridUserManager.SetItemBkColour(nCurrNameRow, i, CURR_USER_BK_COLOR);
 	}
+	m_gridUserManager.SetItemState(nCurrNameRow, 3, GVIS_READONLY);
 
 	m_gridUserManager.Invalidate();
 	m_gridUserManager.UpdateWindow();
@@ -190,6 +195,22 @@
 		return;
 	}
 
+	CInputDialog inputDialog(_T("娣诲姞鐢ㄦ埛"), _T("璇疯緭鍏ョ敤鎴峰悕锛�"));
+	if (inputDialog.DoModal() != IDOK) {
+		return;
+	}
+
+	CString inputText = inputDialog.GetInputText();
+	if (inputText.IsEmpty()) {
+		AfxMessageBox(_T("鐢ㄦ埛鍚嶄笉鑳戒负绌猴紒"), MB_OK | MB_ICONEXCLAMATION);
+		return;
+	}
+
+	if (IsUsernameDuplicate(inputText)) {
+		AfxMessageBox(_T("鐢ㄦ埛鍚嶉噸澶嶏紒"), MB_OK | MB_ICONEXCLAMATION);
+		return;
+	}
+
 	int nRowCount = pGridCtrl->GetRowCount();
 	pGridCtrl->SetRowCount(nRowCount + 1);
 	int newRowIndex = nRowCount;
@@ -197,8 +218,7 @@
 	CString strText;
 	strText.Format(_T("%d"), newRowIndex);
 	pGridCtrl->SetItemText(newRowIndex, 0, strText);
-	strText.Format(_T("User%d"), newRowIndex);
-	pGridCtrl->SetItemText(newRowIndex, 1, strText);
+	pGridCtrl->SetItemText(newRowIndex, 1, inputText);
 	pGridCtrl->SetItemText(newRowIndex, 2, _T("123456"));
 	pGridCtrl->SetItemText(newRowIndex, 3, _T("鎿嶄綔鍛�"));
 	pGridCtrl->SetItemText(newRowIndex, 4, _T("30"));
@@ -445,16 +465,20 @@
 
 	// 绗�4鍒椾负鏉冮檺鍒�, 绗�8鍒椾负瑙掕壊鎻忚堪鍒�, 浠庢槧灏勪腑鏌ユ壘瀵瑰簲鎻忚堪
 	if (nCol == 3) {
-		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);
+		if (m_gridUserManager.GetItemBkColour(nRow, nCol) == CURR_USER_BK_COLOR) {
+			AfxMessageBox(_T("褰撳墠鐧诲綍鐢ㄦ埛鏉冮檺涓嶈兘淇敼锛�"));
 		}
 		else {
-			m_gridUserManager.SetItemText(nRow, 7, _T(""));
-			m_gridUserManager.RedrawCell(nRow, 7);
+			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);
+			}
 		}
 	}
 
@@ -540,11 +564,50 @@
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 	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";
@@ -562,6 +625,6 @@
 		vecData.push_back(rowData);
 	}
 
-	UserManager::getInstance().setUsers(vecData);
+	userManager.setUsers(vecData);
 	CDialogEx::OnOK();
 }

--
Gitblit v1.9.3