From 33f080ddc32f3545b685b2e0a7a5df3c35894270 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期四, 11 十二月 2025 14:43:40 +0800
Subject: [PATCH] 1.Event删除功能的实现;
---
SourceCode/Bond/Servo/CCollectionEvent.h | 4 +-
SourceCode/Bond/Servo/HsmsPassive.h | 5 ++
SourceCode/Bond/Servo/CPageCollectionEvent.cpp | 27 +++++++++++++
SourceCode/Bond/x64/Debug/CollectionEventList.txt | 1
SourceCode/Bond/Servo/CUserManager2.cpp | 1
SourceCode/Bond/Servo/HsmsPassive.cpp | 74 +++++++++++++++++++++++++++++++++++++
6 files changed, 109 insertions(+), 3 deletions(-)
diff --git a/SourceCode/Bond/Servo/CCollectionEvent.h b/SourceCode/Bond/Servo/CCollectionEvent.h
index a0b023d..9bd55a9 100644
--- a/SourceCode/Bond/Servo/CCollectionEvent.h
+++ b/SourceCode/Bond/Servo/CCollectionEvent.h
@@ -2,7 +2,6 @@
#include "CReport.h"
#include <vector>
-
namespace SERVO {
class CCollectionEvent
{
@@ -17,6 +16,7 @@
std::string& getDescription();
std::vector<CReport*>& getReports();
std::string getReportIdsText();
+ const std::vector<unsigned int>& getReportIds() const { return m_rptids; }
BOOL addReport(CReport* pReport);
BOOL deleteReport(unsigned int nReportId);
CReport* getReport(unsigned int nReportId);
@@ -33,4 +33,4 @@
std::vector<unsigned int> m_rptids;
std::vector<CReport*> m_reports;
};
-}
+}
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/CPageCollectionEvent.cpp b/SourceCode/Bond/Servo/CPageCollectionEvent.cpp
index d623697..d28ac2c 100644
--- a/SourceCode/Bond/Servo/CPageCollectionEvent.cpp
+++ b/SourceCode/Bond/Servo/CPageCollectionEvent.cpp
@@ -149,5 +149,30 @@
void CPageCollectionEvent::OnClickedBtn(const char* btnName)
{
- // 鏆傜暀锛氬悗缁疄鐜板鍒犳敼閫昏緫
+ ASSERT(btnName);
+ if (_strcmpi(btnName, "鍒犻櫎") == 0) {
+ POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
+ if (pos == nullptr) return;
+ int nItem = m_listCtrl.GetNextSelectedItem(pos);
+ auto pEvent = reinterpret_cast<SERVO::CCollectionEvent*>(m_listCtrl.GetItemData(nItem));
+ if (pEvent == nullptr) return;
+
+ int rc = UX_CanExecute(L"delEvents");
+ if (rc != 1) {
+ AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+ return;
+ }
+
+ int ret = theApp.m_model.m_hsmsPassive.deleteCollectionEvent((unsigned short)pEvent->getEventId());
+ if (ret == 0) {
+ UX_RecordAction(L"delEvents");
+ m_listCtrl.DeleteAllItems();
+ loadCollectionEvents();
+ if (CButton* pDel = GetBtnByName("鍒犻櫎")) pDel->EnableWindow(FALSE);
+ if (CButton* pEdit = GetBtnByName("缂栬緫")) pEdit->EnableWindow(FALSE);
+ }
+ else {
+ AfxMessageBox(_T("鍒犻櫎浜嬩欢澶辫触"));
+ }
+ }
}
diff --git a/SourceCode/Bond/Servo/CUserManager2.cpp b/SourceCode/Bond/Servo/CUserManager2.cpp
index c0daf4e..dec4178 100644
--- a/SourceCode/Bond/Servo/CUserManager2.cpp
+++ b/SourceCode/Bond/Servo/CUserManager2.cpp
@@ -88,6 +88,7 @@
UX_DefineAction(L"addReports", L"鏂板Report", L"PE");
UX_DefineAction(L"editReports", L"缂栬緫Report", L"PE");
UX_DefineAction(L"delReports", L"鍒犻櫎Report", L"PE");
+ UX_DefineAction(L"delEvents", L"鍒犻櫎Event", L"PE");
}
bool CUserManager2::login(const char* pszAccount, const char* pszPwd)
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index 3b0455c..e11cc50 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -875,6 +875,9 @@
int CHsmsPassive::loadCollectionEvents(const char* pszFilepath)
{
+ m_strCollectionEventFilepath = pszFilepath;
+ m_bCollectionUtf8 = false;
+ m_bCollectionUtf8Bom = false;
CFile file;
if (!file.Open(pszFilepath, CFile::modeRead | CFile::shareDenyNone)) {
return -1;
@@ -897,6 +900,8 @@
// UTF-8 BOM
if (nLen >= 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) {
offset = 3;
+ m_bCollectionUtf8 = true;
+ m_bCollectionUtf8Bom = true;
}
// UTF-16 LE BOM
@@ -926,6 +931,7 @@
MultiByteToWideChar(CP_UTF8, 0, buffer.data() + off,
static_cast<int>(buffer.size() - off), temp.data(), need);
content = temp.c_str();
+ m_bCollectionUtf8 = true;
return true;
};
@@ -1014,6 +1020,18 @@
return m_collectionEvents;
}
+int CHsmsPassive::deleteCollectionEvent(unsigned short CEID)
+{
+ for (auto iter = m_collectionEvents.begin(); iter != m_collectionEvents.end(); ++iter) {
+ if ((*iter)->getEventId() == CEID) {
+ delete (*iter);
+ m_collectionEvents.erase(iter);
+ return writeCollectionEventsToFile(m_strCollectionEventFilepath);
+ }
+ }
+ return -1;
+}
+
void CHsmsPassive::clearAllCollectionEvent()
{
for (auto item : m_collectionEvents) {
@@ -1055,6 +1073,62 @@
return result;
}
+int CHsmsPassive::writeCollectionEventsToFile(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_bCollectionUtf8 && m_bCollectionUtf8Bom) {
+ const BYTE bom[3] = { 0xEF, 0xBB, 0xBF };
+ file.Write(bom, 3);
+ }
+
+ const std::string headerAnsi = "CEID,CE Name,Descriptions,Attached RPTID\r\n";
+ if (m_bCollectionUtf8) {
+ CStringA header = AnsiToUtf8(headerAnsi);
+ file.Write(header.GetString(), header.GetLength());
+ }
+ else {
+ file.Write(headerAnsi.data(), (UINT)headerAnsi.size());
+ }
+
+ for (auto ev : m_collectionEvents) {
+ if (ev == nullptr) continue;
+ std::string line;
+ line.reserve(128);
+ line += std::to_string(ev->getEventId());
+ line.push_back(',');
+ line += ev->getName();
+ line.push_back(',');
+ line += ev->getDescription();
+ line.push_back(',');
+ line.push_back('(');
+ auto rptIds = ev->getReportIds();
+ for (size_t i = 0; i < rptIds.size(); ++i) {
+ line += std::to_string(rptIds[i]);
+ if (i + 1 < rptIds.size()) {
+ line.push_back(',');
+ }
+ }
+ line += ")\r\n";
+
+ if (m_bCollectionUtf8) {
+ CStringA out = AnsiToUtf8(line);
+ file.Write(out.GetString(), out.GetLength());
+ }
+ else {
+ file.Write(line.data(), (UINT)line.size());
+ }
+ }
+
+ file.Close();
+ return 0;
+}
+
int CHsmsPassive::init(CModel* pModel, const char* pszName, unsigned int port)
{
m_pModel = pModel;
diff --git a/SourceCode/Bond/Servo/HsmsPassive.h b/SourceCode/Bond/Servo/HsmsPassive.h
index 91b03a4..8106bc4 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.h
+++ b/SourceCode/Bond/Servo/HsmsPassive.h
@@ -174,6 +174,7 @@
// 鍙栨秷/鍒犻櫎鎵�鏈塁ollectionEvent
void clearAllCollectionEvent();
+ int deleteCollectionEvent(unsigned short CEID);
// 鍙栧緱CCollectionEvent
SERVO::CCollectionEvent* getEvent(unsigned short CEID);
@@ -244,6 +245,7 @@
std::vector<unsigned int> parseVidList(CString& strNums);
int writeVariablesToFile(const std::string& filepath);
int writeReportsToFile(const std::string& filepath);
+ int writeCollectionEventsToFile(const std::string& filepath);
private:
CModel* m_pModel;
@@ -267,6 +269,9 @@
std::string m_strReportFilepath;
bool m_bReportUtf8{ false };
bool m_bReportUtf8Bom{ false };
+ std::string m_strCollectionEventFilepath;
+ bool m_bCollectionUtf8{ false };
+ bool m_bCollectionUtf8Bom{ false };
BOOL m_bCimWorking;
HANDLE m_hCimWorkEvent;
HANDLE m_hCimWorkThreadHandle;
diff --git a/SourceCode/Bond/x64/Debug/CollectionEventList.txt b/SourceCode/Bond/x64/Debug/CollectionEventList.txt
index f955838..0f6f42c 100644
--- a/SourceCode/Bond/x64/Debug/CollectionEventList.txt
+++ b/SourceCode/Bond/x64/Debug/CollectionEventList.txt
@@ -1,3 +1,4 @@
+CEID,CE Name,Descriptions,Attached RPTID
300,AccessMode_To_Manual,,(300)
301,AccessMode_To_Auto,,(301)
600,ControlStateChanged,,(600)
--
Gitblit v1.9.3