// DialListMeasuData.cpp : implementation file // #include "stdafx.h" #include "GeoMative.h" #include "DialListDetailInfoData.h" #include "FileOperTools.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDialListDetailInfoData dialog extern int g_UIOffset; extern int g_iUILanguage; extern float tcp_ntohf(float f); extern CGeoMativeApp theApp; extern CString GetMeasuStatusByAlarm(BYTE ucAlarm); CDialListDetailInfoData::CDialListDetailInfoData(CWnd* pParent /*=NULL*/) : CNetRequestDialog(CDialListDetailInfoData::IDD, pParent) { //{{AFX_DATA_INIT(CDialListDetailInfoData) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // m_iMeasuType = 0; m_iSptType = -1; m_strMeasuStatus = _T(""); m_pMeasuStatus = NULL; m_uCurDisplayPage = 0; m_uTotalPage = 0; m_uCurPageTaskNum = 0; m_ucAlram = 0; m_pCtrlTestStatus = NULL; } void CDialListDetailInfoData::DoDataExchange(CDataExchange* pDX) { CNetRequestDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDialListDetailInfoData) DDX_Control(pDX, IDC_LIST_MEASURE, m_listData); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDialListDetailInfoData, CNetRequestDialog) //{{AFX_MSG_MAP(CDialListDetailInfoData) ON_WM_SHOWWINDOW() ON_BN_CLICKED(IDC_BTN_LIST_PRE, OnBtnListPre) ON_BN_CLICKED(IDC_BTN_LIST_NEXT, OnBtnListNext) //}}AFX_MSG_MAP ON_NOTIFY(NM_CLICK, IDC_LIST_MEASURE, &CDialListDetailInfoData::OnNMClickListMeasure) ON_WM_CTLCOLOR() END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDialListDetailInfoData message handlers BOOL CDialListDetailInfoData::OnInitDialog() { CNetRequestDialog::OnInitDialog(); if (LANG_ZHCN == g_iUILanguage) { GetDlgItem(IDC_BTN_LIST_PRE)->SetWindowText(_T("上一页")); GetDlgItem(IDC_BTN_LIST_NEXT)->SetWindowText(_T("下一页")); } // TODO: Add extra initialization here CString strColTitle; int iColIndex = 0; m_listData.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_GRIDLINES); m_listData.InsertColumn(iColIndex++, _T("ID"),LVCFMT_LEFT,50); m_listData.InsertColumn(iColIndex++, _T("A"), LVCFMT_CENTER, 60); m_listData.InsertColumn(iColIndex++, _T("B"), LVCFMT_CENTER, 60); m_listData.InsertColumn(iColIndex++, _T("M"), LVCFMT_CENTER, 60); m_listData.InsertColumn(iColIndex++, _T("N"), LVCFMT_CENTER, 60); m_listData.InsertColumn(iColIndex++, _T("Stack"), LVCFMT_CENTER, 80); m_listData.InsertColumn(iColIndex++, _T("K"), LVCFMT_CENTER, 120); m_listData.InsertColumn(iColIndex++, _T("V(mV)"), LVCFMT_CENTER, 120); m_listData.InsertColumn(iColIndex++, _T("I(mA)"), LVCFMT_CENTER, 120); m_listData.InsertColumn(iColIndex++, _T("R0(Ohm*m)"), LVCFMT_CENTER, 120); m_listData.InsertColumn(iColIndex++, _T("SP(mV)"), LVCFMT_CENTER, 110); m_pCtrlTestStatus = (CStatic*)GetDlgItem(IDC_STATIC_PASS); if (m_pCtrlTestStatus != NULL) { if (LANG_ZHCN == g_iUILanguage) m_pCtrlTestStatus->SetWindowText(_T("测量状态:")); else m_pCtrlTestStatus->SetWindowText(_T("Status: ")); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CDialListDetailInfoData::ShowMeasuStatus(CString strStatus) { m_strMeasuStatus = strStatus; //GetDlgItem(IDC_STATIC_MEASU_SHOW_STATUS)->ShowWindow(SW_SHOW); CWnd* pStatusValue = GetDlgItem(IDC_STATIC_MEASU_SHOW_STATUS); if (pStatusValue != NULL) { CRect rect, dlgRect,staticRect; GetClientRect(&dlgRect); pStatusValue->GetClientRect(&rect); if (m_pCtrlTestStatus != NULL) { rect.left = 0; rect.right = 65; rect.bottom = dlgRect.bottom; rect.top = dlgRect.bottom - 20; m_pCtrlTestStatus->ShowWindow(SW_SHOW); m_pCtrlTestStatus->MoveWindow(&rect); m_pCtrlTestStatus->GetClientRect(&staticRect); } rect.left = staticRect.right +5; rect.right = staticRect.right + 100; pStatusValue->MoveWindow(rect); pStatusValue->SetWindowText(m_strMeasuStatus); } } void CDialListDetailInfoData::EnablePreviousOrNextBtn(bool bEnablePre, bool bEnableNext) { CWnd* pWnd = GetDlgItem(IDC_BTN_LIST_PRE); if (pWnd != NULL) pWnd->EnableWindow(bEnablePre); pWnd = GetDlgItem(IDC_BTN_LIST_NEXT); if (pWnd != NULL) pWnd->EnableWindow(bEnableNext); } void CDialListDetailInfoData::OnShowWindow(BOOL bShow, UINT nStatus) { CNetRequestDialog::OnShowWindow(bShow, nStatus); if (TRUE == bShow) { CRect rect,orgrect; GetClientRect(&rect); orgrect = rect; rect.left += 5; rect.top += 5; rect.right -= 5; rect.bottom -= 35; m_listData.MoveWindow(&rect); CRect ctrRect; GetDlgItem(IDC_BTN_LIST_PRE)->GetClientRect(&ctrRect); GetDlgItem(IDC_BTN_LIST_PRE)->MoveWindow(orgrect.Width()/2-2-ctrRect.Width(), orgrect.bottom-ctrRect.Height(), ctrRect.Width(),ctrRect.Height()); GetDlgItem(IDC_BTN_LIST_NEXT)->MoveWindow(orgrect.Width()/2+2, orgrect.bottom-ctrRect.Height(), ctrRect.Width(),ctrRect.Height()); CRect rcTipsRect; GetDlgItem(IDC_STATIC_PASS)->GetClientRect(&rcTipsRect); rcTipsRect.top = orgrect.bottom - rcTipsRect.Height(); rcTipsRect.bottom = orgrect.bottom; GetDlgItem(IDC_STATIC_PASS)->MoveWindow(&rcTipsRect); GetDlgItem(IDC_STATIC_MEASU_SHOW_STATUS)->ShowWindow(SW_SHOW); GetDlgItem(IDC_STATIC_MEASU_SHOW_STATUS)->SetWindowText(m_strMeasuStatus); CRect rectStatus; rectStatus.bottom = rcTipsRect.bottom; rectStatus.top = rcTipsRect.top; rectStatus.left = rcTipsRect.right + 5; rectStatus.right = orgrect.Width() / 2 - 2 - ctrRect.Width() - 5; GetDlgItem(IDC_STATIC_MEASU_SHOW_STATUS)->MoveWindow(&rectStatus); } // TODO: Add your message handler code here } void CDialListDetailInfoData::OnShowTdData(const std::vector& vtTdData) { if (vtTdData.empty()) { return; } m_listData.DeleteAllItems(); CString strTxt; for (int i = 0; i < vtTdData.size(); i++) { strTxt.Empty(); strTxt.Format(_T("%d"), vtTdData[i].iID); m_listData.InsertItem(i, strTxt); int iColIndex = 1; if (0 == m_iSptType) { strTxt.Empty(); strTxt.Format(_T("%.2f"), vtTdData[i].fA); m_listData.SetItemText(i, iColIndex++, strTxt); strTxt.Empty(); strTxt.Format(_T("%.2f"), vtTdData[i].fB); m_listData.SetItemText(i, iColIndex++, strTxt); strTxt.Empty(); strTxt.Format(_T("%.2f"), vtTdData[i].fX); m_listData.SetItemText(i, iColIndex++, strTxt); strTxt.Empty(); strTxt.Format(_T("%.2f"), vtTdData[i].fY); m_listData.SetItemText(i, iColIndex++, strTxt); } else { strTxt.Empty(); strTxt.Format(_T("%d"), vtTdData[i].iA); m_listData.SetItemText(i, iColIndex++, strTxt); strTxt.Empty(); strTxt.Format(_T("%d"), vtTdData[i].iB); m_listData.SetItemText(i, iColIndex++, strTxt); strTxt.Empty(); strTxt.Format(_T("%d"), vtTdData[i].iM); m_listData.SetItemText(i, iColIndex++, strTxt); strTxt.Empty(); strTxt.Format(_T("%d"), vtTdData[i].iN); m_listData.SetItemText(i, iColIndex++, strTxt); } strTxt.Empty(); strTxt.Format(_T("%d"), vtTdData[i].ucStack); m_listData.SetItemText(i, iColIndex++, strTxt); strTxt.Empty(); strTxt.Format(_T("%.2f"), vtTdData[i].fK); m_listData.SetItemText(i, iColIndex++, strTxt); if (vtTdData[i].ucIsUse != 0) { strTxt.Empty(); strTxt.Format(_T("%.2f"), vtTdData[i].fV); m_listData.SetItemText(i, iColIndex++, strTxt); strTxt.Empty(); strTxt.Format(_T("%.2f"), vtTdData[i].fI); m_listData.SetItemText(i, iColIndex++, strTxt); strTxt.Empty(); strTxt.Format(_T("%.2f"), vtTdData[i].fR0); m_listData.SetItemText(i, iColIndex++, strTxt); strTxt.Empty(); strTxt.Format(_T("%.2f"), vtTdData[i].fSP); m_listData.SetItemText(i, iColIndex++, strTxt); } m_listData.SetItemData(i, vtTdData[i].iID); } } void CDialListDetailInfoData::ShowPage(UINT32 uPage) { if (uPage <= 0 || uPage > m_uTotalPage) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("无效页")); else MessageBoxEx(NULL, _T("Invalid page"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return; } m_uCurDisplayPage = uPage; UINT32 uiStartPoint; UINT32 uiEndPoint; m_uCurPageTaskNum = DISPLAY_PER_PAGE_SIZE; CString strLog; char chStr[2700] = {0}; if (m_stTaskArg.uiTotalNum < m_uCurDisplayPage*DISPLAY_PER_PAGE_SIZE) { uiStartPoint = (m_uCurDisplayPage - 1)*DISPLAY_PER_PAGE_SIZE + 1; uiEndPoint = m_stTaskArg.uiTotalNum; m_uCurPageTaskNum = uiEndPoint - uiStartPoint +1; if (m_uCurDisplayPage == 1)//只有第一页 { EnablePreviousOrNextBtn(false, false); } else { EnablePreviousOrNextBtn(true, false); } strLog.Format(_T("zm:CDialListDetailInfoData::ShowPage() [uiStartPoint=%u, uiEndPoint=%u,m_uCurPageTaskNum=%d]"), uiStartPoint, uiEndPoint, m_uCurPageTaskNum); CFileOperTools::GetInstance()->WriteComLog(strLog); } else { if (m_uCurDisplayPage == 1)//第一页 { EnablePreviousOrNextBtn(false, true); } uiStartPoint = (m_uCurDisplayPage - 1)*DISPLAY_PER_PAGE_SIZE + 1; uiEndPoint = m_uCurDisplayPage*DISPLAY_PER_PAGE_SIZE; strLog.Format(_T("zm:222 startpoint uiStartPoint=%u, uiEndPoint=%u,m_uCurPageTaskNum=%d"), uiStartPoint, uiEndPoint, m_uCurPageTaskNum); CFileOperTools::GetInstance()->WriteComLog(strLog); } memcpy(chStr, m_stTaskArg.ucTaskID, MAX_NAME_LEN * sizeof(BYTE)); UINT32 uiNetStartPoint = htonl(uiStartPoint); //转网络序给云端 UINT32 uiNetEndPoint = htonl(uiEndPoint); memcpy(&chStr[MAX_NAME_LEN * sizeof(BYTE)], &uiNetStartPoint, sizeof(UINT32)); memcpy(&chStr[MAX_NAME_LEN * sizeof(BYTE) + sizeof(UINT32)], &uiNetEndPoint, sizeof(UINT32)); int iSendLen = MAX_NAME_LEN * sizeof(BYTE) + sizeof(UINT32) * 2; int iRevLen = MAX_NAME_LEN*sizeof(BYTE) + sizeof(UINT32) + m_uCurPageTaskNum*(11 * sizeof(float) + 2 * sizeof(BYTE))+1; PostNetRequest(EN_REQ_DOWNLOAD_DATA_INFO, this->m_hWnd, chStr, iSendLen, iRevLen); } void CDialListDetailInfoData::PreNetResponse(WPARAM wParam, LPARAM lParam) { LPRESPONSEPACKET pResponsePacket = (LPRESPONSEPACKET)lParam; if (pResponsePacket == NULL) { ASSERT(pResponsePacket != NULL); return; } switch (pResponsePacket->clsPacketBase.ucCmd) { case EN_REQ_DOWNLOAD_DATA_INFO: { STSynTaskDataRes *ptTaskDataHeader = (STSynTaskDataRes *)pResponsePacket->pData; if (ptTaskDataHeader == NULL) { ASSERT(ptTaskDataHeader != NULL); return; } UINT32 dwPointNum = ntohl(ptTaskDataHeader->dwPointNum); if ((pResponsePacket->wDataLen < 1) || (m_uCurPageTaskNum != dwPointNum)) { /*if (LANG_ZHCN == g_iUILanguage) { AfxMessageBox(_T("查看详细测试数据失败")); } else { AfxMessageBox(_T("Failed to check detail test data")); }*/ CFileOperTools::GetInstance()->WriteComLog(_T("Failed to check detail test data")); return; } //清空列表 m_listData.DeleteAllItems(); STTaskDataRes* ptTaskDataAddress = (STTaskDataRes *)(pResponsePacket->pData + MAX_NAME_LEN * sizeof(BYTE) + sizeof(UINT32)); STTaskDataRes stMeasuBasicData, *ptTaskData; int iColIndex = 0; CString strTemp; for (int i = 0; i < dwPointNum; i++) { iColIndex = 0; ptTaskData = ptTaskDataAddress++; //ptTaskData = (STTaskDataRes *)(pResponsePacket->pData + MAX_NAME_LEN * sizeof(BYTE) + sizeof(UINT32) + i*sizeof(STTaskDataRes)); m_listData.InsertItem(i, _T("")); stMeasuBasicData.dwID = ntohl(ptTaskData->dwID); strTemp.Format(_T("%u"), stMeasuBasicData.dwID); m_listData.SetItemText(i, iColIndex++, strTemp); if (m_iSptType != 1) { stMeasuBasicData.fA = tcp_ntohf(ptTaskData->fA); strTemp.Format(_T("%.2f"), stMeasuBasicData.fA); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fB = tcp_ntohf(ptTaskData->fB); strTemp.Format(_T("%.2f"), stMeasuBasicData.fB); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fM = tcp_ntohf(ptTaskData->fM); strTemp.Format(_T("%.2f"), stMeasuBasicData.fM); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fN = tcp_ntohf(ptTaskData->fN); strTemp.Format(_T("%.2f"), stMeasuBasicData.fN); m_listData.SetItemText(i, iColIndex++, strTemp); } else { stMeasuBasicData.fA = tcp_ntohf(ptTaskData->fA); strTemp.Format(_T("%.f"), stMeasuBasicData.fA); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fB = tcp_ntohf(ptTaskData->fB); strTemp.Format(_T("%.f"), stMeasuBasicData.fB); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fM = tcp_ntohf(ptTaskData->fM); strTemp.Format(_T("%.f"), stMeasuBasicData.fM); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fN = tcp_ntohf(ptTaskData->fN); strTemp.Format(_T("%.f"), stMeasuBasicData.fN); m_listData.SetItemText(i, iColIndex++, strTemp); } stMeasuBasicData.ucStack = ptTaskData->ucStack; strTemp.Format(_T("%d"), stMeasuBasicData.ucStack); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fK = tcp_ntohf(ptTaskData->fK); strTemp.Format(_T("%.2f"), stMeasuBasicData.fK); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fV = tcp_ntohf(ptTaskData->fV); strTemp.Format(_T("%.2f"), stMeasuBasicData.fV); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fI = tcp_ntohf(ptTaskData->fI); strTemp.Format(_T("%.2f"), stMeasuBasicData.fI); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fR0 = tcp_ntohf(ptTaskData->fR0); strTemp.Format(_T("%.2f"), stMeasuBasicData.fR0); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.fSP = tcp_ntohf(ptTaskData->fSP); strTemp.Format(_T("%.2f"), stMeasuBasicData.fSP); m_listData.SetItemText(i, iColIndex++, strTemp); stMeasuBasicData.ucAlram = ptTaskData->ucAlram; m_listData.SetItemData(i, stMeasuBasicData.ucAlram); } break; } default: break; } } void CDialListDetailInfoData::OnBtnListPre() { --m_uCurDisplayPage; CString strLog; strLog.Format(_T("zm:current page=%d"), m_uCurDisplayPage); CFileOperTools::GetInstance()->WriteComLog(strLog); if (m_uCurDisplayPage <= 1) { EnablePreviousOrNextBtn(false, true); } else { EnablePreviousOrNextBtn(true, true); } ShowPage(m_uCurDisplayPage); } void CDialListDetailInfoData::OnBtnListNext() { ++m_uCurDisplayPage; CString strLog; strLog.Format(_T("zm:current page=%d"), m_uCurDisplayPage); CFileOperTools::GetInstance()->WriteComLog(strLog); if (m_uCurDisplayPage >= m_uTotalPage) { EnablePreviousOrNextBtn(true, false); } else { EnablePreviousOrNextBtn(true, true); } ShowPage(m_uCurDisplayPage); } void CDialListDetailInfoData::OnNMClickListMeasure(NMHDR *pNMHDR, LRESULT *pResult) { LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast(pNMHDR); // TODO: 在此添加控件通知处理程序代码 *pResult = 0; BYTE ucAlram = m_listData.GetItemData(pNMItemActivate->iItem); CString strMeasuStaus = _T(""); m_ucAlram = ucAlram; strMeasuStaus.Format(_T("%s"), GetMeasuStatusByAlarm(ucAlram)); ShowMeasuStatus(strMeasuStaus); } HBRUSH CDialListDetailInfoData::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: 在此更改 DC 的任何特性 if (IDC_STATIC_MEASU_SHOW_STATUS == pWnd->GetDlgCtrlID() && m_ucAlram != 0) { pDC->SetTextColor(RGB(255, 0, 0)); } // TODO: 如果默认的不是所需画笔,则返回另一个画笔 return hbr; }