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/SystemLogManagerDlg.cpp |  293 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 293 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/SystemLogManagerDlg.cpp b/SourceCode/Bond/Servo/SystemLogManagerDlg.cpp
new file mode 100644
index 0000000..2b51726
--- /dev/null
+++ b/SourceCode/Bond/Servo/SystemLogManagerDlg.cpp
@@ -0,0 +1,293 @@
+锘�// SystemLogManagerDlg.cpp: 瀹炵幇鏂囦欢
+//
+
+#include "stdafx.h"
+#include "Servo.h"
+#include "afxdialogex.h"
+#include "SystemLogManagerDlg.h"
+#include "UserManager.h"
+#include "SystemLogManager.h"
+
+
+// CSystemLogManagerDlg 瀵硅瘽妗�
+
+IMPLEMENT_DYNAMIC(CSystemLogManagerDlg, CBaseDlg)
+
+CSystemLogManagerDlg::CSystemLogManagerDlg(CWnd* pParent /*=nullptr*/)
+	: CBaseDlg(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent)
+{
+}
+
+CSystemLogManagerDlg::~CSystemLogManagerDlg()
+{
+}
+
+void CSystemLogManagerDlg::DoDataExchange(CDataExchange* pDX)
+{
+	CBaseDlg::DoDataExchange(pDX);
+	DDX_Control(pDX, IDC_COMBO_TYPE, m_comboType);
+	DDX_Control(pDX, IDC_COMBO_USER, m_comboUser);
+	DDX_Control(pDX, IDC_DATETIMEPICKER_START, m_dateTimeStart);
+	DDX_Control(pDX, IDC_DATETIMEPICKER_END, m_dateTimeEnd);
+	DDX_Control(pDX, IDC_EDIT_DESCRIPTION, m_editDescription);
+	DDX_Control(pDX, IDC_CUSTOM_LIST_LOGS, m_listLogs);
+	DDX_Control(pDX, IDC_STATIC_PAGE_NUMBER, m_staticPageNum);
+}
+
+void CSystemLogManagerDlg::InitSystemLogManager()
+{
+	if (m_listLogs.GetSafeHwnd() == NULL)
+		return;
+
+	int nRows = 21; // 鍖呮嫭琛ㄥご锛�1 琛岋級鍜屾暟鎹紙20 琛岋級
+	int nCols = 5;
+
+	int nFixRows = 1;
+	int nFixCols = 0;
+	int nRowIdx = 0;
+	int nColIdx = 0;
+
+	m_listLogs.DeleteAllItems();
+	m_listLogs.SetVirtualMode(FALSE);
+	m_listLogs.GetDefaultCell(TRUE, FALSE)->SetBackClr(g_nGridFixCellColor); // 璁剧疆鍥哄畾琛岃儗鏅壊
+	m_listLogs.GetDefaultCell(FALSE, TRUE)->SetBackClr(g_nGridFixCellColor); // 璁剧疆鍥哄畾鍒楄儗鏅壊
+	m_listLogs.GetDefaultCell(FALSE, FALSE)->SetBackClr(g_nGridCellColor);	// 璁剧疆鍗曞厓鏍艰儗鏅壊
+	m_listLogs.SetFixedTextColor(g_nGridFixFontColor); // 璁剧疆鍥哄畾琛屽垪瀛椾綋棰滆壊
+
+	m_listLogs.SetRowCount(nRows);
+	m_listLogs.SetColumnCount(nCols);
+	m_listLogs.SetFixedRowCount(nFixRows);
+	m_listLogs.SetFixedColumnCount(nFixCols);
+
+	// Col
+	m_listLogs.SetColumnWidth(nColIdx, 10);
+	m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("No."));
+	m_listLogs.SetColumnWidth(nColIdx, 10);
+	m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("绫诲瀷"));
+	m_listLogs.SetColumnWidth(nColIdx, 100);
+	m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("浜嬩欢"));
+	m_listLogs.SetColumnWidth(nColIdx, 30);
+	m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("鐢ㄦ埛"));
+	m_listLogs.SetColumnWidth(nColIdx, 50);
+	m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("鏃堕棿"));
+
+	// 鍒涘缓 20 琛岀┖鐧芥暟鎹
+	for (int i = 1; i < nRows; ++i) {
+		for (int j = 0; j < nCols; ++j) {
+			m_listLogs.SetItemText(i, j, _T("")); // 鍒濆鍖栦负绌哄瓧绗︿覆
+		}
+	}
+
+	m_listLogs.SetFixedRowSelection(FALSE);
+	m_listLogs.SetFixedColumnSelection(FALSE);
+	m_listLogs.SetEditable(FALSE);
+	m_listLogs.SetRowResize(FALSE);
+	m_listLogs.SetColumnResize(TRUE);
+	m_listLogs.ExpandColumnsToFit(TRUE);
+	m_listLogs.SetListMode(TRUE);				// 鍚敤鍒楄〃妯″紡
+	m_listLogs.EnableSelection(TRUE);			// 鍚敤閫夋嫨
+	m_listLogs.SetSingleRowSelection(TRUE);		// 鑷姩鏁磋楂樹寒锛堥檺鍒朵负鍗曡閫夋嫨锛�
+	m_listLogs.ExpandLastColumn();				// 鏈�鍚庝竴鍒楀~鍏呯綉鏍�
+
+	try {
+		FillSystemLogManager();
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒濆鍖栬繍琛屾棩蹇楀け璐ワ細%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
+}
+
+void CSystemLogManagerDlg::FillSystemLogManager()
+{
+	// 鑾峰彇绛涢�夋潯浠�
+	CString selectedType, selectedUser, description;
+	m_comboType.GetLBText(m_comboType.GetCurSel(), selectedType);
+	m_comboUser.GetLBText(m_comboUser.GetCurSel(), selectedUser);
+	m_editDescription.GetWindowText(description);
+
+	COleDateTime startTime, endTime;
+	m_dateTimeStart.GetTime(startTime);
+	m_dateTimeEnd.GetTime(endTime);
+	CString strStartTime = startTime.Format(_T("%Y-%m-%d %H:%M:%S"));
+	CString strEndTime = endTime.Format(_T("%Y-%m-%d %H:%M:%S"));
+
+	std::string type = CT2A(selectedType);
+	std::string user = CT2A(selectedUser);
+	std::string desc = CT2A(description);
+	std::string start = CT2A(strStartTime);
+	std::string end = CT2A(strEndTime);
+
+	// 鑾峰彇鏃ュ織绠$悊瀹炰緥
+	SystemLogManager& logManager = SystemLogManager::getInstance();
+
+	int pageSize = 20; // 姣忛〉鏄剧ず 20 鏉¤褰�
+	int totalRecords = logManager.getTotalLogCount(type, user, desc, start, end);
+	m_nTotalPages = (totalRecords + pageSize - 1) / pageSize;
+	auto logs = logManager.getFilteredLogs(type, user, desc, start, end, m_nCurrentPage, pageSize);
+
+	// 鏇存柊琛ㄦ牸鏁版嵁
+	int rowIdx = 1;
+	for (const auto& log : logs) {
+		m_listLogs.SetItemText(rowIdx, 0, CString(std::to_string(rowIdx).c_str())); // 搴忓彿
+		m_listLogs.SetItemText(rowIdx, 1, CString(log[1].c_str()));                 // 绫诲瀷
+		m_listLogs.SetItemText(rowIdx, 2, CString(log[2].c_str()));                 // 浜嬩欢
+		m_listLogs.SetItemText(rowIdx, 3, CString(log[3].c_str()));                 // 鐢ㄦ埛
+		m_listLogs.SetItemText(rowIdx, 4, CString(log[4].c_str()));                 // 鏃堕棿
+		++rowIdx;
+	}
+
+	// 娓呯┖澶氫綑琛�
+	for (; rowIdx <= 20; ++rowIdx) {
+		m_listLogs.SetItemText(rowIdx, 0, CString(std::to_string(rowIdx).c_str())); // 搴忓彿鍒�
+		for (int colIdx = 1; colIdx < m_listLogs.GetColumnCount(); ++colIdx) {
+			m_listLogs.SetItemText(rowIdx, colIdx, _T(""));
+		}
+	}
+
+	m_listLogs.ExpandColumnsToFit(FALSE);
+	m_listLogs.ExpandLastColumn();
+	m_listLogs.Invalidate();
+	m_listLogs.UpdateWindow();
+
+	UpdatePageInfo();
+}
+
+void CSystemLogManagerDlg::UpdatePageInfo()
+{
+	// 鏍煎紡鍖栭〉鐮佷俊鎭负 "褰撳墠椤�/鎬婚〉鏁�"
+	CString pageInfo;
+	pageInfo.Format(_T("%d/%d 椤�"), m_nCurrentPage, m_nTotalPages);
+	m_staticPageNum.SetWindowText(pageInfo);
+}
+
+
+BEGIN_MESSAGE_MAP(CSystemLogManagerDlg, CBaseDlg)
+	ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CSystemLogManagerDlg::OnBnClickedButtonSearch)
+	ON_BN_CLICKED(IDC_BUTTON_PREV_PAGE, &CSystemLogManagerDlg::OnBnClickedButtonPrevPage)
+	ON_BN_CLICKED(IDC_BUTTON_NEXT_PAGE, &CSystemLogManagerDlg::OnBnClickedButtonNextPage)
+	ON_CBN_SELCHANGE(IDC_COMBO_TYPE, &CSystemLogManagerDlg::OnSelchangeComboType)
+	ON_CBN_SELCHANGE(IDC_COMBO_USER, &CSystemLogManagerDlg::OnSelchangeComboUser)
+END_MESSAGE_MAP()
+
+
+// CSystemLogManagerDlg 娑堟伅澶勭悊绋嬪簭
+
+
+BOOL CSystemLogManagerDlg::OnInitDialog()
+{
+	CBaseDlg::OnInitDialog();
+
+	// TODO:  鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
+	SetWindowText(_T("绯荤粺杩愯鏃ュ織"));
+
+	m_nCurrentPage = 1;  // 浠庣涓�椤靛紑濮�
+	m_nTotalPages = 1;   // 榛樿鎬婚〉鏁颁负 1
+
+	m_comboType.AddString(_T("ALL"));
+	m_comboType.AddString(_T("淇℃伅"));
+	m_comboType.AddString(_T("鎿嶄綔"));
+	m_comboType.AddString(_T("閿欒"));
+	m_comboType.AddString(_T("鏈煡"));
+	m_comboType.SetCurSel(0);
+
+	m_comboUser.AddString(_T("ALL"));
+	m_comboUser.AddString(_T("SYSTEM"));
+	auto usernames = UserManager::getInstance().getUsernames();
+	for (const auto& username : usernames) {
+		CString cstrUsername(username.c_str());
+		m_comboUser.AddString(cstrUsername);
+	}
+	m_comboUser.SetCurSel(0);
+	
+	// 璁剧疆涓� 30 澶╁墠
+	COleDateTime currentTime = COleDateTime::GetCurrentTime();
+	COleDateTime defaultStartTime = currentTime - COleDateTimeSpan(30, 0, 0, 0);
+	m_dateTimeStart.SetTime(defaultStartTime);
+
+	InitSystemLogManager();
+
+	return TRUE;  // return TRUE unless you set the focus to a control
+	// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
+}
+
+void CSystemLogManagerDlg::OnBnClickedButtonSearch()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		m_nCurrentPage = 1;
+		FillSystemLogManager();
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鎼滅储澶辫触锛�%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
+}
+
+void CSystemLogManagerDlg::OnBnClickedButtonPrevPage()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		if (m_nCurrentPage > 1) {
+			m_nCurrentPage--;
+			FillSystemLogManager();
+		}
+		else {
+			AfxMessageBox(_T("宸茬粡鏄涓�椤碉紒"));
+		}
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒囨崲鍒颁笂涓�椤靛け璐ワ細%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
+}
+
+void CSystemLogManagerDlg::OnBnClickedButtonNextPage()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		if (m_nCurrentPage < m_nTotalPages) {
+			m_nCurrentPage++;
+			FillSystemLogManager();
+		}
+		else {
+			AfxMessageBox(_T("宸茬粡鏄渶鍚庝竴椤碉紒"));
+		}
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒囨崲鍒颁笅涓�椤靛け璐ワ細%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
+}
+
+void CSystemLogManagerDlg::OnSelchangeComboType()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		m_nCurrentPage = 1;
+		FillSystemLogManager();
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒囨崲绫诲瀷澶辫触锛�%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
+}
+
+void CSystemLogManagerDlg::OnSelchangeComboUser()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		m_nCurrentPage = 1;
+		FillSystemLogManager();
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒囨崲瑙掕壊澶辫触锛�%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
+}

--
Gitblit v1.9.3