From 1318cc77e20a82b3328aa82ea6b8d8ca600de44f Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期二, 10 六月 2025 15:51:55 +0800
Subject: [PATCH] 1. 拆分数据库,每一个管理类是单独的数据库文件 2. 修复复制产生的ID错误

---
 SourceCode/Bond/Servo/ServoDlg.cpp |  124 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 119 insertions(+), 5 deletions(-)

diff --git a/SourceCode/Bond/Servo/ServoDlg.cpp b/SourceCode/Bond/Servo/ServoDlg.cpp
index 80117a5..b8c863c 100644
--- a/SourceCode/Bond/Servo/ServoDlg.cpp
+++ b/SourceCode/Bond/Servo/ServoDlg.cpp
@@ -15,6 +15,12 @@
 #include "HmTab.h"
 #include "CRobotCmdContainerDlg.h"
 #include "CRobotCmdTestDlg.h"
+#include "LoginDlg.h"
+#include "ChangePasswordDlg.h"
+#include "UserManagerDlg.h"
+#include "SystemLogManagerDlg.h"
+#include "UserManager.h"
+#include "SystemLogManager.h"
 
 
 #ifdef _DEBUG
@@ -81,6 +87,7 @@
 	m_pPageGraph2 = nullptr;
 	m_pPageAlarm = nullptr;
 	m_pPageLog = nullptr;
+	m_pPageTransferLog = nullptr;
 	m_pPageRecipe = nullptr;
 	m_pTopToolbar = nullptr;
 	m_pMyStatusbar = nullptr;
@@ -174,6 +181,8 @@
 			else if (RX_CODE_MASTER_STATE_CHANGED == code) {
 				SERVO::MASTERSTATE state = theApp.m_model.getMaster().getState();
 				if (state == SERVO::MASTERSTATE::READY) {
+					m_pTopToolbar->GetBtn(IDC_BUTTON_RUN)->EnableWindow(TRUE);
+					m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(FALSE);
 					m_pMyStatusbar->setBackgroundColor(STATUSBAR_BK_NORMAL);
 					m_pMyStatusbar->setForegroundColor(RGB(0, 0, 0));
 					KillTimer(TIMER_ID_UPDATE_RUMTIME);
@@ -182,6 +191,8 @@
 					m_pMyStatusbar->setRunTimeText((LPTSTR)(LPCTSTR)strText);
 				}
 				else if (state == SERVO::MASTERSTATE::RUNNING) {
+					m_pTopToolbar->GetBtn(IDC_BUTTON_RUN)->EnableWindow(FALSE);
+					m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(TRUE);
 					m_pMyStatusbar->setBackgroundColor(STATUSBAR_BK_RUNNING);
 					m_pMyStatusbar->setForegroundColor(RGB(255, 255, 255));
 					SetTimer(TIMER_ID_UPDATE_RUMTIME, 500, nullptr);
@@ -207,6 +218,9 @@
 						}
 					}
 					else if (exCode == ROBOT_EVENT_FINISH) {
+						m_pMyStatusbar->setCurTaskBtnText("无");
+					}
+					else if (exCode == ROBOT_EVENT_ABORT) {
 						m_pMyStatusbar->setCurTaskBtnText("无");
 					}
 				}
@@ -283,6 +297,8 @@
 	m_pPageAlarm->Create(IDD_DIALOG_ALARM, this);
 	m_pPageLog = new CPageLog();
 	m_pPageLog->Create(IDD_DIALOG_LOG, this);
+	m_pPageTransferLog = new CPageTransferLog();
+	m_pPageTransferLog->Create(IDD_PAGE_TRANSFER_LOG, this);
 
 	CHmTab* m_pTab = CHmTab::Hook(GetDlgItem(IDC_TAB1)->m_hWnd);
 	m_pTab->SetPaddingLeft(20);
@@ -292,6 +308,7 @@
 	m_pTab->AddItem("配方", TRUE);
 	m_pTab->AddItem("报警", TRUE);
 	m_pTab->AddItem("日志", TRUE);
+	m_pTab->AddItem("搬运", TRUE);
 	m_pTab->SetCurSel(0);
 	m_pTab->SetBkgndColor(RGB(222, 222, 222));
 	ShowChildPage(0);
@@ -336,6 +353,12 @@
 
 	// 初始化master以后需要控件绑定数据
 	m_pPageGraph1->BindEquipmentToGraph();
+
+
+	// 更新登录状态
+	UpdateLoginStatus();
+	//SystemLogManager::getInstance.log(SystemLogManager::LogType::Info, _T("BondEq启动..."));
+	//SystemLogManager::getInstance.
 
 
 	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
@@ -632,6 +655,12 @@
 		m_pPageLog = nullptr;
 	}
 
+	if (m_pPageTransferLog != nullptr) {
+		m_pPageTransferLog->DestroyWindow();
+		delete m_pPageTransferLog;
+		m_pPageTransferLog = nullptr;
+	}
+
 	if (m_hbrBkgnd != nullptr) {
 		::DeleteObject(m_hbrBkgnd);
 	}
@@ -652,6 +681,7 @@
 	if (m_pPageRecipe == nullptr) return;
 	if (m_pPageAlarm == nullptr) return;
 	if (m_pPageLog == nullptr) return;
+	if (m_pPageTransferLog == nullptr) return;
 	
 	Resize();
 	Invalidate();
@@ -706,6 +736,7 @@
 	m_pPageRecipe->MoveWindow(x, y, rcClient.Width() - x, y2 - y);
 	m_pPageAlarm->MoveWindow(x, y, rcClient.Width() - x, y2 - y);
 	m_pPageLog->MoveWindow(x, y, rcClient.Width() - x, y2 - y);
+	m_pPageTransferLog->MoveWindow(x, y, rcClient.Width() - x, y2 - y);
 
 
 	m_pMyStatusbar->MoveWindow(0, y2, rcClient.Width(), STATUSBAR_HEIGHT);
@@ -780,10 +811,43 @@
 
 void CServoDlg::ShowChildPage(int index)
 {
-	ASSERT(0 <= index && index < 5);
-	static CWnd* pPages[] = { m_pPageGraph1, m_pPageGraph2, m_pPageRecipe, m_pPageAlarm, m_pPageLog };
-	for (int i = 0; i < 5; i++) {
+	ASSERT(0 <= index && index < 6);
+	static CWnd* pPages[] = { m_pPageGraph1, m_pPageGraph2, m_pPageRecipe, m_pPageAlarm, m_pPageLog, m_pPageTransferLog };
+	for (int i = 0; i < 6; i++) {
 		pPages[i]->ShowWindow(i == index ? SW_SHOW : SW_HIDE);
+	}
+}
+
+void CServoDlg::UpdateLoginStatus()
+{
+	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_OPERATOR_SYSTEM_LOG, 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_OPERATOR_SYSTEM_LOG, 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("未登录"));
 	}
 }
 
@@ -793,11 +857,9 @@
 	if (id == IDC_BUTTON_RUN) {
 		theApp.m_model.getMaster().start();
 		m_pTopToolbar->GetBtn(IDC_BUTTON_RUN)->EnableWindow(FALSE);
-		m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(TRUE);
 	}
 	else if (id == IDC_BUTTON_STOP) {
 		theApp.m_model.getMaster().stop();
-		m_pTopToolbar->GetBtn(IDC_BUTTON_RUN)->EnableWindow(TRUE);
 		m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(FALSE);
 	}
 	else if (id == IDC_BUTTON_ROBOT) {
@@ -806,6 +868,58 @@
 		dlg.SetEFEM(pEFEM);
 		dlg.DoModal();
 	}
+	else if (id == IDC_BUTTON_OPERATOR) {
+		int menuId = (int)wParam;
+		SystemLogManager& logManager = SystemLogManager::getInstance();
+		UserManager& userManager = UserManager::getInstance();
+		if (menuId == 0) {
+			CLoginDlg loginDlg;
+			loginDlg.DoModal();
+		}
+		else if (1 == menuId) {
+			CChangePasswordDlg changePasswordDlg;
+			changePasswordDlg.DoModal();
+		}
+		else if (2 == menuId) {
+			CUserManagerDlg dlg;
+			if (dlg.DoModal() != IDOK) {
+				logManager.log(SystemLogManager::LogType::Operation, _T("用户管理的预操作被取消!"));
+			}
+		}
+		else if (3 == menuId) {
+			CSystemLogManagerDlg dlg;
+			dlg.DoModal();
+		}
+		else if (4 == menuId) {
+			int ret = AfxMessageBox(_T("是否切换用户?切换用户会退出当前账号!"), MB_OKCANCEL | MB_ICONEXCLAMATION);
+			if (ret != IDOK) {
+				return 0;
+			}
+
+			logManager.log(SystemLogManager::LogType::Operation, _T("确认切换角色!"));
+			if (userManager.isLoggedIn()) {
+				logManager.log(SystemLogManager::LogType::Info, _T("退出登录!"));
+				userManager.logout();
+			}
+
+			CLoginDlg loginDlg;
+			loginDlg.DoModal();
+		}
+		else {
+			CString cstrMessage;
+			cstrMessage.Format(_T("是否退出用户 [%s]?"), userManager.getCurrentUser().c_str());
+			int ret = AfxMessageBox(_T(cstrMessage), MB_OKCANCEL | MB_ICONEXCLAMATION);
+			if (ret != IDOK) {
+				return 0;
+			}
+
+			logManager.log(SystemLogManager::LogType::Info, _T("退出登录!"));
+			userManager.logout();
+		}
+
+		UpdateLoginStatus();
+	}
+
 	return 0;
 }
 

--
Gitblit v1.9.3