chenluhua1980
2025-12-11 aadeadede11fabacebc5378ac0548794f5f49a74
1.实现报告的增加和删除;
已添加2个文件
已修改11个文件
277 ■■■■■ 文件已修改
SourceCode/Bond/Servo/CPageReport.cpp 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CReport.cpp 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CReport.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CReportEditDlg.cpp 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CReportEditDlg.h 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CUserManager2.cpp 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/HsmsPassive.cpp 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/HsmsPassive.h 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.rc 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.vcxproj 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.vcxproj.filters 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/resource.h 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/x64/Debug/ReportList.txt 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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("新增报告失败(可能ID重复或文件写入失败)"));
        }
    }
    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("编辑报告失败(可能文件写入失败)"));
        }
    }
}
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()
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:
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();
}
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;
};
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");
}
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) {
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();
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
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>
</Project>
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>
</Project>
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
SourceCode/Bond/x64/Debug/ReportList.txt
@@ -26,5 +26,4 @@
50008,(5010)
50009,(5011)
50010,(5012)
50011,(5013)