From b43897d4f69cf85a425f48df9270a289bc0a0125 Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期二, 19 十一月 2024 18:04:20 +0800
Subject: [PATCH] 1. 添加用户管理的菜单栏 2.更新菜单栏的状态
---
SourceCode/Bond/BondEq/Resource.h | 0
SourceCode/Bond/BondEq/BondEqDlg.h | 2
SourceCode/Bond/BondEq/BondEq.rc | 0
SourceCode/Bond/BondEq/BondEqDlg.cpp | 82 +++++++++++++++++++++------
SourceCode/Bond/BondEq/UserManagerDlg.cpp | 38 ++++++++++++
SourceCode/Bond/x64/Debug/Config/BondEq.db | 0
SourceCode/Bond/BondEq/BondEq.vcxproj | 2
7 files changed, 102 insertions(+), 22 deletions(-)
diff --git a/SourceCode/Bond/BondEq/BondEq.rc b/SourceCode/Bond/BondEq/BondEq.rc
index 075337a..28c39e3 100644
--- a/SourceCode/Bond/BondEq/BondEq.rc
+++ b/SourceCode/Bond/BondEq/BondEq.rc
Binary files differ
diff --git a/SourceCode/Bond/BondEq/BondEq.vcxproj b/SourceCode/Bond/BondEq/BondEq.vcxproj
index fa72b3b..aabce71 100644
--- a/SourceCode/Bond/BondEq/BondEq.vcxproj
+++ b/SourceCode/Bond/BondEq/BondEq.vcxproj
@@ -223,6 +223,7 @@
<ClInclude Include="HmTab.h" />
<ClInclude Include="HmVerticalTab.h" />
<ClInclude Include="HorizontalLine.h" />
+ <ClInclude Include="InputDialog.h" />
<ClInclude Include="Intent.h" />
<ClInclude Include="LoadMonitor.h" />
<ClInclude Include="Log.h" />
@@ -279,6 +280,7 @@
<ClCompile Include="HmTab.cpp" />
<ClCompile Include="HmVerticalTab.cpp" />
<ClCompile Include="HorizontalLine.cpp" />
+ <ClCompile Include="InputDialog.cpp" />
<ClCompile Include="Intent.cpp" />
<ClCompile Include="LoadMonitor.cpp" />
<ClCompile Include="Log.cpp" />
diff --git a/SourceCode/Bond/BondEq/BondEqDlg.cpp b/SourceCode/Bond/BondEq/BondEqDlg.cpp
index 0860fa8..0735685 100644
--- a/SourceCode/Bond/BondEq/BondEqDlg.cpp
+++ b/SourceCode/Bond/BondEq/BondEqDlg.cpp
@@ -11,6 +11,8 @@
#include "SettingsDlg.h"
#include "UserManager.h"
#include "LoginDlg.h"
+#include "ChangePasswordDlg.h"
+#include "InputDialog.h"
// test
#include "AxisSettingsDlg.h"
@@ -224,10 +226,8 @@
InitRxWindows();
- // 登录管理
- if (userManager.isLoggedIn()) {
- m_pTopToolbar->SetOperatorBtnText(userManager.getCurrentUser().c_str());
- }
+ // 更新登录状态
+ UpdateLoginStatus();
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
@@ -512,6 +512,22 @@
LRESULT CBondEqDlg::OnToolbarBtnClicked(WPARAM wParam, LPARAM lParam)
{
int id = (int)lParam;
+ if (id == IDC_BUTTON_RUN || id == IDC_BUTTON_STOP || id == IDC_BUTTON_SETTINGS)
+ {
+ CInputDialog inputDialog(_T("验证用户"), _T("请输入用户密码:"));
+ if (inputDialog.DoModal() != IDOK) {
+ AfxMessageBox(_T("取消验证!"));
+ return 0;
+ }
+
+ CString inputText = inputDialog.GetInputText();
+ std::string strPass = UserManager::getInstance().getCurrentPass();
+ if (inputText.Compare(strPass.c_str()) != 0) {
+ AfxMessageBox(_T("密码错误!"));
+ return 0;
+ }
+ }
+
if (id == IDC_BUTTON_RUN) {
m_pTopToolbar->GetBtn(IDC_BUTTON_RUN)->EnableWindow(FALSE);
m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(TRUE);
@@ -528,24 +544,36 @@
int menuId = (int)wParam;
UserManager& userManager = UserManager::getInstance();
if (menuId == 0) {
- ShowLoginDlg();
+ CLoginDlg loginDlg;
+ loginDlg.DoModal();
+ UpdateLoginStatus();
}
else if (1 == menuId) {
+ CChangePasswordDlg changePasswordDlg;
+ if (changePasswordDlg.DoModal() == IDOK) {
+ }
+ }
+ else if (2 == menuId) {
+ CUserManagerDlg dlg;
+ dlg.DoModal();
+ }
+ else if (3 == menuId) {
+ int ret = AfxMessageBox(_T("是否切换用户?切换用户会退出当前账号!"), MB_OK | MB_ICONEXCLAMATION);
+ if (ret != MB_OK) {
+ return 0;
+ }
+
if (userManager.isLoggedIn()) {
userManager.logout();
}
- ShowLoginDlg();
+ CLoginDlg loginDlg;
+ loginDlg.DoModal();
+ UpdateLoginStatus();
}
- else if (2 == menuId) {
- // test
- CUserManagerDlg dlg;
- dlg.DoModal();
-
- //if (userManager.isLoggedIn()) {
- // userManager.logout();
- // m_pTopToolbar->SetOperatorBtnText(_T("未登录"));
- //}
+ else {
+ userManager.logout();
+ UpdateLoginStatus();
}
}
@@ -618,17 +646,33 @@
return pDlg;
}
-void CBondEqDlg::ShowLoginDlg()
+void CBondEqDlg::UpdateLoginStatus()
{
- CLoginDlg loginDlg;
- loginDlg.DoModal();
-
+ HMENU hMenu = m_pTopToolbar->GetOperatorMenu();
UserManager& userManager = UserManager::getInstance();
if (userManager.isLoggedIn())
{
+ ::EnableMenuItem(hMenu, ID_OPEATOR_LOGIN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
+ ::EnableMenuItem(hMenu, ID_OPERATOR_CHANGE_PASSWORD, MF_BYCOMMAND | MF_ENABLED);
+ ::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_ENABLED);
+ ::EnableMenuItem(hMenu, ID_OPERATOR_LOGOUT, MF_BYCOMMAND | MF_ENABLED);
+
+ if (userManager.getCurrentUserRole() == UserRole::SuperAdmin) {
+ ::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_ENABLED);
+ }
+ else {
+ ::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
+ }
+
m_pTopToolbar->SetOperatorBtnText(userManager.getCurrentUser().c_str());
}
else {
+ ::EnableMenuItem(hMenu, ID_OPEATOR_LOGIN, MF_BYCOMMAND | MF_ENABLED);
+ ::EnableMenuItem(hMenu, ID_OPERATOR_CHANGE_PASSWORD, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
+ ::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
+ ::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
+ ::EnableMenuItem(hMenu, ID_OPERATOR_LOGOUT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
+
m_pTopToolbar->SetOperatorBtnText(_T("未登录"));
}
}
diff --git a/SourceCode/Bond/BondEq/BondEqDlg.h b/SourceCode/Bond/BondEq/BondEqDlg.h
index 4743df0..bcb13fd 100644
--- a/SourceCode/Bond/BondEq/BondEqDlg.h
+++ b/SourceCode/Bond/BondEq/BondEqDlg.h
@@ -24,7 +24,7 @@
void CloseView(CBaseView* pView);
CHomeDialog* CreateHomeDlg();
CBaseView* CreateRemoteEqView(BEQ::IRemoteEquipment* pEquipment);
- void ShowLoginDlg();
+ void UpdateLoginStatus();
private:
COLORREF m_crBkgnd;
diff --git a/SourceCode/Bond/BondEq/Resource.h b/SourceCode/Bond/BondEq/Resource.h
index 01e5ecb..bd8fa27 100644
--- a/SourceCode/Bond/BondEq/Resource.h
+++ b/SourceCode/Bond/BondEq/Resource.h
Binary files differ
diff --git a/SourceCode/Bond/BondEq/UserManagerDlg.cpp b/SourceCode/Bond/BondEq/UserManagerDlg.cpp
index 993edb9..24df33f 100644
--- a/SourceCode/Bond/BondEq/UserManagerDlg.cpp
+++ b/SourceCode/Bond/BondEq/UserManagerDlg.cpp
@@ -5,9 +5,12 @@
#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>
// CUserManagerDlg 瀵硅瘽妗�
@@ -190,6 +193,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 +216,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"));
@@ -540,11 +558,27 @@
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
std::vector<std::vector<std::string>> vecData;
+ std::set<std::string> usernameSet; // 鐢ㄤ簬瀛樺偍鐢ㄦ埛鍚嶏紝妫�鏌ユ槸鍚﹂噸澶�
+
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());
+
+ if (usernameSet.find(username) != usernameSet.end()) {
+ CString message;
+ message.Format(_T("鐢ㄦ埛鍚� [%s] 閲嶅锛岃淇敼鍚庝繚瀛橈紒"), cellText);
+ AfxMessageBox(message, MB_ICONEXCLAMATION);
+ return;
+ }
+
+ usernameSet.insert(username);
+
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";
diff --git a/SourceCode/Bond/x64/Debug/Config/BondEq.db b/SourceCode/Bond/x64/Debug/Config/BondEq.db
index da92352..f424b51 100644
--- a/SourceCode/Bond/x64/Debug/Config/BondEq.db
+++ b/SourceCode/Bond/x64/Debug/Config/BondEq.db
Binary files differ
--
Gitblit v1.9.3