From 5e9b9b53a8a853365c29149871bd024c9ca0cbac Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期四, 11 十二月 2025 11:26:27 +0800
Subject: [PATCH] 1.报告的删除功能;

---
 SourceCode/Bond/Servo/HsmsPassive.cpp |   67 +++++++++++++++++++++++++++++++++
 1 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index d6f97cb..722eacd 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -600,6 +600,9 @@
 
 int CHsmsPassive::loadReports(const char* pszFilepath)
 {
+	m_strReportFilepath = pszFilepath;
+	m_bReportUtf8 = false;
+	m_bReportUtf8Bom = false;
 	// 鍏煎 UTF-8/BOM 涓庢湰鍦扮紪鐮佽鍙�
 	CFile file;
 	if (!file.Open(pszFilepath, CFile::modeRead | CFile::shareDenyNone)) {
@@ -623,6 +626,8 @@
 	// UTF-8 BOM
 	if (nLen >= 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) {
 		offset = 3;
+		m_bReportUtf8 = true;
+		m_bReportUtf8Bom = true;
 	}
 
 	// UTF-16 LE BOM
@@ -652,6 +657,7 @@
 			MultiByteToWideChar(CP_UTF8, 0, buffer.data() + off,
 				static_cast<int>(buffer.size() - off), temp.data(), need);
 			content = temp.c_str();
+			m_bReportUtf8 = true;
 			return true;
 		};
 
@@ -752,6 +758,14 @@
 	return false;
 }
 
+int CHsmsPassive::deleteReport(int rptid)
+{
+	if (!removeReport(rptid)) {
+		return -1;
+	}
+	return writeReportsToFile(m_strReportFilepath);
+}
+
 void CHsmsPassive::clearAllReport()
 {
 	for (auto item : m_reports) {
@@ -760,6 +774,59 @@
 	m_reports.clear();
 }
 
+int CHsmsPassive::writeReportsToFile(const std::string& filepath)
+{
+	if (filepath.empty()) return -1;
+
+	CFile file;
+	if (!file.Open(filepath.c_str(), CFile::modeCreate | CFile::modeWrite)) {
+		return -1;
+	}
+
+	if (m_bReportUtf8 && m_bReportUtf8Bom) {
+		const BYTE bom[3] = { 0xEF, 0xBB, 0xBF };
+		file.Write(bom, 3);
+	}
+
+	// header
+	const std::string headerAnsi = "RPTID,(VID1,VID2,...)\r\n";	
+	if (m_bReportUtf8) {
+		CStringA header = AnsiToUtf8(headerAnsi);
+		file.Write(header.GetString(), header.GetLength());
+	}
+	else {
+		file.Write(headerAnsi.data(), (UINT)headerAnsi.size());
+	}
+
+	for (auto rpt : m_reports) {
+		if (rpt == nullptr) continue;
+		std::string line;
+		line.reserve(64);
+		line += std::to_string(rpt->getReportId());
+		line += ",(";
+
+		const auto& vids = rpt->getVids();
+		for (size_t i = 0; i < vids.size(); ++i) {
+			line += std::to_string(vids[i]);
+			if (i + 1 < vids.size()) {
+				line.push_back(',');
+			}
+		}
+		line += ")\r\n";
+
+		if (m_bReportUtf8) {
+			CStringA out = AnsiToUtf8(line);
+			file.Write(out.GetString(), out.GetLength());
+		}
+		else {
+			file.Write(line.data(), (UINT)line.size());
+		}
+	}
+
+	file.Close();
+	return 0;
+}
+
 int CHsmsPassive::loadCollectionEvents(const char* pszFilepath)
 {
 	CFile file;

--
Gitblit v1.9.3