// DialListMeasuGR.cpp : implementation file // #include "stdafx.h" #include "geomative.h" #include "DialListDetailInfoGR.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDialListDetailInfoGR dialog extern int g_iUILanguage; extern CGeoMativeApp theApp; extern CString GetGrCodeText(int iCode); CDialListDetailInfoGR::CDialListDetailInfoGR(CWnd* pParent /*=NULL*/) : CNetRequestDialog(CDialListDetailInfoGR::IDD, pParent) { //{{AFX_DATA_INIT(CDialListDetailInfoGR) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_iSptType = -1; } void CDialListDetailInfoGR::DoDataExchange(CDataExchange* pDX) { CNetRequestDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDialListDetailInfoGR) DDX_Control(pDX, IDC_LIST_GR, m_listData); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDialListDetailInfoGR, CNetRequestDialog) //{{AFX_MSG_MAP(CDialListDetailInfoGR) ON_WM_SHOWWINDOW() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDialListDetailInfoGR message handlers BOOL CDialListDetailInfoGR::OnInitDialog() { CNetRequestDialog::OnInitDialog(); // 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,100); // strColTitle.Empty(); // strColTitle.LoadString(IDS_MEASU_GR_P1+g_UIOffset); m_listData.InsertColumn(iColIndex++, _T("P1(Ω)"), LVCFMT_CENTER, 190); // strColTitle.Empty(); // strColTitle.LoadString(IDS_MEASU_GR_STATUS+g_UIOffset); m_listData.InsertColumn(iColIndex++, _T("Status"), LVCFMT_CENTER, 190); // strColTitle.Empty(); // strColTitle.LoadString(IDS_MEASU_GR_P2+g_UIOffset); m_listData.InsertColumn(iColIndex++, _T("P2(Ω)"), LVCFMT_CENTER, 190); // strColTitle.Empty(); // strColTitle.LoadString(IDS_MEASU_GR_STATUS+g_UIOffset); m_listData.InsertColumn(iColIndex++, _T("Status"), LVCFMT_CENTER, 190); InitiShowGR(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CDialListDetailInfoGR::InitiShowGR() { if (0 == m_iSptType) { m_listData.InsertItem(0, _T("AB")); if (0 == theApp.m_ucIsMultiChannel ) m_listData.InsertItem(1, _T("MN")); } } void CDialListDetailInfoGR::OnShowWindow(BOOL bShow, UINT nStatus) { CNetRequestDialog::OnShowWindow(bShow, nStatus); // TODO: Add your message handler code here if (TRUE == bShow) { CRect rect; GetClientRect(&rect); rect.left += 5; rect.top += 5; rect.right -= 5; rect.bottom -= 5; m_listData.MoveWindow(&rect); } } void CDialListDetailInfoGR::GetGRRequest(STRemTaskArg stTaskArg) { m_stTaskArg = stTaskArg; char chStr[210] = {0}; memcpy(chStr, &stTaskArg.ucTaskID, MAX_NAME_LEN* sizeof(BYTE)); UINT32 uiStartElec = htonl(stTaskArg.uiStartElec); //转网络字节序给云端 UINT32 uiEndElec = htonl(stTaskArg.uiEndElec); memcpy(&chStr[MAX_NAME_LEN* sizeof(BYTE)], &uiStartElec, sizeof(UINT32)); memcpy(&chStr[MAX_NAME_LEN* sizeof(BYTE) + sizeof(UINT32)], &uiEndElec, sizeof(UINT32)); int iSendLen = MAX_NAME_LEN * sizeof(BYTE) + 2 * sizeof(UINT32); PostNetRequest(EN_REQ_DOWNLOAD_RG_INFO, this->m_hWnd, chStr, iSendLen, MAX_RECV_ELOC_SIZE); } void CDialListDetailInfoGR::PreNetResponse(WPARAM wParam, LPARAM lParam) { LPRESPONSEPACKET pResponsePacket = (LPRESPONSEPACKET)lParam; if (pResponsePacket == NULL) { return; } switch (pResponsePacket->clsPacketBase.ucCmd) { case EN_REQ_DOWNLOAD_RG_INFO: { if ((pResponsePacket->wDataLen < 0)) { if (LANG_ZHCN == g_iUILanguage) { AfxMessageBox(_T("查看接地电阻数据失败")); } else { MessageBoxEx(NULL, _T("Failed to check ground resistance data"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return; } INT32* pTotalElec = (INT32*)(&pResponsePacket->pData[MAX_NAME_LEN]); INT32 iTotalElec = ntohl(*pTotalElec); char chMsgSyn[MAX_RECV_ELOC_SIZE] = { 0 }; memcpy(chMsgSyn, pResponsePacket->pData, pResponsePacket->wDataLen); INT32 iElecID = 0; CString strEcode; CString strOMVal; CString strStatus; CString strOMVal1; CString strStatus1; STMeasuSigGRResult* pGrInfo = NULL; int iOMVal = -1, iOMVal1 = -1; COLORREF color = RGB(0, 0, 0); for (int iIndex = 0; iIndex < iTotalElec; iIndex++) { strOMVal.Empty(); strStatus.Empty(); strOMVal1.Empty(); strStatus1.Empty(); pGrInfo = (STMeasuSigGRResult*)(&pResponsePacket->pData[MAX_NAME_LEN + sizeof(INT32) + iIndex*sizeof(STMeasuSigGRResult)]); //pGrInfo = (STMeasuSigGRResult*)(pResponsePacket->pData[1] + iIndex); if (0 == m_stTaskArg.stMeasuArg.ucSptType) iElecID = (INT32)pGrInfo->ucElecID; else iElecID = (INT32)pGrInfo->ucElecID; strEcode.Format(_T("%d"), ntohl(iElecID)); iOMVal = (int)(ntohl(pGrInfo->iP1)); iOMVal1 = (int)(ntohl(pGrInfo->iP2)); if (-1 != iOMVal) { strOMVal.Format(_T("%d"), iOMVal); strStatus = GetGrCodeText(pGrInfo->ucP1Status); } if (-1 != iOMVal1) { strOMVal1.Format(_T("%d"), iOMVal1); strStatus1 = GetGrCodeText(pGrInfo->ucP2Status); } m_listData.InsertItem(iIndex, strEcode); m_listData.SetItemText(iIndex, 0, strEcode); m_listData.SetItemText(iIndex, 1, strOMVal); if (!strOMVal.IsEmpty()) { switch (pGrInfo->ucP1Status) { case 1://短路 case 2://开路 m_listData.SetItemTextColor(2, iIndex, RGB(255, 0, 0)); break; case 3://过大 m_listData.SetItemTextColor(2, iIndex, RGB(0, 0, 255)); break; default: m_listData.UpdateItemTextColor(2, iIndex, color); break; } } m_listData.SetItemText(iIndex, 2, strStatus); m_listData.SetItemText(iIndex, 3, strOMVal1); if (!strOMVal1.IsEmpty()) { switch (pGrInfo->ucP2Status) { case 1://短路 case 2://开路 m_listData.SetItemTextColor(4, iIndex, RGB(255, 0, 0)); break; case 3://过大 m_listData.SetItemTextColor(4, iIndex, RGB(0, 0, 255)); break; default: m_listData.UpdateItemTextColor(4, iIndex, color); break; } } m_listData.SetItemText(iIndex, 4, strStatus1); } } break; default: break; } }