From 829fe6c6bc33d53fda9c31fd45a37e1df87befff Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 30 一月 2026 11:16:24 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang

---
 SourceCode/Bond/Servo/CPageReport.cpp |  126 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 124 insertions(+), 2 deletions(-)

diff --git a/SourceCode/Bond/Servo/CPageReport.cpp b/SourceCode/Bond/Servo/CPageReport.cpp
index d2900e3..4e3fd2e 100644
--- a/SourceCode/Bond/Servo/CPageReport.cpp
+++ b/SourceCode/Bond/Servo/CPageReport.cpp
@@ -5,6 +5,8 @@
 #include "Servo.h"
 #include "CPageReport.h"
 #include "afxdialogex.h"
+#include "CReportEditDlg.h"
+#include <algorithm>
 
 
 // CPageReport 瀵硅瘽妗�
@@ -32,6 +34,7 @@
 	ON_WM_CTLCOLOR()
 	ON_WM_DESTROY()
 	ON_WM_SIZE()
+	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &CPageReport::OnLvnItemchangedList1)
 END_MESSAGE_MAP()
 
 
@@ -64,7 +67,7 @@
 	m_listCtrl.InsertColumn(0, _T(""), LVCFMT_RIGHT, width[0]);
 	m_listCtrl.InsertColumn(1, _T("RPT ID"), LVCFMT_LEFT, width[1]);
 	m_listCtrl.InsertColumn(2, _T("VID"), LVCFMT_LEFT, width[2]);
-	// loadVariables();
+	loadReports();
 
 	return TRUE;  // return TRUE unless you set the focus to a control
 				  // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
@@ -108,8 +111,127 @@
 	CHMPropertyPage::OnSize(nType, cx, cy);
 	if (GetDlgItem(IDC_LIST1) == nullptr) return;
 
-	CWnd* pItem;
 	CRect rcClient, rcItem;
 	GetClientRect(&rcClient);
 	m_listCtrl.MoveWindow(12, 12, rcClient.Width() - 24, rcClient.Height() - 24);
 }
+
+void CPageReport::loadReports()
+{
+	auto& reports = theApp.m_model.m_hsmsPassive.getReports();
+	for (auto item : reports) {
+		int index = m_listCtrl.InsertItem(m_listCtrl.GetItemCount(), _T(""));
+		m_listCtrl.SetItemData(index, (DWORD_PTR)item);
+		m_listCtrl.SetItemText(index, 1, std::to_string(item->getReportId()).c_str());
+		m_listCtrl.SetItemText(index, 2, item->getVariablesIdsText().c_str());
+	}
+}
+
+void CPageReport::OnCreateBtns()
+{
+	const int BTN_W = 80;
+	const int BTN_H = 28;
+	CreateBtn(_T("鏂板"), BTN_W, BTN_H, 2001);
+	CreateBtn(_T("鍒犻櫎"), BTN_W, BTN_H, 2002)->EnableWindow(FALSE);
+	CreateBtn(_T("缂栬緫"), BTN_W, BTN_H, 2003)->EnableWindow(FALSE);
+}
+
+void CPageReport::OnLvnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
+{
+	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
+	int nSelCount = m_listCtrl.GetSelectedCount();
+
+	if (CButton* pDel = GetBtnByName("鍒犻櫎")) {
+		pDel->EnableWindow(nSelCount > 0);
+	}
+	if (CButton* pEdit = GetBtnByName("缂栬緫")) {
+		pEdit->EnableWindow(nSelCount > 0);
+	}
+
+	*pResult = 0;
+}
+
+void CPageReport::OnClickedBtn(const char* btnName)
+{
+	ASSERT(btnName);
+	if (_strcmpi(btnName, "鏂板") == 0) {
+		int rc = UX_CanExecute(L"addReports");
+		if (rc != 1) {
+			AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+			return;
+		}
+
+		unsigned int newId = theApp.m_model.m_hsmsPassive.getMaxReportId() + 1;
+		std::vector<unsigned int> initVids;
+		CReportEditDlg dlg(_T("鏂板鎶ュ憡"), static_cast<int>(newId), initVids, this);
+		if (dlg.DoModal() != IDOK) return;
+		const auto& vids = dlg.GetSelectedVids();
+
+		int ret = theApp.m_model.m_hsmsPassive.addReport(static_cast<int>(newId), vids);
+		if (ret == 0) {
+			UX_RecordAction(L"addReports");
+			m_listCtrl.DeleteAllItems();
+			loadReports();
+			if (CButton* pDel = GetBtnByName("鍒犻櫎")) pDel->EnableWindow(FALSE);
+			if (CButton* pEdit = GetBtnByName("缂栬緫")) pEdit->EnableWindow(FALSE);
+		}
+		else {
+			AfxMessageBox(_T("鏂板鎶ュ憡澶辫触锛堝彲鑳絀D閲嶅鎴栨枃浠跺啓鍏ュけ璐ワ級"));
+		}
+	}
+	else if (_strcmpi(btnName, "鍒犻櫎") == 0) {
+		POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
+		if (pos == nullptr) return;
+		int nItem = m_listCtrl.GetNextSelectedItem(pos);
+		auto pRpt = reinterpret_cast<SERVO::CReport*>(m_listCtrl.GetItemData(nItem));
+		if (pRpt == nullptr) return;
+
+		int rc = UX_CanExecute(L"delReports");
+		if (rc != 1) {
+			AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+			return;
+		}
+
+		int ret = theApp.m_model.m_hsmsPassive.deleteReport((int)pRpt->getReportId());
+		if (ret == 0) {
+			UX_RecordAction(L"delReports");
+			m_listCtrl.DeleteAllItems();
+			loadReports();
+			if (CButton* pDel = GetBtnByName("鍒犻櫎")) pDel->EnableWindow(FALSE);
+			if (CButton* pEdit = GetBtnByName("缂栬緫")) pEdit->EnableWindow(FALSE);
+		}
+		else {
+			AfxMessageBox(_T("鍒犻櫎鎶ュ憡澶辫触"));
+		}
+	}
+	else if (_strcmpi(btnName, "缂栬緫") == 0) {
+		POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
+		if (pos == nullptr) return;
+		int nItem = m_listCtrl.GetNextSelectedItem(pos);
+		auto pRpt = reinterpret_cast<SERVO::CReport*>(m_listCtrl.GetItemData(nItem));
+		if (pRpt == nullptr) return;
+
+		int rc = UX_CanExecute(L"editReports");
+		if (rc != 1) {
+			AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+			return;
+		}
+
+		std::vector<unsigned int> vidsExisting = pRpt->getVids();
+		CReportEditDlg dlg(_T("缂栬緫鎶ュ憡"), (int)pRpt->getReportId(), vidsExisting, this);
+		if (dlg.DoModal() != IDOK) return;
+		const auto& vids = dlg.GetSelectedVids();
+
+		int ret = theApp.m_model.m_hsmsPassive.updateReport((int)pRpt->getReportId(), vids);
+		if (ret == 0) {
+			UX_RecordAction(L"editReports");
+			m_listCtrl.DeleteAllItems();
+			loadReports();
+			if (CButton* pDel = GetBtnByName("鍒犻櫎")) pDel->EnableWindow(FALSE);
+			if (CButton* pEdit = GetBtnByName("缂栬緫")) pEdit->EnableWindow(FALSE);
+		}
+		else {
+			AfxMessageBox(_T("缂栬緫鎶ュ憡澶辫触锛堝彲鑳芥枃浠跺啓鍏ュけ璐ワ級"));
+		}
+	}
+}

--
Gitblit v1.9.3