Files
coco df489d5640 a
2026-07-03 16:05:30 +08:00

2362 lines
71 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "GeoMative.h"
#include "Constant.h"
#include "MainFrm.h"
#include "scheduler.h"
#include "devmngframe.h"
#include "datamngframe.h"
#include "sptmngframe.h"
#include "ExecOperator.h"
#include "SynOperator.h"
#include "OLSynOperato.h"
#include "DevLinkRecord.h"
#include "SComPort.h"
#include "checkupdate.h"
#include "Markup.h"
#include "opexec2drsptestsetdlg.h"
#include "opexec2drsptestdlg.h"
#include "Splash.h"
#include "LicenseUpgrade.h"
#include "PasswordMng.h"
#include "DetcGD10Dev.h"
#include "DialFindComShow.h"
#include "FileOperTools.h"
#include <WinUser.h>
#include <Windows.h>
#include <Dbt.h>
#include "DialUpgDeviceInfo.h"
#include "CtrlProtocolDef.h"
#include "httpClient/http_client.h"
#include "logging/CDialogLoggingTestMainWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CString g_szMacAddress;
extern BOOL g_bCancelCopyFile;
extern int g_iUILanguage;
extern int g_UIOffset;
#define MODULE_NAME "CMainFrame"
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
extern HHOOK hHook;
extern LRESULT __stdcall CBTHookProc(long nCode, WPARAM wParam, LPARAM lParam);
extern unsigned char DeviceEnumCommPort();
extern int g_iTransFileMode;
extern int g_UIOffset;
extern char* G2U(const char* gb2312);
extern CString g_strUSBDevSN;
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(IDM_MNG_DATA_WIN, OnMngDataWin)
ON_COMMAND(IDM_MNG_EXEC_WIN, OnMngExecWin)
ON_COMMAND(IDM_MNG_DEV_WIN, OnMngDevWin)
ON_MESSAGE(WM_SCHEDULE, OnSchedule)
ON_MESSAGE(WM_REFRESH, OnRefresh)
ON_MESSAGE(WM_NEWLINK, OnNewLink)
ON_MESSAGE(WM_BREAKLINE, OnBreakLine)
ON_MESSAGE(WM_UPG_GEOMATIVE, OnUpgGeomative)
ON_MESSAGE(WM_CHANGE_LANGUAGE, OnChangeLanguage)
ON_MESSAGE(WM_NET_RESPONSE, PreNetResponse)
ON_COMMAND(IDM_FILE_EXP, OnFileExp)
ON_COMMAND(IDM_FILE_IMP, OnFileImp)
ON_COMMAND(IDM_TEST_2DRSP_WIN, OnTestrspWin)
ON_COMMAND(IDM_SYN_WIN, OnSynWin)
ON_COMMAND(IDM_LOGGING_TEST, OnLoggingTest)
ON_COMMAND(IDM_SET_LINK_USB, OnSetLinkUsb)
ON_COMMAND(IDM_SET_LINK_BLUETOOTH, OnSetLinkBluetooth)
ON_COMMAND(IDM_HELP_UPG, OnHelpUpg)
ON_MESSAGE(WM_CLOSE, CloseWindows)
ON_MESSAGE(WM_DETECT_LINE, DetectLine)
ON_COMMAND(IDM_LICENSE_UPG, OnLicenseUpg)
ON_COMMAND(IDM_PASSWORD_MANAGE, OnPasswordManage)
ON_COMMAND(IDM_GEOMATIVE_WEB, OnShowGeoWebsite)
ON_MESSAGE(WM_SHOW_DEV_UPG_INFO, OnShowUpgInfo)
ON_MESSAGE(WM_CLEAR_DEV_UPG_INFO, OnClearUpgInfo)
ON_COMMAND(IDM_CHG_CHINESE, OnChangeChinese)
ON_COMMAND(IDM_CHG_ENGLISH, OnChangeEnglish)
ON_WM_DEVICECHANGE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
ON_NOTIFY_EX(TTN_NEEDTEXT,0,OnToolTipText)
ON_MESSAGE(WM_MSG_NOTIFY_DEVICE_ON_OR_OFF, OnMsgNotifyDeviceOnOrOff)
ON_MESSAGE(WM_MSG_REFRESH_MAIN_MAIN_MENU, OnRefreshMainWndMenu)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
extern CGeoMativeApp theApp;
extern int g_iTransMode;
extern CRITICAL_SECTION g_ScanTabSection;
extern CDevLinkRecord* aDevLinkTable[256];
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_pDataMngFrm = NULL;
m_pDevMngFrm = NULL;
m_pSptMngFrm = NULL;
m_pScheduler = new CScheduler(this);
m_bAutoMenuEnable = false;
m_bIsShowUpgText = true;
m_pUpgDevInfo = NULL;
}
CMainFrame::~CMainFrame()
{
delete m_pScheduler;
OnClearUpgInfo(0,0);
}
BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,CWnd* pParentWnd, CCreateContext* pContext)
{
CMDIFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
HWND hWnd = this->m_hWnd;
//::SetTimer(theApp.m_pMainWnd->GetSafeHwnd(), ID_TIMER_HEARTBEAT_PACKET, HEARTBEAT_INTERVAL, NULL);
return TRUE;
}
LRESULT CMainFrame::CloseWindows(WPARAM wParam, LPARAM lParam)
{
int nCode = (int)wParam;
::KillTimer(theApp.m_pMainWnd->GetSafeHwnd(), ID_TIMER_HEARTBEAT_PACKET);
::KillTimer(theApp.m_pMainWnd->GetSafeHwnd(), ID_UPLOAD_DEVICE_MARKET_DATA);
CDevice* pDevice = NULL;
CString szDevSN = _T("");
szDevSN.Empty();
for (int n = 0; n < 256; n++)
{
if (aDevLinkTable[n])
{
pDevice = theApp.m_pDevManager->GetDevice(aDevLinkTable[n]->aDevSN);
if (pDevice != NULL)
{
pDevice->Reset();
pDevice->m_sComPort.CloseComm();
}
}
}
CMainFrame::OnClose();
return 0;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT|TBSTYLE_TOOLTIPS , WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
// CG: The following line was added by the Splash Screen component.
CSplashWnd::ShowSplashScreen(this);
Sleep(750);
theApp.m_ucIsMultiChannel = (EN_CHANNEL_INFO)GetPrivateProfileInt(_T("CHANNEL_INFO"), _T("IsMultiChannel"), EN_MULTI_CHANNEL, _T("./config.ini"));
//在这里首先判断GD10设备是不是已经在了,在程序初始化的时候就要进行判断
UsbRegistNotify();
CDetcGD10Dev::GetInstance()->DetectGD10Dev();
if (CDetcGD10Dev::GetInstance()->IsGD10DevConnect())
{
g_bCancelCopyFile = FALSE;
}
if (EN_TRANSFER_FILE_BY_CLOUND == g_iTransFileMode)
{
OutputDebugString(_T("zm:CMainFrm::OnCreate send 登录请求\n"));
ST_REQUEST_PACKET stLoginRequest;
stLoginRequest.clsPacketBase.ucCmd = EN_CTRL_USER_LOGIN;
stLoginRequest.hWnd = m_hWnd;
stLoginRequest.wDataLen = sizeof(UINT32);
stLoginRequest.pData = new char[stLoginRequest.wDataLen];
stLoginRequest.dwMsgID = WM_NET_RESPONSE;
memcpy(stLoginRequest.pData, (char*)(&theApp.m_uiUserID), stLoginRequest.wDataLen);
theApp.m_NetWorkOper.PutRequestPacket(stLoginRequest);
if (stLoginRequest.pData != NULL)
{
delete[] stLoginRequest.pData;
stLoginRequest.pData = NULL;
}
}
//////////////////////////////////////////////////////////////////////////
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
LRESULT CMainFrame::OnBreakLine(WPARAM wParam, LPARAM lParam)
{
CString szStr = _T("");
szStr.Empty();
szStr.Format(_T("%d"), (int)lParam);
CString szStrCN = _T("");
szStrCN = _T(" 掉线") + szStr + _T(" !");
szStr = _T("Break line") + szStr + _T(" !");
CDevice* pDevice = NULL;
int iTabIndex = (int)lParam;
CString szDevSN = _T("");
szDevSN.Empty();
szDevSN = aDevLinkTable[iTabIndex]->aDevSN;
pDevice = theApp.m_pDevManager->GetDevice(szDevSN);
if (NULL == pDevice)
{
CString strTmp = _T("");
strTmp.Format(_T("Parser offline device errorm. com_port_index = %d, SN = %s"), iTabIndex, szDevSN);
CFileOperTools::GetInstance()->WriteComLog(strTmp);
AfxMessageBox(strTmp);
}
else
{
pDevice->m_sComPort.CloseComm();
if (PZ_STATE_NEW == pDevice->m_uState)
{
theApp.m_pDevManager->DeleteObjInMem(szDevSN);
}
else
{
try
{
pDevice->DelSynInfo();
pDevice->DelGRInfo();
}
catch(_com_error e)
{
return 0;
}
pDevice->m_uState = PZ_STATE_OFFLINE;
}
}
EnterCriticalSection(&g_ScanTabSection);
if (aDevLinkTable[iTabIndex])
{
delete aDevLinkTable[iTabIndex];
aDevLinkTable[iTabIndex] = NULL;
}
LeaveCriticalSection(&g_ScanTabSection);
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (LANG_ZHCN == g_iUILanguage)
MessageBox(szStrCN);
else
MessageBox(szStr);
//如果判断当前设备管理框架出于激活状态,那么则进行刷新
if (NULL != m_pDevMngFrm)
{
if (m_pDevMngFrm->IsActiveMDIWindow())
{
m_pDevMngFrm->SendMessage(WM_REFRESH_NAV_DEVICE,(WPARAM)0, (LPARAM)0);
}
}
return 0;
}
LRESULT CMainFrame::OnNewLink(WPARAM wParam, LPARAM lParam)
{
// char aSend[16] = "Hello aaa!";
char aSend[16] = {0};
CDevLinkRecord* pDevLinkRecord = (CDevLinkRecord*)wParam;
CDevice* pDevice = NULL;
int iComID = (int)lParam;
CString szDevSN = _T("");
CString szDevName = _T("");
CString szDevModelNO = _T("");
CString szDevCom = _T("");
szDevSN.Empty();
szDevSN.Format(_T("%s"), pDevLinkRecord->aDevSN);
szDevSN.TrimRight(0x0d);
szDevName.Empty();
szDevName.Format(_T("%s"), pDevLinkRecord->aDevName);
szDevName.TrimRight(0x0d);
szDevModelNO.Empty();
szDevModelNO.Format(_T("%s"), pDevLinkRecord->aDevModelNO);
szDevModelNO.TrimRight(0x0d);
szDevCom.Empty();
szDevCom = pDevLinkRecord->aDevCom;
bool bIsRegDevice = false;
pDevice = theApp.m_pDevManager->GetRegisterDevice(szDevSN, bIsRegDevice);
if (NULL == pDevice)
{
//如果已经注册了,并且还没获取到设备信息,
//说明此时数据库的MAC信息和本机的MAC信息存在偏差,将数据库的设备删除
if (bIsRegDevice)
{
int nRet = 0;
CString strTip = _T("");
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (LANG_ZHCN == g_iUILanguage)
{
strTip = _T("系统环境发生变化,如果点击是按钮,设备将会需要重新注册. ");
nRet = AfxMessageBox(strTip, MB_YESNO);
}
else
{
strTip = _T("The operation system environment has been changed,\r\nthis device would needed to registration if you click yes! ");
nRet = MessageBoxEx(NULL, strTip, STRING_MESSAGEBOXEX_TITLE, MB_YESNO, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
if (IDYES != nRet)
{
PostQuitMessage(0);
return 0;
}
if (!theApp.m_pDevManager->DeleteDevice(szDevSN))
{
PostQuitMessage(0);
return 0;
}
//此时操作删除成功,则需要重新获取设备信息
theApp.m_pDevManager->InitialDevLinkList();
}
theApp.m_pDevManager->AddObjInMem(szDevSN);
pDevice = theApp.m_pDevManager->GetDevice(szDevSN);
if (pDevice == NULL)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("不能获取设备信息"));
else
MessageBoxEx(NULL, _T("Can't get device information!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
PostQuitMessage(0);
return 0;
}
pDevice->m_szDevName = szDevName;
pDevice->m_szModelNO = szDevModelNO;
pDevice->m_pConnection = theApp.m_pConnection;
pDevice->m_uState = PZ_STATE_NEW;
}
else
{
pDevice->m_uState = PZ_STATE_ONLINE;
}
// TRACE("aDevCom = %s\n", pDevLinkRecord->aDevCom);
// TRACE("iComID = %d\n", iComID);
/*pDevice->m_sComPort.SetOwnerWnd(this->m_hWnd);
pDevice->m_sComPort.SetCommID(iComID);
pDevice->m_sComPort.OpenComm(szDevCom);
pDevice->m_sComPort.ClearCommReceiveBuff();
pDevice->m_sComPort.ClearCommSendBuff();
if (!pDevice->LockDevice())
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("设备正在测试,连接失败."));
else
MessageBoxEx(NULL, _T("Device is testing now, Connect failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
pDevice->m_sComPort.CloseComm();
if (PZ_STATE_NEW == pDevice->m_uState)
{
theApp.m_pDevManager->DeleteObjInMem(szDevSN);
}
else
{
pDevice->DelSynInfo();
pDevice->DelGRInfo();
pDevice->m_uState = PZ_STATE_OFFLINE;
}
return 0;
}*/
/////////////////////////////added by lsq 20160427/////////////////////////////////////////////
//在这里加这段代码主要是为了防止发现串口和USB时间不同步引起的问题,所以在发现串口之后,
//最多再等30秒来USB连接上来
// if (EN_TRANSFER_FILE_BY_USB == g_iTransFileMode)
// {
// int iWaitCnt = 100;
// while (iWaitCnt > 0)
// {
// if (CDetcGD10Dev::GetInstance()->IsGD10DevConnect())
// {
// break;
// }
// Sleep(500);
// iWaitCnt--;
// }
// //此时没有找到,说明还没发现USB设备,此时将导致不同步,告警
// if (iWaitCnt <= 0)
// {
// AfxMessageBox(_T("Get gd10 connect information failed,please restart device!"));
// PostQuitMessage(0);
// return;
// }
//
// }
//////////////////////////////////////////////////////////////////////////
CString szCaption = _T("");
szCaption.Empty();
if (EN_MULTI_CHANNEL == theApp.m_ucIsMultiChannel)
{
if (LANG_ZHCN == g_iUILanguage)
szCaption.Format(_T("在%s上发现了GD-20设备"), szDevCom);
else
szCaption.Format(_T("Found GD-20 device on %s!"), szDevCom);
}
else
{
if (LANG_ZHCN == g_iUILanguage)
szCaption.Format(_T("在%s上发现了GD-10设备"), szDevCom);
else
szCaption.Format(_T("Found GD-10 device on %s!"), szDevCom);
}
CDialFindComShow dialFindCom;
dialFindCom.SetShowText(szCaption);
dialFindCom.DoModal();
// hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
// MessageBox(szCaption);
//added by lsq 20160823
//在这里加入自动注册的功能
if (PZ_STATE_NEW == pDevice->m_uState)
{
if (TRUE == pDevice->Register())
{
theApp.m_pDevManager->AddDevice(pDevice);
pDevice->DelSynInfo();
pDevice->DelGRInfo();
if (pDevice->GetSynInfo() == TRUE)
{
pDevice->m_uState = PZ_STATE_ONLINE;
}
else
{
pDevice->m_uState = PZ_STATE_OFFLINE;
}
}
else
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("注册失败."));
else
MessageBoxEx(NULL, _T("Register failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
pDevice->m_uState = PZ_STATE_OFFLINE;
}
}
if (PZ_STATE_ONLINE == pDevice->m_uState)
{
// NULL; //从设备上载设备信息文件以及各个列表文件
// GetFileFromHost(pDevice);
try
{
pDevice->DelSynInfo();
pDevice->DelGRInfo();
if (pDevice->GetSynInfo() != TRUE)
{
pDevice->m_uState = PZ_STATE_OFFLINE;
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("请重启设备."));
else
MessageBoxEx(NULL, _T("Please restart device"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
PostQuitMessage(0);
return 0;
}
//如果判断当前设备管理框架出于激活状态,那么则进行刷新
if (NULL != m_pDevMngFrm)
{
if (m_pDevMngFrm->IsActiveMDIWindow())
{
m_pDevMngFrm->SendMessage(WM_REFRESH_NAV_DEVICE,(WPARAM)0, (LPARAM)0);
}
}
}
catch (_com_error e)
{
PostQuitMessage(0);
return 0;
}
}
else if(PZ_STATE_NEW == pDevice->m_uState)
{
//如果判断当前设备管理框架出于激活状态,那么则进行刷新
if (NULL != m_pDevMngFrm)
{
if (m_pDevMngFrm->IsActiveMDIWindow())
{
m_pDevMngFrm->SendMessage(WM_REFRESH_NAV_DEVICE,(WPARAM)0, (LPARAM)0);
}
}
}
return 0;
}
LRESULT CMainFrame::OnSchedule(WPARAM wParam, LPARAM lParam)
{
m_pScheduler->Execute((UINT)wParam, (UINT)lParam);
m_wndToolBar.Invalidate();
ShowControlBar(&m_wndToolBar, TRUE, FALSE);
return 0;
}
LRESULT CMainFrame::OnRefresh(WPARAM wParam, LPARAM lParam)
{
switch ((UINT)wParam)
{
case OP_TD_SYN:
case OP_FILE_IMP:
if (NULL != this->m_pDataMngFrm)
{
::SendMessage(m_pDataMngFrm->m_hWnd, WM_REFRESH, (WPARAM)OP_FILE_IMP, (LPARAM)VAL_ZERO);
}
break;
case OP_SPT_SYN:
if (NULL != this->m_pSptMngFrm)
{
::SendMessage(m_pSptMngFrm->m_hWnd, WM_REFRESH, (WPARAM)OP_SPT_SYN, (LPARAM)VAL_ZERO);
}
break;
case OP_DE_F_D:
if (NULL != this->m_pDataMngFrm)
{
::SendMessage(m_pDataMngFrm->m_hWnd, WM_REFRESH, (WPARAM)OP_DE_F_D, (LPARAM)VAL_ZERO);
}
if (NULL != this->m_pSptMngFrm)
{
::SendMessage(m_pSptMngFrm->m_hWnd, WM_REFRESH, (WPARAM)OP_DE_F_D, (LPARAM)VAL_ZERO);
}
break;
default:
break;
}
return 0;
}
void CMainFrame::OnMngDataWin()
{
// TODO: Add your command handler code here
if (NULL == m_pDataMngFrm)
{
m_pDataMngFrm = (CDataMngFrame*)CreateNewChild(RUNTIME_CLASS(CDataMngFrame), IDR_MAINFRAME);
m_pDataMngFrm->ShowWindow(SW_SHOWMAXIMIZED);
}
else
{
m_pDataMngFrm->ActivateFrame();
}
}
void CMainFrame::OnMngExecWin()
{
// TODO: Add your command handler code here
if (NULL == m_pSptMngFrm)
{
m_pSptMngFrm = (CSptMngFrame*)CreateNewChild(RUNTIME_CLASS(CSptMngFrame), IDR_MAINFRAME);
m_pSptMngFrm->ShowWindow(SW_SHOWMAXIMIZED);
}
else
{
m_pSptMngFrm->ActivateFrame();
}
}
void CMainFrame::OnMngDevWin()
{
// TODO: Add your command handler code here
if (NULL == m_pDevMngFrm)
{
m_pDevMngFrm = (CDevMngFrame*)CreateNewChild(RUNTIME_CLASS(CDevMngFrame), IDR_MAINFRAME);
// if (EN_TRANSFER_FILE_BY_CLOUND == g_iTransFileMode)
// {
// theApp.m_NetWorkOper.RegisterDevNotify(&(CDevMngFrame::NotifyDevInfo), m_pDevMngFrm);
// }
m_pDevMngFrm->ShowWindow(SW_SHOWMAXIMIZED);
}
else
{
m_pDevMngFrm->ActivateFrame();
}
}
CToolBar* CMainFrame::GetToolBar()
{
return &m_wndToolBar;
}
void CMainFrame::OnFileExp()
{
// TODO: Add your command handler code here
CString szCaption;
switch (theApp.m_pIOManager->Export())
{
case APP_SUCCESS:
szCaption.Empty();
szCaption.LoadString(IDS_OP_SUCCESS+g_UIOffset);
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (OFFSET_CHINESE == g_UIOffset)
AfxMessageBox(szCaption, MB_ICONINFORMATION);
else
MessageBoxEx(NULL, szCaption, STRING_MESSAGEBOXEX_TITLE, MB_ICONINFORMATION, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
break;
case APP_ERR_LOC_EXEC:
szCaption.Empty();
szCaption.LoadString(IDS_OP_FAIL+g_UIOffset);
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (OFFSET_CHINESE == g_UIOffset)
AfxMessageBox(szCaption, MB_ICONINFORMATION);
else
MessageBoxEx(NULL, szCaption, STRING_MESSAGEBOXEX_TITLE, MB_ICONINFORMATION, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
break;
case APP_ERR_DB:
szCaption.Empty();
szCaption.LoadString(IDS_OP_FAIL+g_UIOffset);
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (OFFSET_CHINESE == g_UIOffset)
AfxMessageBox(szCaption, MB_ICONINFORMATION);
else
MessageBoxEx(NULL, szCaption, STRING_MESSAGEBOXEX_TITLE, MB_ICONINFORMATION, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
break;
default:
break;
}
}
void CMainFrame::OnFileImp()
{
// TODO: Add your command handler code here
CString szCaption;
switch (theApp.m_pIOManager->Import())
{
case APP_SUCCESS:
::SendMessage(m_hWnd, WM_REFRESH, (WPARAM)OP_FILE_IMP, (LPARAM)VAL_ZERO);
szCaption.Empty();
szCaption.LoadString(IDS_OP_SUCCESS+g_UIOffset);
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (OFFSET_CHINESE == g_UIOffset)
AfxMessageBox(szCaption, MB_ICONINFORMATION);
else
MessageBoxEx(NULL, szCaption, STRING_MESSAGEBOXEX_TITLE, MB_ICONINFORMATION, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
break;
case APP_ERR_LOC_EXEC:
szCaption.Empty();
szCaption.LoadString(IDS_OP_FAIL+g_UIOffset);
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (OFFSET_CHINESE == g_UIOffset)
AfxMessageBox(szCaption, MB_ICONINFORMATION);
else
MessageBoxEx(NULL, szCaption, STRING_MESSAGEBOXEX_TITLE, MB_ICONINFORMATION, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
break;
case APP_ERR_DB:
szCaption.Empty();
szCaption.LoadString(IDS_OP_FAIL+g_UIOffset);
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (OFFSET_CHINESE == g_UIOffset)
AfxMessageBox(szCaption, MB_ICONINFORMATION);
else
MessageBoxEx(NULL, szCaption, STRING_MESSAGEBOXEX_TITLE, MB_ICONINFORMATION, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
break;
default:
break;
}
}
void CMainFrame::OnTestrspWin()
{
// TODO: Add your command handler code here
CExecOperator execOperator(theApp.m_pConnection);
execOperator.ExecRSPTest();
}
void CMainFrame::OnLineSynData()//在线同步data
{
long lRet = VAL_ZERO;
COLSynOperato* pOpSynDlg = new COLSynOperato(theApp.m_pConnection);
pOpSynDlg->Create(IDD_OP_SYN_ONLINE, AfxGetMainWnd());
//InitialSynDlg(pOpSynDlg);
int iIndex = (int)VAL_ZERO;
CPtrArray olDevList;
CDevice* pDev = NULL;
olDevList.RemoveAll();
theApp.m_pDevManager->GetOLDevList(&olDevList);
/*iIndex = (int)VAL_ZERO;
while (iIndex < olDevList.GetSize())
{
pDev = NULL;
pDev = (CDevice*)olDevList.GetAt(iIndex);
if (PZ_STATE_NEW != pDev->m_uState)
{
pOpSynDlg->m_cbDevSN.AddString(pDev->m_szDevSN);
pOpSynDlg->m_cbDevSN.SetItemDataPtr(pOpSynDlg->m_cbDevSN.GetCount() - 1, pDev);
}
iIndex++;
}*/
// 获取远端在线设备
std::set<STSigRemoteDev> setRemoteDev = theApp.m_pDevManager->GetRemoteDeviceInfo();
CString strSN;
int iDevStyle = 0;
iIndex = (int)VAL_ZERO;
std::set<STSigRemoteDev>::iterator iter;
for (iter = setRemoteDev.begin(); iter != setRemoteDev.end(); iter++)
{
strSN.Empty();
if (iter->ucDevType == EN_DEV_GD10)
{
strSN.Format(_T("SN%u"), iter->uiDevID);
//iDevStyle = PZ_STYLE_REMOTE_GD10;
pOpSynDlg->m_cbDevSN.AddString(strSN);
pOpSynDlg->m_cbDevSN.SetItemDataPtr(pOpSynDlg->m_cbDevSN.GetCount() - 1, NULL);
iIndex++;
}
else if (iter->ucDevType == EN_DEV_PLC)
{
pOpSynDlg->m_uiPlcId = iter->uiDevID;
}
}
pOpSynDlg->InitialDevShow();
pOpSynDlg->CenterWindow();
pOpSynDlg->ShowWindow(SW_SHOW);
lRet = pOpSynDlg->RunModalLoop(MLF_SHOWONIDLE); // 开始非模态窗口模态循环
if (RET_OK == lRet)
{
NULL;
}
pOpSynDlg->DestroyWindow();
delete pOpSynDlg;
}
void CMainFrame::OnSynWin()
{
// TODO: Add your command handler code here
if (EN_TRANSFER_FILE_BY_CLOUND == g_iTransFileMode)
{
//在线同步data
//OnLineSynData();
}
else
{
CSynOperator synOperator(theApp.m_pConnection);
synOperator.Syn();
}
}
void CMainFrame::OnLoggingTest()
{
theApp.m_NetWorkOper.UnRegeditRealMsgCall(this->m_hWnd);
CDialogLoggingTestMainWnd dlgLoggingTestMainWnd;
dlgLoggingTestMainWnd.DoModal();
theApp.m_NetWorkOper.RegeditRealMsgCall(this->m_hWnd);
}
void CMainFrame::GetFileFromHost(CDevice *pDevice)
{
char aPath[2048] = {0};
CString szCurFilePath = _T("");
CString szLocFilePath = _T("");
CString szLocFileName = _T("");
CString szHostFilePath = _T("");
CString szHostFileName = _T("");
SHFILEOPSTRUCT shFileOP = {0};
CMarkup xmlDev;
CMarkup xmlPro;
CMarkup xmlTz;
szCurFilePath.Empty();
szCurFilePath.GetBufferSetLength(2048);
::GetCurrentDirectory(szCurFilePath.GetLength(), szCurFilePath.GetBuffer(szCurFilePath.GetLength()));
szCurFilePath.ReleaseBuffer();
szLocFilePath = szCurFilePath + _T("\\") + pDevice->m_szDevSN;
CreateDirectory((LPCTSTR)szLocFilePath, NULL);
if (ERROR_ALREADY_EXISTS == GetLastError())
{
memset(aPath , 0, sizeof(aPath));
strncpy(aPath, (LPCTSTR)szLocFilePath, sizeof(aPath));
shFileOP.hwnd = this->m_hWnd;
shFileOP.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
shFileOP.pFrom = aPath;
shFileOP.pTo = NULL;
shFileOP.wFunc = FO_DELETE;
SHFileOperation(&shFileOP);
CreateDirectory((LPCTSTR)szLocFilePath, NULL);
}
szHostFileName = _T("/SD/users/")+ g_szMacAddress + _T(".xml");
szLocFilePath = szLocFilePath+_T("\\");
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szLocFileName = szLocFilePath+"\\"+ g_szMacAddress + _T(".xml");
xmlDev.Load(szLocFileName);
xmlDev.FindChildElem(_T("user_info"));
xmlDev.IntoElem();
xmlDev.FindChildElem(_T("path_dictionary"));
xmlDev.IntoElem();
szLocFilePath = szCurFilePath+_T("\\")+pDevice->m_szDevSN+_T("\\projects\\");
CreateDirectory((LPCTSTR)szLocFilePath, NULL);
while (xmlDev.FindChildElem(_T("path")))//开始取工程文件
{
szLocFilePath.Empty();
szLocFilePath = szCurFilePath+_T("\\")+pDevice->m_szDevSN+_T("\\projects\\")+xmlDev.GetChildData()+_T("\\");
// if (TRUE == CreateDirectory((LPCTSTR)szLocFilePath, NULL))
if (TRUE == MakeSureDirectoryPathExists(szLocFilePath))
{
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/");
szHostFileName = szHostFileName+xmlDev.GetChildData()+_T("/project.xml");
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szLocFileName = szLocFilePath+"\\project.xml";
xmlPro.Load(szLocFileName);
xmlPro.FindChildElem(_T("testzones"));
xmlPro.IntoElem();
while (xmlPro.FindChildElem(_T("testzone")))
{
szLocFilePath.Empty();
szLocFilePath = szCurFilePath+_T("\\")+pDevice->m_szDevSN+_T("\\projects\\")+xmlDev.GetChildData()+_T("\\")+xmlPro.GetChildData()+_T("\\");
//if (TRUE == CreateDirectory(szLocFilePath,NULL))
if (TRUE == MakeSureDirectoryPathExists(szLocFilePath))
{
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/")+xmlDev.GetChildData()+_T("/")+xmlPro.GetChildData()+_T("/")+_T("testzone.xml");
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szLocFileName = szLocFilePath+"\\testzone.xml";
xmlTz.Load(szLocFileName);
xmlTz.FindChildElem(_T("vess"));
xmlTz.IntoElem();
while (xmlTz.FindChildElem(_T("ves")))
{
try
{
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/")+xmlDev.GetChildData()+_T("/")+xmlPro.GetChildData()+_T("/")+xmlTz.GetChildData()+_T(".xml");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/")+xmlDev.GetChildData()+_T("/")+xmlPro.GetChildData()+_T("/")+xmlTz.GetChildData()+_T(".dat");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/")+xmlDev.GetChildData()+_T("/")+xmlPro.GetChildData()+_T("/")+xmlTz.GetChildData()+_T(".org");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
}
catch (...)
{
CString str = szHostFileName +"\r\n"+szLocFilePath;
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
MessageBox(str);
continue;
}
}
xmlTz.OutOfElem();
xmlTz.FindChildElem(_T("eris"));
xmlTz.IntoElem();
while (xmlTz.FindChildElem(_T("eri")))
{
try
{
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/")+xmlDev.GetChildData()+_T("/")+xmlPro.GetChildData()+_T("/")+xmlTz.GetChildData()+_T(".xml");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/")+xmlDev.GetChildData()+_T("/")+xmlPro.GetChildData()+_T("/")+xmlTz.GetChildData()+_T(".dat");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/")+xmlDev.GetChildData()+_T("/")+xmlPro.GetChildData()+_T("/")+xmlTz.GetChildData()+_T(".org");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
}
catch (...)
{
CString str = szHostFileName +"\r\n"+szLocFilePath;
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
MessageBox(str);
continue;
}
}
xmlTz.OutOfElem();
//waston
xmlTz.FindChildElem(_T("erts"));
xmlTz.IntoElem();
while (xmlTz.FindChildElem(_T("ert")))
{
try
{
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/")+xmlDev.GetChildData()+_T("/")+xmlPro.GetChildData()+_T("/")+xmlTz.GetChildData()+_T(".xml");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/")+xmlDev.GetChildData()+_T("/")+xmlPro.GetChildData()+_T("/")+xmlTz.GetChildData()+_T(".dat");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/")+xmlDev.GetChildData()+_T("/")+xmlPro.GetChildData()+_T("/")+xmlTz.GetChildData()+_T(".org");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
}
catch (...)
{
CString str = szHostFileName +"\r\n"+szLocFilePath;
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
MessageBox(str);
continue;
}
}
xmlPro.OutOfElem();
//waston
//waston
xmlTz.FindChildElem(_T("wels"));
xmlTz.IntoElem();
while (xmlTz.FindChildElem(_T("wel")))
{
try
{
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/") + xmlDev.GetChildData() + _T("/") + xmlPro.GetChildData() + _T("/") + xmlTz.GetChildData() + _T(".xml");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/") + xmlDev.GetChildData() + _T("/") + xmlPro.GetChildData() + _T("/") + xmlTz.GetChildData() + _T(".dat");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
szHostFileName.Empty();
szHostFileName = _T("/SD/projects/") + xmlDev.GetChildData() + _T("/") + xmlPro.GetChildData() + _T("/") + xmlTz.GetChildData() + _T(".org");
// MessageBox(szLocFilePath+"\r\n"+szHostFileName);
pDevice->ReceiveFile(szLocFilePath, szHostFileName);
}
catch (...)
{
CString str = szHostFileName + "\r\n" + szLocFilePath;
hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTHookProc, AfxGetInstanceHandle(), NULL);
MessageBox(str);
continue;
}
}
xmlPro.OutOfElem();
}
}
xmlPro.OutOfElem();
}
}
xmlDev.OutOfElem();
}
void CMainFrame::OnSetLinkUsb()
{
// TODO: Add your command handler code here
this->GetMenu()->CheckMenuItem(IDM_SET_LINK_USB, MF_CHECKED);
this->GetMenu()->CheckMenuItem(IDM_SET_LINK_BLUETOOTH, MF_UNCHECKED);
g_iTransMode = (int)VAL_ZERO;
}
void CMainFrame::OnSetLinkBluetooth()
{
// TODO: Add your command handler code here
this->GetMenu()->CheckMenuItem(IDM_SET_LINK_USB, MF_UNCHECKED);
this->GetMenu()->CheckMenuItem(IDM_SET_LINK_BLUETOOTH, MF_CHECKED);
g_iTransMode = (int)VAL_ONE;
}
void CMainFrame::GetLastErrorEx()
{
TCHAR szBuf[128];
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
wsprintf(szBuf,
_T("出错码:%d: %s"),
dw, lpMsgBuf);
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
// AfxMessageBox(szBuf);
LocalFree(lpMsgBuf);
}
CString CMainFrame::GetGeoMativeVersion()
{
TCHAR szFullPath[MAX_PATH];
DWORD dwVerInfoSize = 0;
DWORD dwVerHnd;
VS_FIXEDFILEINFO * pFileInfo;
CString strVersion = "NULL";
GetModuleFileName(NULL, szFullPath, sizeof(szFullPath));
dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
if (dwVerInfoSize)
{
// If we were able to get the information, process it:
HANDLE hMem;
LPVOID lpvMem;
unsigned int uInfoSize = 0;
hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
lpvMem = GlobalLock(hMem);
if( !GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem) )
{
GetLastErrorEx();
return strVersion;
}
if( !::VerQueryValue(lpvMem, (LPTSTR)_T("\\"), (void**)&pFileInfo, &uInfoSize) )
{
GetLastErrorEx();
return strVersion;
}
WORD m_nProdVersion[4];
// Product version from the FILEVERSION of the version info resource
m_nProdVersion[0] = HIWORD(pFileInfo->dwProductVersionMS);
m_nProdVersion[1] = LOWORD(pFileInfo->dwProductVersionMS);
m_nProdVersion[2] = HIWORD(pFileInfo->dwProductVersionLS);
m_nProdVersion[3] = LOWORD(pFileInfo->dwProductVersionLS);
//在这里只需要前三个版本信息,比如1.1.2
strVersion.Format(_T("%d.%d.%d"),m_nProdVersion[0],
m_nProdVersion[1],m_nProdVersion[2]);
GlobalUnlock(hMem);
GlobalFree(hMem);
}
return strVersion;
}
void CMainFrame::OnShowGeoWebsite()
{
ShellExecute(NULL,"open",theApp.m_strHomePage,NULL,NULL,SW_SHOWNORMAL);
}
void CMainFrame::OnHelpUpg()
{
// TODO: Add your command handler code here
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
int nBtnRes = IDYES;
if (m_bIsShowUpgText)
{
if (LANG_ZHCN == g_iUILanguage)
nBtnRes = AfxMessageBox(_T("是否升级Geomative Studio?"),MB_YESNO);
else
nBtnRes = MessageBoxEx(NULL, _T("Do you want to upgrade Geomative Studio?"), STRING_MESSAGEBOXEX_TITLE, MB_YESNO, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
if(IDYES == nBtnRes)
{
CString strVersion = GetGeoMativeVersion();
if (0 == strVersion.Compare("NULL"))
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("获取版本信息错误"));
else
MessageBoxEx(NULL, _T("Get version info failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
//写版本信息文件
FILE* file = fopen(".//version_info.txt", "wb+");
CString strTips;
if (NULL == file)
{
if (LANG_ZHCN == g_iUILanguage)
{
strTips.Format(_T("写版本信息文件错误, 错误码 = %d"), GetLastError());
AfxMessageBox(strTips);
}
else
{
strTips.Format(_T("Write version info failed, errorno = %d"), GetLastError());
MessageBoxEx(NULL, strTips, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return;
}
CString strInfo = _T("");
strInfo.Format(_T("geomative_version=%s"), strVersion.GetBuffer(0));
fwrite(strInfo.GetBuffer(0), 1, strInfo.GetLength(), file);
fflush(file);
fclose(file);
ShellExecute(NULL,"open","upGeoMative.exe",NULL,NULL,SW_SHOWNORMAL);
theApp.OnFileExit();
}
/*
Ccheckupdate *update;
update = new Ccheckupdate();
if(update->checkGeoMaive())
{
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if(AfxMessageBox("update?",MB_YESNO) == IDYES)
{
ShellExecute(NULL,"open","upGeomative.exe",NULL,NULL,SW_SHOWNORMAL);
theApp.OnFileExit();
}
}
else
{
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
AfxMessageBox("this version is newest");
}
delete update;
*/
}
LRESULT CMainFrame::DetectLine(WPARAM wParam, LPARAM lParam)
{
CDevLinkRecord* pDevLinkRecord = (CDevLinkRecord*)wParam;
CDevice* pDevice = NULL;
CString szDevSN = _T("");
szDevSN.Empty();
szDevSN.Format(_T("%s"), pDevLinkRecord->aDevSN);
szDevSN.TrimRight(0x0d);
pDevice = theApp.m_pDevManager->GetDevice(szDevSN);
//pDevice->m_sComPort.DetectLine();
return 0;
}
// void CMainFrame::Ontest()
// {
// AfxMessageBox("ontest");
// CDevice *pDevice = NULL;
//
// pDevice = theApp.m_pDevManager->GetDevice("SN150120002");
// FILE *pFile = NULL;
// pFile = fopen("d:\\download.txt", "ab");
//
// CString szTmp = _T("");
// for (int n = 0; n < 1000; n++)
// {
// szTmp.Format("\r\n%d\r\n", n);
// fwrite(szTmp.GetBuffer(0), 1, szTmp.GetLength(), pFile);
// fflush(pFile);
// // pDevice->ReceiveFile("E:\\code\\Release_Code\\Geomative相关\\Trunk_1.0.3\\logg\\","11.rar");
// if (!pDevice->SendFile("/SD","E:\\code\\Release_Code\\Geomative相关\\Trunk_1.0.3\\CACHE\\","testzone.xml"))
// {
// AfxMessageBox("error");
// break;
// }
// }
//
// fclose(pFile);
// for (int n = 0; n < 1000; n++)
// {
// szTmp.Format("\r\n%d\r\n", n);
// fwrite(szTmp.GetBuffer(0), 1, szTmp.GetLength(), pFile);
// fflush(pFile);
//
// szTmp.Format("send big\r\n");
// fwrite(szTmp.GetBuffer(0), 1, szTmp.GetLength(), pFile);
// fflush(pFile);
//
// pDevice->ReceiveFile("E:\\code\\Release_Code\\Geomative相关\\Trunk_1.0.3\\logg\\","SD/TestFile_small.txt");
// // pDevice->SendFile("/SD","E:\\code\\Release_Code\\Geomative相关\\Trunk_1.0.3\\CACHE\\","TestFile_small.txt");
// szTmp.Format("send small\r\n");
// fwrite(szTmp.GetBuffer(0), 1, szTmp.GetLength(), pFile);
// fflush(pFile);
// pDevice->ReceiveFile("E:\\code\\Release_Code\\Geomative相关\\Trunk_1.0.3\\logg\\","11.rar");
// // pDevice->SendFile("/SD","E:\\code\\Release_Code\\Geomative相关\\Trunk_1.0.3\\CACHE\\","TestFile_small.txt");
//
// }
// fclose(pFile);
//}
void CMainFrame::OnLicenseUpg()
{
// TODO: Add your command handler code here
CLicenseUpgrade CLciUpgDlg;
CLciUpgDlg.DoModal();
}
void CMainFrame::OnPasswordManage()
{
// TODO: Add your command handler code here
CPasswordMng *pPasswordMng = new CPasswordMng(theApp.m_pConnection);
if (NULL == pPasswordMng)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("初始化密码管理对话框错误!"));
else
MessageBoxEx(NULL, _T("Initialize Password Manage Dialog Error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
if (IDOK == pPasswordMng->DoModal())
{
//此时已经改变了密码,需要重新更新
theApp.GetDBPasswordInfo();
}
delete pPasswordMng;
pPasswordMng = NULL;
}
BOOL CMainFrame::OnDeviceChange(UINT nEventType, DWORD dwData)
{
switch (nEventType)
{
//u盘插入
case DBT_DEVICEARRIVAL:
{
if (CDetcGD10Dev::GetInstance()->IsGD10DevConnect())
{
g_bCancelCopyFile = FALSE;
}
else
{
CDetcGD10Dev::GetInstance()->DetectGD10Dev();
if (CDetcGD10Dev::GetInstance()->IsGD10DevConnect())
{
g_bCancelCopyFile = FALSE;
OutputDebugString(_T("zm: GD10 device was found!"));
//CDevLinkRecord* aDevLinkTable[256];
memset(aDevLinkTable, 0, sizeof(aDevLinkTable));
}
else
g_bCancelCopyFile = TRUE;
}
}
break;
//u盘被拔出,此时需要探测GD10还在不在
case DBT_DEVICEREMOVECOMPLETE:
{
if (CDetcGD10Dev::GetInstance()->IsGD10DevConnect())
{
CDetcGD10Dev::GetInstance()->DetectGD10Dev();
if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect())
{
CString strLog;
if (LANG_ENUS == g_iUILanguage)
strLog = _T("GD device was pull out!");
else
strLog = _T("GD设备被拔出!");
// strLog.Format(_T("[CopyFile][%d]Usb device was pull out,copy file was canceled!"), __LINE__);
CFileOperTools::GetInstance()->WriteComLog(strLog);
AfxMessageBox(strLog);
OutputDebugString(_T("zm: GD10 device was pull out!"));
CPtrArray* pDevList = new CPtrArray;
theApp.m_pDevManager->GetOLDevList(pDevList);
int iIndex = (int)VAL_ZERO;
CDevice* pDev = NULL;
CString strDevSN;
if ((int)VAL_ZERO != pDevList->GetSize())
{
while (iIndex < pDevList->GetSize())
{
pDev = NULL;
pDev = (CDevice*)pDevList->GetAt(iIndex);
if (NULL != pDev)
{
if (g_strUSBDevSN.CompareNoCase(pDev->m_szDevSN) == 0)
{
strDevSN.Empty();
strDevSN = pDev->m_szDevSN;
theApp.m_pDevManager->DeleteObjInMem(pDev->m_szDevSN);
theApp.m_pDevManager->AddOfflineObjInMem(strDevSN);
break;
}
}
iIndex++;
}
}
if (pDevList != NULL)
{
delete pDevList;
pDevList = NULL;
}
//如果判断当前设备管理框架出于激活状态,那么则进行刷新
if (NULL != m_pDevMngFrm)
{
if (m_pDevMngFrm->IsActiveMDIWindow())
{
m_pDevMngFrm->SendMessage(WM_REFRESH_NAV_DEVICE, (WPARAM)0, (LPARAM)0);
}
}
g_bCancelCopyFile = TRUE;
}
else
g_bCancelCopyFile = FALSE;
}
else
g_bCancelCopyFile = TRUE;
}
break;
default:
break;
}
return TRUE;
}
//DEL BOOL CMainFrame::DoRegisterDeviceInterface(GUID InterfaceClassGuid, HDEVNOTIFY *hDevNotify)
//DEL {
//DEL /*
//DEL DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
//DEL DWORD Err;
//DEL
//DEL ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
//DEL NotificationFilter.dbcc_size = 32;
//DEL // sizeof(DEV_BROADCAST_DEVICEINTERFACE);
//DEL NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
//DEL NotificationFilter.dbcc_classguid = InterfaceClassGuid;
//DEL
//DEL *hDevNotify = RegisterDeviceNotification(GetSafeHwnd(),&NotificationFilter,DEVICE_NOTIFY_WINDOW_HANDLE);
//DEL if(!*hDevNotify)
//DEL {
//DEL Err = GetLastError();
//DEL CString str;
//DEL str.Format(_T("RegisterDeviceNotification failed: %lx."),Err);
//DEL DT((LPCSTR)str);
//DEL return FALSE;
//DEL }
//DEL DT("RegisterDeviceNotification Successed :)");
//DEL //UnregisterDeviceNotification(*hDevNotify);
//DEL */
//DEL return TRUE;
//DEL
//DEL }
bool CMainFrame::UsbRegistNotify(void)
{
HDEVNOTIFY hDevNotify;
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
for(int i=0; i<sizeof(GUID_DEVINTERFACE_LIST)/sizeof(GUID); i++)
{
NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_LIST[i];//我们在此只注册HID USB设备消息
hDevNotify = RegisterDeviceNotification(this->GetSafeHwnd(), &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
if( !hDevNotify )
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("不能注册设备通知"));
else
MessageBoxEx(NULL, _T("Can't register device notification"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return false;
}
}
return true;
}
LRESULT CMainFrame::OnUpgGeomative(WPARAM wParam, LPARAM lParam)
{
m_bIsShowUpgText = false;
OnHelpUpg();
return 0;
}
LRESULT CMainFrame::OnShowUpgInfo(WPARAM wParam, LPARAM lParam)
{
if (NULL == m_pUpgDevInfo)
{
m_pUpgDevInfo = new CDialUpgDeviceInfo;
m_pUpgDevInfo->Create(IDD_DIALOG_UPG_DEVICE, this);
m_pUpgDevInfo->ShowWindow(SW_SHOW);
if (LANG_ZHCN == g_iUILanguage)
m_pUpgDevInfo->GetDlgItem(IDC_STATIC_UPG_TXT)->SetWindowText(_T(" 升级中, 请稍候..."));
else
m_pUpgDevInfo->GetDlgItem(IDC_STATIC_UPG_TXT)->SetWindowText(_T(" upgrading, please wait..."));
m_pUpgDevInfo->Invalidate();
}
return 0;
}
void CMainFrame::NotifyDevInfo(LPVOID lParam, LPARAM rParam, LPVOID pWnd)
{
CMainFrame* pMainFr = (CMainFrame*)pWnd;
LPSTCTRLCMDINFO pCtrlCmdInfo = NULL;
char* pData=((LPSTCTRLCMDINFO)lParam)->pData;
int iLen = ((LPSTCTRLCMDINFO)lParam)->iDataLen;
CString strLog;
_RecordsetPtr pRecDev = NULL;
_CommandPtr pCmdUpd = NULL;
CString szSql = _T("");
DWORD dwDeID = (DWORD)VAL_ZERO;
_ConnectionPtr pConnection = theApp.m_pConnection;
pRecDev.CreateInstance(_uuidof(Recordset));
pCmdUpd.CreateInstance(_uuidof(Command));
if (NULL == pRecDev)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("数据库连接失败"));
else
MessageBoxEx(NULL, _T("Database connection failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
if (EN_FORCE_LOGIN == rParam)
{
theApp.m_NetWorkOper.SetSuspendForThread(true);
OutputDebugString(_T("zm:CMainFrm::NotifyDevInfo send 登录请求\n"));
ST_REQUEST_PACKET stLoginRequest;
stLoginRequest.clsPacketBase.ucCmd = EN_CTRL_USER_LOGIN;
stLoginRequest.hWnd = pMainFr->m_hWnd;
stLoginRequest.wDataLen = sizeof(UINT32);
stLoginRequest.pData = new char[stLoginRequest.wDataLen];
stLoginRequest.dwMsgID = WM_NET_RESPONSE;
memcpy(stLoginRequest.pData, (char*)(&theApp.m_uiUserID), stLoginRequest.wDataLen);
theApp.m_NetWorkOper.PutRequestPacket(stLoginRequest);
if (stLoginRequest.pData != NULL)
{
delete[] stLoginRequest.pData;
stLoginRequest.pData = NULL;
}
// if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_CTRL_USER_LOGIN, 0xFFFFFFFF, 1, (char*)(&theApp.m_uiUserID), sizeof(UINT32)))
// {
// theApp.m_NetWorkOper.SetSuspendForThread(false);
// AfxMessageBox(_T("user login information send failed"));
// return;
// }
//
// char chMsg[200] = { 0 };
// char chMsgSyn[801] = { 0 };
// int ilen = 0;
//
// if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chMsg, &ilen, 200, 5000))
// {
// short usDevNum = ntohs(*((short*)chMsg));
// if (ilen != (2 + usDevNum*sizeof(STSigRemoteDev)))
// {
// CString strErr = _T("");
// strErr.Format(_T("recv device number error.total_len = %d, device_number = %d"), ilen, usDevNum);
// theApp.m_NetWorkOper.SetSuspendForThread(false);
// AfxMessageBox(strErr);
// return;
// }
//
// strLog.Empty();
// strLog.Format(_T("[%s][%d]recv login's response,device_num = %d"), MODULE_NAME, __LINE__, usDevNum);
// CFileOperTools::GetInstance()->WriteComLog(strLog);
//
// STSigRemoteDev stRemDev;
// pConnection->BeginTrans();
// for (int i = 0; i < usDevNum; i++)
// {
// memcpy(&stRemDev, chMsg + 2 + i*sizeof(STSigRemoteDev), sizeof(STSigRemoteDev));
// stRemDev.uiDevID = ntohl(stRemDev.uiDevID);
// theApp.m_pDevManager->AddRemoteDevice(stRemDev);
//
// CString szDevName = _T("Geo-electrical online");
// char s[12];
// itoa(stRemDev.uiDevID, s, 10);
// CString str = s;
// CString szDevSN;
// CString szModelNO;
// if (EN_DEV_GD10 == stRemDev.ucDevType)
// {
// szModelNO = _T("GD-20");
// szDevSN = _T("SN") + _T(str);
// }
// else if (EN_DEV_PLC == stRemDev.ucDevType)
// {
// szModelNO = _T("PLC");
// szDevSN = _T("PLC") + _T(str);
// }
// else
// {
// continue; //未知设备
// }
//
// try
// {
// //先查找是否是已有ID再插入
// szSql.Empty();
// szSql.Format(_T("select ID from device where SN = '%s'"), szDevSN);
// pRecDev->Open(szSql.AllocSysString(), _variant_t((IDispatch*)pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
// dwDeID = (DWORD)VAL_ZERO;
// if (!pRecDev->adoEOF)
// {
// dwDeID = pRecDev->GetCollect(_T("ID")).ulVal;
// }
// pRecDev->Close();
//
// if (0 == dwDeID)
// {
// szSql.Empty();
// szSql.Format(_T("insert into device(DEname,modelNO,SN,MacAddress) values('%s','%s','%s','%s')"), szDevName, szModelNO, szDevSN, g_szMacAddress);
// pCmdIns->CommandText = szSql.AllocSysString();
// pCmdIns->Execute(NULL, NULL, adCmdText);
// }
// else
// {
// theApp.m_pDevManager->DeleteObjInMem(szDevSN);
// }
// }
// catch (_com_error e)
// {
// // 显示错误信息
// AfxMessageBox(e.Description());
// }
//
// ////从云端获取历史信息
// //if (EN_DEV_GD10 == stRemDev.ucDevType)
// //{
// // ///////////////////////////////////从云端获取历史设备信息/////////////////////////////////////////////////////
// // if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_REQ_DOWNLOAD_DEV_INFO, 0xFFFFFFFF, 1, (char*)(&stRemDev.uiDevID), sizeof(UINT32)))
// // {
// // theApp.m_NetWorkOper.SetSuspendForThread(false);
// // AfxMessageBox(_T("user login information send failed"));
// // return;
// // }
//
// // if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chMsgSyn, &ilen, 200, 5000))
// // {
// // if (iLen >= sizeof(STSynDevParam))
// // {
// // STSynDevParam *DevPar = (STSynDevParam*)chMsgSyn;
// // CString Hwv = _T("V") + DevPar->ucHWVer[0] + '.'+ DevPar->ucHWVer[1];
// // CString Swv = _T("V") + DevPar->ucSWVer[0] + '.' + DevPar->ucSWVer[1] + '.'\
// // + DevPar->ucSWVer[2] + ' '+'T' + DevPar->ucSWVer[3];
// // try
// // {
// // //写入数据库
// // szSql.Empty();
// // szSql.Format(_T("update device set HWV = '%s' SWV = '%s' BatVol = '%f' PowerFreq = '%d' \
// // CableType = '%d' GrTh = '%d' BatAlarm = '%d' Stack = '%d' ChanNum = '%d' \
// // DownNum = '%d' where SN = '%s'"),Hwv,Swv,DevPar->fBatteryVol,DevPar->ucPowerFreq,\
// // DevPar->ucCableType,DevPar->iGrThreshold,DevPar->ucBatteryAlarm,DevPar->ucStacking,\
// // DevPar->ucChannelNum,DevPar->ucDownLoadNum,szDevSN);
// // pCmdUpd->CommandText = szSql.AllocSysString();
// // pCmdUpd->Execute(NULL, NULL, adCmdText);
// // }
// // catch (_com_error e)
// // {
// // // 显示错误信息
// // AfxMessageBox(e.Description());
// // }
// // }
// // }
//
// // /////////////////////////////////获取历史电缆头信息///////////////////////////////////////
// // if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_REQ_DOWNLOAD_CABLE_INFO, 0xFFFFFFFF, 1, (char*)(&stRemDev.uiDevID), sizeof(UINT32)))
// // {
// // theApp.m_NetWorkOper.SetSuspendForThread(false);
// // AfxMessageBox(_T("user login information send failed"));
// // return;
// // }
//
// // if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chMsgSyn, &ilen, 800, 5000))
// // {
// // BYTE ucCableNum = (BYTE)(chMsgSyn[0]);
// // if ((ucCableNum < 1) || (iLen < (1 + 3 * ucCableNum)))
// // {
// // continue;
// // }
// // try
// // {
// // szSql.Empty();
// // szSql.Format(_T("delete from CableInfo where SN = '%s'"), szDevSN);
// // pCmdIns->CommandText = szSql.AllocSysString();
// // pCmdIns->Execute(NULL, NULL, adCmdText);
// //
// // STRemCableCallInfo *stCableInfo = (STRemCableCallInfo *)chMsgSyn;
// // for (int j = 0; j < ucCableNum; j++)
// // {
// // szSql.Empty();
// // szSql.Format(_T("insert into CableInfo(SN,ToNum,N_ID,N_Dir,N_Pow) values('%s','%d','%d','%d','%f')"),szDevSN,\
// // stCableInfo->uiTotalCount, stCableInfo->stCableInfo[j].ucID, stCableInfo->stCableInfo[j].ucDir,\
// // stCableInfo->stCableInfo[j].fPowe);
// // pCmdIns->CommandText = szSql.AllocSysString();
// // pCmdIns->Execute(NULL, NULL, adCmdText);
// // }
// // }
// // catch (_com_error e)
// // {
// // // 显示错误信息
// // AfxMessageBox(e.Description());
// // }
// // }
// //}
// }
// pConnection->CommitTrans();
// if (pMainFr->m_pDevMngFrm)
// pMainFr->m_pDevMngFrm->RefreshNavDevice(NULL, NULL);
// // pDevManage->OnRefreshNavDevice(NULL, NULL);
// }
// else
// {
// strLog.Empty();
// strLog.Format(_T("[%s][%d]recv login's response time out"), MODULE_NAME, __LINE__);
// CFileOperTools::GetInstance()->WriteComLog(strLog);
// }
theApp.m_NetWorkOper.SetSuspendForThread(false);
}
else if ((EN_DEV_ONLINE == rParam) || ( (0 == rParam) && (EN_TRANSFER_FILE_BY_WIFI == g_iTransFileMode)))
{
WORD wNum = ntohs(*(WORD*)pData);
if (iLen != (2 + wNum*sizeof(STSigRemoteDev)))
{
CString strErr;
strErr.Format(_T("Add Device msg length errorshould be %d,but actually is %d"),2 + wNum*sizeof(STSigRemoteDev),iLen);
CFileOperTools::GetInstance()->WriteComLog(strErr);
//AfxMessageBox(strErr);
return;
}
STSigRemoteDev* pRemDev = NULL;
for (int i=0; i < wNum; i++)
{
pRemDev = (STSigRemoteDev*)(pData+2+i*sizeof(STSigRemoteDev));
pRemDev->uiDevID = ntohl(pRemDev->uiDevID);
strLog.Format(_T("zm:设备列表添加设备CMainFrame::NotifyDevInfo 开机 SN=%u"), pRemDev->uiDevID);
CFileOperTools::GetInstance()->WriteComLog(strLog);
theApp.m_pDevManager->AddRemoteDevice(*pRemDev);
}
strLog.Empty();
strLog.Format(_T("[%s][%d]recv device online message,device_num = %d"),MODULE_NAME, __LINE__, wNum);
CFileOperTools::GetInstance()->WriteComLog(strLog);
if (pMainFr->m_pDevMngFrm)
pMainFr->m_pDevMngFrm->RefreshNavDevice(NULL, NULL);
// pDevManage->OnRefreshNavDevice(NULL, NULL);
}
else
{
CString strErr = _T("");
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知命令(%d)"), rParam);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow cmd(%d) in ctr_cmd"), rParam);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
}
}
LRESULT CMainFrame::OnClearUpgInfo(WPARAM wParam, LPARAM lParam)
{
if (NULL != m_pUpgDevInfo)
{
m_pUpgDevInfo->DestroyWindow();
delete m_pUpgDevInfo;
m_pUpgDevInfo = NULL;
}
return 0;
}
LRESULT CMainFrame::OnChangeLanguage(WPARAM wParam, LPARAM lParam)
{
int iLanguage = (int)wParam;
if (LANG_ZHCN == iLanguage)
OnChangeChinese();
else
OnChangeEnglish();
return 0;
}
LRESULT CMainFrame::OnMsgNotifyDeviceOnOrOff(WPARAM wParam, LPARAM lParam)
{
if (NULL != m_pDevMngFrm)
m_pDevMngFrm->RefreshNavDevice(NULL, NULL);
return 0;
}
void CMainFrame::OnChangeEnglish()
{
if (LANG_ENUS == g_iUILanguage)
{
return;
}
g_iUILanguage = LANG_ENUS;
g_UIOffset = OFFSET_ENGLISH;
ModifyMenuLanguage(2);
RefreshFrameWindows();
//更新配置文件
WritePrivateProfileString(_T("UI"),_T("Language"),_T("2"),_T("./config.ini"));
}
void CMainFrame::OnChangeChinese()
{
if (LANG_ZHCN == g_iUILanguage)
{
return;
}
g_iUILanguage = LANG_ZHCN;
g_UIOffset = OFFSET_CHINESE;
ModifyMenuLanguage(1);
RefreshFrameWindows();
//更新配置文件
WritePrivateProfileString(_T("UI"),_T("Language"),_T("1"),_T("./config.ini"));
}
void CMainFrame::RefreshFrameWindows()
{
int iRefreshFlag = 0;
//首先获取哪个是当前活跃的子窗口,不能一边关闭窗口一边获取
//因为在关闭当前窗口后,前一个打开的窗口又会自动变成活跃窗口
if (m_pDataMngFrm)
{
if (m_pDataMngFrm->IsActiveMDIWindow())
iRefreshFlag += 1;
}
if (m_pDevMngFrm)
{
if (m_pDevMngFrm->IsActiveMDIWindow())
iRefreshFlag += 2;
}
if (m_pSptMngFrm)
{
if (m_pSptMngFrm->IsActiveMDIWindow())
iRefreshFlag += 4;
}
//关闭所有已经打开的窗口
if (m_pDataMngFrm)
{
m_pDataMngFrm->SendMessage(WM_CLOSE_FRAME_WINDOW, 0, 0);
}
if (m_pDevMngFrm)
{
m_pDevMngFrm->SendMessage(WM_CLOSE_FRAME_WINDOW, 0, 0);
}
if (m_pSptMngFrm)
{
m_pSptMngFrm->SendMessage(WM_CLOSE_FRAME_WINDOW, 0, 0);
}
//重新打开之前活跃的子窗口
switch(iRefreshFlag)
{
case 0:
break;
case 1:
OnMngDataWin();
break;
case 2:
OnMngDevWin();
break;
case 4:
OnMngExecWin();
break;
default:
CString str = _T("");
if (LANG_ZHCN == g_iUILanguage)
{
str.Format(_T("未知刷新窗口标志(%d)"), iRefreshFlag);
AfxMessageBox(str);
}
else
{
str.Format(_T("Unknow refresh frame windows flag(%d)"), iRefreshFlag);
MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
break;
}
}
void CMainFrame::ModifyMenuLanguage(int iLanguage)
{
CMenu *pMenu = GetMenu();
//如果是子菜单存在第9项的话,则表明最前面有一个隐藏的菜单,后面需要加1
int iOffset = (pMenu->GetSubMenu(8) != NULL) ? 1 : 0;
if (2 == iLanguage)
{
//在调用ModifyMenu,第三个参数代表原来的ID号一定不能更改,否则将失去响应
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("File(&F)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_FILE_IMP, _T("Import"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(1, MF_BYPOSITION, IDM_FILE_EXP, _T("Export"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(3, MF_BYPOSITION, IDM_FILE_EXIT, _T("Exit(&x)"));
pMenu->GetSubMenu(iOffset)->EnableMenuItem(0, MF_BYPOSITION|MF_GRAYED);
pMenu->GetSubMenu(iOffset)->EnableMenuItem(1, MF_BYPOSITION|MF_GRAYED);
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("Project(&P)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_MNG_DATA_WIN, _T("Main view"));
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("Script(&S)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_MNG_EXEC_WIN, _T("Main view"));
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("Device(&D)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_MNG_DEV_WIN, _T("Main view"));
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("Function(&F)"));
//清除菜单子项
pMenu->GetSubMenu(iOffset)->RemoveMenu(IDM_SYN_WIN, 0);
pMenu->GetSubMenu(iOffset)->RemoveMenu(IDM_LOGGING_TEST, 1);
if (EN_TRANSFER_FILE_BY_CLOUND != g_iTransFileMode)
{
pMenu->GetSubMenu(iOffset)->AppendMenuA(MF_STRING, IDM_SYN_WIN, _T("Synchronization"));
//pMenu->GetSubMenu(iOffset)->AppendMenuA(MF_STRING, IDM_LOGGING_TEST, _T("Logging test"));
}
else
{
//暂时屏蔽logging版本
//pMenu->GetSubMenu(iOffset)->AppendMenuA(MF_STRING, IDM_LOGGING_TEST, _T("Logging test"));
}
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("Language(&L)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_CHG_ENGLISH, _T("English"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(1, MF_BYPOSITION, IDM_CHG_CHINESE, _T("Chinese"));
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("Windows(&W)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, ID_WINDOW_CASCADE, _T("Cascade(&C)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(1, MF_BYPOSITION, ID_WINDOW_TILE_HORZ, _T("Overlap(&T)"));
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("Help(&H)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_HELP_UPG, _T("Upgrade Geomative Studio(&U)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(1, MF_BYPOSITION, IDM_LICENSE_UPG, _T("Upgrade License"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(3, MF_BYPOSITION, IDM_HELP_ABOUT, _T("About Geomative Studio(&A)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(4, MF_BYPOSITION, IDM_GEOMATIVE_WEB, _T("Geomative Website(&G)"));
}
else
{
//在调用ModifyMenu,第三个参数代表原来的ID号一定不能更改,否则将失去响应
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("文件(&F)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_FILE_IMP, _T("导入"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(1, MF_BYPOSITION, IDM_FILE_EXP, _T("导出"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(3, MF_BYPOSITION, IDM_FILE_EXIT, _T("退出(&x)"));
//使对于的菜单栏变灰不可用
pMenu->GetSubMenu(iOffset)->EnableMenuItem(0, MF_BYPOSITION|MF_GRAYED);
pMenu->GetSubMenu(iOffset)->EnableMenuItem(1, MF_BYPOSITION|MF_GRAYED);
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("工程(&P)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_MNG_DATA_WIN, _T("主视图"));
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("脚本(&S)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_MNG_EXEC_WIN, _T("主视图"));
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("设备(&D)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_MNG_DEV_WIN, _T("主视图"));
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("功能(&F)"));
//清除菜单子项
pMenu->GetSubMenu(iOffset)->RemoveMenu(IDM_SYN_WIN, 0);
pMenu->GetSubMenu(iOffset)->RemoveMenu(IDM_LOGGING_TEST, 1);
if (EN_TRANSFER_FILE_BY_CLOUND != g_iTransFileMode)
{
pMenu->GetSubMenu(iOffset)->AppendMenuA(MF_STRING, IDM_SYN_WIN, _T("同步"));
//pMenu->GetSubMenu(iOffset)->AppendMenuA(MF_STRING, IDM_LOGGING_TEST, _T("Logging测试"));
}
else
{
//暂时屏蔽logging版本
//pMenu->GetSubMenu(iOffset)->AppendMenuA(MF_STRING, IDM_LOGGING_TEST, _T("Logging测试"));
}
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("语言(&L)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_CHG_ENGLISH, _T("英文"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(1, MF_BYPOSITION, IDM_CHG_CHINESE, _T("中文"));
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("窗口(&W)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, ID_WINDOW_CASCADE, _T("级联(&C)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(1, MF_BYPOSITION, ID_WINDOW_TILE_HORZ, _T("层叠(&T)"));
iOffset++;
pMenu->ModifyMenu(iOffset, MF_BYPOSITION, NULL, _T("帮助(&H)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(0, MF_BYPOSITION, IDM_HELP_UPG, _T("升级Geomative Studio(&U)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(1, MF_BYPOSITION, IDM_LICENSE_UPG, _T("升级License"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(3, MF_BYPOSITION, IDM_HELP_ABOUT, _T("关于Geomative Studio(&A)"));
pMenu->GetSubMenu(iOffset)->ModifyMenu(4, MF_BYPOSITION, IDM_GEOMATIVE_WEB, _T("Geomative主页(&G)"));
}
DrawMenuBar();
}
BOOL CMainFrame::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
{
ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
UINT nID =(UINT)pNMHDR->idFrom;
switch(nID)
{
case IDM_FILE_EXIT:
if(LANG_ZHCN == g_iUILanguage)
pTTT->lpszText= _T("关闭");
else
pTTT->lpszText= _T("Close");
break;
case IDM_HELP_ABOUT:
if(LANG_ZHCN == g_iUILanguage)
pTTT->lpszText=_T("关于Geomative Studio");
else
pTTT->lpszText=_T("About Geomative Studio");
break;
case IDM_TERRAIN_SET:
if(LANG_ZHCN == g_iUILanguage)
pTTT->lpszText=_T("地形");
else
pTTT->lpszText=_T("Topography");
break;
default:
break;
}
return TRUE;
}
LRESULT CMainFrame::PreNetResponse(WPARAM wParam, LPARAM lParam)
{
LPRESPONSEPACKET pResponsePacket = (LPRESPONSEPACKET)lParam;
BOOL bRet = FALSE;
if (pResponsePacket == NULL)
{
return bRet;
}
switch (pResponsePacket->clsPacketBase.ucCmd)
{
case EN_CTRL_USER_LOGIN:
{
//删除本地及树型控件列表数据,如果客户端不想保存数据的话,需要服务器返回删除的ID
bRet = OnLoginResponse(wParam, lParam);
}
break;
case EN_REQ_HEART_BEAT_PACKET:
{
CFileOperTools::GetInstance()->WriteComLog(_T("zm:CMainFrame::PreNetResponse recv heart beat from Sever\n"));
}
break;
default:
break;
}
return bRet;
}
BOOL CMainFrame::OnLoginResponse(WPARAM wParam, LPARAM lParam)
{
OutputDebugString(_T("zmCMainFrame::OnLoginResponse\n"));;
CString strLog;
_RecordsetPtr pRecDev = NULL;
_CommandPtr pCmdIns = NULL;
_ConnectionPtr pConnection = theApp.m_pConnection;
pRecDev.CreateInstance(_uuidof(Recordset));
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = pConnection;
if (0 != wParam)
{
strLog.Format(_T("wParam=[%d]recv login's response time out"), wParam);
CFileOperTools::GetInstance()->WriteComLog(strLog);
OutputDebugString(strLog);
return FALSE;
}
LPRESPONSEPACKET pResponsePacket = (LPRESPONSEPACKET)lParam;
if (!pResponsePacket || (EN_CTRL_USER_LOGIN != pResponsePacket->clsPacketBase.ucCmd))
{
strLog.Format(_T("CMainFrame::OnLoginResponse EN_CTRL_USER_LOGIN != pResponsePacket->clsPacketBase.ucCmd"));
CFileOperTools::GetInstance()->WriteComLog(strLog);
OutputDebugString(strLog);
return FALSE;
}
DWORD dwDeID = (DWORD)VAL_ZERO;
CString szSql;
//short uiDevNum = ntohs(*((short*)pResponsePacket->pData));
//if (pResponsePacket->wDataLen != (sizeof(short) + uiDevNum*sizeof(STSigRemoteDev)))
UINT32 uiDevNum = ntohl(*((UINT32*)pResponsePacket->pData));
if (pResponsePacket->wDataLen != (sizeof(UINT32) + uiDevNum*sizeof(STSigRemoteDev)))
{
CString strErr = _T("");
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("接收设备信息长度错误。total_len = %d, device_number = %d"), pResponsePacket->wDataLen, uiDevNum);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Receive device info length error.total_len = %d, device_number = %d"), pResponsePacket->wDataLen, uiDevNum);
MessageBoxEx(NULL,strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return FALSE;
}
strLog.Empty();
strLog.Format(_T("[%s][%d]recv login's response,device_num = %d"), MODULE_NAME, __LINE__, uiDevNum);
CFileOperTools::GetInstance()->WriteComLog(strLog);
OutputDebugString(strLog);
STSigRemoteDev stRemDev;
CString szDevName;
CString szDevSN;
CString szModelNO;
pConnection->BeginTrans();
for (int i = 0; i < uiDevNum; i++)
{
memcpy(&stRemDev, pResponsePacket->pData + sizeof(UINT32) + i*sizeof(STSigRemoteDev), sizeof(STSigRemoteDev));
stRemDev.uiDevID = ntohl(stRemDev.uiDevID);
strLog.Format(_T("zm:设备列表添加设备CMainFrame::OnLoginResponse 开机 SN=%u"), stRemDev.uiDevID);
OutputDebugString(strLog);
CFileOperTools::GetInstance()->WriteComLog(strLog);
if (stRemDev.byDevStatus)
theApp.m_pDevManager->AddRemoteDevice(stRemDev);
szDevName = _T("Geo-electrical online");
if (EN_DEV_GD10 == stRemDev.ucDevType)
{
szModelNO = _T("GD-20");
szDevSN.Format(_T("SN%u"), stRemDev.uiDevID);
}
else if (EN_DEV_PLC == stRemDev.ucDevType)
{
szModelNO = _T("PLC");
szDevSN.Format(_T("PLC%u"), stRemDev.uiDevID);
}
else
{
continue; //未知设备
}
try
{
//先查找是否是已有ID再插入
szSql.Empty();
szSql.Format(_T("select ID from device where SN = '%s'"), szDevSN);
pRecDev->Open(szSql.AllocSysString(), _variant_t((IDispatch*)pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
dwDeID = (DWORD)VAL_ZERO;
if (!pRecDev->adoEOF)
{
dwDeID = pRecDev->GetCollect(_T("ID")).ulVal;
}
pRecDev->Close();
if (0 == dwDeID)
{
szSql.Empty();
szSql.Format(_T("insert into device(DEname,modelNO,SN,MacAddress) values('%s','%s','%s','%s')"), szDevName, szModelNO, szDevSN, g_szMacAddress);
OutputDebugString(szSql);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
}
else if (stRemDev.byDevStatus)
{
szSql.Format(_T("zm:用户登录成功后,删除设备%s\n"), szDevSN);
OutputDebugString(szSql);
theApp.m_pDevManager->DeleteObjInMem(szDevSN);
}
}
catch (_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
pConnection->CommitTrans();
if (m_pDevMngFrm != NULL)
{
m_pDevMngFrm->RefreshNavDevice(NULL, NULL);
}
OutputDebugString(_T("zm:CMainFrm::OnLoginResponse return TRUE\n"));
return TRUE;
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch (nIDEvent)
{
case ID_TIMER_HEARTBEAT_PACKET:
{
//CFileOperTools::GetInstance()->WriteComLog(_T("zm:CMainFrame::OnTimer() Geomative send heart beat to Sever\n"));
//OutputDebugString(_T("zm:CMainFrame::OnTimer() Geomative send heart beat to Sever\n"));
//PostNetRequest(EN_REQHEART_BEAT_PACKET, this->m_hWnd, NULL, 0);
STRequestPacket requestPacket;
requestPacket.clsPacketBase.ucCmd = EN_REQ_HEART_BEAT_PACKET;
requestPacket.clsPacketBase.ucDevType = EN_DEV_CLOUND;
requestPacket.clsPacketBase.uiDevID = CLOUD_DEV_ID;
requestPacket.hWnd = this->m_hWnd;
requestPacket.wDataLen = 0;
requestPacket.pData = NULL;
theApp.m_NetWorkOper.PutRequestPacket(requestPacket);
}
break;
case ID_UPLOAD_DEVICE_MARKET_DATA:
{
::KillTimer(theApp.m_pMainWnd->GetSafeHwnd(), ID_UPLOAD_DEVICE_MARKET_DATA);
HANDLE hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)UploadDevMarketDataToCloudThread, NULL, 0, 0);
if (INVALID_HANDLE_VALUE == hThread)
{
CFileOperTools::GetInstance()->WriteComLog(_T("Create Thread failed to upload device market data to Cloud"));
break;
}
CloseHandle(hThread);
}
break;
default:
break;
}
CMDIFrameWnd::OnTimer(nIDEvent);
}
//上传设备市场数据到云端
UINT CMainFrame::UploadDevMarketDataToCloudThread(LPVOID lParam)
{
//是否有需要上传的文件
CString szCurFilePath = _T("");
szCurFilePath.Empty();
szCurFilePath.GetBufferSetLength(256);
::GetCurrentDirectory(szCurFilePath.GetLength(), szCurFilePath.GetBuffer(szCurFilePath.GetLength()));
szCurFilePath.ReleaseBuffer();
CString strRecordDir;
CString strRecordPath;
strRecordPath.Format(_T("%s\\record"), szCurFilePath);
strRecordDir.Format(_T("%s\\*.*"), strRecordPath);
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile(strRecordDir, &wfd);
if (INVALID_HANDLE_VALUE == hFind)
return 1;
CString strRecordFile = _T("");
CString strTmp;
CString strFileExt = _T("");
CFile cFile;
BOOL bRes = FALSE;
DWORD dwLength = 0;
char* pszFileContent = NULL;
CString strFileContent = _T("");
//遍历该目录下所有的log文件
do
{
strRecordFile.Format(_T("%s\\%s"), strRecordPath, wfd.cFileName);
strFileExt = PathFindExtension(strRecordFile);
//上传日志的文件
if ((wfd.dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE) && (_tcscmp(strFileExt, _T(".log")) == 0))
{
strTmp.Format(_T("CMainFrame::UploadDevMarketDataToCloudThread() need upload file name:%s"), strRecordFile);
CFileOperTools::GetInstance()->WriteComLog(strTmp);
bRes = cFile.Open(strRecordFile, CFile::modeRead);
//打开文件失败
if (!bRes)
{
continue;
}
cFile.SeekToBegin();
dwLength = cFile.GetLength();
pszFileContent = new char[dwLength + 1];
memset(pszFileContent, 0, dwLength + 1);
cFile.Read(pszFileContent, dwLength);
cFile.Close();
strTmp.Format(_T("CMainFrame::UploadDevMarketDataToCloudThread() pszFileContent=%s"), pszFileContent);
CFileOperTools::GetInstance()->WriteComLog(strTmp);
strFileContent = pszFileContent;
if (strFileContent.IsEmpty())
{
bRes = DeleteFile(strRecordFile);
if (!bRes)
{
CFileOperTools::GetInstance()->WriteComLog(_T("CMainFrame::UploadDevMarketDataToCloudThread() delete empty file failed"));
}
continue;
}
CString strServerCgi;
strServerCgi.Format(_T("http://120.79.204.194:8080/st-site/devicelog"));
mjz::SmartPtr<mjz::HttpSession> pSession = new mjz::HttpSession(TRUE);
mjz::SmartPtr<mjz::HttpConnection> pConnection = new mjz::HttpConnection(pSession, strServerCgi.AllocSysString());
mjz::SmartPtr<mjz::HttpRequest> pRequest = new mjz::HttpRequest(strServerCgi.AllocSysString(), pSession, pConnection);
//GB2312到UTF-8的转换
char* pszUftFileContent = G2U(pszFileContent);
//特殊字符转换
char* pszUrlEncodeContent = curl_escape(pszUftFileContent, dwLength);
dwLength = strlen(pszUrlEncodeContent);
pRequest->SetAdditionalDataToSend((BYTE*)pszUrlEncodeContent, dwLength);
bRes = FALSE;
if (pRequest->Send(VERB_POST) == ERROR_SUCCESS)
{
bRes = pRequest->WaitResult();
}
if (!bRes)
{
CFileOperTools::GetInstance()->WriteComLog(_T("CMainFrame::UploadDevMarketDataToCloudThread() upload market data failed"));
}
else
{
bRes = DeleteFile(strRecordFile);
if (!bRes)
{
CFileOperTools::GetInstance()->WriteComLog(_T("CMainFrame::UploadDevMarketDataToCloudThread() delete local market data file failed"));
}
}
if (pszFileContent != NULL)
{
delete[] pszFileContent;
pszFileContent = NULL;
}
}
} while (FindNextFile(hFind, &wfd));
FindClose(hFind);
return 0;
}
LRESULT CMainFrame::OnRefreshMainWndMenu(WPARAM wParam, LPARAM lParam)
{
ModifyMenuLanguage(g_iUILanguage);
return 0;
}