From aedb3b85fed48cb2cf0abb5fafa8e7591644c9f4 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 02 十二月 2024 08:53:06 +0800
Subject: [PATCH] Merge branch 'liuyang' into clh

---
 SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp |  498 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 498 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp b/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
new file mode 100644
index 0000000..f5603fb
--- /dev/null
+++ b/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
@@ -0,0 +1,498 @@
+锘�// SystemLogManagerDlg.cpp: 瀹炵幇鏂囦欢
+//
+
+#include "stdafx.h"
+#include "BondEq.h"
+#include "afxdialogex.h"
+#include "SystemLogManagerDlg.h"
+
+
+// CSystemLogManagerDlg 瀵硅瘽妗�
+
+IMPLEMENT_DYNAMIC(CSystemLogManagerDlg, CDialogEx)
+
+CSystemLogManagerDlg::CSystemLogManagerDlg(CWnd* pParent /*=nullptr*/)
+	: CDialogEx(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent)
+{
+	m_nInitialWidth = 0;
+	m_nInitialHeight = 0;
+}
+
+CSystemLogManagerDlg::~CSystemLogManagerDlg()
+{
+	for (auto& pair : m_mapFonts) {
+		if (pair.second) {
+			pair.second->DeleteObject();
+			delete pair.second;
+		}
+	}
+	m_mapFonts.clear();
+}
+
+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, 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();
+}
+
+CFont* CSystemLogManagerDlg::GetOrCreateFont(int nFontSize)
+{
+	auto it = m_mapFonts.find(nFontSize);
+	if (it != m_mapFonts.end()) {
+		return it->second;
+	}
+
+	CFont* font = new CFont();
+	LOGFONT logFont = { 0 };
+	_tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
+	logFont.lfHeight = -nFontSize;
+	logFont.lfQuality = CLEARTYPE_QUALITY;
+	font->CreateFontIndirect(&logFont);
+	m_mapFonts[nFontSize] = font;
+
+	return font;
+}
+
+void CSystemLogManagerDlg::UpdatePageInfo()
+{
+	// 鏍煎紡鍖栭〉鐮佷俊鎭负 "褰撳墠椤�/鎬婚〉鏁�"
+	CString pageInfo;
+	pageInfo.Format(_T("%d/%d 椤�"), m_nCurrentPage, m_nTotalPages);
+	m_staticPageNum.SetWindowText(pageInfo);
+}
+
+void CSystemLogManagerDlg::SetDefaultFont()
+{
+	CFont* defaultFont = GetOrCreateFont(12);
+
+	// 閬嶅巻鎵�鏈夋帶浠讹紝搴旂敤榛樿瀛椾綋
+	CWnd* pWnd = GetWindow(GW_CHILD);
+	while (pWnd) {
+		// 璺宠繃鐗规畩鎺т欢锛堝 MFCGridCtrl锛�
+		TCHAR szClassName[256];
+		GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
+		if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
+			pWnd = pWnd->GetNextWindow();
+			continue;
+		}
+
+		pWnd->SetFont(defaultFont, TRUE);
+		pWnd = pWnd->GetNextWindow();
+	}
+}
+
+void CSystemLogManagerDlg::AdjustControls(float dScaleX, float dScaleY)
+{
+	CWnd* pWnd = GetWindow(GW_CHILD);
+	while (pWnd) {
+		int nCtrlID = pWnd->GetDlgCtrlID();
+		if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end())
+		{
+			CRect originalRect = m_mapCtrlLayouts[nCtrlID];
+			CRect newRect(
+				static_cast<int>(originalRect.left * dScaleX),
+				static_cast<int>(originalRect.top * dScaleY),
+				static_cast<int>(originalRect.right * dScaleX),
+				static_cast<int>(originalRect.bottom * dScaleY));
+
+			TCHAR szClassName[256];
+			GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
+
+			if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
+				CComboBox* pComboBox = (CComboBox*)pWnd;
+				pComboBox->SetItemHeight(-1, newRect.Height());  // -1 琛ㄧず鎵�鏈夐」鐨勯珮搴�
+			}
+
+			if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
+				CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd;
+				pGridCtrl->SetDefCellHeight(newRect.Height() / 21);
+				pGridCtrl->ExpandColumnsToFit(TRUE);
+				pGridCtrl->ExpandLastColumn();
+				pGridCtrl->Invalidate();
+				pGridCtrl->UpdateWindow();
+			}
+
+			pWnd->MoveWindow(&newRect);
+			AdjustControlFont(pWnd, newRect.Width(), newRect.Height());
+		}
+		pWnd = pWnd->GetNextWindow();
+	}
+}
+
+void CSystemLogManagerDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight)
+{
+	TCHAR szClassName[256];
+	GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
+
+	// 璺宠繃鐗规畩鎺т欢锛堝 MFCGridCtrl锛�
+	if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
+		return;
+	}
+
+	// 鏍规嵁鎺т欢楂樺害鍔ㄦ�佽皟鏁村瓧浣撳ぇ灏�
+	int fontSize = nHeight / 2;
+	if (fontSize < 8) fontSize = 8;
+
+	// 鑾峰彇鎴栧垱寤哄瓧浣�
+	CFont* pFont = GetOrCreateFont(fontSize);
+
+	pWnd->SetFont(pFont);
+	pWnd->Invalidate(); // 鍒锋柊鎺т欢鏄剧ず
+}
+
+
+void CSystemLogManagerDlg::AdjustComboBoxStyle(CComboBox& comboBox)
+{
+	DWORD dwStyle = comboBox.GetStyle();
+	comboBox.ModifyStyle(0, CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_OWNERDRAWFIXED);
+
+	comboBox.Invalidate();
+	comboBox.UpdateWindow();
+}
+
+
+void CSystemLogManagerDlg::AdjustDateTimeCtrlStyle(CDateTimeCtrl& dateTimeCtrl)
+{
+	dateTimeCtrl.ModifyStyle(0, DTS_RIGHTALIGN);
+	dateTimeCtrl.Invalidate();
+	dateTimeCtrl.UpdateWindow();
+}
+
+
+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)
+	ON_CBN_SELCHANGE(IDC_COMBO_TYPE, &CSystemLogManagerDlg::OnSelchangeComboType)
+	ON_CBN_SELCHANGE(IDC_COMBO_USER, &CSystemLogManagerDlg::OnSelchangeComboUser)
+	ON_WM_SIZE()
+	ON_WM_GETMINMAXINFO()
+END_MESSAGE_MAP()
+
+
+// CSystemLogManagerDlg 娑堟伅澶勭悊绋嬪簭
+
+
+BOOL CSystemLogManagerDlg::OnInitDialog()
+{
+	CDialogEx::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);
+
+	CRect screenRect, dlgRect, clientRect;
+	GetClientRect(&clientRect);
+	m_nInitialWidth = clientRect.Width();
+	m_nInitialHeight = clientRect.Height();
+
+	// 鍒濆鍖栭粯璁ゅ瓧浣�
+	CFont* pDefaultFont = GetOrCreateFont(12);
+
+	// 閬嶅巻鎵�鏈夊瓙鎺т欢锛岃褰曞垵濮嬩綅缃苟璁剧疆榛樿瀛椾綋
+	CWnd* pWnd = GetWindow(GW_CHILD);
+	while (pWnd) {
+		int nCtrlID = pWnd->GetDlgCtrlID();
+		if (nCtrlID != -1) {
+			// 璁板綍鎺т欢鍒濆甯冨眬
+			CRect ctrlRect;
+			pWnd->GetWindowRect(&ctrlRect);
+			ScreenToClient(&ctrlRect);
+			m_mapCtrlLayouts[nCtrlID] = ctrlRect;
+
+			// 璺宠繃鐗规畩鎺т欢锛堝 MFCGridCtrl锛�
+			TCHAR szClassName[256];
+			GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
+			if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
+				pWnd = pWnd->GetNextWindow();
+				continue;
+			}
+
+			// 璁剧疆榛樿瀛椾綋
+			pWnd->SetFont(pDefaultFont);
+		}
+		pWnd = pWnd->GetNextWindow();
+	}
+
+	GetWindowRect(&dlgRect);
+	int dlgWidth = dlgRect.Width() * 2;
+	int dlgHeight = dlgRect.Height() * 2;
+
+	SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0);
+	if (dlgWidth > screenRect.Width()) {
+		dlgWidth = screenRect.Width();
+	}
+	if (dlgHeight > screenRect.Height()) {
+		dlgHeight = screenRect.Height();
+	}
+
+	int centerX = screenRect.left + (screenRect.Width() - dlgWidth) / 2;
+	int centerY = screenRect.top + (screenRect.Height() - dlgHeight) / 2;
+	MoveWindow(centerX, centerY, dlgWidth, dlgHeight);
+
+	InitSystemLogManager();
+
+	return TRUE;  // return TRUE unless you set the focus to a control
+	// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
+}
+
+
+void CSystemLogManagerDlg::OnSize(UINT nType, int cx, int cy)
+{
+	CDialogEx::OnSize(nType, cx, cy);
+
+	// TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
+	if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) {
+		return;
+	}
+
+	float dScaleX = static_cast<float>(cx) / m_nInitialWidth;
+	float dScaleY = static_cast<float>(cy) / m_nInitialHeight;
+
+	// 閬嶅巻瀵硅瘽妗嗕腑鐨勬墍鏈夋帶浠�
+	AdjustControls(dScaleX, dScaleY);
+}
+
+
+void CSystemLogManagerDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
+{
+	// TODO: 鍦ㄦ娣诲姞娑堟伅澶勭悊绋嬪簭浠g爜鍜�/鎴栬皟鐢ㄩ粯璁ゅ��
+	lpMMI->ptMinTrackSize.x = 400; // 鏈�灏忓搴�
+	lpMMI->ptMinTrackSize.y = 300; // 鏈�灏忛珮搴�
+
+	CDialogEx::OnGetMinMaxInfo(lpMMI);
+}
+
+
+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);
+	}
+}
\ No newline at end of file

--
Gitblit v1.9.3