chenluhua1980
2025-12-11 5e9b9b53a8a853365c29149871bd024c9ca0cbac
1.报告的删除功能;
已修改6个文件
105 ■■■■■ 文件已修改
SourceCode/Bond/Servo/CPageReport.cpp 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CPageReport.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CReport.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CUserManager2.cpp 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/HsmsPassive.cpp 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/HsmsPassive.h 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CPageReport.cpp
@@ -148,3 +148,33 @@
    *pResult = 0;
}
void CPageReport::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 pRpt = reinterpret_cast<SERVO::CReport*>(m_listCtrl.GetItemData(nItem));
        if (pRpt == nullptr) return;
        int rc = UX_CanExecute(L"delReports");
        if (rc != 1) {
            AfxMessageBox("操作权限不足,请联系管理人员!");
            return;
        }
        int ret = theApp.m_model.m_hsmsPassive.deleteReport((int)pRpt->getReportId());
        if (ret == 0) {
            UX_RecordAction(L"delReports");
            m_listCtrl.DeleteAllItems();
            loadReports();
            if (CButton* pDel = GetBtnByName("删除")) pDel->EnableWindow(FALSE);
            if (CButton* pEdit = GetBtnByName("编辑")) pEdit->EnableWindow(FALSE);
        }
        else {
            AfxMessageBox(_T("删除报告失败"));
        }
    }
}
SourceCode/Bond/Servo/CPageReport.h
@@ -17,6 +17,7 @@
private:
    CListCtrlEx m_listCtrl;
    void OnCreateBtns() override;
    void OnClickedBtn(const char* btnName) override;
// 对话框数据
#ifdef AFX_DESIGN_TIME
SourceCode/Bond/Servo/CReport.h
@@ -18,6 +18,7 @@
        std::vector<CVariable*>& getVariables();
        std::string getVariablesIdsText();
        bool getVariableName(unsigned int vid, std::string& strName);
        const std::vector<unsigned int>& getVids() const { return m_vids; }
    private:
        unsigned int m_nReportId;
SourceCode/Bond/Servo/CUserManager2.cpp
@@ -78,6 +78,7 @@
        UX_DefineAction(L"addVarialbles", L"新增变量", L"PE");
        UX_DefineAction(L"editVarialbles", L"编辑变量", L"PE");
    }
    UX_DefineAction(L"delReports", L"删除Report", L"PE");
}
bool CUserManager2::login(const char* pszAccount, const char* pszPwd)
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;
SourceCode/Bond/Servo/HsmsPassive.h
@@ -176,6 +176,7 @@
    // 取得Report
    SERVO::CReport* getReport(int rptid);
    int deleteReport(int rptid);
    void setListener(SECSListener listener);
    unsigned OnCimWork();
@@ -239,6 +240,7 @@
    void clearAllVariabel();
    std::vector<unsigned int> parseVidList(CString& strNums);
    int writeVariablesToFile(const std::string& filepath);
    int writeReportsToFile(const std::string& filepath);
private:
    CModel* m_pModel;
@@ -259,6 +261,9 @@
    std::string m_strVariableFilepath;
    bool m_bVariableUtf8{ false };
    bool m_bVariableUtf8Bom{ false };
    std::string m_strReportFilepath;
    bool m_bReportUtf8{ false };
    bool m_bReportUtf8Bom{ false };
    BOOL m_bCimWorking;
    HANDLE m_hCimWorkEvent;
    HANDLE m_hCimWorkThreadHandle;