Browse Source

完成上报功能。

JeffWang 2 years ago
parent
commit
8e63fea432

+ 115 - 0
Source/OGCAssistTool/OGCAssistTool/Global.cpp

@@ -9,6 +9,9 @@ using namespace std;
 #pragma comment(lib,"Psapi.lib")
 #include <locale.h>
 #include <io.h>//_access头文件;
+// 获取本机ip地址;
+#include <Iphlpapi.h>  
+#pragma comment(lib,"Iphlpapi.lib") //需要添加Iphlpapi.lib库 
 
 namespace GLOBAL
 {
@@ -1310,4 +1313,116 @@ end:
 		return npt ? 2 : 1;
 	}
 
+	bool InitSocket()
+	{
+		static bool bInit = false;
+		if ( !bInit )
+		{
+			WSADATA wsaData;
+			int nResult;
+			nResult = WSAStartup(MAKEWORD(2,2), &wsaData);
+			// 错误(一般都不可能出现)
+			if (NO_ERROR != nResult)
+			{
+				return false; 
+			}
+
+			bInit = true;
+		}
+
+		return bInit;
+	}
+
+	TString GetHostName()
+	{
+		if ( InitSocket() )
+		{
+			char szHostName[MAX_PATH] = {0};
+			if ( 0 == gethostname(szHostName, MAX_PATH) )
+			{
+#ifdef UNICODE
+				wchar_t szName[MAX_PATH] = {0};
+				if ( -1 != mbstowcs(szName, szHostName, strlen(szHostName)) )
+				{
+					return TString(szName);
+				}				
+#else
+				return TString(szHostName);
+#endif
+			}
+		}
+
+		return TString();
+	}
+
+	TString GetLocalAddress()
+	{
+		int nCardNo = 1;
+		TString strIPAddress;
+		// PIP_ADAPTER_INFO结构体指针存储本机网卡信息 
+		PIP_ADAPTER_INFO pIpAdapterInfo = new IP_ADAPTER_INFO();
+		// 得到结构体大小,用于GetAdaptersInfo参数 
+		unsigned long stSize = sizeof(IP_ADAPTER_INFO);
+		// 调用GetAdaptersInfo函数,填充pIpAdapterInfo指针变量;其中stSize参数既是一个输入量也是一个输出量 
+		int nRel = GetAdaptersInfo(pIpAdapterInfo,&stSize);
+		// 记录网卡数量 
+		int netCardNum = 0;
+		// 记录每张网卡上的IP地址数量 
+		int IPnumPerNetCard = 0;
+		if(ERROR_BUFFER_OVERFLOW == nRel)
+		{
+			// 如果函数返回的是ERROR_BUFFER_OVERFLOW 
+			// 则说明GetAdaptersInfo参数传递的内存空间不够,同时其传出stSize,表示需要的空间大小 
+			// 这也是说明为什么stSize既是一个输入量也是一个输出量 
+			// 释放原来的内存空间 
+			delete pIpAdapterInfo; 
+			// 重新申请内存空间用来存储所有网卡信息 
+			pIpAdapterInfo = (PIP_ADAPTER_INFO)new BYTE[stSize];
+			// 再次调用GetAdaptersInfo函数,填充pIpAdapterInfo指针变量 
+			nRel = GetAdaptersInfo(pIpAdapterInfo,&stSize);
+		}
+
+		PIP_ADAPTER_INFO pIpAdp = pIpAdapterInfo;
+
+		if(ERROR_SUCCESS == nRel)
+		{
+			// 输出网卡信息 
+			// 可能有多网卡,因此通过循环去判断 
+			while (pIpAdapterInfo)
+			{
+				// 可能网卡有多IP,因此通过循环去判断 
+				IP_ADDR_STRING*pIpAddrString = &(pIpAdapterInfo->IpAddressList);
+				if ( pIpAdapterInfo->Type == MIB_IF_TYPE_ETHERNET || pIpAdapterInfo->Type == IF_TYPE_IEEE80211 )
+				{
+					if(std::string("0.0.0.0") == pIpAddrString->IpAddress.String)
+					{
+						pIpAdapterInfo = pIpAdapterInfo->Next;
+						continue;
+					}
+#ifdef UNICODE
+					wchar_t szName[MAX_PATH] = {0};
+					if ( -1 != mbstowcs(szName, pIpAddrString->IpAddress.String, strlen(pIpAddrString->IpAddress.String)) )
+					{
+						strIPAddress = szName;
+					}				
+#else
+					strIPAddress = pIpAddrString->IpAddress.String;
+#endif
+					break;
+				}
+				pIpAdapterInfo = pIpAdapterInfo->Next;
+			}
+		}
+		else{
+			strIPAddress = _T("127.0.0.1");
+		}
+
+		// 释放内存空间 
+		if (pIpAdp)
+		{
+			delete pIpAdp;
+		}
+
+		return strIPAddress;
+	}
 };

+ 3 - 0
Source/OGCAssistTool/OGCAssistTool/Global.h

@@ -209,6 +209,9 @@ namespace GLOBAL {
 	int IsDigitString(IN CONST CString& str);
 	int IsDigitStringA(LPCSTR lpString);
 	int IsDigitString(LPTSTR lpString);
+	bool InitSocket();
+	TString GetHostName();
+	TString GetLocalAddress();
 };
 
 #endif

+ 20 - 2
Source/OGCAssistTool/OGCAssistTool/PageDebug.cpp

@@ -444,7 +444,10 @@ DWORD CPageDebug::ThreadGoProc(LPVOID lpParam)
 										// 在线模式,上报结果;
 										if ( !GLOBAL::g_config.nOffline )
 										{
-											m_pDlg->UpLoadTestData(strSN, bRet, _T(""));
+											if ( m_pDlg->UpLoadTestData(strSN, bRet, _T("")) )
+											{
+
+											}
 										}	
 
 										// 更新数据库;
@@ -1016,7 +1019,22 @@ void CPageDebug::UpdateList(std::vector<GLOBAL::RGB_PAT> &vtRGB)
 
 bool CPageDebug::UpLoadTestData(CString strSN, BOOL bResult, CString strErrorMsg)
 {
-	return true;
+	CString strDateTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
+	if ( CMESdb::GetInstance()->UploadTestData(strSN.GetString(), bResult ? _T("PASS") : _T("FAIL"), strDateTime.GetString()) )
+	{
+		// 主机名;
+		TString strHostName = GLOBAL::GetHostName();
+		// IP地址;
+		TString strIPAddress = GLOBAL::GetLocalAddress();
+
+		TString strOutMsg;
+		if ( CMESdb::GetInstance()->Scan(strSN.GetString(), GLOBAL::g_config.szCompanyCode, GLOBAL::g_config.szProcessCode, strHostName, strIPAddress, _T("PE"), _T("PE"), _T(""), strOutMsg))
+		{
+			return true;
+		}
+	}
+	
+	return false;
 }
 
 void CPageDebug::OnNMCustomdrawDebugData(NMHDR *pNMHDR, LRESULT *pResult)