chenluhua1980
2026-01-10 9198ac12e4e2ff64a2cf65c32d576f02d54c346a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// CPageProOverview.cpp: 实现文件
//
 
#include "stdafx.h"
#include "Servo.h"
#include "CPageProdOverview.h"
#include "afxdialogex.h"
#include "CPanelProduction.h"
 
namespace
{
    constexpr UINT_PTR kTimerRefreshId = 2001;
    constexpr UINT kTimerRefreshIntervalMs = 10000;
}
 
IMPLEMENT_DYNAMIC(CPageProdOverview, CDialogEx)
 
CPageProdOverview::CPageProdOverview(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_PROD_OVERVIEW, pParent)
    , m_clrBackground(RGB(240, 240, 240))
{
}
 
CPageProdOverview::~CPageProdOverview()
{
}
 
void CPageProdOverview::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
 
void CPageProdOverview::SetBackgroundColor(COLORREF color)
{
    m_clrBackground = color;
    m_brushBackground.DeleteObject();
    m_brushBackground.CreateSolidBrush(m_clrBackground);
    if (::IsWindow(m_hWnd)) {
        Invalidate();
    }
}
 
BEGIN_MESSAGE_MAP(CPageProdOverview, CDialogEx)
    ON_WM_CTLCOLOR()
    ON_WM_DESTROY()
    ON_WM_SIZE()
    ON_WM_TIMER()
END_MESSAGE_MAP()
 
BOOL CPageProdOverview::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
 
    // 使用自定义标签
    if (CWnd* pDay = GetDlgItem(IDC_PROD_DAY_OUTPUT)) {
        m_labelDayOut.SubclassWindow(pDay->GetSafeHwnd());
        m_labelDayOut.setFontSize(28);
        m_labelDayOut.setNoteTextColor(RGB(128, 128, 128));
        m_labelDayOut.setNote1(_T("白班产出"));
        m_labelDayOut.setBackground(m_clrBackground);
        m_labelDayOut.setForeground(RGB(18, 18, 18), TRUE);
    }
    if (CWnd* pNight = GetDlgItem(IDC_PROD_NIGHT_OUTPUT)) {
        m_labelNightOut.SubclassWindow(pNight->GetSafeHwnd());
        m_labelNightOut.setFontSize(28);
        m_labelNightOut.setNoteTextColor(RGB(128, 128, 128));
        m_labelNightOut.setNote1(_T("夜班产出"));
        m_labelNightOut.setBackground(m_clrBackground);
        m_labelNightOut.setForeground(RGB(18, 18, 18), TRUE);
    }
    if (CWnd* pDayTakt = GetDlgItem(IDC_PROD_DAY_TAKT)) {
        m_labelDayTakt.SubclassWindow(pDayTakt->GetSafeHwnd());
        m_labelDayTakt.setFontSize(28);
        m_labelDayTakt.setNoteTextColor(RGB(128, 128, 128));
        m_labelDayTakt.setNote1(_T("白班平均TT"));
        m_labelDayTakt.setBackground(m_clrBackground);
        m_labelDayTakt.setForeground(RGB(18, 18, 18), TRUE);
    }
    if (CWnd* pNightTakt = GetDlgItem(IDC_PROD_NIGHT_TAKT)) {
        m_labelNightTakt.SubclassWindow(pNightTakt->GetSafeHwnd());
        m_labelNightTakt.setFontSize(28);
        m_labelNightTakt.setNoteTextColor(RGB(128, 128, 128));
        m_labelNightTakt.setNote1(_T("夜班平均TT"));
        m_labelNightTakt.setBackground(m_clrBackground);
        m_labelNightTakt.setForeground(RGB(18, 18, 18), TRUE);
    }
 
    RefreshData();
    m_timerId = SetTimer(kTimerRefreshId, kTimerRefreshIntervalMs, nullptr);
    return TRUE;
}
 
HBRUSH CPageProdOverview::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
 
    if (nCtlColor == CTLCOLOR_DLG || nCtlColor == CTLCOLOR_STATIC) {
        if (m_brushBackground.GetSafeHandle() == NULL) {
            m_brushBackground.CreateSolidBrush(m_clrBackground);
        }
        pDC->SetBkMode(TRANSPARENT);
        return (HBRUSH)m_brushBackground.GetSafeHandle();
    }
 
    return hbr;
}
 
void CPageProdOverview::OnDestroy()
{
    if (m_timerId != 0) {
        KillTimer(m_timerId);
        m_timerId = 0;
    }
    CDialogEx::OnDestroy();
}
 
void CPageProdOverview::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
}
 
void CPageProdOverview::OnTimer(UINT_PTR nIDEvent)
{
    if (nIDEvent == kTimerRefreshId) {
        RefreshData();
    }
    CDialogEx::OnTimer(nIDEvent);
}
 
void CPageProdOverview::RefreshData()
{
    auto* pPanel = dynamic_cast<CPanelProduction*>(GetParent());
    if (pPanel == nullptr) {
        pPanel = dynamic_cast<CPanelProduction*>(GetParent() ? GetParent()->GetParent() : nullptr);
    }
    if (pPanel == nullptr) {
        m_labelDayOut.setText(_T("--"));
        m_labelNightOut.setText(_T("--"));
        m_labelDayTakt.setText(_T("--"));
        m_labelNightTakt.setText(_T("--"));
        return;
    }
 
    ProductionShiftSummary day;
    ProductionShiftSummary night;
    if (!pPanel->TryGetDayNightSummaries(day, night)) {
        m_labelDayOut.setText(_T("--"));
        m_labelNightOut.setText(_T("--"));
        m_labelDayTakt.setText(_T("--"));
        m_labelNightTakt.setText(_T("--"));
        return;
    }
 
    CString text;
    text.Format(_T("%lld"), day.output.pairsTotal);
    m_labelDayOut.setText(text);
    text.Format(_T("%lld"), night.output.pairsTotal);
    m_labelNightOut.setText(text);
 
    text.Format(_T("%.1fs"), day.output.avgTaktSeconds);
    m_labelDayTakt.setText(text);
    text.Format(_T("%.1fs"), night.output.avgTaktSeconds);
    m_labelNightTakt.setText(text);
}