From aadeadede11fabacebc5378ac0548794f5f49a74 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期四, 11 十二月 2025 13:51:57 +0800
Subject: [PATCH] 1.实现报告的增加和删除;
---
SourceCode/Bond/Servo/Servo.vcxproj | 4
SourceCode/Bond/Servo/HsmsPassive.h | 5
SourceCode/Bond/Servo/resource.h | 13 ++
SourceCode/Bond/Servo/CUserManager2.cpp | 9 +
SourceCode/Bond/Servo/HsmsPassive.cpp | 46 +++++++++
SourceCode/Bond/Servo/CReportEditDlg.cpp | 78 +++++++++++++++
SourceCode/Bond/Servo/Servo.vcxproj.filters | 8 +
SourceCode/Bond/Servo/CReportEditDlg.h | 30 ++++++
SourceCode/Bond/Servo/CReport.h | 2
SourceCode/Bond/Servo/Servo.rc | 14 ++
SourceCode/Bond/Servo/CPageReport.cpp | 59 +++++++++++
SourceCode/Bond/x64/Debug/ReportList.txt | 3
SourceCode/Bond/Servo/CReport.cpp | 6
13 files changed, 262 insertions(+), 15 deletions(-)
diff --git a/SourceCode/Bond/Servo/CPageReport.cpp b/SourceCode/Bond/Servo/CPageReport.cpp
index b537d06..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 瀵硅瘽妗�
@@ -152,7 +154,32 @@
void CPageReport::OnClickedBtn(const char* btnName)
{
ASSERT(btnName);
- if (_strcmpi(btnName, "鍒犻櫎") == 0) {
+ 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);
@@ -177,4 +204,34 @@
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("缂栬緫鎶ュ憡澶辫触锛堝彲鑳芥枃浠跺啓鍏ュけ璐ワ級"));
+ }
+ }
}
diff --git a/SourceCode/Bond/Servo/CReport.cpp b/SourceCode/Bond/Servo/CReport.cpp
index 1ab15fa..29d57d3 100644
--- a/SourceCode/Bond/Servo/CReport.cpp
+++ b/SourceCode/Bond/Servo/CReport.cpp
@@ -8,12 +8,10 @@
m_nReportId = 0;
}
- CReport::CReport(unsigned int reportId, std::vector<unsigned int>& vids)
+ CReport::CReport(unsigned int reportId, const std::vector<unsigned int>& vids)
{
m_nReportId = reportId;
- for (auto vid : vids) {
- m_vids.push_back(vid);
- }
+ m_vids = vids;
}
CReport::~CReport()
diff --git a/SourceCode/Bond/Servo/CReport.h b/SourceCode/Bond/Servo/CReport.h
index 8597a1e..41952df 100644
--- a/SourceCode/Bond/Servo/CReport.h
+++ b/SourceCode/Bond/Servo/CReport.h
@@ -7,7 +7,7 @@
{
public:
CReport();
- CReport(unsigned int reportId, std::vector<unsigned int>& vids);
+ CReport(unsigned int reportId, const std::vector<unsigned int>& vids);
virtual ~CReport();
public:
diff --git a/SourceCode/Bond/Servo/CReportEditDlg.cpp b/SourceCode/Bond/Servo/CReportEditDlg.cpp
new file mode 100644
index 0000000..5dd368b
--- /dev/null
+++ b/SourceCode/Bond/Servo/CReportEditDlg.cpp
@@ -0,0 +1,78 @@
+锘�#include "stdafx.h"
+#include "CReportEditDlg.h"
+#include "Servo.h"
+#include "resource.h"
+#include <algorithm>
+
+IMPLEMENT_DYNAMIC(CReportEditDlg, CDialogEx)
+
+CReportEditDlg::CReportEditDlg(const CString& title, int rptId, const std::vector<unsigned int>& vids, CWnd* pParent)
+ : CDialogEx(IDD_DIALOG_REPORT_EDIT, pParent)
+ , m_strTitle(title)
+ , m_rptId(rptId)
+ , m_vids(vids)
+{
+}
+
+CReportEditDlg::~CReportEditDlg()
+{
+}
+
+void CReportEditDlg::DoDataExchange(CDataExchange* pDX)
+{
+ CDialogEx::DoDataExchange(pDX);
+ DDX_Control(pDX, IDC_EDIT_RPT_ID, m_editId);
+ DDX_Control(pDX, IDC_LIST_RPT_VARS, m_listVars);
+}
+
+BEGIN_MESSAGE_MAP(CReportEditDlg, CDialogEx)
+END_MESSAGE_MAP()
+
+BOOL CReportEditDlg::OnInitDialog()
+{
+ CDialogEx::OnInitDialog();
+ SetWindowText(m_strTitle);
+
+ CString strId;
+ strId.Format(_T("%d"), m_rptId);
+ m_editId.SetWindowText(strId);
+ m_editId.SetReadOnly(TRUE);
+
+ // 鍒濆鍖栧垪琛�
+ m_listVars.SetExtendedStyle(m_listVars.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES);
+ m_listVars.InsertColumn(0, _T("ID"), LVCFMT_LEFT, 60);
+ m_listVars.InsertColumn(1, _T("鍚嶇О"), LVCFMT_LEFT, 140);
+ m_listVars.InsertColumn(2, _T("鏍煎紡"), LVCFMT_LEFT, 80);
+
+ auto& vars = theApp.m_model.m_hsmsPassive.getVariables();
+ for (int i = 0; i < (int)vars.size(); ++i) {
+ auto v = vars[i];
+ if (v == nullptr) continue;
+ int idx = m_listVars.InsertItem(m_listVars.GetItemCount(), std::to_string(v->getVarialbleId()).c_str());
+ m_listVars.SetItemText(idx, 1, v->getName().c_str());
+ m_listVars.SetItemText(idx, 2, SERVO::CVariable::formatToString(v->getFormat()).c_str());
+ m_listVars.SetItemData(idx, (DWORD_PTR)v->getVarialbleId());
+ if (std::find(m_vids.begin(), m_vids.end(), v->getVarialbleId()) != m_vids.end()) {
+ m_listVars.SetCheck(idx, TRUE);
+ }
+ }
+
+ return TRUE;
+}
+
+void CReportEditDlg::OnOK()
+{
+ std::vector<unsigned int> selected;
+ int count = m_listVars.GetItemCount();
+ for (int i = 0; i < count; ++i) {
+ if (m_listVars.GetCheck(i)) {
+ selected.push_back((unsigned int)m_listVars.GetItemData(i));
+ }
+ }
+ if (selected.empty()) {
+ AfxMessageBox(_T("鑷冲皯閫夋嫨涓�涓彉閲�"));
+ return;
+ }
+ m_vids.swap(selected);
+ CDialogEx::OnOK();
+}
diff --git a/SourceCode/Bond/Servo/CReportEditDlg.h b/SourceCode/Bond/Servo/CReportEditDlg.h
new file mode 100644
index 0000000..00fc4dc
--- /dev/null
+++ b/SourceCode/Bond/Servo/CReportEditDlg.h
@@ -0,0 +1,30 @@
+锘�#pragma once
+#include "afxdialogex.h"
+
+// 鎶ュ憡缂栬緫瀵硅瘽妗嗭紙鏂板/缂栬緫鍏辩敤锛�
+class CReportEditDlg : public CDialogEx
+{
+ DECLARE_DYNAMIC(CReportEditDlg)
+
+public:
+ CReportEditDlg(const CString& title, int rptId, const std::vector<unsigned int>& vids, CWnd* pParent = nullptr);
+ virtual ~CReportEditDlg();
+
+ int GetReportId() const { return m_rptId; }
+ const std::vector<unsigned int>& GetSelectedVids() const { return m_vids; }
+
+protected:
+ virtual BOOL OnInitDialog() override;
+ virtual void DoDataExchange(CDataExchange* pDX) override;
+ afx_msg void OnOK();
+
+ DECLARE_MESSAGE_MAP()
+
+private:
+ CString m_strTitle;
+ int m_rptId;
+ std::vector<unsigned int> m_vids;
+
+ CEdit m_editId;
+ CListCtrl m_listVars;
+};
diff --git a/SourceCode/Bond/Servo/CUserManager2.cpp b/SourceCode/Bond/Servo/CUserManager2.cpp
index 334333c..c0daf4e 100644
--- a/SourceCode/Bond/Servo/CUserManager2.cpp
+++ b/SourceCode/Bond/Servo/CUserManager2.cpp
@@ -77,7 +77,16 @@
UX_DefineAction(L"delVarialbles", L"鍒犻櫎鍙橀噺", L"PE");
UX_DefineAction(L"addVarialbles", L"鏂板鍙橀噺", L"PE");
UX_DefineAction(L"editVarialbles", L"缂栬緫鍙橀噺", L"PE");
+ 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"addVarialbles", L"鏂板鍙橀噺", L"PE");
+ UX_DefineAction(L"editVarialbles", L"缂栬緫鍙橀噺", L"PE");
+ UX_DefineAction(L"delVarialbles", L"鍒犻櫎鍙橀噺", L"PE");
+ UX_DefineAction(L"addReports", L"鏂板Report", L"PE");
+ UX_DefineAction(L"editReports", L"缂栬緫Report", L"PE");
UX_DefineAction(L"delReports", L"鍒犻櫎Report", L"PE");
}
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index 722eacd..3b0455c 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -734,6 +734,17 @@
return m_reports;
}
+unsigned int CHsmsPassive::getMaxReportId() const
+{
+ unsigned int maxId = 0;
+ for (auto item : m_reports) {
+ if (item && item->getReportId() > maxId) {
+ maxId = item->getReportId();
+ }
+ }
+ return maxId;
+}
+
SERVO::CReport* CHsmsPassive::getReport(int rptid)
{
for (auto item : m_reports) {
@@ -766,6 +777,41 @@
return writeReportsToFile(m_strReportFilepath);
}
+int CHsmsPassive::addReport(int rptid, const std::vector<unsigned int>& vids)
+{
+ if (getReport(rptid) != nullptr) {
+ return -1;
+ }
+ SERVO::CReport* pReport = new SERVO::CReport(rptid, vids);
+ for (auto vid : vids) {
+ SERVO::CVariable* pVariable = getVariable((int)vid);
+ if (pVariable != nullptr) {
+ pReport->addVariable(pVariable);
+ }
+ }
+ m_reports.push_back(pReport);
+ return writeReportsToFile(m_strReportFilepath);
+}
+
+int CHsmsPassive::updateReport(int rptid, const std::vector<unsigned int>& vids)
+{
+ for (auto iter = m_reports.begin(); iter != m_reports.end(); ++iter) {
+ if ((*iter)->getReportId() == rptid) {
+ delete (*iter);
+ SERVO::CReport* pReport = new SERVO::CReport(rptid, vids);
+ for (auto vid : vids) {
+ SERVO::CVariable* pVariable = getVariable((int)vid);
+ if (pVariable != nullptr) {
+ pReport->addVariable(pVariable);
+ }
+ }
+ *iter = pReport;
+ return writeReportsToFile(m_strReportFilepath);
+ }
+ }
+ return -1;
+}
+
void CHsmsPassive::clearAllReport()
{
for (auto item : m_reports) {
diff --git a/SourceCode/Bond/Servo/HsmsPassive.h b/SourceCode/Bond/Servo/HsmsPassive.h
index aeb5bde..91b03a4 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.h
+++ b/SourceCode/Bond/Servo/HsmsPassive.h
@@ -135,6 +135,9 @@
// 鍙栨秷 define report
bool removeReport(int rptid);
+ int deleteReport(int rptid);
+ int addReport(int rptid, const std::vector<unsigned int>& vids);
+ int updateReport(int rptid, const std::vector<unsigned int>& vids);
void clearAllReport();
// 浠庢枃浠朵腑鍔犺浇CVariable鍒楄〃
@@ -161,6 +164,7 @@
// 鍙栧緱Report鍒楄〃
std::vector<SERVO::CReport*>& getReports();
+ unsigned int getMaxReportId() const;
// 浠庢枃浠朵腑鍔犺浇CCollectionEvent鍒楄〃
int loadCollectionEvents(const char* pszFilepath);
@@ -176,7 +180,6 @@
// 鍙栧緱Report
SERVO::CReport* getReport(int rptid);
- int deleteReport(int rptid);
void setListener(SECSListener listener);
unsigned OnCimWork();
diff --git a/SourceCode/Bond/Servo/Servo.rc b/SourceCode/Bond/Servo/Servo.rc
index 9d021e9..ac0144e 100644
--- a/SourceCode/Bond/Servo/Servo.rc
+++ b/SourceCode/Bond/Servo/Servo.rc
@@ -542,8 +542,18 @@
PUSHBUTTON "取消",IDCANCEL,130,140,50,14
END
-
-
+IDD_DIALOG_REPORT_EDIT DIALOGEX 0, 0, 320, 240
+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_RPT_ID,70,10,170,14,ES_AUTOHSCROLL | ES_READONLY
+ LTEXT "选择变量:",IDC_STATIC_SELECT_VARS,12,32,60,8
+ CONTROL "",IDC_LIST_RPT_VARS,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP,12,42,296,150
+ DEFPUSHBUTTON "确定",IDOK,170,200,50,14
+ PUSHBUTTON "取消",IDCANCEL,230,200,50,14
+END
IDD_PAGE_LINK_SIGNAL DIALOGEX 0, 0, 543, 239
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj b/SourceCode/Bond/Servo/Servo.vcxproj
index 617b69d..3312b3b 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj
+++ b/SourceCode/Bond/Servo/Servo.vcxproj
@@ -248,6 +248,7 @@
<ClInclude Include="CCjPage1.h" />
<ClInclude Include="CProcessDataListDlg.h" />
<ClInclude Include="CReport.h" />
+ <ClInclude Include="CReportEditDlg.h" />
<ClInclude Include="CRobotCmdContainerDlg.h" />
<ClInclude Include="CRobotCmdTestDlg.h" />
<ClInclude Include="CPagePortStatus.h" />
@@ -467,6 +468,7 @@
<ClCompile Include="CCjPage1.cpp" />
<ClCompile Include="CProcessDataListDlg.cpp" />
<ClCompile Include="CReport.cpp" />
+ <ClCompile Include="CReportEditDlg.cpp" />
<ClCompile Include="CRobotCmdContainerDlg.cpp" />
<ClCompile Include="CRobotCmdTestDlg.cpp" />
<ClCompile Include="CPagePortStatus.cpp" />
@@ -653,4 +655,4 @@
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2903.40\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2903.40\build\native\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
</Target>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj.filters b/SourceCode/Bond/Servo/Servo.vcxproj.filters
index 27e614c..9362a64 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj.filters
+++ b/SourceCode/Bond/Servo/Servo.vcxproj.filters
@@ -172,6 +172,9 @@
<ClCompile Include="CCustomCheckBox.cpp" />
<ClCompile Include="CCollectionEvent.cpp" />
<ClCompile Include="CReport.cpp" />
+ <ClCompile Include="CReportEditDlg.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="CVariable.cpp" />
<ClCompile Include="CPageVarialbles.cpp" />
<ClCompile Include="CPageReport.cpp" />
@@ -411,6 +414,9 @@
<ClInclude Include="CCustomCheckBox.h" />
<ClInclude Include="CCollectionEvent.h" />
<ClInclude Include="CReport.h" />
+ <ClInclude Include="CReportEditDlg.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="CVariable.h" />
<ClInclude Include="CPageVarialbles.h" />
<ClInclude Include="CPageReport.h" />
@@ -554,4 +560,4 @@
<UniqueIdentifier>{885738f6-3122-4bb9-8308-46b7f692fb13}</UniqueIdentifier>
</Filter>
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/SourceCode/Bond/Servo/resource.h b/SourceCode/Bond/Servo/resource.h
index f545c6f..9d23997 100644
--- a/SourceCode/Bond/Servo/resource.h
+++ b/SourceCode/Bond/Servo/resource.h
@@ -45,6 +45,7 @@
#define IDD_DIALOG_LOGIN 163
#define IDD_DIALOG_INPUT 164
#define IDD_DIALOG_VARIABLE_EDIT2 186
+#define IDD_DIALOG_REPORT_EDIT 187
#define IDD_PAGE_LINK_SIGNAL 165
#define IDD_DIALOG_SYSTEM_LOG_MANAGER 166
#define IDD_DIALOG_RECIPE_DEVICE_BIND 167
@@ -308,6 +309,14 @@
#define IDC_EDIT_USER_PASSWORD 1232
#define IDC_COMBO_USER_ROLE 1233
#define IDC_CHECK_USER_ENABLED 1234
+#define IDC_LIST_RPT_VARS 1241
+#define IDC_STATIC_SELECT_VARS 1242
+#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 IDC_EDIT_RPT_ID 1239
+#define IDC_EDIT_RPT_VIDS 1240
#define IDC_EDIT_VAR_ID 1235
#define IDC_COMBO_VAR_TYPE 1236
#define IDC_EDIT_VAR_NAME 1237
@@ -347,9 +356,9 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 187
+#define _APS_NEXT_RESOURCE_VALUE 188
#define _APS_NEXT_COMMAND_VALUE 32802
-#define _APS_NEXT_CONTROL_VALUE 1239
+#define _APS_NEXT_CONTROL_VALUE 1243
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/SourceCode/Bond/x64/Debug/ReportList.txt b/SourceCode/Bond/x64/Debug/ReportList.txt
index ceadc9c..803c147 100644
--- a/SourceCode/Bond/x64/Debug/ReportList.txt
+++ b/SourceCode/Bond/x64/Debug/ReportList.txt
@@ -26,5 +26,4 @@
50008,(5010)
50009,(5011)
50010,(5012)
-
-
+50011,(5013)
--
Gitblit v1.9.3