1. 添加生产履历的报表的界面,并且绑定生产履历的报表管理器
| | |
| | | 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) { |
| | |
| | | |
| | | // éåæ°æ®å¹¶æå
¥å°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); |
| | | } |
| | | |
| | | // è·ååæ° |
| | |
| | | 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) { |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // 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::LoadAlarms() |
| | | { |
| | | // å·æ°å岿¥è¦æ°æ® |
| | | m_nCurPage = 1; |
| | | UpdatePageData(); |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | int nRow = pListCtrl->GetItemCount(); |
| | | CString str; |
| | | |
| | | str.Format(_T("%d"), step.nStepId); pListCtrl->InsertItem(nRow, str); |
| | | pListCtrl->SetItemText(nRow, 1, step.strProductId.c_str()); |
| | | pListCtrl->SetItemText(nRow, 2, step.strBatchNo.c_str()); |
| | | str.Format(_T("%d"), step.nDeviceId); pListCtrl->SetItemText(nRow, 3, str); |
| | | pListCtrl->SetItemText(nRow, 4, step.strOperator.c_str()); |
| | | pListCtrl->SetItemText(nRow, 5, step.strStartTime.c_str()); |
| | | pListCtrl->SetItemText(nRow, 6, step.strEndTime.c_str()); |
| | | str.Format(_T("%d"), step.nYield); pListCtrl->SetItemText(nRow, 7, str); |
| | | str.Format(_T("%d"), step.nGoodCount); pListCtrl->SetItemText(nRow, 8, str); |
| | | str.Format(_T("%d"), step.nBadCount); pListCtrl->SetItemText(nRow, 9, str); |
| | | pListCtrl->SetItemText(nRow, 10, 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[11] = { 60, 100, 100, 70, 100, 140, 140, 60, 60, 60, 80 }; |
| | | for (int i = 0; i < 11; ++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("æ¥éª¤ID"), LVCFMT_LEFT, width[0]); |
| | | pListCtrl->InsertColumn(1, _T("产åID"), LVCFMT_LEFT, width[1]); |
| | | pListCtrl->InsertColumn(2, _T("æ¹æ¬¡å·"), LVCFMT_LEFT, width[2]); |
| | | pListCtrl->InsertColumn(3, _T("设å¤ID"), LVCFMT_LEFT, width[3]); |
| | | pListCtrl->InsertColumn(4, _T("æä½å"), 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]); |
| | | |
| | | // åå§ååé¡µæ°æ® |
| | | 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(); // è°ç¨åé¡µæ´æ°å½æ° |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #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 LoadAlarms(); |
| | | 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() |
| | | }; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #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; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #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 |
| | |
| | | AfxMessageBox(errorMsg, MB_ICONERROR); |
| | | return FALSE; |
| | | } |
| | | ProductionLogManager::getInstance().insertMockData(); |
| | | |
| | | |
| | | // åå§åSECSè¿è¡è®¾ç½®ç®¡çåº |
| | |
| | | <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" /> |
| | |
| | | <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="CEqReadIntStep.cpp" /> |
| | | <ClCompile Include="CEqCassetteTransferStateStep.cpp" /> |
| | | <ClCompile Include="ProductionLogManager.cpp" /> |
| | | <ClCompile Include="ProductionLogDlg.cpp" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClInclude Include="AlarmManager.h" /> |
| | |
| | | <ClInclude Include="CEqReadIntStep.h" /> |
| | | <ClInclude Include="CEqCassetteTransferStateStep.h" /> |
| | | <ClInclude Include="ProductionLogManager.h" /> |
| | | <ClInclude Include="ProductionLogDlg.h" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ResourceCompile Include="Servo.rc" /> |