mrDarker
7 天以前 829fe6c6bc33d53fda9c31fd45a37e1df87befff
SourceCode/Bond/Servo/CPageProdOverview.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,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);
}