LAPTOP-SNT8I5JK\Boounion
2025-05-10 709e6278abe167a6ff96a7f9814651a7812f142c
1.合并刘洋的修改,主要是将警告和日志窗口上移,方便查看和调试。
已添加4个文件
已修改16个文件
1970 ■■■■ 文件已修改
SourceCode/Bond/Servo/AlarmDlg.cpp 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/AlarmDlg.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CPageGraph1.cpp 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CPageGraph1.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CPageGraph2.cpp 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/LogDlg.cpp 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/LogDlg.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/ProductionLogDlg.cpp 466 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/ProductionLogDlg.h 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/ProductionLogManager.cpp 407 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/ProductionLogManager.h 113 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/SECSRuntimeManager.cpp 520 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/SECSRuntimeManager.h 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.cpp 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.rc 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.vcxproj 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.vcxproj.filters 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/ServoDlg.cpp 217 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/ServoDlg.h 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/TerminalDisplayDlg.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/AlarmDlg.cpp
@@ -115,7 +115,6 @@
    GetDlgItem(IDC_BUTTON_NEXT_PAGE)->EnableWindow(m_nCurPage < m_nTotalPages);
}
static char* pszAlarmLevel[] = {"Warning", "Error"};
void CAlarmDlg::FillDataToListCtrl(CListCtrl* pListCtrl, const std::vector<AlarmData>& vecData)
{
    if (pListCtrl == nullptr || pListCtrl->m_hWnd == nullptr) {
@@ -127,17 +126,7 @@
    // éåŽ†æ•°æ®å¹¶æ’å…¥åˆ°CListCtrl中
    for (const auto& alarm : vecData) {
        int nItem = pListCtrl->InsertItem(pListCtrl->GetItemCount(), _T(""));    // æ’入新行
        CString str;
        // è®¾ç½®åˆ—内容
        str.Format(_T("%d"), alarm.nId);
        pListCtrl->SetItemText(nItem, 1, str);                                          // æŠ¥è­¦ID
        pListCtrl->SetItemText(nItem, 2, pszAlarmLevel[alarm.nSeverityLevel % 2]);                                          // ç­‰çº§
        pListCtrl->SetItemText(nItem, 3, alarm.strDeviceName.c_str());                // è®¾å¤‡åç§°
        pListCtrl->SetItemText(nItem, 4, alarm.strUnitName.c_str());                  // å•元名称
        pListCtrl->SetItemText(nItem, 5, alarm.strStartTime.c_str());                 // å¼€å§‹æ—¶é—´
        pListCtrl->SetItemText(nItem, 6, alarm.strEndTime.c_str());                   // ç»“束时间
        pListCtrl->SetItemText(nItem, 7, alarm.strDescription.c_str());               // æè¿°
        InsertAlarmData(pListCtrl, alarm);
    }
    // èŽ·å–åˆ—æ•°
@@ -145,6 +134,7 @@
    pListCtrl->SetColumnWidth(nColCount - 1, LVSCW_AUTOSIZE_USEHEADER);
}
static char* pszAlarmLevel[] = { "Warning", "Error" };
void CAlarmDlg::InsertAlarmData(CListCtrl* pListCtrl, const AlarmData& alarmData)
{
    if (pListCtrl == nullptr || pListCtrl->m_hWnd == nullptr) {
@@ -162,7 +152,7 @@
    CString str;
    str.Format(_T("%d"), alarmData.nId);
    pListCtrl->SetItemText(nNewItem, 1, str);                                            // æŠ¥è­¦ID
    pListCtrl->SetItemText(nNewItem, 2, pszAlarmLevel[alarmData.nSeverityLevel % 2]);                                            // ç­‰çº§
    pListCtrl->SetItemText(nNewItem, 2, pszAlarmLevel[alarmData.nSeverityLevel % 2]);    // ç­‰çº§
    pListCtrl->SetItemText(nNewItem, 3, alarmData.strDeviceName.c_str());               // è®¾å¤‡åç§°
    pListCtrl->SetItemText(nNewItem, 4, alarmData.strUnitName.c_str());                 // å•元名称
    pListCtrl->SetItemText(nNewItem, 5, alarmData.strStartTime.c_str());                // å¼€å§‹æ—¶é—´
@@ -197,6 +187,7 @@
    ON_WM_DESTROY()
    ON_WM_CLOSE()
    ON_WM_SIZE()
    ON_WM_TIMER()
    ON_CBN_SELCHANGE(IDC_COMBO_DATETIME, &CAlarmDlg::OnCbnSelchangeComboDatetime)
    ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CAlarmDlg::OnBnClickedButtonSearch)
    ON_BN_CLICKED(IDC_BUTTON_EXPORT, &CAlarmDlg::OnBnClickedButtonExport)
@@ -209,7 +200,7 @@
BOOL CAlarmDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    InitRxWindow();
    SetTimer(1, 3000, nullptr);
    // ä¸‹æ‹‰æ¡†æŽ§ä»¶
    CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DATETIME);
@@ -254,7 +245,6 @@
    pListCtrl->InsertColumn(6, _T("解除时间"), LVCFMT_LEFT, width[6]);
    pListCtrl->InsertColumn(7, _T("描述"), LVCFMT_LEFT, width[7]);
    pListCtrl->SetColumnWidth(7, LVSCW_AUTOSIZE_USEHEADER);
    // è®¡ç®—总页数
@@ -325,6 +315,14 @@
    Resize();
}
void CAlarmDlg::OnTimer(UINT_PTR nIDEvent)
{
    if (1 == nIDEvent) {
        KillTimer(1);
        InitRxWindow();
    }
}
void CAlarmDlg::OnCbnSelchangeComboDatetime()
{
    CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DATETIME);
SourceCode/Bond/Servo/AlarmDlg.h
@@ -63,6 +63,7 @@
    afx_msg void OnDestroy();
    afx_msg void OnClose();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnCbnSelchangeComboDatetime();
    afx_msg void OnBnClickedButtonSearch();
    afx_msg void OnBnClickedButtonExport();
SourceCode/Bond/Servo/CPageGraph1.cpp
@@ -393,15 +393,44 @@
    Invalidate();
}
void CPageGraph1::BindEquipmentToGraph()
{
    struct EquipmentBindInfo
    {
        int nEquipmentID;
        int nIndicateID;
    };
    static const EquipmentBindInfo EQUIPMENT_BIND_LIST[] = {
        { EQ_ID_EFEM,           INDICATE_ROBOT_ARM1 },
        { EQ_ID_EFEM,           INDICATE_ROBOT_ARM2 },
        { EQ_ID_Bonder1,        INDICATE_BONDER1 },
        { EQ_ID_Bonder2,        INDICATE_BONDER2 },
        { EQ_ID_LOADPORT1,      INDICATE_LPORT1 },
        { EQ_ID_LOADPORT2,      INDICATE_LPORT2 },
        { EQ_ID_LOADPORT3,      INDICATE_LPORT3 },
        { EQ_ID_LOADPORT4,      INDICATE_LPORT4 },
        { EQ_ID_FLIPER,         INDICATE_FLIPER },
        { EQ_ID_VACUUMBAKE,     INDICATE_VACUUM_BAKE },
        { EQ_ID_ALIGNER,        INDICATE_ALIGNER },
        { EQ_ID_BAKE_COOLING,   INDICATE_BAKE_COOLING }
    };
    for (const auto& stBindInfo : EQUIPMENT_BIND_LIST)
    {
        SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(stBindInfo.nEquipmentID);
        m_pGraph->SetIndicateBoxData(stBindInfo.nIndicateID, pEquipment);
    }
}
void CPageGraph1::OnGraphItemClicked(NMHDR* pNMHDR, LRESULT* pResult)
{
    BYSERVOGRAPH_NMHDR* pGraphNmhdr = reinterpret_cast<BYSERVOGRAPH_NMHDR*>(pNMHDR);
    CString s; s.Format(_T("OnGraphItemClicked %d"), pGraphNmhdr->dwData);
    SERVO::CEquipment* pEquipment = (SERVO::CEquipment*)m_pGraph->GetIndicateBoxData(pGraphNmhdr->dwData);
    if (pEquipment != nullptr) {
        AfxMessageBox(pEquipment->getName().c_str());
        theApp.m_model.notifyPtr(RX_CODE_SELECT_EQUIPMENT, pEquipment);
    }
    *pResult = 0;
}
SourceCode/Bond/Servo/CPageGraph1.h
@@ -24,6 +24,7 @@
    void UpdateDeviceStatus(int id, DeviceStatus status);
    void UpdateRobotPosition(float percentage);
    void RotateRobot(float angleInDegrees);
    void BindEquipmentToGraph();
private:
    IObserver* m_pObserver;
SourceCode/Bond/Servo/CPageGraph2.cpp
@@ -404,6 +404,9 @@
    std::list<SERVO::CEquipment*>& eqs = theApp.m_model.m_master.getEquipmentList();
    for (auto item : eqs) {
        EQITEM* pEqItem = m_pEqsGraphWnd->GetItem((DWORD_PTR)item);
        if (nullptr == pEqItem) {
            continue;
        }
        strValue.Format(_T("%d"), pEqItem->rect.left);
        WritePrivateProfileString(item->getName().c_str(), _T("Left"),
SourceCode/Bond/Servo/LogDlg.cpp
@@ -40,6 +40,7 @@
BEGIN_MESSAGE_MAP(CLogDlg, CDialogEx)
    ON_WM_CTLCOLOR()
    ON_WM_SIZE()
    ON_WM_TIMER()
    ON_WM_DESTROY()
    ON_WM_CLOSE()
    ON_NOTIFY(BLBUTTON_MENU_ITEM_CLICKED, IDC_BUTTON_LEVEL, &CLogDlg::OnButtonLevelMenuClicked)
@@ -105,6 +106,7 @@
BOOL CLogDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    SetTimer(1, 3000, nullptr);
    // ç¼“å­˜
@@ -158,7 +160,6 @@
    m_logEdit.SetLimitText(-1);
    InitRxWindow();
    Resize();
@@ -173,6 +174,14 @@
    Resize();
}
void CLogDlg::OnTimer(UINT_PTR nIDEvent)
{
    if (1 == nIDEvent) {
        KillTimer(1);
        InitRxWindow();
    }
}
void CLogDlg::Resize()
{
    int x, y, y2, temp;
@@ -180,7 +189,7 @@
    CWnd* pItem;
    GetClientRect(&rcClient);
    y = 0;
    y = 12;
    x = 8;
    pItem = GetDlgItem(IDC_BUTTON_LEVEL);
    pItem->GetWindowRect(&rcItem);
SourceCode/Bond/Servo/LogDlg.h
@@ -51,6 +51,7 @@
public:
    virtual BOOL OnInitDialog();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnDestroy();
    afx_msg void OnClose();
    afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
SourceCode/Bond/Servo/ProductionLogDlg.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,466 @@
// ProductionLogDlg.cpp: å®žçŽ°æ–‡ä»¶
//
#include "stdafx.h"
#include "Servo.h"
#include "afxdialogex.h"
#include "ProductionLogDlg.h"
#include "Common.h"
#include <iomanip>
#define PAGE_SIZE                        100
#define PAGE_BACKGROUND_COLOR            RGB(252, 252, 255)
// CProductionLogDlg å¯¹è¯æ¡†
//IMPLEMENT_DYNAMIC(CProductionLogDlg, CDialogEx)
//
//CProductionLogDlg::CProductionLogDlg(CWnd* pParent /*=nullptr*/)
//    : CDialogEx(IDD_DIALOG_PRODUCTION_LOG, pParent)
//{
//    m_crBkgnd = PAGE_BACKGROUND_COLOR;
//    m_hbrBkgnd = nullptr;
//    m_pObserver = nullptr;
//
//    m_strKeyword = "";
//    m_strProductId = "";
//    m_strBatchNo = "";
//    m_strDeviceId = "";
//    m_strOperatorName = "";
//    m_strStatus = "";
//
//    m_nCurPage = 0;
//    m_nTotalPages = 0;
//    m_nDateTimeFlag = 0;
//
//    memset(m_szTimeStart, 0, sizeof(m_szTimeStart));
//    memset(m_szTimeEnd, 0, sizeof(m_szTimeEnd));
//    m_szTimeStart[0] = '\0';
//    m_szTimeEnd[0] = '\0';
//}
//CProductionLogDlg::~CProductionLogDlg()
//{
//}
//
//void CProductionLogDlg::InitRxWindow()
//{
//    /* code */
//    // è®¢é˜…数据
//    IRxWindows* pRxWindows = RX_GetRxWindows();
//    pRxWindows->enableLog(5);
//    if (m_pObserver == NULL) {
//        m_pObserver = pRxWindows->allocObserver([&](IAny* pAny) -> void {
//            // onNext
//            pAny->addRef();
//            int code = pAny->getCode();
//
//            //if (RX_CODE_ALARM_SET == code) {
//            //}
//
//        pAny->release();
//        }, [&]() -> void {
//        // onComplete
//        }, [&](IThrowable* pThrowable) -> void {
//        // onErrorm
//        pThrowable->printf();
//        });
//
//        theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread())->subscribe(m_pObserver);
//    }
//}
/*
void CProductionLogDlg::Resize()
{
    CRect rcClient;
    GetClientRect(&rcClient);
    m_listCtrl.MoveWindow(12, 58, rcClient.Width() - 24, rcClient.Height() - 64);
}
void CProductionLogDlg::UpdatePageData()
{
    // æ ¹æ®è¿‡æ»¤æ¡ä»¶åŠ è½½æ•°æ®ï¼ˆæ”¯æŒåˆ†é¡µã€æ¨¡ç³ŠæŸ¥è¯¢ã€æ—¶é—´èŒƒå›´ï¼‰
    auto vecData = ProductionLogManager::getInstance().getFilteredSteps(
        m_strProductId,         // äº§å“ID
        m_strBatchNo,           // æ‰¹æ¬¡å·
        m_strDeviceId,          // è®¾å¤‡ID
        m_strOperatorName,      // æ“ä½œå‘˜
        m_strStatus,            // çŠ¶æ€
        m_szTimeStart,          // èµ·å§‹æ—¶é—´
        m_szTimeEnd,            // ç»“束时间
        m_nCurPage,             // å½“前页码
        PAGE_SIZE               // æ¯é¡µæ¡æ•°
    );
    // å¡«å……数据到列表控件
    FillDataToListCtrl(&m_listCtrl, vecData);
    // æ›´æ–°åˆ†é¡µæŽ§ä»¶
    UpdatePageControls();
}
void CProductionLogDlg::UpdatePageControls()
{
    // æ›´æ–°åˆ†é¡µä¿¡æ¯
    CString strPage;
    strPage.Format(_T("第 %d é¡µ"), m_nCurPage);
    SetDlgItemText(IDC_LABEL_PAGE_NUMBER, strPage);
    // å¯ç”¨/禁用翻页按钮
    GetDlgItem(IDC_BUTTON_PREV_PAGE)->EnableWindow(m_nCurPage > 1);
    GetDlgItem(IDC_BUTTON_NEXT_PAGE)->EnableWindow(m_nCurPage < m_nTotalPages);
}
void CProductionLogDlg::FillDataToListCtrl(CListCtrl* pListCtrl, const std::vector<ProductionStep>& vecSteps)
{
    if (pListCtrl == nullptr || pListCtrl->m_hWnd == nullptr) {
        return;
    }
    // æ¸…空当前CListCtrl中的所有项
    pListCtrl->DeleteAllItems();
    // éåŽ†æ•°æ®å¹¶æ’å…¥åˆ°CListCtrl中
    for (const auto& step : vecSteps) {
        InsertStepData(pListCtrl, step);
    }
    // èŽ·å–åˆ—æ•°
    int nColCount = pListCtrl->GetHeaderCtrl()->GetItemCount();
    pListCtrl->SetColumnWidth(nColCount - 1, LVSCW_AUTOSIZE_USEHEADER);
}
void CProductionLogDlg::InsertStepData(CListCtrl* pListCtrl, const ProductionStep& step)
{
    if (pListCtrl == nullptr || pListCtrl->m_hWnd == nullptr) {
        return;
    }
    int nRowCount = pListCtrl->GetItemCount();
    if (nRowCount >= PAGE_SIZE) {
        pListCtrl->DeleteItem(nRowCount - 1);
    }
    CString str;
    int nNewItem = pListCtrl->InsertItem(0, _T(""));
    str.Format(_T("%d"), step.nStepId);          pListCtrl->SetItemText(nNewItem, 1, str);
    pListCtrl->SetItemText(nNewItem, 2, step.strProductId.c_str());
    pListCtrl->SetItemText(nNewItem, 3, step.strBatchNo.c_str());
    str.Format(_T("%d"), step.nDeviceId);     pListCtrl->SetItemText(nNewItem, 4, str);
    pListCtrl->SetItemText(nNewItem, 5, step.strOperator.c_str());
    pListCtrl->SetItemText(nNewItem, 6, step.strStartTime.c_str());
    pListCtrl->SetItemText(nNewItem, 7, step.strEndTime.c_str());
    str.Format(_T("%d"), step.nYield);        pListCtrl->SetItemText(nNewItem, 8, str);
    str.Format(_T("%d"), step.nGoodCount);    pListCtrl->SetItemText(nNewItem, 9, str);
    str.Format(_T("%d"), step.nBadCount);     pListCtrl->SetItemText(nNewItem, 10, str);
    pListCtrl->SetItemText(nNewItem, 11, step.strStatus.c_str());
}
std::string CProductionLogDlg::getCurrentTimeString()
{
    auto now = std::chrono::system_clock::now();
    auto time_t_now = std::chrono::system_clock::to_time_t(now);
    std::tm tm_now = {};
    localtime_s(&tm_now, &time_t_now);
    std::stringstream ss;
    ss << std::put_time(&tm_now, "%Y-%m-%d %H:%M:%S");
    return ss.str();
}
void CProductionLogDlg::DoDataExchange(CDataExchange* pDX)
{
    DDX_Control(pDX, IDC_DATETIMEPICKER_START, m_dateTimeStart);
    DDX_Control(pDX, IDC_DATETIMEPICKER_END, m_dateTimeEnd);
    DDX_Control(pDX, IDC_LIST_PRODUCTION_LOG, m_listCtrl);
    CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CProductionLogDlg, CDialogEx)
    ON_WM_CTLCOLOR()
    ON_WM_DESTROY()
    ON_WM_CLOSE()
    ON_WM_SIZE()
    ON_CBN_SELCHANGE(IDC_COMBO_DATETIME, &CProductionLogDlg::OnCbnSelchangeComboDatetime)
    ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CProductionLogDlg::OnBnClickedButtonSearch)
    ON_BN_CLICKED(IDC_BUTTON_EXPORT, &CProductionLogDlg::OnBnClickedButtonExport)
    ON_BN_CLICKED(IDC_BUTTON_PREV_PAGE, &CProductionLogDlg::OnBnClickedButtonPrevPage)
    ON_BN_CLICKED(IDC_BUTTON_NEXT_PAGE, &CProductionLogDlg::OnBnClickedButtonNextPage)
END_MESSAGE_MAP()
// CProductionLogDlg æ¶ˆæ¯å¤„理程序
BOOL CProductionLogDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    InitRxWindow();
    // åˆå§‹åŒ–时间范围选择
    CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DATETIME);
    pComboBox->AddString(_T("不限"));
    pComboBox->AddString(_T("今天"));
    pComboBox->AddString(_T("七天内"));
    pComboBox->AddString(_T("本月"));
    pComboBox->AddString(_T("今年"));
    pComboBox->AddString(_T("自定义"));
    pComboBox->SetCurSel(0);
    m_dateTimeStart.EnableWindow(FALSE);
    m_dateTimeEnd.EnableWindow(FALSE);
    // è¯»å–列宽配置
    CString strIniFile, strItem;
    strIniFile.Format(_T("%s\\configuration.ini"), (LPCTSTR)theApp.m_strAppDir);
    int width[12] = { 0, 60, 100, 100, 70, 100, 140, 140, 60, 60, 60, 80 };
    for (int i = 0; i < 12; ++i) {
        strItem.Format(_T("Col_%d_Width"), i);
        width[i] = GetPrivateProfileInt("ProductionListCtrl", strItem, width[i], strIniFile);
    }
    // åˆå§‹åŒ–列表控件
    CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_PRODUCTION_LOG);
    DWORD dwStyle = pListCtrl->GetExtendedStyle();
    dwStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
    pListCtrl->SetExtendedStyle(dwStyle);
    HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
    ListView_SetImageList(pListCtrl->GetSafeHwnd(), imageList, LVSIL_SMALL);
    pListCtrl->InsertColumn(0, _T(""), LVCFMT_RIGHT, width[0]);
    pListCtrl->InsertColumn(1, _T("步骤ID"), LVCFMT_LEFT, width[1]);
    pListCtrl->InsertColumn(2, _T("产品ID"), LVCFMT_LEFT, width[2]);
    pListCtrl->InsertColumn(3, _T("批次号"), LVCFMT_LEFT, width[3]);
    pListCtrl->InsertColumn(4, _T("设备ID"), LVCFMT_LEFT, width[4]);
    pListCtrl->InsertColumn(5, _T("操作员"), LVCFMT_LEFT, width[5]);
    pListCtrl->InsertColumn(6, _T("开始时间"), LVCFMT_LEFT, width[6]);
    pListCtrl->InsertColumn(7, _T("结束时间"), LVCFMT_LEFT, width[7]);
    pListCtrl->InsertColumn(8, _T("产量"), LVCFMT_LEFT, width[8]);
    pListCtrl->InsertColumn(9, _T("良品数"), LVCFMT_LEFT, width[9]);
    pListCtrl->InsertColumn(10, _T("不良品数"), LVCFMT_LEFT, width[10]);
    pListCtrl->InsertColumn(11, _T("状态"), LVCFMT_LEFT, width[11]);
    // åˆå§‹åŒ–分页数据
    int totalRecords = ProductionLogManager::getInstance().getTotalStepCount(
        m_strProductId, m_strBatchNo, m_strDeviceId, m_strOperatorName,
        m_strStatus, m_szTimeStart, m_szTimeEnd);
    m_nTotalPages = (totalRecords + PAGE_SIZE - 1) / PAGE_SIZE;
    m_nCurPage = 1;
    Resize();
    UpdatePageData();
    return TRUE;  // return TRUE unless you set the focus to a control
    // å¼‚常: OCX å±žæ€§é¡µåº”返回 FALSE
}
HBRUSH CProductionLogDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
    if (nCtlColor == CTLCOLOR_STATIC) {
        pDC->SetBkColor(m_crBkgnd);
    }
    if (m_hbrBkgnd == nullptr) {
        m_hbrBkgnd = CreateSolidBrush(m_crBkgnd);
    }
    return m_hbrBkgnd;
}
void CProductionLogDlg::OnDestroy()
{
    CDialogEx::OnDestroy();
    // ä¿å­˜åˆ—宽
    CString strIniFile, strItem, strTemp;
    strIniFile.Format(_T("%s\\configuration.ini"), (LPCTSTR)theApp.m_strAppDir);
    CHeaderCtrl* pHeader = m_listCtrl.GetHeaderCtrl();
    for (int i = 0; i < pHeader->GetItemCount(); ++i) {
        RECT rect;
        pHeader->GetItemRect(i, &rect);
        strItem.Format(_T("Col_%d_Width"), i);
        strTemp.Format(_T("%d"), rect.right - rect.left);
        WritePrivateProfileString("ProductionListCtrl", strItem, strTemp, strIniFile);
    }
    if (m_hbrBkgnd != nullptr) {
        ::DeleteObject(m_hbrBkgnd);
    }
    if (m_pObserver != NULL) {
        m_pObserver->unsubscribe();
        m_pObserver = NULL;
    }
}
void CProductionLogDlg::OnClose()
{
    ShowWindow(SW_HIDE);
    //GetParent()->PostMessage(ID_MSG_ALARMDLG_HIDE, 0, 0);
    CDialogEx::OnClose();
}
void CProductionLogDlg::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
    if (GetDlgItem(IDC_LIST_PRODUCTION_LOG) == nullptr) return;
    Resize();
}
void CProductionLogDlg::OnCbnSelchangeComboDatetime()
{
    CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DATETIME);
    int nIndex = pComboBox->GetCurSel();
    int nCount = pComboBox->GetCount();
    m_dateTimeStart.EnableWindow(nIndex == nCount - 1);
    m_dateTimeEnd.EnableWindow(nIndex == nCount - 1);
}
void CProductionLogDlg::OnBnClickedButtonSearch()
{
    // èŽ·å–å…³é”®å­—
    CString cstrKeyword;
    GetDlgItemText(IDC_EDIT_KEYWORD, cstrKeyword);
    m_strKeyword = CT2A(cstrKeyword);
    // èŽ·å–æ—¥æœŸ
    CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DATETIME);
    m_nDateTimeFlag = pComboBox->GetCurSel();
    if (m_nDateTimeFlag == 0) {
        memset(m_szTimeStart, 0, sizeof(m_szTimeStart));
        memset(m_szTimeEnd, 0, sizeof(m_szTimeEnd));
        m_szTimeStart[0] = '\0';
        m_szTimeEnd[0] = '\0';
    }
    else {
        CTime time = CTime::GetCurrentTime();
        if (m_nDateTimeFlag == 1) {
            // ä»Šå¤©
            sprintf_s(m_szTimeStart, 64, "%d-%02d-%02d 00:00:00", time.GetYear(), time.GetMonth(), time.GetDay());
            sprintf_s(m_szTimeEnd, 64, "%d-%02d-%02d 23:59:59", time.GetYear(), time.GetMonth(), time.GetDay());
        }
        else if (m_nDateTimeFlag == 2) {
            // 7天内
            CTime time2 = time - CTimeSpan(7, 0, 0, 0);
            sprintf_s(m_szTimeStart, 64, "%d-%02d-%02d 00:00:00", time2.GetYear(), time2.GetMonth(), time2.GetDay());
            sprintf_s(m_szTimeEnd, 64, "%d-%02d-%02d 23:59:59", time.GetYear(), time.GetMonth(), time.GetDay());
        }
        else if (m_nDateTimeFlag == 3) {
            // æœ¬æœˆ
            sprintf_s(m_szTimeStart, 64, "%d-%02d-01 00:00:00", time.GetYear(), time.GetMonth());
            sprintf_s(m_szTimeEnd, 64, "%d-%02d-%02d 23:59:59", time.GetYear(), time.GetMonth(), time.GetDay());
        }
        else if (m_nDateTimeFlag == 4) {
            // ä»Šå¹´
            sprintf_s(m_szTimeStart, 64, "%d-01-01 00:00:00", time.GetYear());
            sprintf_s(m_szTimeEnd, 64, "%d-12-31 23:59:59", time.GetYear());
        }
        else if (m_nDateTimeFlag == 5) {
            // è‡ªå®šä¹‰
            SYSTEMTIME t1, t2;
            m_dateTimeStart.GetTime(&t1);
            m_dateTimeEnd.GetTime(&t2);
            sprintf_s(m_szTimeStart, 64, "%d-%02d-%02d %02d:%02d:%02d",
                t1.wYear, t1.wMonth, t1.wDay, t1.wHour, t1.wMinute, t1.wSecond);
            sprintf_s(m_szTimeEnd, 64, "%d-%02d-%02d %02d:%02d:%02d",
                t2.wYear, t2.wMonth, t2.wDay, t2.wHour, t2.wMinute, t2.wSecond);
        }
    }
    // è®¡ç®—总页数
    int totalRecords = ProductionLogManager::getInstance().getTotalStepCount(
        m_strProductId, m_strBatchNo, m_strDeviceId, m_strOperatorName,
        m_strStatus, m_szTimeStart, m_szTimeEnd);
    m_nTotalPages = (totalRecords + PAGE_SIZE - 1) / PAGE_SIZE;
    m_nCurPage = 1;
    UpdatePageData();  // è°ƒç”¨åˆ†é¡µæ›´æ–°å‡½æ•°
}
void CProductionLogDlg::OnBnClickedButtonExport()
{
    CFileDialog fileDialog(FALSE, "csv", "", OFN_HIDEREADONLY, "CSV Files (*.csv)|*.csv||");
    if (fileDialog.DoModal() != IDOK) {
        return;
    }
    CStdioFile file;
    if (!file.Open(fileDialog.GetPathName(), CFile::modeCreate | CFile::modeWrite | CFile::typeText)) {
        CString err;
        err.Format(_T("无法创建文件: %s"), fileDialog.GetPathName());
        AfxMessageBox(err);
        return;
    }
    const int MAX_COLS = 32;
    char szItem[256] = { 0 };
    HDITEM hdItem[MAX_COLS];
    for (int i = 0; i < MAX_COLS; i++) {
        hdItem[i].pszText = szItem;
        hdItem[i].cchTextMax = 256;
        hdItem[i].mask = HDI_TEXT | HDI_WIDTH;
    }
    // èŽ·å–åˆ—æ•°
    CHeaderCtrl* pHeader = m_listCtrl.GetHeaderCtrl();
    int nSubItemCount = min(pHeader->GetItemCount(), MAX_COLS);
    // è¡¨å¤´
    CString strHeader;
    for (int i = 0; i < nSubItemCount; i++) {
        pHeader->GetItem(i, &hdItem[i]);
        if (hdItem[i].cxy > 0) {
            if (!strHeader.IsEmpty()) strHeader += ",";
            strHeader += CString(hdItem[i].pszText);
        }
    }
    strHeader += "\n";
    file.WriteString(strHeader);
    // è¡¨æ ¼å†…容
    int nItemCount = m_listCtrl.GetItemCount();
    for (int i = 0; i < nItemCount; i++) {
        CStringArray arrRow;
        for (int j = 0; j < nSubItemCount; j++) {
            if (hdItem[j].cxy > 0) {
                CString strText = m_listCtrl.GetItemText(i, j);
                strText.Replace(_T("* "), _T(""));
                // å¦‚果字段中含逗号,包裹双引号
                if (strText.Find(',') != -1) {
                    strText = _T("\"") + strText + _T("\"");
                }
                arrRow.Add(strText);
            }
        }
        CString strRow;
        for (int k = 0; k < arrRow.GetCount(); ++k) {
            if (k > 0) strRow += ",";
            strRow += arrRow[k];
        }
        strRow += "\n";
        file.WriteString(strRow);
    }
    file.Close();
}
void CProductionLogDlg::OnBnClickedButtonPrevPage()
{
    // ç‚¹å‡»ä¸Šä¸€é¡µ
    m_nCurPage--;
    UpdatePageData();  // è°ƒç”¨åˆ†é¡µæ›´æ–°å‡½æ•°
}
void CProductionLogDlg::OnBnClickedButtonNextPage()
{
    // ç‚¹å‡»ä¸‹ä¸€é¡µ
    m_nCurPage++;
    UpdatePageData();  // è°ƒç”¨åˆ†é¡µæ›´æ–°å‡½æ•°
}
*/
SourceCode/Bond/Servo/ProductionLogDlg.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,72 @@
#pragma once
#include "afxdialogex.h"
#include "ListCtrlEx.h"
#include "ProductionLogManager.h"
// CProductionLogDlg å¯¹è¯æ¡†
/*
class CProductionLogDlg : public CDialogEx
{
    DECLARE_DYNAMIC(CProductionLogDlg)
public:
    CProductionLogDlg(CWnd* pParent = nullptr);   // æ ‡å‡†æž„造函数
    virtual ~CProductionLogDlg();
private:
    void InitRxWindow();
    void Resize();
    void UpdatePageData();
    void UpdatePageControls();
    void FillDataToListCtrl(CListCtrl* pListCtrl, const std::vector<ProductionStep>& vecSteps);
    void InsertStepData(CListCtrl* pListCtrl, const ProductionStep& step);
    std::string getCurrentTimeString();
private:
    COLORREF m_crBkgnd;
    HBRUSH m_hbrBkgnd;
    IObserver* m_pObserver;
    // æœç´¢å…³é”®å­—
    std::string m_strKeyword;
    std::string m_strProductId;
    std::string m_strBatchNo;
    std::string m_strDeviceId;
    std::string m_strOperatorName;
    std::string m_strStatus;
    // é¡µç 
    int m_nCurPage;
    int m_nTotalPages;
    // æ—¥æœŸ
    int m_nDateTimeFlag;
    char m_szTimeStart[64];
    char m_szTimeEnd[64];
    // æŽ§ä»¶
    CDateTimeCtrl m_dateTimeStart;
    CDateTimeCtrl m_dateTimeEnd;
    CListCtrlEx m_listCtrl;
// å¯¹è¯æ¡†æ•°æ®
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_DIALOG_PRODUCTION_LOG };
#endif
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV æ”¯æŒ
    virtual BOOL OnInitDialog();
    afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
    afx_msg void OnDestroy();
    afx_msg void OnClose();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnCbnSelchangeComboDatetime();
    afx_msg void OnBnClickedButtonSearch();
    afx_msg void OnBnClickedButtonExport();
    afx_msg void OnBnClickedButtonPrevPage();
    afx_msg void OnBnClickedButtonNextPage();
    DECLARE_MESSAGE_MAP()
};
*/
SourceCode/Bond/Servo/ProductionLogManager.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,407 @@
#include "stdafx.h"
#include "ProductionLogManager.h"
#include <sstream>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <iomanip>
const std::string PRODUCTION_DB_FILE = R"(ProductionLog.db)";
std::mutex ProductionLogManager::m_mutex;
ProductionLogManager& ProductionLogManager::getInstance() {
    static ProductionLogManager instance;
    return instance;
}
ProductionLogManager::ProductionLogManager() {
    m_pDB = new BL::SQLiteDatabase();
}
ProductionLogManager::~ProductionLogManager() {
    if (m_pDB) {
        delete m_pDB;
        m_pDB = nullptr;
    }
}
bool ProductionLogManager::initProductionTable() {
    char path[MAX_PATH];
    GetModuleFileName(NULL, path, MAX_PATH);
    std::string exePath(path);
    std::string dbFileDir = exePath.substr(0, exePath.find_last_of("\\/")) + "\\DB";
    if (!CreateDirectory(dbFileDir.c_str(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
        throw std::runtime_error("Failed to create DB directory.");
    }
    std::string dbFilePath = dbFileDir + "\\" + PRODUCTION_DB_FILE;
    if (!m_pDB->connect(dbFilePath, true)) {
        throw std::runtime_error("Failed to connect to production database.");
    }
    const std::string createTableQuery = R"(
        CREATE TABLE IF NOT EXISTS production_log (
            step_id INTEGER PRIMARY KEY AUTOINCREMENT,
            product_id TEXT NOT NULL,
            batch_no TEXT NOT NULL,
            device_id INTEGER NOT NULL,
            prev_device_id INTEGER,
            next_device_id INTEGER,
            operator_name TEXT,
            start_time DATETIME,
            end_time DATETIME,
            yield INTEGER,
            good_count INTEGER,
            bad_count INTEGER,
            status TEXT,
            note TEXT
        )
    )";
    return m_pDB->executeQuery(createTableQuery);
}
void ProductionLogManager::termProductionTable() {
    if (m_pDB) {
        m_pDB->disconnect();
    }
}
bool ProductionLogManager::destroyProductionTable() {
    if (!m_pDB) return false;
    const std::string query = "DROP TABLE IF EXISTS production_log";
    return m_pDB->executeQuery(query);
}
void ProductionLogManager::insertMockData() {
    // TODO: å®žçŽ°æ¨¡æ‹Ÿæ•°æ®æ’å…¥é€»è¾‘ï¼ˆä½¿ç”¨ std::ostringstream)
    ProductionStep step;
    step.strProductId = "P888";
    step.strBatchNo = "B999";
    step.nDeviceId = 3;
    step.nPrevDeviceId = 2;
    step.nNextDeviceId = 4;
    step.strOperator = "MockUser";
    step.strStartTime = "2025-04-02 10:00:00";
    step.strEndTime = "2025-04-02 10:20:00";
    step.nYield = 100;
    step.nGoodCount = 98;
    step.nBadCount = 2;
    step.strStatus = "测试";
    step.strNote = "这是模拟履历";
    int id = 0;
    addProductionStep(id, step);
}
bool ProductionLogManager::addProductionStep(int stepId, const ProductionStep& stepData) {
    std::ostringstream query;
    query << "INSERT INTO production_log (product_id, batch_no, device_id, prev_device_id, next_device_id, operator_name, start_time, end_time, yield, good_count, bad_count, status, note) "
        << "VALUES ('" << stepData.strProductId << "', '" << stepData.strBatchNo << "', " << stepData.nDeviceId << ", "
        << stepData.nPrevDeviceId << ", " << stepData.nNextDeviceId << ", '" << stepData.strOperator << "', '"
        << stepData.strStartTime << "', '" << stepData.strEndTime << "', " << stepData.nYield << ", "
        << stepData.nGoodCount << ", " << stepData.nBadCount << ", '" << stepData.strStatus << "', '"
        << stepData.strNote << "') RETURNING step_id;";
    std::lock_guard<std::mutex> lock(m_mutex);
    auto results = m_pDB->fetchResults(query.str());
    if (!results.empty() && !results[0].empty()) {
        try {
            stepId = std::stoi(results[0][0]);
            m_mapStepCache[stepId] = stepData;
            return true;
        }
        catch (...) {
            return false;
        }
    }
    return false;
}
std::vector<ProductionStep> ProductionLogManager::getAllSteps() {
    const std::string query = R"(
        SELECT step_id, product_id, batch_no, device_id, prev_device_id, next_device_id,
               operator_name, start_time, end_time, yield, good_count, bad_count, status, note
        FROM production_log
    )";
    auto results = m_pDB->fetchResults(query);
    std::vector<ProductionStep> steps;
    for (const auto& row : results) {
        ProductionStep step;
        step.nStepId = std::stoi(row[0]);
        step.strProductId = row[1];
        step.strBatchNo = row[2];
        step.nDeviceId = std::stoi(row[3]);
        step.nPrevDeviceId = std::stoi(row[4]);
        step.nNextDeviceId = std::stoi(row[5]);
        step.strOperator = row[6];
        step.strStartTime = row[7];
        step.strEndTime = row[8];
        step.nYield = std::stoi(row[9]);
        step.nGoodCount = std::stoi(row[10]);
        step.nBadCount = std::stoi(row[11]);
        step.strStatus = row[12];
        step.strNote = row[13];
        steps.push_back(step);
    }
    return steps;
}
std::vector<ProductionStep> ProductionLogManager::getStepsByProductId(const std::string& productId) {
    std::ostringstream query;
    query << "SELECT * FROM production_log WHERE product_id = '" << productId << "'";
    auto results = m_pDB->fetchResults(query.str());
    std::vector<ProductionStep> steps;
    for (const auto& row : results) {
        ProductionStep step;
        step.nStepId = std::stoi(row[0]);
        step.strProductId = row[1];
        step.strBatchNo = row[2];
        step.nDeviceId = std::stoi(row[3]);
        step.nPrevDeviceId = std::stoi(row[4]);
        step.nNextDeviceId = std::stoi(row[5]);
        step.strOperator = row[6];
        step.strStartTime = row[7];
        step.strEndTime = row[8];
        step.nYield = std::stoi(row[9]);
        step.nGoodCount = std::stoi(row[10]);
        step.nBadCount = std::stoi(row[11]);
        step.strStatus = row[12];
        step.strNote = row[13];
        steps.push_back(step);
    }
    return steps;
}
std::vector<ProductionStep> ProductionLogManager::getStepsByBatchNo(const std::string& batchNo) {
    std::ostringstream query;
    query << "SELECT * FROM production_log WHERE batch_no = '" << batchNo << "'";
    auto results = m_pDB->fetchResults(query.str());
    std::vector<ProductionStep> steps;
    for (const auto& row : results) {
        ProductionStep step;
        step.nStepId = std::stoi(row[0]);
        step.strProductId = row[1];
        step.strBatchNo = row[2];
        step.nDeviceId = std::stoi(row[3]);
        step.nPrevDeviceId = std::stoi(row[4]);
        step.nNextDeviceId = std::stoi(row[5]);
        step.strOperator = row[6];
        step.strStartTime = row[7];
        step.strEndTime = row[8];
        step.nYield = std::stoi(row[9]);
        step.nGoodCount = std::stoi(row[10]);
        step.nBadCount = std::stoi(row[11]);
        step.strStatus = row[12];
        step.strNote = row[13];
        steps.push_back(step);
    }
    return steps;
}
std::vector<ProductionStep> ProductionLogManager::getStepsByDeviceId(int nDeviceId) {
    std::ostringstream query;
    query << "SELECT * FROM production_log WHERE device_id = " << nDeviceId;
    auto results = m_pDB->fetchResults(query.str());
    std::vector<ProductionStep> steps;
    for (const auto& row : results) {
        ProductionStep step;
        step.nStepId = std::stoi(row[0]);
        step.strProductId = row[1];
        step.strBatchNo = row[2];
        step.nDeviceId = std::stoi(row[3]);
        step.nPrevDeviceId = std::stoi(row[4]);
        step.nNextDeviceId = std::stoi(row[5]);
        step.strOperator = row[6];
        step.strStartTime = row[7];
        step.strEndTime = row[8];
        step.nYield = std::stoi(row[9]);
        step.nGoodCount = std::stoi(row[10]);
        step.nBadCount = std::stoi(row[11]);
        step.strStatus = row[12];
        step.strNote = row[13];
        steps.push_back(step);
    }
    return steps;
}
std::vector<ProductionStep> ProductionLogManager::getStepsByTimeRange(const std::string& startTime, const std::string& endTime) {
    std::ostringstream query;
    query << "SELECT * FROM production_log WHERE start_time >= '" << startTime << "' AND end_time <= '" << endTime << "'";
    auto results = m_pDB->fetchResults(query.str());
    std::vector<ProductionStep> steps;
    for (const auto& row : results) {
        ProductionStep step;
        step.nStepId = std::stoi(row[0]);
        step.strProductId = row[1];
        step.strBatchNo = row[2];
        step.nDeviceId = std::stoi(row[3]);
        step.nPrevDeviceId = std::stoi(row[4]);
        step.nNextDeviceId = std::stoi(row[5]);
        step.strOperator = row[6];
        step.strStartTime = row[7];
        step.strEndTime = row[8];
        step.nYield = std::stoi(row[9]);
        step.nGoodCount = std::stoi(row[10]);
        step.nBadCount = std::stoi(row[11]);
        step.strStatus = row[12];
        step.strNote = row[13];
        steps.push_back(step);
    }
    return steps;
}
std::vector<ProductionStep> ProductionLogManager::getFilteredSteps(
    const std::string& productId,
    const std::string& batchNo,
    const std::string& deviceId,
    const std::string& operatorName,
    const std::string& status,
    const std::string& startTime,
    const std::string& endTime,
    int pageNumber,
    int pageSize) {
    std::ostringstream query;
    query << "SELECT * FROM production_log WHERE 1=1";
    if (!productId.empty()) {
        query << " AND product_id LIKE '%" << productId << "%'";
    }
    if (!batchNo.empty()) {
        query << " AND batch_no LIKE '%" << batchNo << "%'";
    }
    if (!deviceId.empty()) {
        query << " AND device_id = " << deviceId;
    }
    if (!operatorName.empty()) {
        query << " AND operator_name LIKE '%" << operatorName << "%'";
    }
    if (!status.empty()) {
        query << " AND status LIKE '%" << status << "%'";
    }
    if (!startTime.empty()) {
        query << " AND start_time >= '" << startTime << "'";
    }
    if (!endTime.empty()) {
        query << " AND end_time <= '" << endTime << "'";
    }
    int offset = (pageNumber - 1) * pageSize;
    query << " ORDER BY start_time DESC LIMIT " << pageSize << " OFFSET " << offset;
    auto results = m_pDB->fetchResults(query.str());
    std::vector<ProductionStep> steps;
    for (const auto& row : results) {
        ProductionStep step;
        step.nStepId = std::stoi(row[0]);
        step.strProductId = row[1];
        step.strBatchNo = row[2];
        step.nDeviceId = std::stoi(row[3]);
        step.nPrevDeviceId = std::stoi(row[4]);
        step.nNextDeviceId = std::stoi(row[5]);
        step.strOperator = row[6];
        step.strStartTime = row[7];
        step.strEndTime = row[8];
        step.nYield = std::stoi(row[9]);
        step.nGoodCount = std::stoi(row[10]);
        step.nBadCount = std::stoi(row[11]);
        step.strStatus = row[12];
        step.strNote = row[13];
        steps.push_back(step);
    }
    return steps;
}
int ProductionLogManager::getTotalStepCount(
    const std::string& productId,
    const std::string& batchNo,
    const std::string& deviceId,
    const std::string& operatorName,
    const std::string& status,
    const std::string& startTime,
    const std::string& endTime) {
    std::ostringstream query;
    query << "SELECT COUNT(*) FROM production_log WHERE 1=1";
    if (!productId.empty()) {
        query << " AND product_id LIKE '%" << productId << "%'";
    }
    if (!batchNo.empty()) {
        query << " AND batch_no LIKE '%" << batchNo << "%'";
    }
    if (!deviceId.empty()) {
        query << " AND device_id = " << deviceId;
    }
    if (!operatorName.empty()) {
        query << " AND operator_name LIKE '%" << operatorName << "%'";
    }
    if (!status.empty()) {
        query << " AND status LIKE '%" << status << "%'";
    }
    if (!startTime.empty()) {
        query << " AND start_time >= '" << startTime << "'";
    }
    if (!endTime.empty()) {
        query << " AND end_time <= '" << endTime << "'";
    }
    auto results = m_pDB->fetchResults(query.str());
    if (!results.empty() && !results[0].empty()) {
        return std::stoi(results[0][0]);
    }
    return 0;
}
bool ProductionLogManager::updateStepEndTime(int nStepId, const std::string& newEndTime) {
    std::ostringstream query;
    query << "UPDATE production_log SET end_time = '" << newEndTime << "' WHERE step_id = " << nStepId;
    return m_pDB->executeQuery(query.str());
}
bool ProductionLogManager::saveProductionFile(const std::string& filename) {
    std::ofstream file(filename);
    if (!file.is_open()) return false;
    file << "StepID,ProductID,BatchNo,DeviceID,PrevDeviceID,NextDeviceID,Operator,StartTime,EndTime,Yield,Good,Bad,Status,Note\n";
    for (auto it = m_mapStepCache.begin(); it != m_mapStepCache.end(); ++it) {
        const int id = it->first;
        const ProductionStep& step = it->second;
        file << id << "," << step.strProductId << "," << step.strBatchNo << ","
            << step.nDeviceId << "," << step.nPrevDeviceId << "," << step.nNextDeviceId << ","
            << step.strOperator << "," << step.strStartTime << "," << step.strEndTime << ","
            << step.nYield << "," << step.nGoodCount << "," << step.nBadCount << ","
            << step.strStatus << "," << step.strNote << "\n";
    }
    file.close();
    return true;
}
bool ProductionLogManager::readProductionFile(const std::string& filename) {
    std::ifstream file(filename);
    if (!file.is_open()) return false;
    std::string line;
    bool first = true;
    while (std::getline(file, line)) {
        if (first) { first = false; continue; }
        std::stringstream ss(line);
        std::string cell;
        ProductionStep step;
        std::getline(ss, cell, ','); step.nStepId = std::stoi(cell);
        std::getline(ss, step.strProductId, ',');
        std::getline(ss, step.strBatchNo, ',');
        std::getline(ss, cell, ','); step.nDeviceId = std::stoi(cell);
        std::getline(ss, cell, ','); step.nPrevDeviceId = std::stoi(cell);
        std::getline(ss, cell, ','); step.nNextDeviceId = std::stoi(cell);
        std::getline(ss, step.strOperator, ',');
        std::getline(ss, step.strStartTime, ',');
        std::getline(ss, step.strEndTime, ',');
        std::getline(ss, cell, ','); step.nYield = std::stoi(cell);
        std::getline(ss, cell, ','); step.nGoodCount = std::stoi(cell);
        std::getline(ss, cell, ','); step.nBadCount = std::stoi(cell);
        std::getline(ss, step.strStatus, ',');
        std::getline(ss, step.strNote);
        m_mapStepCache[step.nStepId] = step;
    }
    return true;
}
SourceCode/Bond/Servo/ProductionLogManager.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,113 @@
#ifndef PRODUCTION_LOG_MANAGER_H
#define PRODUCTION_LOG_MANAGER_H
#include <string>
#include <vector>
#include <mutex>
#include <unordered_map>
#include "Database.h"
// å•条生产履历记录
struct ProductionStep {
    int nStepId;                         // æ­¥éª¤ID(主键)
    std::string strProductId;            // äº§å“ID
    std::string strBatchNo;              // æ‰¹æ¬¡å·
    int nDeviceId;                       // å½“前设备ID
    std::string strDeviceName;           // å½“前设备名称
    int nPrevDeviceId;                   // ä¸Šä¸€ä¸ªè®¾å¤‡ID
    std::string strPrevDeviceName;       // ä¸Šä¸€ä¸ªè®¾å¤‡åç§°
    int nNextDeviceId;                   // ä¸‹ä¸€ä¸ªè®¾å¤‡ID
    std::string strNextDeviceName;       // ä¸‹ä¸€ä¸ªè®¾å¤‡åç§°
    std::string strOperator;             // æ“ä½œå‘˜
    std::string strStartTime;            // å·¥åºå¼€å§‹æ—¶é—´
    std::string strEndTime;              // å·¥åºç»“束时间
    int nYield;                          // æ€»äº§é‡
    int nGoodCount;                      // è‰¯å“æ•°
    int nBadCount;                       // ä¸è‰¯å“æ•°
    std::string strStatus;               // çŠ¶æ€ï¼ˆå®Œæˆã€æš‚åœã€å¼‚å¸¸ç­‰ï¼‰
    std::string strNote;                 // å¤‡æ³¨ä¿¡æ¯
};
using ProductionStepMap = std::unordered_map<int, ProductionStep>;
class ProductionLogManager {
public:
    // èŽ·å–å•ä¾‹å®žä¾‹
    static ProductionLogManager& getInstance();
    // åˆå§‹åŒ–生产履历表
    bool initProductionTable();
    // å…³é—­æ•°æ®åº“连接
    void termProductionTable();
    // åˆ é™¤ç”Ÿäº§å±¥åŽ†è¡¨
    bool destroyProductionTable();
    // æ’入模拟数据
    void insertMockData();
    // æ·»åŠ ç”Ÿäº§å±¥åŽ†è®°å½•
    bool addProductionStep(int stepId, const ProductionStep& stepData);
    // æŸ¥è¯¢æ‰€æœ‰ç”Ÿäº§å±¥åކ
    std::vector<ProductionStep> getAllSteps();
    // æ ¹æ®äº§å“ID查询
    std::vector<ProductionStep> getStepsByProductId(const std::string& productId);
    // æ ¹æ®æ‰¹æ¬¡å·æŸ¥è¯¢
    std::vector<ProductionStep> getStepsByBatchNo(const std::string& batchNo);
    // æ ¹æ®è®¾å¤‡ID查询
    std::vector<ProductionStep> getStepsByDeviceId(int nDeviceId);
    // æ ¹æ®æ—¶é—´èŒƒå›´æŸ¥è¯¢
    std::vector<ProductionStep> getStepsByTimeRange(const std::string& startTime, const std::string& endTime);
    // åˆ†é¡µæŸ¥è¯¢ + å¤šæ¡ä»¶è¿‡æ»¤
    std::vector<ProductionStep> getFilteredSteps(
        const std::string& productId,
        const std::string& batchNo,
        const std::string& deviceId,
        const std::string& operatorName,
        const std::string& status,
        const std::string& startTime,
        const std::string& endTime,
        int pageNumber,
        int pageSize);
    // èŽ·å–æ»¡è¶³æ¡ä»¶çš„æ€»æ•°
    int getTotalStepCount(
        const std::string& productId,
        const std::string& batchNo,
        const std::string& deviceId,
        const std::string& operatorName,
        const std::string& status,
        const std::string& startTime,
        const std::string& endTime);
    // æ›´æ–°æŸä¸€å±¥åŽ†çš„ç»“æŸæ—¶é—´
    bool updateStepEndTime(int nStepId, const std::string& newEndTime);
    // ä¿å­˜åˆ°CSV文件
    bool saveProductionFile(const std::string& filename);
    // ä»ŽCSV文件导入
    bool readProductionFile(const std::string& filename);
private:
    ProductionLogManager();
    ~ProductionLogManager();
    // ç¦ç”¨æ‹·è´æž„造和赋值
    ProductionLogManager(const ProductionLogManager&) = delete;
    ProductionLogManager& operator=(const ProductionLogManager&) = delete;
private:
    BL::Database* m_pDB;
    ProductionStepMap m_mapStepCache;
    static std::mutex m_mutex;
};
#endif // PRODUCTION_LOG_MANAGER_H
SourceCode/Bond/Servo/SECSRuntimeManager.cpp
@@ -104,8 +104,8 @@
        return 1;
    }
    // æž„建删除所有数据的 SQL è¯­å¥
    std::string deleteSQL = "DELETE FROM " + tableName + ";";
    // æž„建删除所有数据的 SQL è¯­å¥, é‡ç½®è‡ªå¢ž ID
    std::string deleteSQL = "TRUNCATE TABLE " + tableName + ";";
    if (!m_pDB->executeQuery(deleteSQL)) {
        return 2;
    }
@@ -789,6 +789,157 @@
    }
}
// æ·»åŠ  SystemEC æ•°æ®
int SECSRuntimeManager::addSystemEC(int nID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultVal, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return 1; // æ•°æ®åº“未连接
    }
    if (isIDDuplicate(nID)) {
        return 2; // ID é‡å¤
    }
    if (isNameDuplicate(sName)) {
        return 3; // Name é‡å¤
    }
    // æž„建插入 SQL è¯­å¥
    std::string insertSQL = "INSERT INTO SystemEC (ID, Name, DataType, MinValue, MaxValue, DefaultVal, Unit, Remark, SystemID) VALUES ("
        + std::to_string(nID) + ", '" + sName + "', '" + sDataType + "', "
        + (nMinValue >= 0 ? std::to_string(nMinValue) : "NULL") + ", "
        + (nMaxValue >= 0 ? std::to_string(nMaxValue) : "NULL") + ", "
        + (nDefaultVal >= 0 ? std::to_string(nDefaultVal) : "NULL") + ", "
        + ((sUnit == "NULL" || sUnit.empty()) ? "NULL" : "'" + sUnit + "'") + ", '"
        + sRemark + "', " + std::to_string(nSystemID) + ");";
    if (!m_pDB->executeQuery(insertSQL)) {
        return 4; // æ’入失败
    }
    return 0; // æ’入成功
}
// æŸ¥è¯¢æŒ‡å®š ID çš„ SystemEC æ•°æ®
std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemECByID(int nID) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return {};
    }
    std::string querySQL = "SELECT * FROM SystemEC WHERE ID = " + std::to_string(nID) + ";";
    return m_pDB->fetchResults(querySQL);
}
// æŸ¥è¯¢æ‰€æœ‰ SystemEC æ•°æ®
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemEC() {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return {};
    }
    std::string querySQL = "SELECT * FROM SystemEC;";
    return m_pDB->fetchResults(querySQL);
}
// æ›´æ–°æŒ‡å®š ID çš„ SystemEC æ•°æ®
int SECSRuntimeManager::updateSystemEC(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultVal, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return 1;
    }
    // æ£€æŸ¥æ˜¯å¦å­˜åœ¨è¯¥ ID
    if (!isIDDuplicate(nID)) {
        return 2;
    }
    // æ£€æŸ¥æ–°çš„ ID æ˜¯å¦å·²å­˜åœ¨
    if (isIDDuplicate(nNewID) && nNewID != nID) {
        return 3;
    }
    // æž„建更新 SQL è¯­å¥
    std::string updateSQL = "UPDATE SystemEC SET ";
    bool firstField = true;
    if (nNewID > 0 && nNewID != nID) {
        updateSQL += "ID = " + std::to_string(nNewID);
        firstField = false;
    }
    if (!sName.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Name = '" + sName + "'";
        firstField = false;
    }
    if (!sDataType.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "DataType = '" + sDataType + "'";
        firstField = false;
    }
    if (nMinValue >= 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "MinValue = " + std::to_string(nMinValue);
        firstField = false;
    }
    if (nMaxValue >= 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "MaxValue = " + std::to_string(nMaxValue);
        firstField = false;
    }
    if (nDefaultVal >= 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "DefaultVal = " + std::to_string(nDefaultVal);
        firstField = false;
    }
    if (sUnit != "NULL" && !sUnit.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Unit = '" + sUnit + "'";
        firstField = false;
    }
    else if (sUnit == "NULL") {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Unit = NULL";
        firstField = false;
    }
    if (!sRemark.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Remark = '" + sRemark + "'";
        firstField = false;
    }
    if (nSystemID > 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "SystemID = " + std::to_string(nSystemID);
    }
    updateSQL += " WHERE ID = " + std::to_string(nID) + ";";
    if (!m_pDB->executeQuery(updateSQL)) {
        return 4;
    }
    return 0;
}
// åˆ é™¤æŒ‡å®š ID çš„ SystemEC æ•°æ®
int SECSRuntimeManager::deleteSystemECByID(int nID) {
    return deleteDataByID("SystemEC", nID);
}
// åˆ é™¤æ‰€æœ‰ SystemEC æ•°æ®
int SECSRuntimeManager::deleteAllSystemEC() {
    return deleteAllDataFromTable("SystemEC");
}
// åˆå§‹åŒ– EqpEC è¡¨
void SECSRuntimeManager::initEqpECTable() {
    std::lock_guard<std::mutex> lock(m_mutex);
@@ -816,6 +967,168 @@
    }
}
// æ·»åŠ  EqpEC æ•°æ®
int SECSRuntimeManager::addEqpEC(int nID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultValue, const std::string& sUnit, const std::string& sRemark, int nSeqNo, int nLength, int bCanUpdateByHost) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return 1; // æ•°æ®åº“未连接
    }
    if (isIDDuplicate(nID)) {
        return 2; // ID é‡å¤
    }
    if (isNameDuplicate(sName)) {
        return 3; // Name é‡å¤
    }
    // æž„建插入 SQL è¯­å¥
    std::string insertSQL = "INSERT INTO EqpEC (ID, Name, DataType, MinValue, MaxValue, DefaultValue, Unit, Remark, SeqNo, Length, CanUpdateByHost) VALUES ("
        + std::to_string(nID) + ", '" + sName + "', '" + sDataType + "', "
        + (nMinValue >= 0 ? std::to_string(nMinValue) : "NULL") + ", "
        + (nMaxValue >= 0 ? std::to_string(nMaxValue) : "NULL") + ", "
        + (nDefaultValue >= 0 ? std::to_string(nDefaultValue) : "NULL") + ", "
        + ((sUnit == "NULL" || sUnit.empty()) ? "NULL" : "'" + sUnit + "'") + ", '"
        + sRemark + "', " + std::to_string(nSeqNo) + ", "
        + std::to_string(nLength) + ", " + std::to_string(bCanUpdateByHost) + ");";
    if (!m_pDB->executeQuery(insertSQL)) {
        return 4; // æ’入失败
    }
    return 0; // æ’入成功
}
// æŸ¥è¯¢æŒ‡å®š ID çš„ EqpEC æ•°æ®
std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpECByID(int nID) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return {};
    }
    std::string querySQL = "SELECT * FROM EqpEC WHERE ID = " + std::to_string(nID) + ";";
    return m_pDB->fetchResults(querySQL);
}
// æŸ¥è¯¢æ‰€æœ‰ EqpEC æ•°æ®
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllEqpEC() {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return {};
    }
    std::string querySQL = "SELECT * FROM EqpEC;";
    return m_pDB->fetchResults(querySQL);
}
// æ›´æ–°æŒ‡å®š ID çš„ EqpEC æ•°æ®
int SECSRuntimeManager::updateEqpEC(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultValue, const std::string& sUnit, const std::string& sRemark, int nSeqNo, int nLength, int bCanUpdateByHost) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return 1;
    }
    // æ£€æŸ¥æ˜¯å¦å­˜åœ¨è¯¥ ID
    if (!isIDDuplicate(nID)) {
        return 2;
    }
    // æ£€æŸ¥æ–°çš„ ID æ˜¯å¦å·²å­˜åœ¨
    if (isIDDuplicate(nNewID) && nNewID != nID) {
        return 3;
    }
    // æž„建更新 SQL è¯­å¥
    std::string updateSQL = "UPDATE EqpEC SET ";
    bool firstField = true;
    if (nNewID > 0 && nNewID != nID) {
        updateSQL += "ID = " + std::to_string(nNewID);
        firstField = false;
    }
    if (!sName.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Name = '" + sName + "'";
        firstField = false;
    }
    if (!sDataType.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "DataType = '" + sDataType + "'";
        firstField = false;
    }
    if (nMinValue >= 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "MinValue = " + std::to_string(nMinValue);
        firstField = false;
    }
    if (nMaxValue >= 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "MaxValue = " + std::to_string(nMaxValue);
        firstField = false;
    }
    if (nDefaultValue >= 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "DefaultValue = " + std::to_string(nDefaultValue);
        firstField = false;
    }
    if (sUnit != "NULL" && !sUnit.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Unit = '" + sUnit + "'";
        firstField = false;
    }
    else if (sUnit == "NULL") {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Unit = NULL";
        firstField = false;
    }
    if (!sRemark.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Remark = '" + sRemark + "'";
        firstField = false;
    }
    if (nSeqNo > 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "SeqNo = " + std::to_string(nSeqNo);
    }
    if (nLength > 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Length = " + std::to_string(nLength);
    }
    if (bCanUpdateByHost >= 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "CanUpdateByHost = " + std::to_string(bCanUpdateByHost);
    }
    updateSQL += " WHERE ID = " + std::to_string(nID) + ";";
    if (!m_pDB->executeQuery(updateSQL)) {
        return 4;
    }
    return 0;
}
// åˆ é™¤æŒ‡å®š ID çš„ EqpEC æ•°æ®
int SECSRuntimeManager::deleteEqpECByID(int nID) {
    return deleteDataByID("EqpEC", nID);
}
// åˆ é™¤æ‰€æœ‰ EqpEC æ•°æ®
int SECSRuntimeManager::deleteAllEqpEC() {
    return deleteAllDataFromTable("EqpEC");
}
// åˆå§‹åŒ– SystemEvent è¡¨
void SECSRuntimeManager::initSystemEventTable() {
    std::lock_guard<std::mutex> lock(m_mutex);
@@ -836,6 +1149,110 @@
    }
}
// æ·»åŠ  SystemEvent æ•°æ®
int SECSRuntimeManager::addSystemEvent(int nCEID, const std::string& sName, const std::string& sRemark, int nSystemID) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return 1; // æ•°æ®åº“未连接
    }
    // æž„建 SQL æ’入语句
    std::string insertSQL = "INSERT INTO SystemEvent (CEID, Name, Remark, SystemID) VALUES ("
        + std::to_string(nCEID) + ", '" + sName + "', '" + sRemark + "', " + std::to_string(nSystemID) + ");";
    if (!m_pDB->executeQuery(insertSQL)) {
        return 2; // æ’入失败
    }
    return 0; // æ’入成功
}
// æŸ¥è¯¢æŒ‡å®š CEID çš„ SystemEvent æ•°æ®
std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemEventByID(int nCEID) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return {};
    }
    std::string querySQL = "SELECT * FROM SystemEvent WHERE CEID = " + std::to_string(nCEID) + ";";
    return m_pDB->fetchResults(querySQL);
}
// æŸ¥è¯¢æ‰€æœ‰ SystemEvent æ•°æ®
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemEvents() {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return {};
    }
    std::string querySQL = "SELECT * FROM SystemEvent;";
    return m_pDB->fetchResults(querySQL);
}
// æ›´æ–°æŒ‡å®š CEID çš„ SystemEvent æ•°æ®
int SECSRuntimeManager::updateSystemEvent(int nCEID, int nNewCEID, const std::string& sName, const std::string& sRemark, int nSystemID) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return 1;
    }
    // æž„建更新 SQL è¯­å¥
    std::string updateSQL = "UPDATE SystemEvent SET ";
    bool firstField = true;
    if (nNewCEID > 0 && nNewCEID != nCEID) {
        updateSQL += "CEID = " + std::to_string(nNewCEID);
        firstField = false;
    }
    if (!sName.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Name = '" + sName + "'";
        firstField = false;
    }
    if (!sRemark.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Remark = '" + sRemark + "'";
        firstField = false;
    }
    if (nSystemID > 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "SystemID = " + std::to_string(nSystemID);
    }
    updateSQL += " WHERE CEID = " + std::to_string(nCEID) + ";";
    if (!m_pDB->executeQuery(updateSQL)) {
        return 2;
    }
    return 0;
}
// åˆ é™¤æŒ‡å®š CEID çš„ SystemEvent æ•°æ®
int SECSRuntimeManager::deleteSystemEventByID(int nCEID) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return 1; // æ•°æ®åº“未连接,返回 1
    }
    // æž„建删除 SQL è¯­å¥
    std::string deleteSQL = "DELETE FROM SystemEvent WHERE CEID = " + std::to_string(nCEID) + ";";
    if (!m_pDB->executeQuery(deleteSQL)) {
        return 2; // åˆ é™¤å¤±è´¥ï¼Œè¿”回 2
    }
    return 0; // åˆ é™¤æˆåŠŸï¼Œè¿”å›ž 0
}
// åˆ é™¤æ‰€æœ‰ SystemEvent æ•°æ®
int SECSRuntimeManager::deleteAllSystemEvents() {
    return deleteAllDataFromTable("SystemEvent");
}
// åˆå§‹åŒ– EqpEvent è¡¨
void SECSRuntimeManager::initEqpEventTable() {
    std::lock_guard<std::mutex> lock(m_mutex);
@@ -856,6 +1273,105 @@
    }
}
// æ·»åŠ  EqpEvent æ•°æ®
int SECSRuntimeManager::addEqpEvent(const std::string& sName, const std::string& sRemark, int nBitNo) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return 1; // æ•°æ®åº“未连接
    }
    // æž„建 SQL æ’入语句
    std::string insertSQL = "INSERT INTO EqpEvent (Name, Remark, BitNo) VALUES ('"
        + sName + "', '" + sRemark + "', " + std::to_string(nBitNo) + ");";
    if (!m_pDB->executeQuery(insertSQL)) {
        return 2; // æ’入失败
    }
    return 0; // æ’入成功
}
// æŸ¥è¯¢æŒ‡å®š CEID çš„ EqpEvent æ•°æ®
std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpEventByID(int nCEID) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return {};
    }
    std::string querySQL = "SELECT * FROM EqpEvent WHERE CEID = " + std::to_string(nCEID) + ";";
    return m_pDB->fetchResults(querySQL);
}
// æŸ¥è¯¢æ‰€æœ‰ EqpEvent æ•°æ®
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllEqpEvents() {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return {};
    }
    std::string querySQL = "SELECT * FROM EqpEvent;";
    return m_pDB->fetchResults(querySQL);
}
// æ›´æ–°æŒ‡å®š CEID çš„ EqpEvent æ•°æ®
int SECSRuntimeManager::updateEqpEvent(int nCEID, const std::string& sName, const std::string& sRemark, int nBitNo) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return 1;
    }
    // æž„建更新 SQL è¯­å¥
    std::string updateSQL = "UPDATE EqpEvent SET ";
    bool firstField = true;
    if (!sName.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Name = '" + sName + "'";
        firstField = false;
    }
    if (!sRemark.empty()) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "Remark = '" + sRemark + "'";
        firstField = false;
    }
    if (nBitNo >= 0) {
        if (!firstField) updateSQL += ", ";
        updateSQL += "BitNo = " + std::to_string(nBitNo);
    }
    updateSQL += " WHERE CEID = " + std::to_string(nCEID) + ";";
    if (!m_pDB->executeQuery(updateSQL)) {
        return 2;
    }
    return 0;
}
// åˆ é™¤æŒ‡å®š CEID çš„ EqpEvent æ•°æ®
int SECSRuntimeManager::deleteEqpEventByID(int nCEID) {
    std::lock_guard<std::mutex> lock(m_mutex);
    if (m_pDB == nullptr) {
        return 1; // æ•°æ®åº“未连接,返回 1
    }
    // æž„建删除 SQL è¯­å¥
    std::string deleteSQL = "DELETE FROM EqpEvent WHERE CEID = " + std::to_string(nCEID) + ";";
    if (!m_pDB->executeQuery(deleteSQL)) {
        return 2; // åˆ é™¤å¤±è´¥ï¼Œè¿”回 2
    }
    return 0; // åˆ é™¤æˆåŠŸï¼Œè¿”å›ž 0
}
// åˆ é™¤æ‰€æœ‰ EqpEvent æ•°æ®
int SECSRuntimeManager::deleteAllEqpEvents() {
    return deleteAllDataFromTable("EqpEvent");
}
// åˆå§‹åŒ– EventLink è¡¨
void SECSRuntimeManager::initEventLinkTable() {
    std::lock_guard<std::mutex> lock(m_mutex);
SourceCode/Bond/Servo/SECSRuntimeManager.h
@@ -316,21 +316,69 @@
    */ 
    void initSystemECTable();
    int addSystemEC(int nID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultVal, const std::string& sUnit, const std::string& sRemark, int nSystemID);
    std::vector<std::vector<std::string>> getSystemECByID(int nID);
    std::vector<std::vector<std::string>> getAllSystemEC();
    int updateSystemEC(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultVal, const std::string& sUnit, const std::string& sRemark, int nSystemID);
    int deleteSystemECByID(int nID);
    int deleteAllSystemEC();
    /**
    * åˆå§‹åŒ– EqpEC è¡¨
    */
    void initEqpECTable();
    int addEqpEC(int nID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultValue, const std::string& sUnit, const std::string& sRemark, int nSeqNo, int nLength, int bCanUpdateByHost);
    std::vector<std::vector<std::string>> getEqpECByID(int nID);
    std::vector<std::vector<std::string>> getAllEqpEC();
    int updateEqpEC(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultValue, const std::string& sUnit, const std::string& sRemark, int nSeqNo, int nLength, int bCanUpdateByHost);
    int deleteEqpECByID(int nID);
    int deleteAllEqpEC();
    /**
    * åˆå§‹åŒ– SystemEvent è¡¨
    */
    void initSystemEventTable();
    int addSystemEvent(int nCEID, const std::string& sName, const std::string& sRemark, int nSystemID);
    std::vector<std::vector<std::string>> getSystemEventByID(int nCEID);
    std::vector<std::vector<std::string>> getAllSystemEvents();
    int updateSystemEvent(int nCEID, int nNewCEID, const std::string& sName, const std::string& sRemark, int nSystemID);
    int deleteSystemEventByID(int nCEID);
    int deleteAllSystemEvents();
    /**
    * åˆå§‹åŒ– EqpEvent è¡¨
    */
    void initEqpEventTable();
    int addEqpEvent(const std::string& sName, const std::string& sRemark, int nBitNo);
    std::vector<std::vector<std::string>> getEqpEventByID(int nCEID);
    std::vector<std::vector<std::string>> getAllEqpEvents();
    int updateEqpEvent(int nCEID, const std::string& sName, const std::string& sRemark, int nBitNo);
    int deleteEqpEventByID(int nCEID);
    int deleteAllEqpEvents();
    /**
    * åˆå§‹åŒ– EventLink è¡¨
    */
SourceCode/Bond/Servo/Servo.cpp
@@ -8,6 +8,7 @@
#include "ServoGraph.h"
#include "AlarmManager.h"
#include "SECSRuntimeManager.h"
#include "ProductionLogManager.h"
#include "VerticalLine.h"
#include "EqsGraphWnd.h"
#include "MapPosWnd.h"
@@ -128,6 +129,21 @@
    AlarmManager::getInstance().insertMockData();
    // åˆå§‹åŒ–生产履历管理器
    try {
        if (!ProductionLogManager::getInstance().initProductionTable()) {
            AfxMessageBox("初始化生产履历管理器失败!");
            return FALSE;
        }
    }
    catch (const std::exception& ex) {
        CString errorMsg;
        errorMsg.Format(_T("初始化生产履历管理器失败:%s"), CString(ex.what()));
        AfxMessageBox(errorMsg, MB_ICONERROR);
        return FALSE;
    }
    // åˆå§‹åŒ–SECS运行设置管理库
    try {
        if (!SECSRuntimeManager::getInstance().initRuntimeSetting()) {
@@ -185,6 +201,9 @@
    // é”€æ¯æŠ¥è­¦è¡¨
    AlarmManager::getInstance().termAlarmTable();
    // é”€æ¯ç”Ÿäº§è¡¨
    ProductionLogManager::getInstance().termProductionTable();
    // é”€æ¯SECS运行设置管理库
    SECSRuntimeManager::getInstance().termRuntimeSetting();
SourceCode/Bond/Servo/Servo.rc
Binary files differ
SourceCode/Bond/Servo/Servo.vcxproj
@@ -275,6 +275,8 @@
    <ClInclude Include="LogEdit.h" />
    <ClInclude Include="MapPosWnd.h" />
    <ClInclude Include="Model.h" />
    <ClInclude Include="ProductionLogDlg.h" />
    <ClInclude Include="ProductionLogManager.h" />
    <ClInclude Include="Resource.h" />
    <ClInclude Include="SECSRuntimeManager.h" />
    <ClInclude Include="SecsTestDlg.h" />
@@ -367,6 +369,8 @@
    <ClCompile Include="LogEdit.cpp" />
    <ClCompile Include="MapPosWnd.cpp" />
    <ClCompile Include="Model.cpp" />
    <ClCompile Include="ProductionLogDlg.cpp" />
    <ClCompile Include="ProductionLogManager.cpp" />
    <ClCompile Include="SECSRuntimeManager.cpp" />
    <ClCompile Include="SecsTestDlg.cpp" />
    <ClCompile Include="Servo.cpp" />
SourceCode/Bond/Servo/Servo.vcxproj.filters
@@ -99,6 +99,8 @@
    <ClCompile Include="CRecipeList.cpp" />
    <ClCompile Include="CArm.cpp" />
    <ClCompile Include="CArmTray.cpp" />
    <ClCompile Include="ProductionLogDlg.cpp" />
    <ClCompile Include="ProductionLogManager.cpp" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="AlarmManager.h" />
@@ -196,6 +198,8 @@
    <ClInclude Include="CRecipeList.h" />
    <ClInclude Include="CArm.h" />
    <ClInclude Include="CArmTray.h" />
    <ClInclude Include="ProductionLogDlg.h" />
    <ClInclude Include="ProductionLogManager.h" />
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="Servo.rc" />
SourceCode/Bond/Servo/ServoDlg.cpp
@@ -68,10 +68,6 @@
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    m_crBkgnd = APPDLG_BACKGROUND_COLOR;
    m_hbrBkgnd = nullptr;
    m_bShowLogWnd = FALSE;
    m_bShowAlarmWnd = FALSE;
    m_pLogDlg = nullptr;
    m_pAlarmDlg = nullptr;
    m_pTerminalDisplayDlg = nullptr;
    m_pObserver = nullptr;
    m_pPanelMaster = nullptr;
@@ -79,6 +75,8 @@
    m_pPanelAttributes = nullptr;
    m_pPageGraph1 = nullptr;
    m_pPageGraph2 = nullptr;
    m_pPageAlarm = nullptr;
    m_pPageLog = nullptr;
}
void CServoDlg::DoDataExchange(CDataExchange* pDX)
@@ -96,11 +94,8 @@
    ON_BN_CLICKED(IDCANCEL, &CServoDlg::OnBnClickedCancel)
    ON_WM_CTLCOLOR()
    ON_WM_DESTROY()
    ON_BN_CLICKED(IDC_BUTTON_LOG, &CServoDlg::OnBnClickedButtonLog)
    ON_WM_SIZE()
    ON_WM_CLOSE()
    ON_MESSAGE(ID_MSG_LOGDLG_HIDE, &CServoDlg::OnLogDlgHide)
    ON_MESSAGE(ID_MSG_ALARMDLG_HIDE, &CServoDlg::OnAlarmDlgHide)
    ON_WM_MOVING()
    ON_WM_MOVE()
    ON_COMMAND(ID_MENU_FILE_EXIT, &CServoDlg::OnMenuFileExit)
@@ -109,10 +104,6 @@
    ON_UPDATE_COMMAND_UI(ID_MENU_FILE_SETTINGS, &CServoDlg::OnUpdateMenuFileSettings)
    ON_COMMAND(ID_MENU_FILE_SECSTEST, &CServoDlg::OnMenuFileSecsTest)
    ON_UPDATE_COMMAND_UI(ID_MENU_FILE_SECSTEST, &CServoDlg::OnUpdateMenuFileSecsTest)
    ON_COMMAND(ID_MENU_WND_LOG, &CServoDlg::OnMenuWndLog)
    ON_UPDATE_COMMAND_UI(ID_MENU_WND_LOG, &CServoDlg::OnUpdateMenuWndLog)
    ON_COMMAND(ID_MENU_WND_ALARM, &CServoDlg::OnMenuWndAlarm)
    ON_UPDATE_COMMAND_UI(ID_MENU_WND_ALARM, &CServoDlg::OnUpdateMenuWndAlarm)
    ON_COMMAND(ID_MENU_TEST_MESSAGE_SET, &CServoDlg::OnMenuTestMessageSet)
    ON_UPDATE_COMMAND_UI(ID_MENU_TEST_MESSAGE_SET, &CServoDlg::OnUpdateMenuTestMessageSet)
    ON_COMMAND(ID_MENU_TEST_MESSAGE_CLEAR, &CServoDlg::OnMenuTestMessageClear)
@@ -120,8 +111,6 @@
    ON_COMMAND(ID_MENU_HELP_ABOUT, &CServoDlg::OnMenuHelpAbout)
    ON_WM_INITMENUPOPUP()
    ON_WM_TIMER()
    ON_BN_CLICKED(IDC_BUTTON_ALARM, &CServoDlg::OnBnClickedButtonAlarm)
    ON_BN_CLICKED(IDC_BUTTON_ALARM, &CServoDlg::OnBnClickedButtonAlarm)
    ON_MESSAGE(ID_MSG_PANEL_RESIZE, OnPanelResize)
    ON_NOTIFY(BYHMTAB_SEL_CHANGED, IDC_TAB1, &CServoDlg::OnTabSelChanged)
END_MESSAGE_MAP()
@@ -224,18 +213,23 @@
    SetMenu(&menu);
    // Tab
    m_pPageGraph1 = new CPageGraph1();
    m_pPageGraph1->Create(IDD_PAGE_GRAPH1, this);
    m_pPageGraph2 = new CPageGraph2();
    m_pPageGraph2->Create(IDD_PAGE_GRAPH2, this);
    m_pPageAlarm = new CAlarmDlg();
    m_pPageAlarm->Create(IDD_DIALOG_ALARM, this);
    m_pPageLog = new CLogDlg();
    m_pPageLog->Create(IDD_DIALOG_LOG, this);
    CHmTab* m_pTab = CHmTab::Hook(GetDlgItem(IDC_TAB1)->m_hWnd);
    m_pTab->SetPaddingLeft(20);
    m_pTab->SetItemMarginLeft(18);
    m_pTab->AddItem("״̬ͼ", FALSE);
    m_pTab->AddItem("连接图", TRUE);
    m_pTab->AddItem("报警", TRUE);
    m_pTab->AddItem("日志", TRUE);
    m_pTab->SetCurSel(0);
    m_pTab->SetBkgndColor(RGB(222, 222, 222));
    ShowChildPage(0);
@@ -249,7 +243,6 @@
    m_pPanelAttributes = new CPanelAttributes();
    m_pPanelAttributes->Create(IDD_PANEL_ATTRIBUTES, this);
    
    // è°ƒæ•´åˆå§‹çª—口位置
    CRect rcWnd;
@@ -265,14 +258,15 @@
    SetTimer(TIMER_ID_CREATE_TERMINAL, 3000, nullptr);
    InitRxWindows();
    OnBnClickedButtonLog();
    UpdateLogBtn();
    UpdateAlarmBtn();
    Resize();
    // ç›¸å½“于延时调用master的初始化
    theApp.m_model.m_master.init();
    // åˆå§‹åŒ–master以后需要控件绑定数据
    m_pPageGraph1->BindEquipmentToGraph();
    return TRUE;  // é™¤éžå°†ç„¦ç‚¹è®¾ç½®åˆ°æŽ§ä»¶ï¼Œå¦åˆ™è¿”回 TRUE
@@ -419,26 +413,6 @@
    pCmdUI->Enable(TRUE);
}
void CServoDlg::OnMenuWndLog()
{
    OnBnClickedButtonLog();
}
void CServoDlg::OnUpdateMenuWndLog(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck(m_bShowLogWnd);
}
void CServoDlg::OnMenuWndAlarm()
{
    OnBnClickedButtonAlarm();
}
void CServoDlg::OnUpdateMenuWndAlarm(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck(m_bShowAlarmWnd);
}
void CServoDlg::OnMenuFileExit()
{
    PostMessage(WM_CLOSE);
@@ -516,17 +490,6 @@
{
    CDialogEx::OnDestroy();
    if (m_pLogDlg != nullptr) {
        m_pLogDlg->DestroyWindow();
        delete m_pLogDlg;
        m_pLogDlg = nullptr;
    }
    if (m_pAlarmDlg != nullptr) {
        m_pAlarmDlg->DestroyWindow();
        delete m_pAlarmDlg;
        m_pAlarmDlg = nullptr;
    }
    if (m_pTerminalDisplayDlg != nullptr) {
        m_pTerminalDisplayDlg->DestroyWindow();
@@ -564,6 +527,18 @@
        m_pPageGraph2 = nullptr;
    }
    if (m_pPageAlarm != nullptr) {
        m_pPageAlarm->DestroyWindow();
        delete m_pPageAlarm;
        m_pPageAlarm = nullptr;
    }
    if (m_pPageLog != nullptr) {
        m_pPageLog->DestroyWindow();
        delete m_pPageLog;
        m_pPageLog = nullptr;
    }
    if (m_hbrBkgnd != nullptr) {
        ::DeleteObject(m_hbrBkgnd);
    }
@@ -575,92 +550,14 @@
}
void CServoDlg::OnBnClickedButtonAlarm()
{
    m_bShowAlarmWnd = !m_bShowAlarmWnd;
    // å¦‚果要显示报警窗口,则隐藏日志窗口
    if (m_bShowLogWnd) {
        m_bShowLogWnd = false;
        if (m_pLogDlg != nullptr) {
            m_pLogDlg->ShowWindow(SW_HIDE);
            UpdateLogBtn();
        }
    }
    if (m_pAlarmDlg == nullptr) {
        m_pAlarmDlg = new CAlarmDlg();
        m_pAlarmDlg->Create(IDD_DIALOG_ALARM, this);
        CRect rcWnd;
        GetWindowRect(&rcWnd);
        int nHeight = GetSystemMetrics(SM_CYSCREEN) - rcWnd.bottom - 38;
        if (nHeight < 280) nHeight = 280;
        m_pAlarmDlg->MoveWindow(rcWnd.left, rcWnd.bottom - 8, rcWnd.Width(), nHeight);
    }
    ASSERT(m_pAlarmDlg);
    m_pAlarmDlg->ShowWindow(m_bShowAlarmWnd ? SW_SHOW : SW_HIDE);
    UpdateAlarmBtn();
}
void CServoDlg::OnBnClickedButtonLog()
{
    m_bShowLogWnd = !m_bShowLogWnd;
    // å¦‚果要显示日志窗口,则隐藏报警窗口
    if (m_bShowLogWnd) {
        m_bShowAlarmWnd = false;
        if (m_pAlarmDlg != nullptr) {
            m_pAlarmDlg->ShowWindow(SW_HIDE);
            UpdateAlarmBtn();
        }
    }
    if (m_pLogDlg == nullptr) {
        m_pLogDlg = new CLogDlg();
        m_pLogDlg->Create(IDD_DIALOG_LOG, this);
        CRect rcWnd;
        GetWindowRect(&rcWnd);
        int nHeight = GetSystemMetrics(SM_CYSCREEN) - rcWnd.bottom - 38;
        if (nHeight < 280) nHeight = 280;
        m_pLogDlg->MoveWindow(rcWnd.left, rcWnd.bottom - 8, rcWnd.Width(), nHeight);
    }
    ASSERT(m_pLogDlg);
    m_pLogDlg->ShowWindow(m_bShowLogWnd ? SW_SHOW : SW_HIDE);
    UpdateLogBtn();
}
void CServoDlg::UpdateLogBtn()
{
    m_btnLog.SetFrameColor(BS_NORMAL, BTN_LOG_FRAME_NORMAL);
    m_btnLog.SetFrameColor(BS_HOVER, BTN_LOG_FRAME_HOVER);
    m_btnLog.SetFrameColor(BS_PRESS, BTN_LOG_FRAME_PRESS);
    m_btnLog.SetBkgndColor(BS_NORMAL, m_bShowLogWnd ? BTN_LOG_BKGND_PRESS : BTN_LOG_BKGND_NORMAL);
    m_btnLog.SetBkgndColor(BS_HOVER, BTN_LOG_BKGND_HOVER);
    m_btnLog.SetBkgndColor(BS_PRESS, BTN_LOG_BKGND_PRESS);
    m_btnLog.Invalidate();
}
void CServoDlg::UpdateAlarmBtn()
{
    m_btnAlarm.SetFrameColor(BS_NORMAL, BTN_ALARM_FRAME_NORMAL);
    m_btnAlarm.SetFrameColor(BS_HOVER, BTN_ALARM_FRAME_HOVER);
    m_btnAlarm.SetFrameColor(BS_PRESS, BTN_ALARM_FRAME_PRESS);
    m_btnAlarm.SetBkgndColor(BS_NORMAL, m_bShowAlarmWnd ? BTN_ALARM_BKGND_PRESS : BTN_ALARM_BKGND_NORMAL);
    m_btnAlarm.SetBkgndColor(BS_HOVER, BTN_ALARM_BKGND_HOVER);
    m_btnAlarm.SetBkgndColor(BS_PRESS, BTN_ALARM_BKGND_PRESS);
    m_btnAlarm.Invalidate();
}
void CServoDlg::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
    if (GetDlgItem(IDC_TAB1) == nullptr) return;
    if (m_pPageGraph1 == nullptr) return;
    if (m_pPageGraph2 == nullptr) return;
    if (m_pPageAlarm == nullptr) return;
    if (m_pPageLog == nullptr) return;
    
    Resize();
    Invalidate();
@@ -701,21 +598,10 @@
    y += rcItem.Height();
    m_pPageGraph1->MoveWindow(x, y, rcClient.Width() - x, rcClient.Height());
    m_pPageGraph2->MoveWindow(x, y, rcClient.Width() - x, rcClient.Height());
    x = rcClient.right - 8;
    pItem = GetDlgItem(IDC_BUTTON_LOG);
    pItem->GetClientRect(&rcItem);
    x -= rcItem.Width();
    pItem->MoveWindow(x, rcClient.bottom - 8 - rcItem.Height(), rcItem.Width(), rcItem.Height());
    x -= 8;
    pItem = GetDlgItem(IDC_BUTTON_ALARM);
    pItem->GetClientRect(&rcItem);
    x -= rcItem.Width();
    pItem->MoveWindow(x, rcClient.bottom - 8 - rcItem.Height(), rcItem.Width(), rcItem.Height());
    m_pPageGraph1->MoveWindow(x, y, rcClient.Width() - x, rcClient.Height() - y);
    m_pPageGraph2->MoveWindow(x, y, rcClient.Width() - x, rcClient.Height() - y);
    m_pPageAlarm->MoveWindow(x, y, rcClient.Width() - x, rcClient.Height() - y);
    m_pPageLog->MoveWindow(x, y, rcClient.Width() - x, rcClient.Height() - y);
}
void CServoDlg::OnClose()
@@ -725,32 +611,6 @@
    CDialogEx::OnClose();
}
LRESULT CServoDlg::OnLogDlgHide(WPARAM wParam, LPARAM lParam)
{
    m_bShowLogWnd = FALSE;
    UpdateLogBtn();
    LOGE("OnLogDlgHide");
    unsigned int DATAID, RPTID;
    DATAID = 111;
    RPTID = 1001;
    std::vector<std::string> v;
    v.push_back("abc");
    v.push_back("def");
    theApp.m_model.m_hsmsPassive.requestEventReportSend(DATAID, RPTID, v);
    return 0;
}
LRESULT CServoDlg::OnAlarmDlgHide(WPARAM wParam, LPARAM lParam)
{
    m_bShowAlarmWnd = FALSE;
    UpdateAlarmBtn();
    LOGE("OnAlarmDlgHide");
    return 0;
}
void CServoDlg::OnMoving(UINT fwSide, LPRECT pRect)
{
    CDialogEx::OnMoving(fwSide, pRect);
@@ -758,17 +618,6 @@
void CServoDlg::OnMove(int x, int y)
{
    if (m_pLogDlg != nullptr && !m_pLogDlg->IsZoomed()) {
        CRect rcWnd;
        GetWindowRect(&rcWnd);
        m_pLogDlg->SetWindowPos(nullptr, rcWnd.left, rcWnd.bottom - 8, 0, 0, SWP_NOSIZE);
    }
    if (m_pAlarmDlg != nullptr && !m_pAlarmDlg->IsZoomed()) {
        CRect rcWnd;
        GetWindowRect(&rcWnd);
        m_pAlarmDlg->SetWindowPos(nullptr, rcWnd.left, rcWnd.bottom - 8, 0, 0, SWP_NOSIZE);
    }
    CDialogEx::OnMove(x, y);
}
@@ -813,9 +662,9 @@
void CServoDlg::ShowChildPage(int index)
{
    ASSERT(0 <= index && index < 3);
    static CWnd* pPages[] = { m_pPageGraph1, m_pPageGraph2 };
    for (int i = 0; i < 2; i++) {
    ASSERT(0 <= index && index < 4);
    static CWnd* pPages[] = { m_pPageGraph1, m_pPageGraph2, m_pPageAlarm, m_pPageLog };
    for (int i = 0; i < 4; i++) {
        pPages[i]->ShowWindow(i == index ? SW_SHOW : SW_HIDE);
    }
}
SourceCode/Bond/Servo/ServoDlg.h
@@ -28,20 +28,16 @@
private:
    void InitRxWindows();
    void Resize();
    void UpdateLogBtn();
    void UpdateAlarmBtn();
    void ShowChildPage(int index);
private:
    IObserver* m_pObserver;
    BOOL m_bShowLogWnd;
    BOOL m_bShowAlarmWnd;
    CLogDlg* m_pLogDlg;
    CAlarmDlg* m_pAlarmDlg;
    CTerminalDisplayDlg* m_pTerminalDisplayDlg;
    CPageGraph1* m_pPageGraph1;
    CPageGraph2* m_pPageGraph2;
    CAlarmDlg*     m_pPageAlarm;
    CLogDlg*     m_pPageLog;
// å¯¹è¯æ¡†æ•°æ®
@@ -75,11 +71,8 @@
    afx_msg void OnBnClickedCancel();
    afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
    afx_msg void OnDestroy();
    afx_msg void OnBnClickedButtonLog();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnClose();
    afx_msg LRESULT OnLogDlgHide(WPARAM wParam, LPARAM lParam);
    afx_msg LRESULT OnAlarmDlgHide(WPARAM wParam, LPARAM lParam);
    afx_msg void OnMoving(UINT fwSide, LPRECT pRect);
    afx_msg void OnMove(int x, int y);
    afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
@@ -87,10 +80,6 @@
    afx_msg void OnUpdateMenuFileSettings(CCmdUI* pCmdUI);
    afx_msg void OnMenuFileSecsTest();
    afx_msg void OnUpdateMenuFileSecsTest(CCmdUI* pCmdUI);
    afx_msg void OnMenuWndLog();
    afx_msg void OnUpdateMenuWndLog(CCmdUI* pCmdUI);
    afx_msg void OnMenuWndAlarm();
    afx_msg void OnUpdateMenuWndAlarm(CCmdUI* pCmdUI);
    afx_msg void OnMenuFileExit();
    afx_msg void OnUpdateMenuFileExit(CCmdUI* pCmdUI);
    afx_msg void OnMenuTestMessageSet();
@@ -99,7 +88,6 @@
    afx_msg void OnUpdateMenuTestMessageClear(CCmdUI* pCmdUI);
    afx_msg void OnMenuHelpAbout();
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnBnClickedButtonAlarm();
    afx_msg LRESULT OnPanelResize(WPARAM wParam, LPARAM lParam);
    afx_msg void OnTabSelChanged(NMHDR* nmhdr, LRESULT* result);
};
SourceCode/Bond/Servo/TerminalDisplayDlg.cpp
@@ -148,6 +148,10 @@
                            this->m_webviewController = controller;
                            this->m_webviewController->get_CoreWebView2(&this->m_webWiew);
                        }
                        else {
                            OutputDebugString(_T("WebView2 Controller åˆ›å»ºå¤±è´¥ï¼\n"));
                            return E_FAIL;
                        }
                        // Add a few settings for the webview
                        // The demo step is redundant since the values are the default settings
                        wil::com_ptr<ICoreWebView2Settings> settings;