SourceCode/Bond/BondEq/BondEq.rcBinary files differ
SourceCode/Bond/BondEq/BondEq.vcxproj
@@ -244,10 +244,11 @@ <ClInclude Include="targetver.h" /> <ClInclude Include="ToolUnits.h" /> <ClInclude Include="TopToolbar.h" /> <ClInclude Include="UserManagerDlg.h" /> <ClInclude Include="VerticalLine.h" /> <ClInclude Include="View\ChangePasswordDlg.h" /> <ClInclude Include="View\LoginDlg.h" /> <ClInclude Include="View\SystemLogManagerDlg.h" /> <ClInclude Include="View\UserManagerDlg.h" /> </ItemGroup> <ItemGroup> <ClCompile Include="CPLC.cpp" /> @@ -305,10 +306,11 @@ </ClCompile> <ClCompile Include="ToolUnits.cpp" /> <ClCompile Include="TopToolbar.cpp" /> <ClCompile Include="UserManagerDlg.cpp" /> <ClCompile Include="VerticalLine.cpp" /> <ClCompile Include="View\ChangePasswordDlg.cpp" /> <ClCompile Include="View\LoginDlg.cpp" /> <ClCompile Include="View\SystemLogManagerDlg.cpp" /> <ClCompile Include="View\UserManagerDlg.cpp" /> </ItemGroup> <ItemGroup> <ResourceCompile Include="BondEq.rc" /> SourceCode/Bond/BondEq/BondEqDlg.cpp
@@ -9,13 +9,13 @@ #include "Common.h" #include "CBonder.h" #include "SettingsDlg.h" #include "UserManager.h" #include "SystemLogManager.h" #include "LoginDlg.h" #include "ChangePasswordDlg.h" #include "InputDialog.h" #include "UserManagerDlg.h" // test #include "SystemLogManagerDlg.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -184,21 +184,15 @@ userManager.loadSession(); std::unique_ptr<BL::Database>& db = userManager.getDatabaseInstance(); // 设置æ¥å¿æ¨¡åçæ°æ®åºè¿æ¥ // 设置è¿è¡æ¥å¿æ¨¡åçæ°æ®åºè¿æ¥ SystemLogManager& logManager = SystemLogManager::getInstance(); logManager.setDatabase(db); // åå§åæ¥å¿è¡¨ // åå§åè¿è¡æ¥å¿è¡¨ if (!logManager.initializeLogTable()) { AfxMessageBox("åå§åç³»ç»æ¥å¿è¡¨å¤±è´¥ï¼"); return FALSE; } std::string strUsername = userManager.getCurrentUser(); if (strUsername.empty()) { strUsername = "SYSTEM"; } logManager.log(SystemLogManager::LogType::Info, _T("BondEqå¯å¨..."), strUsername); // èå @@ -243,6 +237,7 @@ // æ´æ°ç»å½ç¶æ UpdateLoginStatus(); logManager.log(SystemLogManager::LogType::Info, _T("BondEqå¯å¨...")); return TRUE; // é¤éå°ç¦ç¹è®¾ç½®å°æ§ä»¶ï¼å¦åè¿å TRUE @@ -368,11 +363,7 @@ KillTimer(1); #endif std::string strUsername = UserManager::getInstance().getCurrentUser(); if (strUsername.empty()) { strUsername = "SYSTEM"; } SystemLogManager::getInstance().log(SystemLogManager::LogType::Info, _T("BondEqå ³é..."), strUsername); SystemLogManager::getInstance().log(SystemLogManager::LogType::Info, _T("BondEqå ³é...")); } void CBondEqDlg::OnSize(UINT nType, int cx, int cy) @@ -533,6 +524,7 @@ LRESULT CBondEqDlg::OnToolbarBtnClicked(WPARAM wParam, LPARAM lParam) { int id = (int)lParam; SystemLogManager& logManager = SystemLogManager::getInstance(); if (id == IDC_BUTTON_RUN || id == IDC_BUTTON_STOP || id == IDC_BUTTON_SETTINGS) { CInputDialog inputDialog(_T("éªè¯ç¨æ·"), _T("请è¾å ¥ç¨æ·å¯ç ï¼")); @@ -545,6 +537,7 @@ std::string strPass = UserManager::getInstance().getCurrentPass(); if (inputText.Compare(strPass.c_str()) != 0) { AfxMessageBox(_T("å¯ç é误ï¼")); logManager.log(SystemLogManager::LogType::Info, _T("éªè¯æ¶ï¼å¯ç é误ï¼")); return 0; } } @@ -552,10 +545,12 @@ if (id == IDC_BUTTON_RUN) { m_pTopToolbar->GetBtn(IDC_BUTTON_RUN)->EnableWindow(FALSE); m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(TRUE); logManager.log(SystemLogManager::LogType::Operation, _T("è¿è¡...")); } else if (id == IDC_BUTTON_STOP) { m_pTopToolbar->GetBtn(IDC_BUTTON_RUN)->EnableWindow(TRUE); m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(FALSE); logManager.log(SystemLogManager::LogType::Operation, _T("Í£Ö¹...")); } else if (id == IDC_BUTTON_SETTINGS) { CSettingsDlg dlg; @@ -569,20 +564,28 @@ loginDlg.DoModal(); } else if (1 == menuId) { // test CSystemLogManagerDlg dlg; dlg.DoModal(); CChangePasswordDlg changePasswordDlg; changePasswordDlg.DoModal(); } else if (2 == menuId) { CUserManagerDlg dlg; dlg.DoModal(); if (dlg.DoModal()!= IDOK) { logManager.log(SystemLogManager::LogType::Operation, _T("ç¨æ·ç®¡çç颿ä½è¢«åæ¶ï¼")); } } else if (3 == menuId) { int ret = AfxMessageBox(_T("æ¯å¦åæ¢ç¨æ·ï¼åæ¢ç¨æ·ä¼éåºå½åè´¦å·ï¼"), MB_OK | MB_ICONEXCLAMATION); if (ret != MB_OK) { 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(); } @@ -592,11 +595,12 @@ else { CString cstrMessage; cstrMessage.Format(_T("æ¯å¦éåºç¨æ· [%s]ï¼"), userManager.getCurrentUser().c_str()); int ret = AfxMessageBox(_T(cstrMessage), MB_OK | MB_ICONEXCLAMATION); if (ret != MB_OK) { int ret = AfxMessageBox(_T(cstrMessage), MB_OKCANCEL | MB_ICONEXCLAMATION); if (ret != IDOK) { return 0; } logManager.log(SystemLogManager::LogType::Info, _T("éåºç»å½ï¼")); userManager.logout(); } SourceCode/Bond/BondEq/DBManager/SystemLogManager.cpp
@@ -1,5 +1,4 @@ #include "stdafx.h" #include "SystemLogManager.h" #include <iostream> #include <sstream> #include <stdexcept> @@ -41,18 +40,49 @@ log_type TEXT NOT NULL, event TEXT NOT NULL, username TEXT NOT NULL, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP timestamp DATETIME DEFAULT (datetime('now', 'localtime')) ) )"; return (*m_pDB)->executeQuery(createTableQuery); } // æ·»å æ¥å¿ bool SystemLogManager::log(LogType logType, const std::string& event) { if (!m_pDB || !(*m_pDB)) { std::cerr << "Database connection is not set." << std::endl; return false; } // æ¸ çæ§æ¥å¿ cleanOldLogs(30); std::string strUsername = UserManager::getInstance().getCurrentUser(); if (strUsername.empty()) { strUsername = "SYSTEM"; } std::ostringstream query; query << "INSERT INTO system_logs (log_type, event, username) VALUES (" << "'" << logTypeToString(logType) << "', " << "'" << event << "', " << "'" << strUsername << "')"; return (*m_pDB)->executeQuery(query.str()); } bool SystemLogManager::log(LogType logType, const std::string& event, const std::string& username) { if (!m_pDB || !(*m_pDB)) { std::cerr << "Database connection is not set." << std::endl; return false; } std::vector<std::string> vecUserInfo = UserManager::getInstance().getUserInfo(username); if (username.empty() || vecUserInfo.empty()) { std::cerr << "Username empty." << std::endl; return false; } // æ¸ çæ§æ¥å¿ cleanOldLogs(30); std::ostringstream query; query << "INSERT INTO system_logs (log_type, event, username) VALUES (" @@ -90,6 +120,132 @@ return logs; } // è·åçéåçæ¥å¿æ°æ® std::vector<std::vector<std::string>> SystemLogManager::getFilteredLogs( const std::string& logType, const std::string& username, const std::string& description, const std::string& startTime, const std::string& endTime, int pageNumber, int pageSize) { if (!m_pDB || !(*m_pDB)) { throw std::runtime_error("Database connection is not set."); } // æå»ºåºç¡ SQL æ¥è¯¢ std::ostringstream query; query << "SELECT id, log_type, event, username, timestamp FROM system_logs WHERE 1=1"; // ææ¥å¿ç±»åçé if (logType != "ALL") { query << " AND log_type = '" << logType << "'"; } // æç¨æ·åçé if (username != "ALL") { query << " AND username = '" << username << "'"; } // ææè¿°å ³é®è¯çé if (!description.empty()) { query << " AND event LIKE '%" << description << "%'"; } // ææ¶é´èå´çé if (!startTime.empty()) { query << " AND timestamp >= '" << startTime << "'"; } if (!endTime.empty()) { query << " AND timestamp <= '" << endTime << "'"; } // å页é»è¾ï¼è®¾ç½® LIMIT å OFFSET int offset = (pageNumber - 1) * pageSize; query << " ORDER BY timestamp DESC"; // ææ¶é´éåºæå query << " LIMIT " << pageSize << " OFFSET " << offset; // æ§è¡æ¥è¯¢ return (*m_pDB)->fetchResults(query.str()); } // è·åç¬¦åæ¡ä»¶çæ¥å¿æ»æ° int SystemLogManager::getTotalLogCount( const std::string& logType, const std::string& username, const std::string& description, const std::string& startTime, const std::string& endTime) { // æ£æ¥æ°æ®åºè¿æ¥æ¯å¦å¯ç¨ if (!m_pDB || !(*m_pDB)) { throw std::runtime_error("Database connection is not set."); } // æå»ºåºç¡ SQL æ¥è¯¢ std::ostringstream query; query << "SELECT COUNT(*) FROM system_logs WHERE 1=1"; // ææ¥å¿ç±»åçé if (logType != "ALL") { query << " AND log_type = '" << logType << "'"; } // æç¨æ·åçé if (username != "ALL") { query << " AND username = '" << username << "'"; } // ææè¿°å ³é®è¯çé if (!description.empty()) { query << " AND event LIKE '%" << description << "%'"; } // ææ¶é´èå´çé if (!startTime.empty()) { query << " AND timestamp >= '" << startTime << "'"; } if (!endTime.empty()) { query << " AND timestamp <= '" << endTime << "'"; } // æ§è¡æ¥è¯¢ auto results = (*m_pDB)->fetchResults(query.str()); // è¿åè®°å½æ»æ° if (!results.empty() && !results[0].empty()) { return std::stoi(results[0][0]); // 第ä¸è¡ç¬¬ä¸åæ¯è®¡æ°å¼ } return 0; // å¦ææ²¡æç»æï¼è¿å 0 } void SystemLogManager::cleanOldLogs(int daysToKeep) { if (!m_pDB || !(*m_pDB)) { throw std::runtime_error("Database connection is not set."); } // è·åå½åæ¥æå¹¶è®¡ç®æªææ¥æ time_t now = time(nullptr); tm timeInfo; localtime_s(&timeInfo, &now); timeInfo.tm_mday -= daysToKeep; // è®¡ç®æå®å¤©æ°ä¹åçæ¥æ mktime(&timeInfo); // è§è忥æ char buffer[20]; strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &timeInfo); std::string cutoffDate(buffer); std::ostringstream query; query << "DELETE FROM system_logs WHERE timestamp < '" << cutoffDate << "'"; bool ret = (*m_pDB)->executeQuery(query.str()); if (!ret) { throw std::runtime_error("System Log cleanup operation failed."); } } // è½¬æ¢æ¥å¿ç±»å为å符串 std::string SystemLogManager::logTypeToString(LogType logType) const { switch (logType) { SourceCode/Bond/BondEq/DBManager/SystemLogManager.h
@@ -10,9 +10,10 @@ class SystemLogManager { public: enum class LogType { Info, // ä¿¡æ¯æ¥å¿ Error, // é误æ¥å¿ Operation // æä½æ¥å¿ Info, Error, Operation, Unknown }; // è·ååä¾å®ä¾ @@ -21,14 +22,36 @@ // è®¾ç½®æ°æ®åºè¿æ¥ void setDatabase(std::unique_ptr<BL::Database>& db); // åå§åæ¥å¿è¡¨ bool initializeLogTable(); // æ·»å æ¥å¿ bool log(LogType logType, const std::string& event, const std::string& username = "SYSTEM"); bool log(LogType logType, const std::string& event); bool log(LogType logType, const std::string& event, const std::string& username); // è·åæ¥å¿ std::vector<std::vector<std::string>> SystemLogManager::getLogs(int startPosition = -1, int count = -1); // åå§åæ¥å¿è¡¨ bool initializeLogTable(); // è·åçéåçæ¥å¿æ°æ® std::vector<std::vector<std::string>> getFilteredLogs( const std::string& logType, const std::string& username, const std::string& description, const std::string& startTime, const std::string& endTime, int pageNumber, int pageSize); // è·åç¬¦åæ¡ä»¶çæ¥å¿æ»æ° int getTotalLogCount( const std::string& logType, const std::string& username, const std::string& description, const std::string& startTime, const std::string& endTime); // æ¸ çè¶ è¿æå®å¤©æ°çæ§æ¥å¿ void cleanOldLogs(int daysToKeep = 30); private: // æé 彿°ï¼ç§æåï¼ SourceCode/Bond/BondEq/DBManager/UserManager.cpp
@@ -48,7 +48,7 @@ role INT NOT NULL, session_timeout INT DEFAULT 30, session_expiration INT DEFAULT 72, last_login TIMESTAMP last_login DATETIME DEFAULT (datetime('now', 'localtime')) ) )"; m_pDB->executeQuery(createTableQuery); @@ -411,6 +411,39 @@ return success; } // è·åææç¨æ·åç§° std::vector<std::string> UserManager::getUsernames() { std::vector<std::string> usernames; std::string query = "SELECT username FROM users"; auto results = m_pDB->fetchResults(query); for (const auto& row : results) { if (!row.empty()) { usernames.push_back(row[0]); // è·åç¨æ·ååçå¼ } } return usernames; } // è·åæå®ç¨æ·åçç¨æ·ä¿¡æ¯ std::vector<std::string> UserManager::getUserInfo(const std::string& username) { // æå»ºæ¥è¯¢è¯å¥ std::ostringstream query; query << "SELECT username, password, role, session_timeout, session_expiration, last_login " << "FROM users WHERE username = '" << username << "'"; // æ§è¡æ¥è¯¢å¹¶è·åç»æ auto results = m_pDB->fetchResults(query.str()); if (results.empty()) { return {}; } // è¿åæ¥è¯¢å°ç第ä¸è¡æ°æ® return results[0]; } // æ´æ°æåæ´»å¨æ¶é´ï¼ç¨äºæ æä½è¶ æ¶æ£æµ void UserManager::updateActivityTime() { m_tpLastActivity = std::chrono::system_clock::now(); SourceCode/Bond/BondEq/DBManager/UserManager.h
@@ -41,6 +41,8 @@ bool changeUserRole(const std::string& username, UserRole newRole); bool changeUserSessionTimeout(const std::string& username, int newTimeoutMinutes); bool changeUserSessionExpiration(const std::string& username, int newExpirationHours); std::vector<std::string> getUsernames(); std::vector<std::string> getUserInfo(const std::string& username); // ä¼è¯æä»¶æä½ bool loadSession(); // ä»ä¼è¯æä»¶å è½½ä¼è¯ä¿¡æ¯ SourceCode/Bond/BondEq/Resource.hBinary files differ
SourceCode/Bond/BondEq/View/ChangePasswordDlg.cpp
@@ -5,7 +5,6 @@ #include "BondEq.h" #include "afxdialogex.h" #include "ChangePasswordDlg.h" #include "UserManager.h" // CChangePasswordDlg å¯¹è¯æ¡ @@ -82,6 +81,7 @@ return; } SystemLogManager& logManager = SystemLogManager::getInstance(); if (newPassword.Compare(currentPassword) == 0) { EndDialog(IDCANCEL); return; @@ -101,12 +101,14 @@ if (userManager.isLoggedIn() && strCurrentPassword.compare(userManager.getCurrentPass()) == 0) { if (changeUserPassword(userManager, strUsername, strNewPassword)) { EndDialog(IDOK); logManager.log(SystemLogManager::LogType::Info, "ä¿®æ¹å¯ç æåï¼", strUsername); } } else { if (userManager.login(strUsername, strCurrentPassword)) { if (changeUserPassword(userManager, strUsername, strNewPassword)) { EndDialog(IDOK); logManager.log(SystemLogManager::LogType::Info, "ä¿®æ¹å¯ç æåï¼", strUsername); } else { userManager.logout(); SourceCode/Bond/BondEq/View/LoginDlg.cpp
@@ -5,7 +5,6 @@ #include "BondEq.h" #include "afxdialogex.h" #include "LoginDlg.h" #include "UserManager.h" #include "ChangePasswordDlg.h" @@ -98,12 +97,14 @@ #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() SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,266 @@ // SystemLogManagerDlg.cpp: å®ç°æä»¶ // #include "stdafx.h" #include "BondEq.h" #include "afxdialogex.h" #include "SystemLogManagerDlg.h" #include "UserManager.h" #include "SystemLogManager.h" // CSystemLogManagerDlg å¯¹è¯æ¡ IMPLEMENT_DYNAMIC(CSystemLogManagerDlg, CDialogEx) CSystemLogManagerDlg::CSystemLogManagerDlg(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent) { } CSystemLogManagerDlg::~CSystemLogManagerDlg() { } void CSystemLogManagerDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::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, 20); m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("No.")); m_listLogs.SetColumnWidth(nColIdx, 70); m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("ç±»å")); m_listLogs.SetColumnWidth(nColIdx, 150); m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("äºä»¶")); m_listLogs.SetColumnWidth(nColIdx, 70); m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("ç¨æ·")); m_listLogs.SetColumnWidth(nColIdx, 70); 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.Invalidate(); m_listLogs.UpdateWindow(); m_listLogs.ExpandColumnsToFit(FALSE); m_listLogs.ExpandLastColumn(); UpdatePageInfo(); } void CSystemLogManagerDlg::UpdatePageInfo() { // æ ¼å¼å页ç ä¿¡æ¯ä¸º "å½å页/æ»é¡µæ°" CString pageInfo; pageInfo.Format(_T("%d/%d 页"), m_nCurrentPage, m_nTotalPages); m_staticPageNum.SetWindowText(pageInfo); } BEGIN_MESSAGE_MAP(CSystemLogManagerDlg, CDialogEx) 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) END_MESSAGE_MAP() // CSystemLogManagerDlg æ¶æ¯å¤çç¨åº BOOL CSystemLogManagerDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 卿¤æ·»å é¢å¤çåå§å 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: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç 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: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç 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: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç 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); } } SourceCode/Bond/BondEq/View/SystemLogManagerDlg.h
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,48 @@ #pragma once #include "afxdialogex.h" #include "GridCtrl.h" // CSystemLogManagerDlg å¯¹è¯æ¡ class CSystemLogManagerDlg : public CDialogEx { DECLARE_DYNAMIC(CSystemLogManagerDlg) public: CSystemLogManagerDlg(CWnd* pParent = nullptr); // æ åæé 彿° virtual ~CSystemLogManagerDlg(); // å¯¹è¯æ¡æ°æ® #ifdef AFX_DESIGN_TIME enum { IDD = IDD_DIALOG_SYSTEM_LOG_MANAGER }; #endif private: void InitSystemLogManager(); void FillSystemLogManager(); void UpdatePageInfo(); private: int m_nCurrentPage; // å½å页ç int m_nTotalPages; // æ»é¡µæ° private: CComboBox m_comboType; CComboBox m_comboUser; CDateTimeCtrl m_dateTimeStart; CDateTimeCtrl m_dateTimeEnd; CEdit m_editDescription; CGridCtrl m_listLogs; CStatic m_staticPageNum; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV æ¯æ DECLARE_MESSAGE_MAP() public: virtual BOOL OnInitDialog(); afx_msg void OnBnClickedButtonSearch(); afx_msg void OnBnClickedButtonPrevPage(); afx_msg void OnBnClickedButtonNextPage(); }; SourceCode/Bond/BondEq/View/UserManagerDlg.cpp
ÎļþÃû´Ó SourceCode/Bond/BondEq/UserManagerDlg.cpp ÐÞ¸Ä @@ -6,7 +6,6 @@ #include "afxdialogex.h" #include "UserManagerDlg.h" #include "InputDialog.h" #include "UserManager.h" #include "NewCellTypes/GridCellCombo.h" #include "NewCellTypes/GridCellNumeric.h" @@ -202,12 +201,12 @@ CString inputText = inputDialog.GetInputText(); if (inputText.IsEmpty()) { AfxMessageBox(_T("ç¨æ·åä¸è½ä¸ºç©ºï¼"), MB_OK | MB_ICONEXCLAMATION); AfxMessageBox(_T("ç¨æ·åä¸è½ä¸ºç©ºï¼")); return; } if (IsUsernameDuplicate(inputText)) { AfxMessageBox(_T("ç¨æ·åéå¤ï¼"), MB_OK | MB_ICONEXCLAMATION); AfxMessageBox(_T("ç¨æ·åéå¤ï¼")); return; } @@ -259,6 +258,11 @@ pGridCtrl->ExpandLastColumn(); pGridCtrl->Invalidate(); pGridCtrl->UpdateWindow(); CString cstrMessage; cstrMessage.Format(_T("颿·»å ç¨æ· [%s]ï¼"), inputText); std::string strMessage = CT2A(cstrMessage); SystemLogManager::getInstance().log(SystemLogManager::LogType::Operation, strMessage); } void CUserManagerDlg::DeleteSelectedRow(CGridCtrl* pGridCtrl) @@ -286,7 +290,7 @@ if (selectedUser == currentUser) { CString message; message.Format(_T("ç¨æ· [%s] æ¯å½åç»å½ç¨æ·ï¼ä¸è½å é¤ï¼"), currentUser); AfxMessageBox(message, MB_OK | MB_ICONEXCLAMATION); AfxMessageBox(message); return; } @@ -294,7 +298,7 @@ } if (rowsToDelete.empty()) { AfxMessageBox(_T("请å éæ©è¦å é¤çè¡ï¼"), MB_OK | MB_ICONINFORMATION); AfxMessageBox(_T("请å éæ©è¦å é¤çè¡ï¼")); return; } @@ -302,6 +306,11 @@ if (rowsToDelete.size() == 1) { CString selectedUser = pGridCtrl->GetItemText(rowsToDelete[0], 1); message.Format(_T("ç¡®å®è¦å é¤éä¸ç¨æ· [%s] åï¼"), selectedUser); CString cstrMessage; cstrMessage.Format(_T("é¢å é¤ç¨æ· [%s]ï¼"), selectedUser); std::string strMessage = CT2A(cstrMessage); SystemLogManager::getInstance().log(SystemLogManager::LogType::Operation, strMessage); } else { message.Format(_T("ç¡®å®è¦å é¤éä¸ç %d ä¸ªç¨æ·åï¼"), rowsToDelete.size()); @@ -319,7 +328,7 @@ } } else { AfxMessageBox(_T("请å éæ©è¦å é¤çç¨æ·ï¼"), MB_OK | MB_ICONINFORMATION); AfxMessageBox(_T("请å éæ©è¦å é¤çç¨æ·ï¼")); } } @@ -498,14 +507,14 @@ CCellRange selectedRange = m_gridUserManager.GetSelectedCellRange(); if (!selectedRange.IsValid()) { AfxMessageBox(_T("请å éæ©è¦æå ¥çä½ç½®ï¼"), MB_OK | MB_ICONINFORMATION); AfxMessageBox(_T("请å éæ©è¦æå ¥çä½ç½®ï¼")); return; } int minRow = selectedRange.GetMinRow(); int maxRow = selectedRange.GetMaxRow(); if (minRow < 1) { AfxMessageBox(_T("è¯·éæ©ææçè¡ï¼"), MB_OK | MB_ICONEXCLAMATION); AfxMessageBox(_T("è¯·éæ©ææçè¡ï¼")); return; } SourceCode/Bond/BondEq/View/UserManagerDlg.h
SourceCode/Bond/BondEq/stdafx.h
@@ -47,6 +47,10 @@ #include "..\DatabaseSDK\include\MySQLDatabase.h" #include "..\DatabaseSDK\include\SQLiteDatabase.h" // å便¨¡å¼çæ°æ®åºç®¡çç±» #include "UserManager.h" #include "SystemLogManager.h" // æ§ä»¶æ ·å¼ static UINT g_nGridFixCellColor = RGB(144, 200, 246); static UINT g_nGridFixFontColor = RGB(0, 0, 0); SourceCode/Bond/x64/Debug/Config/BondEq.dbBinary files differ