From fe1539643b86cebb50b44c59ae4b7809a165dc6c Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期四, 11 十二月 2025 15:13:08 +0800
Subject: [PATCH] 1.事件的新增和编辑;
---
SourceCode/Bond/Servo/CEventEditDlg.h | 37 +++++++
SourceCode/Bond/Servo/Servo.vcxproj | 2
SourceCode/Bond/Servo/HsmsPassive.h | 3
SourceCode/Bond/Servo/Servo.vcxproj.filters | 6 +
SourceCode/Bond/Servo/resource.h | 11 +
SourceCode/Bond/Servo/CPageCollectionEvent.cpp | 57 +++++++++++
SourceCode/Bond/x64/Debug/CollectionEventList.txt | 2
SourceCode/Bond/Servo/CUserManager2.cpp | 5 +
SourceCode/Bond/Servo/HsmsPassive.cpp | 46 +++++++++
SourceCode/Bond/Servo/Servo.rc | 17 +++
SourceCode/Bond/Servo/CEventEditDlg.cpp | 94 ++++++++++++++++++
11 files changed, 274 insertions(+), 6 deletions(-)
diff --git a/SourceCode/Bond/Servo/CEventEditDlg.cpp b/SourceCode/Bond/Servo/CEventEditDlg.cpp
new file mode 100644
index 0000000..1148a59
--- /dev/null
+++ b/SourceCode/Bond/Servo/CEventEditDlg.cpp
@@ -0,0 +1,94 @@
+#include "stdafx.h"
+#include "CEventEditDlg.h"
+#include "Servo.h"
+#include "resource.h"
+#include <algorithm>
+
+IMPLEMENT_DYNAMIC(CEventEditDlg, CDialogEx)
+
+CEventEditDlg::CEventEditDlg(const CString& title, int eventId, const CString& name, const CString& desc, const std::vector<unsigned int>& rptIds, CWnd* pParent)
+ : CDialogEx(IDD_DIALOG_EVENT_EDIT, pParent)
+ , m_strTitle(title)
+ , m_eventId(eventId)
+ , m_strName(name)
+ , m_strDesc(desc)
+ , m_rptIds(rptIds)
+{
+}
+
+CEventEditDlg::~CEventEditDlg()
+{
+}
+
+void CEventEditDlg::DoDataExchange(CDataExchange* pDX)
+{
+ CDialogEx::DoDataExchange(pDX);
+ DDX_Control(pDX, IDC_EDIT_EVT_ID, m_editId);
+ DDX_Control(pDX, IDC_EDIT_EVT_NAME, m_editName);
+ DDX_Control(pDX, IDC_EDIT_EVT_DESC, m_editDesc);
+ DDX_Control(pDX, IDC_LIST_EVT_RPTS, m_listRpt);
+}
+
+BEGIN_MESSAGE_MAP(CEventEditDlg, CDialogEx)
+END_MESSAGE_MAP()
+
+BOOL CEventEditDlg::OnInitDialog()
+{
+ CDialogEx::OnInitDialog();
+ SetWindowText(m_strTitle);
+
+ CString strId;
+ strId.Format(_T("%d"), m_eventId);
+ m_editId.SetWindowText(strId);
+ m_editId.SetReadOnly(TRUE);
+ m_editName.SetWindowText(m_strName);
+ m_editDesc.SetWindowText(m_strDesc);
+
+ m_listRpt.SetExtendedStyle(m_listRpt.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES);
+ m_listRpt.InsertColumn(0, _T("RPT ID"), LVCFMT_LEFT, 120);
+ m_listRpt.InsertColumn(1, _T("VIDs"), LVCFMT_LEFT, 240);
+
+ auto& reports = theApp.m_model.m_hsmsPassive.getReports();
+ for (int i = 0; i < (int)reports.size(); ++i) {
+ auto rpt = reports[i];
+ if (rpt == nullptr) continue;
+ int idx = m_listRpt.InsertItem(m_listRpt.GetItemCount(), std::to_string(rpt->getReportId()).c_str());
+ m_listRpt.SetItemText(idx, 1, rpt->getVariablesIdsText().c_str());
+ m_listRpt.SetItemData(idx, (DWORD_PTR)rpt->getReportId());
+ if (std::find(m_rptIds.begin(), m_rptIds.end(), rpt->getReportId()) != m_rptIds.end()) {
+ m_listRpt.SetCheck(idx, TRUE);
+ }
+ }
+
+ return TRUE;
+}
+
+void CEventEditDlg::OnOK()
+{
+ CString name, desc;
+ m_editName.GetWindowText(name);
+ m_editDesc.GetWindowText(desc);
+ name.Trim();
+ desc.Trim();
+ if (name.IsEmpty()) {
+ AfxMessageBox(_T("鍚嶇О涓嶈兘涓虹┖"));
+ return;
+ }
+
+ std::vector<unsigned int> selected;
+ int count = m_listRpt.GetItemCount();
+ for (int i = 0; i < count; ++i) {
+ if (m_listRpt.GetCheck(i)) {
+ selected.push_back((unsigned int)m_listRpt.GetItemData(i));
+ }
+ }
+ if (selected.empty()) {
+ AfxMessageBox(_T("鑷冲皯閫夋嫨涓�涓猂eport"));
+ return;
+ }
+
+ m_strName = name;
+ m_strDesc = desc;
+ m_rptIds.swap(selected);
+ CDialogEx::OnOK();
+}
diff --git a/SourceCode/Bond/Servo/CEventEditDlg.h b/SourceCode/Bond/Servo/CEventEditDlg.h
new file mode 100644
index 0000000..a2a1b96
--- /dev/null
+++ b/SourceCode/Bond/Servo/CEventEditDlg.h
@@ -0,0 +1,37 @@
+锘�#pragma once
+#include "afxdialogex.h"
+#include <vector>
+
+// 浜嬩欢缂栬緫瀵硅瘽妗嗭紙鏂板/缂栬緫鍏辩敤锛屽嬀閫塕eport锛�
+class CEventEditDlg : public CDialogEx
+{
+ DECLARE_DYNAMIC(CEventEditDlg)
+
+public:
+ CEventEditDlg(const CString& title, int eventId, const CString& name, const CString& desc, const std::vector<unsigned int>& rptIds, CWnd* pParent = nullptr);
+ virtual ~CEventEditDlg();
+
+ int GetEventId() const { return m_eventId; }
+ CString GetNameText() const { return m_strName; }
+ CString GetDescText() const { return m_strDesc; }
+ const std::vector<unsigned int>& GetSelectedRptIds() const { return m_rptIds; }
+
+protected:
+ virtual BOOL OnInitDialog() override;
+ virtual void DoDataExchange(CDataExchange* pDX) override;
+ afx_msg void OnOK();
+
+ DECLARE_MESSAGE_MAP()
+
+private:
+ CString m_strTitle;
+ int m_eventId;
+ CString m_strName;
+ CString m_strDesc;
+ std::vector<unsigned int> m_rptIds;
+
+ CEdit m_editId;
+ CEdit m_editName;
+ CEdit m_editDesc;
+ CListCtrl m_listRpt;
+};
diff --git a/SourceCode/Bond/Servo/CPageCollectionEvent.cpp b/SourceCode/Bond/Servo/CPageCollectionEvent.cpp
index d28ac2c..46f4b71 100644
--- a/SourceCode/Bond/Servo/CPageCollectionEvent.cpp
+++ b/SourceCode/Bond/Servo/CPageCollectionEvent.cpp
@@ -5,6 +5,7 @@
#include "Servo.h"
#include "CPageCollectionEvent.h"
#include "afxdialogex.h"
+#include "CEventEditDlg.h"
// CPageCollectionEvent 瀵硅瘽妗�
@@ -150,7 +151,30 @@
void CPageCollectionEvent::OnClickedBtn(const char* btnName)
{
ASSERT(btnName);
- if (_strcmpi(btnName, "鍒犻櫎") == 0) {
+ if (_strcmpi(btnName, "鏂板") == 0) {
+ int rc = UX_CanExecute(L"addEvents");
+ if (rc != 1) {
+ AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+ return;
+ }
+ unsigned int newId = theApp.m_model.m_hsmsPassive.getMaxCollectionEventId() + 1;
+ std::vector<unsigned int> rptIds;
+ CEventEditDlg dlg(_T("鏂板浜嬩欢"), (int)newId, _T(""), _T(""), rptIds, this);
+ if (dlg.DoModal() != IDOK) return;
+
+ int ret = theApp.m_model.m_hsmsPassive.addCollectionEvent(newId, CT2A(dlg.GetNameText()), CT2A(dlg.GetDescText()), dlg.GetSelectedRptIds());
+ if (ret == 0) {
+ UX_RecordAction(L"addEvents");
+ m_listCtrl.DeleteAllItems();
+ loadCollectionEvents();
+ 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);
@@ -175,4 +199,35 @@
AfxMessageBox(_T("鍒犻櫎浜嬩欢澶辫触"));
}
}
+ else 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"editEvents");
+ if (rc != 1) {
+ AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+ return;
+ }
+
+ CString name = pEvent->getName().c_str();
+ CString desc = pEvent->getDescription().c_str();
+ auto rptIds = pEvent->getReportIds();
+ CEventEditDlg dlg(_T("缂栬緫浜嬩欢"), (int)pEvent->getEventId(), name, desc, rptIds, this);
+ if (dlg.DoModal() != IDOK) return;
+
+ int ret = theApp.m_model.m_hsmsPassive.updateCollectionEvent(pEvent->getEventId(), CT2A(dlg.GetNameText()), CT2A(dlg.GetDescText()), dlg.GetSelectedRptIds());
+ if (ret == 0) {
+ UX_RecordAction(L"editEvents");
+ 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 dec4178..402b2f6 100644
--- a/SourceCode/Bond/Servo/CUserManager2.cpp
+++ b/SourceCode/Bond/Servo/CUserManager2.cpp
@@ -80,6 +80,9 @@
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"addEvents", L"鏂板Event", L"PE");
+ UX_DefineAction(L"editEvents", L"缂栬緫Event", L"PE");
+ UX_DefineAction(L"delEvents", L"鍒犻櫎Event", L"PE");
}
// 纭繚鏉冮檺瀹氫箟瀛樺湪锛堝箓绛夛級
UX_DefineAction(L"addVarialbles", L"鏂板鍙橀噺", L"PE");
@@ -89,6 +92,8 @@
UX_DefineAction(L"editReports", L"缂栬緫Report", L"PE");
UX_DefineAction(L"delReports", L"鍒犻櫎Report", L"PE");
UX_DefineAction(L"delEvents", L"鍒犻櫎Event", L"PE");
+ UX_DefineAction(L"addEvents", L"鏂板Event", L"PE");
+ UX_DefineAction(L"editEvents", 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 e11cc50..fc512d9 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -1020,6 +1020,17 @@
return m_collectionEvents;
}
+unsigned int CHsmsPassive::getMaxCollectionEventId() const
+{
+ unsigned int maxId = 0;
+ for (auto item : m_collectionEvents) {
+ if (item && item->getEventId() > maxId) {
+ maxId = item->getEventId();
+ }
+ }
+ return maxId;
+}
+
int CHsmsPassive::deleteCollectionEvent(unsigned short CEID)
{
for (auto iter = m_collectionEvents.begin(); iter != m_collectionEvents.end(); ++iter) {
@@ -1032,6 +1043,41 @@
return -1;
}
+int CHsmsPassive::addCollectionEvent(unsigned int CEID, const char* name, const char* desc, const std::vector<unsigned int>& rptids)
+{
+ if (getEvent((unsigned short)CEID) != nullptr) {
+ return -1;
+ }
+ auto* pEvent = new SERVO::CCollectionEvent(CEID, name, desc, const_cast<std::vector<unsigned int>&>(rptids));
+ for (auto rptid : rptids) {
+ SERVO::CReport* pReport = getReport((int)rptid);
+ if (pReport != nullptr) {
+ pEvent->addReport(pReport);
+ }
+ }
+ m_collectionEvents.push_back(pEvent);
+ return writeCollectionEventsToFile(m_strCollectionEventFilepath);
+}
+
+int CHsmsPassive::updateCollectionEvent(unsigned int CEID, const char* name, const char* desc, const std::vector<unsigned int>& rptids)
+{
+ for (auto iter = m_collectionEvents.begin(); iter != m_collectionEvents.end(); ++iter) {
+ if ((*iter)->getEventId() == CEID) {
+ delete (*iter);
+ auto* pEvent = new SERVO::CCollectionEvent(CEID, name, desc, const_cast<std::vector<unsigned int>&>(rptids));
+ for (auto rptid : rptids) {
+ SERVO::CReport* pReport = getReport((int)rptid);
+ if (pReport != nullptr) {
+ pEvent->addReport(pReport);
+ }
+ }
+ *iter = pEvent;
+ return writeCollectionEventsToFile(m_strCollectionEventFilepath);
+ }
+ }
+ return -1;
+}
+
void CHsmsPassive::clearAllCollectionEvent()
{
for (auto item : m_collectionEvents) {
diff --git a/SourceCode/Bond/Servo/HsmsPassive.h b/SourceCode/Bond/Servo/HsmsPassive.h
index 8106bc4..47f4f56 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.h
+++ b/SourceCode/Bond/Servo/HsmsPassive.h
@@ -171,10 +171,13 @@
// 鍙栧緱CCollectionEvent鍒楄〃
std::vector<SERVO::CCollectionEvent*>& getCollectionEvents();
+ unsigned int getMaxCollectionEventId() const;
// 鍙栨秷/鍒犻櫎鎵�鏈塁ollectionEvent
void clearAllCollectionEvent();
int deleteCollectionEvent(unsigned short CEID);
+ int addCollectionEvent(unsigned int CEID, const char* name, const char* desc, const std::vector<unsigned int>& rptids);
+ int updateCollectionEvent(unsigned int CEID, const char* name, const char* desc, const std::vector<unsigned int>& rptids);
// 鍙栧緱CCollectionEvent
SERVO::CCollectionEvent* getEvent(unsigned short CEID);
diff --git a/SourceCode/Bond/Servo/Servo.rc b/SourceCode/Bond/Servo/Servo.rc
index ac0144e..6bcfa7c 100644
--- a/SourceCode/Bond/Servo/Servo.rc
+++ b/SourceCode/Bond/Servo/Servo.rc
@@ -555,6 +555,23 @@
PUSHBUTTON "取消",IDCANCEL,230,200,50,14
END
+IDD_DIALOG_EVENT_EDIT DIALOGEX 0, 0, 340, 220
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "事件"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ LTEXT "事件ID:",IDC_STATIC,12,12,50,8
+ EDITTEXT IDC_EDIT_EVT_ID,70,10,170,14,ES_AUTOHSCROLL | ES_READONLY
+ LTEXT "名称:",IDC_STATIC,12,32,50,8
+ EDITTEXT IDC_EDIT_EVT_NAME,70,30,260,14,ES_AUTOHSCROLL
+ LTEXT "描述:",IDC_STATIC,12,52,50,8
+ EDITTEXT IDC_EDIT_EVT_DESC,70,50,260,34,ES_AUTOHSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL
+ LTEXT "选择Report:",IDC_STATIC_SELECT_VARS,12,90,70,8
+ CONTROL "",IDC_LIST_EVT_RPTS,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP,12,100,316,90
+ DEFPUSHBUTTON "确定",IDOK,200,196,50,14
+ PUSHBUTTON "取消",IDCANCEL,260,196,50,14
+END
+
IDD_PAGE_LINK_SIGNAL DIALOGEX 0, 0, 543, 239
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj b/SourceCode/Bond/Servo/Servo.vcxproj
index 3312b3b..2b022d8 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj
+++ b/SourceCode/Bond/Servo/Servo.vcxproj
@@ -233,6 +233,7 @@
<ClInclude Include="CControlJobManagerDlg.h" />
<ClInclude Include="CCustomCheckBox.h" />
<ClInclude Include="CCollectionEvent.h" />
+ <ClInclude Include="CEventEditDlg.h" />
<ClInclude Include="CEquipmentPage3.h" />
<ClInclude Include="CExpandableListCtrl.h" />
<ClInclude Include="CGlassPool.h" />
@@ -453,6 +454,7 @@
<ClCompile Include="CControlJobManagerDlg.cpp" />
<ClCompile Include="CCustomCheckBox.cpp" />
<ClCompile Include="CCollectionEvent.cpp" />
+ <ClCompile Include="CEventEditDlg.cpp" />
<ClCompile Include="CEquipmentPage3.cpp" />
<ClCompile Include="CExpandableListCtrl.cpp" />
<ClCompile Include="CGlassPool.cpp" />
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj.filters b/SourceCode/Bond/Servo/Servo.vcxproj.filters
index 9362a64..8df064d 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj.filters
+++ b/SourceCode/Bond/Servo/Servo.vcxproj.filters
@@ -171,6 +171,9 @@
<ClCompile Include="RecipeDeviceBindDlg.cpp" />
<ClCompile Include="CCustomCheckBox.cpp" />
<ClCompile Include="CCollectionEvent.cpp" />
+ <ClCompile Include="CEventEditDlg.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="CReport.cpp" />
<ClCompile Include="CReportEditDlg.cpp">
<Filter>Source Files</Filter>
@@ -413,6 +416,9 @@
<ClInclude Include="RecipeDeviceBindDlg.h" />
<ClInclude Include="CCustomCheckBox.h" />
<ClInclude Include="CCollectionEvent.h" />
+ <ClInclude Include="CEventEditDlg.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="CReport.h" />
<ClInclude Include="CReportEditDlg.h">
<Filter>Header Files</Filter>
diff --git a/SourceCode/Bond/Servo/resource.h b/SourceCode/Bond/Servo/resource.h
index 9d23997..a95442e 100644
--- a/SourceCode/Bond/Servo/resource.h
+++ b/SourceCode/Bond/Servo/resource.h
@@ -46,6 +46,7 @@
#define IDD_DIALOG_INPUT 164
#define IDD_DIALOG_VARIABLE_EDIT2 186
#define IDD_DIALOG_REPORT_EDIT 187
+#define IDD_DIALOG_EVENT_EDIT 188
#define IDD_PAGE_LINK_SIGNAL 165
#define IDD_DIALOG_SYSTEM_LOG_MANAGER 166
#define IDD_DIALOG_RECIPE_DEVICE_BIND 167
@@ -317,10 +318,13 @@
#define IDC_EDIT_VAR_REMARK 1238
#define IDC_EDIT_RPT_ID 1239
#define IDC_EDIT_RPT_VIDS 1240
+#define IDC_EDIT_EVT_ID 1243
+#define IDC_EDIT_EVT_NAME 1244
+#define IDC_EDIT_EVT_DESC 1245
+#define IDC_LIST_EVT_RPTS 1246
#define IDC_EDIT_VAR_ID 1235
#define IDC_COMBO_VAR_TYPE 1236
#define IDC_EDIT_VAR_NAME 1237
-#define IDC_EDIT_VAR_REMARK 1238
#define ID_MENU_HELP_ABOUT 32771
#define ID_MENU_FILE_EXIT 32772
#define ID_MENU_FILE_SECSTEST 32773
@@ -351,14 +355,13 @@
#define ID_EQSGRAPHITEM_TEST6 32798
#define ID_MENU_PROJECT_VARIABLE_LIST 32800
#define ID_MENU_TOOLS_CLIENT_LIST 32801
-
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 188
+#define _APS_NEXT_RESOURCE_VALUE 189
#define _APS_NEXT_COMMAND_VALUE 32802
-#define _APS_NEXT_CONTROL_VALUE 1243
+#define _APS_NEXT_CONTROL_VALUE 1247
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/SourceCode/Bond/x64/Debug/CollectionEventList.txt b/SourceCode/Bond/x64/Debug/CollectionEventList.txt
index 0f6f42c..9029707 100644
--- a/SourceCode/Bond/x64/Debug/CollectionEventList.txt
+++ b/SourceCode/Bond/x64/Debug/CollectionEventList.txt
@@ -49,4 +49,4 @@
50008,Port_Unload_Ready,,(50008)
50009,Port_Load_Ready,,(50009)
50010,Port_Blocked,,(50010)
-
+50011,TestEvent,TestEvent,娴嬭瘯涓�涓�,(50011)
--
Gitblit v1.9.3