a
This commit is contained in:
@@ -0,0 +1,660 @@
|
||||
// DevManager.cpp: implementation of the CDevManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "DevManager.h"
|
||||
#include "FileOperTools.h"
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
extern float tcp_ntohf(float f);
|
||||
extern CString g_szMacAddress;
|
||||
extern int g_iUILanguage;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
extern CGeoMativeApp theApp;
|
||||
extern HHOOK hHook;
|
||||
extern LRESULT __stdcall CBTHookProc(long nCode, WPARAM wParam, LPARAM lParam);
|
||||
CDevManager::CDevManager(_ConnectionPtr& pConnection)
|
||||
{
|
||||
ASSERT(NULL != pConnection);
|
||||
m_pConnection = pConnection;
|
||||
m_devLinkList.DeleteAll();
|
||||
m_setRemoteDev.clear();
|
||||
OutputDebugString(_T("zm: CDevManager::CDevManager() m_devLinkList delete all \n"));
|
||||
}
|
||||
|
||||
CDevManager::~CDevManager()
|
||||
{
|
||||
int iDevIndex = (int)VAL_ZERO;
|
||||
|
||||
iDevIndex++;
|
||||
|
||||
while (NULL != m_devLinkList.Find(iDevIndex))
|
||||
{
|
||||
delete m_devLinkList.Find(iDevIndex);
|
||||
iDevIndex++;
|
||||
}
|
||||
m_devLinkList.DeleteAll();
|
||||
OutputDebugString(_T("zm: CDevManager::~CDevManager() m_devLinkList delete all \n"));
|
||||
}
|
||||
|
||||
CDevice* CDevManager::GetDeviceByID(DWORD dwDevID)
|
||||
{
|
||||
CDevice* pDev = NULL;
|
||||
int iDevIndex = (int)VAL_ZERO;
|
||||
// DWORD dwDevID = (DWORD)VAL_ZERO;
|
||||
|
||||
// dwDevID = m_handleProcessor.GetIDFromHandle(dwHandle);
|
||||
int iDevCount = m_devLinkList.Length();
|
||||
CString strLog;
|
||||
for (iDevIndex = 1; iDevIndex <= iDevCount; iDevIndex++)
|
||||
{
|
||||
pDev = m_devLinkList.Find(iDevIndex);
|
||||
if (pDev != NULL && pDev->m_dwID == dwDevID)
|
||||
{
|
||||
strLog.Format(_T("zm:m_devLinkList size=%d CDevManager::GetDeviceByID(%d) 找到设备%s\n"), iDevCount, iDevIndex, pDev->m_szDevSN);
|
||||
OutputDebugString(strLog);
|
||||
|
||||
return pDev;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
/*pDev = m_devLinkList.Find(++iDevIndex);
|
||||
while (NULL != pDev)
|
||||
{
|
||||
if (pDev->m_dwID == dwDevID)
|
||||
{
|
||||
return pDev;
|
||||
}
|
||||
pDev = m_devLinkList.Find(++iDevIndex);
|
||||
}
|
||||
return pDev;*/
|
||||
}
|
||||
|
||||
CDevice* CDevManager::GetDevice(DWORD dwHandle)
|
||||
{
|
||||
CDevice* pDev = NULL;
|
||||
pDev = m_devLinkList.Get(dwHandle);
|
||||
CString strLog;
|
||||
strLog.Format(_T("zm:CDevManager::GetDevice 通过dwHandle=%d,获取设备%s\n"), dwHandle, pDev->m_szDevSN);
|
||||
OutputDebugString(strLog);
|
||||
return pDev;
|
||||
}
|
||||
|
||||
CDevice* CDevManager::GetRegisterDevice(CString szDevSN, bool &bIsRegister)
|
||||
{
|
||||
bIsRegister = false;
|
||||
_RecordsetPtr pRecDevID = NULL;
|
||||
int iDevIndex = (int)VAL_ZERO;
|
||||
CDevice* pDev = NULL;
|
||||
CString szSql = _T("");
|
||||
|
||||
pDev = m_devLinkList.Find(++iDevIndex);
|
||||
|
||||
while (NULL != pDev)
|
||||
{
|
||||
if (pDev->m_szDevSN == szDevSN)//若设备没注册,不会进入
|
||||
{
|
||||
bIsRegister = true;
|
||||
CStringArray szMacList;
|
||||
theApp.m_pProManager->m_guCodeCreator.GetMacList(&szMacList);
|
||||
|
||||
//for循环解决网卡位置变换的问题
|
||||
for (int i = 0; i < szMacList.GetSize(); i++)
|
||||
{
|
||||
if (pDev->m_szMacAddress == szMacList.GetAt(i))
|
||||
{
|
||||
g_szMacAddress = pDev->m_szMacAddress;
|
||||
return pDev;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
pDev = m_devLinkList.Find(++iDevIndex);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CDevice* CDevManager::GetDevice(CString szDevSN)
|
||||
{
|
||||
_RecordsetPtr pRecDevID = NULL;
|
||||
int iDevIndex = (int)VAL_ZERO;
|
||||
CDevice* pDev = NULL;
|
||||
CString szSql = _T("");
|
||||
|
||||
pDev = m_devLinkList.Find(++iDevIndex);
|
||||
|
||||
while (NULL != pDev)
|
||||
{
|
||||
if (0 == strcmp(pDev->m_szDevSN,szDevSN))//若设备没注册,不会进入
|
||||
{
|
||||
CStringArray szMacList;
|
||||
theApp.m_pProManager->m_guCodeCreator.GetMacList(&szMacList);
|
||||
|
||||
//for循环解决网卡位置变换的问题
|
||||
for (int i = 0; i < szMacList.GetSize(); i++)
|
||||
{
|
||||
if (pDev->m_szMacAddress == szMacList.GetAt(i))
|
||||
{
|
||||
g_szMacAddress = pDev->m_szMacAddress;
|
||||
return pDev;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
pDev = m_devLinkList.Find(++iDevIndex);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CDevManager::InitialDevLinkList()
|
||||
{
|
||||
int iDevIndex = (int)VAL_ZERO;
|
||||
DWORD dwDevHandle = (DWORD)VAL_ZERO;
|
||||
CString szSql = _T("");
|
||||
CDevice* pDev = NULL;
|
||||
_RecordsetPtr pRecDevID = NULL;
|
||||
|
||||
iDevIndex++;
|
||||
|
||||
while (NULL != m_devLinkList.Find(iDevIndex))
|
||||
{
|
||||
delete m_devLinkList.Find(iDevIndex);
|
||||
iDevIndex++;
|
||||
}
|
||||
m_devLinkList.DeleteAll();
|
||||
OutputDebugString(_T("zm: CDevManager::InitialDevLinkList() m_devLinkList delete all \n"));
|
||||
|
||||
pRecDevID.CreateInstance(_uuidof(Recordset));
|
||||
|
||||
pRecDevID->Open(_T("select ID,SN,MacAddress from device order by ID"), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
|
||||
CString strLog;
|
||||
while ((short)VAL_ZERO == pRecDevID->adoEOF)
|
||||
{
|
||||
pDev = new CDevice(pRecDevID->GetCollect(_T("ID")).ulVal, m_pConnection);
|
||||
|
||||
if (NULL != pDev)
|
||||
{
|
||||
pDev->m_szDevSN = (LPCTSTR)(_bstr_t)pRecDevID->GetCollect(_T("SN"));
|
||||
pDev->m_szMacAddress = (LPCTSTR)(_bstr_t)pRecDevID->GetCollect(_T("MacAddress"));
|
||||
// short ucDevType = (pRecDevID->GetCollect(_T("DevType")).vt == VT_NULL ) ? 0 : pRecDevID->GetCollect(_T("DevType")).iVal;
|
||||
pDev->m_uState = PZ_STATE_OFFLINE;
|
||||
pDev->m_uType = PZ_STYLE_DEV;
|
||||
dwDevHandle = m_handleProcessor.GenerateHandle((DWORD)pRecDevID->GetCollect(_T("ID")).ulVal, PZ_STYLE_DEV);
|
||||
strLog.Format(_T("zm:CDevManager::InitialDevLinkList() m_devLinkList.Add(%s)\n"),pDev->m_szDevSN);
|
||||
OutputDebugString(strLog);
|
||||
m_devLinkList.Add(dwDevHandle, pDev);
|
||||
}
|
||||
pRecDevID->MoveNext();
|
||||
}
|
||||
pRecDevID->Close();
|
||||
}
|
||||
|
||||
BOOL CDevManager::AddDevice(CDevice* const pDev)
|
||||
{
|
||||
_RecordsetPtr pRecDev = NULL;
|
||||
_CommandPtr pCmdIns = NULL;
|
||||
_CommandPtr pCmdUpd = NULL;
|
||||
CString szSql = _T("");
|
||||
|
||||
DWORD dwDeID = (DWORD)VAL_ZERO;
|
||||
|
||||
if (NULL != pDev)
|
||||
{
|
||||
pRecDev.CreateInstance(_uuidof(Recordset));
|
||||
|
||||
pCmdIns.CreateInstance(_uuidof(Command));
|
||||
pCmdIns->ActiveConnection = m_pConnection;
|
||||
|
||||
pCmdUpd.CreateInstance(_uuidof(Command));
|
||||
pCmdUpd->ActiveConnection = m_pConnection;
|
||||
|
||||
try
|
||||
{
|
||||
m_pConnection->BeginTrans();
|
||||
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("insert into device(DEname,modelNO,SN,MacAddress) values('%s','%s','%s','%s')"), pDev->m_szDevName, pDev->m_szModelNO, pDev->m_szDevSN,g_szMacAddress);
|
||||
pCmdIns->CommandText = szSql.AllocSysString();
|
||||
pCmdIns->Execute(NULL, NULL, adCmdText);
|
||||
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("select ID from device where SN = '%s'"), pDev->m_szDevSN);
|
||||
pRecDev->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
|
||||
dwDeID = pRecDev->GetCollect(_T("ID")).ulVal;
|
||||
|
||||
pRecDev->Close();
|
||||
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("insert into desetting(DEID,Ifrequency,numformat,Tsys,Mvoltage,Msys,maxRG,Tzone,STdelay,PSmode,PBtone,Ttone,Bvoltage,dimmer,lang) "
|
||||
"values(%u,0,0,0,0,0,0,0,0,0,0,0,0,0,0)"), dwDeID);
|
||||
pCmdIns->CommandText = szSql.AllocSysString();
|
||||
pCmdIns->Execute(NULL, NULL, adCmdText);
|
||||
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("insert into acds(DEID,M0ST,M0TW,M1ST,M1TW,M2ST,M2TW,M3ST,M3TW,M4ST,M4TW,M5ST,M5TW,M6ST,M6TW,M7ST,M7TW,M8ST,M8TW,M9ST,M9TW, ")
|
||||
_T("M10ST,M10TW,M11ST,M11TW,M12ST,M12TW,M13ST,M13TW,M14ST,M14TW,M15ST,M15TW,M16ST,M16TW,M17ST,M17TW,M18ST,M18TW,M19ST,M19TW) ")
|
||||
_T("values(%u,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)"), dwDeID);
|
||||
pCmdIns->CommandText = szSql.AllocSysString();
|
||||
pCmdIns->Execute(NULL, NULL, adCmdText);
|
||||
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("update td set DEID = %u where DESN = '%s'"), dwDeID, pDev->m_szDevSN);
|
||||
pCmdUpd->CommandText = szSql.AllocSysString();
|
||||
pCmdUpd->Execute(NULL, NULL, adCmdText);
|
||||
|
||||
pDev->SetID(dwDeID);
|
||||
SetDeviceHandle(pDev);
|
||||
|
||||
m_pConnection->CommitTrans();
|
||||
}
|
||||
catch (_com_error e)
|
||||
{
|
||||
CString strInfo=_T("");
|
||||
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strInfo.Format(_T("添加设备异常 %s"), (LPCTSTR)e.Description());
|
||||
AfxMessageBox(strInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
strInfo.Format(_T("AddDevice exception,msg = %s"), (LPCTSTR)e.Description());
|
||||
MessageBoxEx(NULL, strInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
m_pConnection->RollbackTrans();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CDevManager::SetDeviceHandle(CDevice* const pDev)
|
||||
{
|
||||
DWORD dwDevHandle = (DWORD)VAL_ZERO;
|
||||
if (NULL == pDev)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dwDevHandle = m_handleProcessor.GenerateHandle(pDev->m_dwID, PZ_STYLE_DEV);
|
||||
m_devLinkList.SetHandle(pDev, dwDevHandle);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CDevManager::DeleteObjInMem(DWORD dwHandle)
|
||||
{
|
||||
CDevice* pDev = NULL;
|
||||
|
||||
pDev = m_devLinkList.Get(dwHandle);
|
||||
CString strLog;
|
||||
strLog.Format(_T("zm:CDevManager::DeleteObjInMem(DWORD dwHandle) m_devLinkList.Delete(%s)\n"), pDev->m_szDevSN);
|
||||
OutputDebugString(strLog);
|
||||
delete pDev;
|
||||
|
||||
m_devLinkList.Delete(dwHandle);
|
||||
}
|
||||
|
||||
void CDevManager::DeleteObjInMem(CString szDevSN)
|
||||
{
|
||||
CDevice* pDev = NULL;
|
||||
pDev = this->GetDevice(szDevSN);
|
||||
if (pDev == NULL)
|
||||
{
|
||||
//ASSERT(pDev != NULL);
|
||||
return;
|
||||
}
|
||||
CString strLog;
|
||||
strLog.Format(_T("zm:CDevManager::DeleteObjInMem(CString szDevSN) m_devLinkList.Delete(%s)\n"), pDev->m_szDevSN);
|
||||
OutputDebugString(strLog);
|
||||
m_devLinkList.Delete((CDevice*)pDev);
|
||||
delete pDev;
|
||||
}
|
||||
|
||||
void CDevManager::AddObjInMem(CString szDevSN)
|
||||
{
|
||||
CDevice* pDev = NULL;
|
||||
DWORD dwDevHandle = (DWORD)VAL_ZERO;
|
||||
|
||||
pDev = new CDevice((DWORD)VAL_ZERO, m_pConnection);
|
||||
|
||||
pDev->m_szMacAddress = theApp.m_pProManager->m_guCodeCreator.GenerateMacAddress();
|
||||
|
||||
pDev->m_szDevSN = szDevSN;
|
||||
pDev->m_uState = PZ_STATE_NEW;
|
||||
pDev->m_uType = PZ_STYLE_DEV;
|
||||
|
||||
dwDevHandle = m_handleProcessor.GenerateHandle(pDev->m_dwID, PZ_STYLE_DEV);
|
||||
CString strLog;
|
||||
strLog.Format(_T("zm:CDevManager::AddObjInMem(CString szDevSN) m_devLinkList.Add(%s)"), pDev->m_szDevSN);
|
||||
OutputDebugString(strLog);
|
||||
m_devLinkList.Add(dwDevHandle, pDev);
|
||||
}
|
||||
|
||||
void CDevManager::AddOfflineObjInMem(CString szDevSN)
|
||||
{
|
||||
CDevice* pDev = NULL;
|
||||
DWORD dwDevHandle = (DWORD)VAL_ZERO;
|
||||
CString strLog;
|
||||
pDev = new CDevice((DWORD)VAL_ZERO, m_pConnection);
|
||||
if (NULL == pDev)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("zm:CDevManager::AddOfflineObjInMem NULL == pDev"));
|
||||
return;
|
||||
}
|
||||
|
||||
_RecordsetPtr pRecDev = NULL;
|
||||
pRecDev.CreateInstance(_uuidof(Recordset));
|
||||
CString strSql;
|
||||
strSql.Format(_T("select ID,SN from device where SN='%s'"), szDevSN);
|
||||
pRecDev->Open(strSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true),
|
||||
adOpenStatic, adLockOptimistic, adCmdText);
|
||||
if ((long)VAL_ZERO == pRecDev->GetRecordCount())
|
||||
{
|
||||
return;
|
||||
}
|
||||
pDev->m_dwID = (DWORD)pRecDev->GetCollect(_T("ID")).ulVal;
|
||||
pRecDev->Close();
|
||||
|
||||
|
||||
pDev->m_szMacAddress = theApp.m_pProManager->m_guCodeCreator.GenerateMacAddress();
|
||||
|
||||
pDev->m_szDevSN = szDevSN;
|
||||
pDev->m_uState = PZ_STATE_OFFLINE;
|
||||
pDev->m_uType = PZ_STYLE_DEV;
|
||||
|
||||
dwDevHandle = m_handleProcessor.GenerateHandle(pDev->m_dwID, PZ_STYLE_DEV);
|
||||
strLog.Format(_T("zm:CDevManager::AddOfflineObjInMem(CString szDevSN) m_devLinkList.Add(%s)\n"), pDev->m_szDevSN);
|
||||
OutputDebugString(strLog);
|
||||
m_devLinkList.Add(dwDevHandle, pDev);
|
||||
}
|
||||
|
||||
BOOL CDevManager::DeleteDevice(DWORD dwHandle)
|
||||
{
|
||||
CString szSql = _T("");
|
||||
_CommandPtr pCmdDel = NULL;
|
||||
_CommandPtr pCmdUpd = NULL;
|
||||
|
||||
DWORD dwID = (DWORD)VAL_ZERO;
|
||||
try
|
||||
{
|
||||
m_pConnection->BeginTrans();
|
||||
|
||||
dwID = this->m_handleProcessor.GetIDFromHandle(dwHandle);
|
||||
this->DeleteObjInMem(dwHandle);
|
||||
|
||||
pCmdDel.CreateInstance(_uuidof(Command));
|
||||
pCmdDel->ActiveConnection = m_pConnection;
|
||||
|
||||
pCmdUpd.CreateInstance(_uuidof(Command));
|
||||
pCmdUpd->ActiveConnection = m_pConnection;
|
||||
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("delete from acds where DEID = %u"), dwID);
|
||||
pCmdDel->CommandText = szSql.AllocSysString();
|
||||
pCmdDel->Execute(NULL, NULL, adCmdText);
|
||||
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("delete from desetting where DEID = %u"), dwID);
|
||||
pCmdDel->CommandText = szSql.AllocSysString();
|
||||
pCmdDel->Execute(NULL, NULL, adCmdText);
|
||||
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("delete from device where ID = %u"), dwID);
|
||||
pCmdDel->CommandText = szSql.AllocSysString();
|
||||
pCmdDel->Execute(NULL, NULL, adCmdText);
|
||||
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("update td set DEID = 0 where DEID = %u"), dwID);
|
||||
pCmdUpd->CommandText = szSql.AllocSysString();
|
||||
pCmdUpd->Execute(NULL, NULL, adCmdText);
|
||||
|
||||
m_pConnection->CommitTrans();
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
m_pConnection->RollbackTrans();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CDevManager::DeleteDevice(CString strDev)
|
||||
{
|
||||
CString szSql = _T("");
|
||||
_CommandPtr pCmdDel = NULL;
|
||||
if (strDev.IsEmpty())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("删除设备时设备名不能为空"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Devcie name can not be NULL in Delete device!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m_pConnection->BeginTrans();
|
||||
|
||||
pCmdDel.CreateInstance(_uuidof(Command));
|
||||
pCmdDel->ActiveConnection = m_pConnection;
|
||||
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("delete from device where SN = '%s'"), strDev);
|
||||
pCmdDel->CommandText = szSql.AllocSysString();
|
||||
pCmdDel->Execute(NULL, NULL, adCmdText);
|
||||
|
||||
m_pConnection->CommitTrans();
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
catch (_com_error e)
|
||||
{
|
||||
CString strInfo = _T("");
|
||||
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strInfo.Format(_T("删除设备异常 %s"), (LPCTSTR)e.Description());
|
||||
AfxMessageBox(strInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
strInfo.Format(_T("DeleteDevice exception,msg = %s"), (LPCTSTR)e.Description());
|
||||
MessageBoxEx(NULL, strInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
|
||||
m_pConnection->RollbackTrans();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOL CDevManager::GetOLDevList(CPtrArray *pOLDevList)
|
||||
{
|
||||
CString strLog;
|
||||
strLog.Format(_T("zm:CDevManager::GetOLDevList获取在线设备列表 begin.....\n"));
|
||||
OutputDebugString(strLog);
|
||||
CDevice* pDev = NULL;
|
||||
int iDevIndex = (int)VAL_ZERO;
|
||||
|
||||
pDev = m_devLinkList.Find(++iDevIndex);
|
||||
while (NULL != pDev)
|
||||
{
|
||||
if ((PZ_STATE_ONLINE == pDev->m_uState) || (PZ_STATE_NEW == pDev->m_uState))
|
||||
{
|
||||
pOLDevList->Add(pDev);
|
||||
strLog.Format(_T("zm:CDevManager::GetOLDevList 新增设备 DevSN=%s iDevIndex=%d\n"), pDev->m_szDevSN, iDevIndex);
|
||||
OutputDebugString(strLog);
|
||||
}
|
||||
pDev = m_devLinkList.Find(++iDevIndex);
|
||||
}
|
||||
strLog.Format(_T("zm:CDevManager::GetOLDevList获取在线设备列表 end.....\n"));
|
||||
OutputDebugString(strLog);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CDevManager::GetFLDevList(CPtrArray* pFLDevList)
|
||||
{
|
||||
OutputDebugString(_T("zm:CDevManager::GetFLDevList() 添加离线设备 begin.............\n"));
|
||||
int iIndex = (int)VAL_ZERO;
|
||||
_RecordsetPtr pRecDev = NULL;
|
||||
CDevice* pDevice = NULL;
|
||||
|
||||
pFLDevList->RemoveAll();
|
||||
|
||||
iIndex = (int)VAL_ZERO;
|
||||
|
||||
pRecDev.CreateInstance(_uuidof(Recordset));
|
||||
|
||||
/*//过滤离线数据库中的在线设备
|
||||
//获取远端在线设备
|
||||
std::set<STSigRemoteDev> setRemoteDev = theApp.m_pDevManager->GetRemoteDeviceInfo();
|
||||
std::list<CString> listOnlineDev;
|
||||
if (setRemoteDev.size() > 0)
|
||||
{
|
||||
CString strSN,strLog;
|
||||
int iDevStyle = 0;
|
||||
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);
|
||||
listOnlineDev.push_back(strSN);
|
||||
|
||||
|
||||
strLog.Format(_T("zm: 当前在线的GD设备 DevSN=%s\n"), strSN);
|
||||
OutputDebugString(strLog);
|
||||
}
|
||||
else if (iter->ucDevType == EN_DEV_PLC)
|
||||
{
|
||||
strSN.Format(_T("PLC%u"), iter->uiDevID);
|
||||
listOnlineDev.push_back(strSN);
|
||||
|
||||
strLog.Format(_T("zm: 当前在线的PLC设备 PLCID = %s\n"), strSN);
|
||||
OutputDebugString(strLog);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
pRecDev->Open(_T("select ID,SN from device order by ID"), _variant_t((IDispatch*)m_pConnection, true),
|
||||
adOpenStatic, adLockOptimistic, adCmdText);
|
||||
CString strLog;
|
||||
DWORD dwDevID = 0;
|
||||
CString strDevSN;
|
||||
while ((short)VAL_ZERO == pRecDev->adoEOF)
|
||||
{
|
||||
pDevice = NULL;
|
||||
dwDevID = (DWORD)pRecDev->GetCollect(_T("ID")).ulVal;
|
||||
strDevSN = (LPCTSTR)(_bstr_t)pRecDev->GetCollect(_T("SN"));
|
||||
strLog.Format(_T("zm:设备数据库ID=%d,DevSN=%s\n"), dwDevID,strDevSN);
|
||||
OutputDebugString(strLog);
|
||||
pDevice = this->GetDeviceByID(dwDevID);
|
||||
if (pDevice != NULL)
|
||||
{
|
||||
if (PZ_STATE_OFFLINE == pDevice->m_uState)
|
||||
{
|
||||
strLog.Format(_T("zm:CDevManager::GetFLDevList() 添加离线设备 =%s\n"), pDevice->m_szDevSN);
|
||||
OutputDebugString(strLog);
|
||||
/*std::list<CString>::iterator iter = listOnlineDev.begin();
|
||||
for (iter; iter != listOnlineDev.end(); iter++)
|
||||
{
|
||||
if (strcmp(*iter, pDevice->m_szDevSN) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (iter == listOnlineDev.end())*/
|
||||
pFLDevList->Add(pDevice);
|
||||
}
|
||||
}
|
||||
pRecDev->MoveNext();
|
||||
}
|
||||
pRecDev->Close();
|
||||
OutputDebugString(_T("zm:CDevManager::GetFLDevList() 添加离线设备 end.............\n"));
|
||||
return TRUE;
|
||||
}
|
||||
void CDevManager::UpdateDevInfo(STSynDevParam stDevParam, BYTE bRemoteDeveTyp)
|
||||
{
|
||||
_CommandPtr pCmdUpd = NULL;
|
||||
CString szSql = _T("");
|
||||
_ConnectionPtr pConnection = m_pConnection;
|
||||
|
||||
pCmdUpd.CreateInstance(_uuidof(Command));
|
||||
pCmdUpd->ActiveConnection = m_pConnection;
|
||||
|
||||
pConnection->BeginTrans();
|
||||
//存入数据
|
||||
STSynDevParam *DevPar = (STSynDevParam*)&stDevParam;
|
||||
CString Hwv; Hwv.Format("V%u.%u", DevPar->ucHWVer[0], DevPar->ucHWVer[1]);
|
||||
CString Swv; Swv.Format("V%u.%u.%u_T%u", DevPar->ucSWVer[0], DevPar->ucSWVer[1], DevPar->ucSWVer[2], DevPar->ucSWVer[3]);
|
||||
CString szDevSN;
|
||||
CString szBatVol;
|
||||
int iGrTh;
|
||||
szDevSN.Format(_T("SN%u"), ntohl(DevPar->uiMachineID));
|
||||
iGrTh = ntohl(DevPar->iGrThreshold);
|
||||
szBatVol.Format("%.2f", (tcp_ntohf(DevPar->fBatteryVol)));
|
||||
/*if (EN_DEV_CLOUND == bRemoteDeveTyp)
|
||||
{
|
||||
szBatVol.Format("%.2f", (tcp_ntohf(DevPar->fBatteryVol)));
|
||||
}
|
||||
else
|
||||
{
|
||||
szBatVol.Format("%.2f", DevPar->fBatteryVol);
|
||||
}*/
|
||||
|
||||
int ucDownLoadNum; //下发数不能小于通道数
|
||||
if (DevPar->ucDownLoadNum < DevPar->ucChannelNum){ ucDownLoadNum = DevPar->ucChannelNum; }
|
||||
|
||||
try
|
||||
{
|
||||
//写入数据库
|
||||
szSql.Empty();
|
||||
szSql.Format(_T("update device set HWV = '%s', SWV = '%s', BatVol = %s, PowerFreq = %d, CableType = %d, GrTh = %d,\
|
||||
BatAlarm = %d, Stack = %d, ChanNum = %d, DownNum = %d where SN = '%s'"), Hwv, Swv, szBatVol, DevPar->ucPowerFreq, \
|
||||
DevPar->ucCableType,iGrTh, DevPar->ucBatteryAlarm, DevPar->ucStacking, \
|
||||
DevPar->ucChannelNum, ucDownLoadNum, szDevSN);
|
||||
CFileOperTools::GetInstance()->WriteComLog(szSql);
|
||||
pCmdUpd->CommandText = szSql.AllocSysString();
|
||||
pCmdUpd->Execute(NULL, NULL, adCmdText);
|
||||
}
|
||||
catch (_com_error e)
|
||||
{
|
||||
// 显示错误信息
|
||||
AfxMessageBox(e.Description());
|
||||
}
|
||||
pConnection->CommitTrans();
|
||||
}
|
||||
|
||||
|
||||
//DEL void CDevManager::ModifyTimeWindow(DWORD f_handle)
|
||||
//DEL {
|
||||
//DEL CString szSql = _T("");
|
||||
//DEL
|
||||
//DEL DWORD dwID = (DWORD)VAL_ZERO;
|
||||
//DEL
|
||||
//DEL dwID = this->m_handleProcessor.GetIDFromHandle(f_handle);
|
||||
//DEL
|
||||
//DEL CUpDateTimeWindow timeWindow;
|
||||
//DEL timeWindow.m_dwID = dwID;
|
||||
//DEL timeWindow.m_pConnection = m_pConnection;
|
||||
//DEL timeWindow.DoModal();
|
||||
//DEL
|
||||
//DEL
|
||||
//DEL
|
||||
//DEL }
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,622 @@
|
||||
// PasswordMng.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "PasswordMng.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPasswordMng dialog
|
||||
extern int g_iUILanguage;
|
||||
extern CGeoMativeApp theApp;
|
||||
extern HHOOK hHook;
|
||||
extern LRESULT __stdcall CBTHookProc(long nCode, WPARAM wParam, LPARAM lParam);
|
||||
extern BOOL GetSubStringInHeadAndTail(const CString& szSource, CString& szSub, const CString& szHead, const CString& szTail);
|
||||
CPasswordMng::CPasswordMng(_ConnectionPtr& pConnection,CWnd* pParent /*=NULL*/)
|
||||
: CDialog(CPasswordMng::IDD, pParent)
|
||||
{
|
||||
//{{AFX_DATA_INIT(CPasswordMng)
|
||||
m_edConfirmPass = _T("");
|
||||
m_edNewPass = _T("");
|
||||
m_edOldPass = _T("");
|
||||
//}}AFX_DATA_INIT
|
||||
|
||||
m_pConnection = pConnection;
|
||||
m_strDBGD10Paswword = _T("");
|
||||
m_strDBGeoPassword = _T("");
|
||||
m_mapPasswordMng.clear();
|
||||
}
|
||||
|
||||
|
||||
void CPasswordMng::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(CPasswordMng)
|
||||
DDX_Control(pDX, IDC_COMBO_MACHINE_ID, m_cmbMachineID);
|
||||
DDX_Control(pDX, IDC_COMBO_PASS_OPER_TYPE, m_cmbOperType);
|
||||
DDX_Control(pDX, IDC_COMBO_MACHINE_TYPE, m_cmbMachineType);
|
||||
DDX_Text(pDX, IDC_EDIT_CONFIRM_PASS, m_edConfirmPass);
|
||||
DDV_MaxChars(pDX, m_edConfirmPass, 50);
|
||||
DDX_Text(pDX, IDC_EDIT_NEW_PASS, m_edNewPass);
|
||||
DDV_MaxChars(pDX, m_edNewPass, 50);
|
||||
DDX_Text(pDX, IDC_EDIT_OLD_PASS, m_edOldPass);
|
||||
DDV_MaxChars(pDX, m_edOldPass, 50);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CPasswordMng, CDialog)
|
||||
//{{AFX_MSG_MAP(CPasswordMng)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO_PASS_OPER_TYPE, OnSelchangeComboPassOperType)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO_MACHINE_TYPE, OnSelchangeComboMachineType)
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPasswordMng message handlers
|
||||
|
||||
void CPasswordMng::OnSelchangeComboPassOperType()
|
||||
{
|
||||
// TODO: Add your control notification handler code here
|
||||
int nCurSel = m_cmbOperType.GetCurSel();
|
||||
if (CB_ERR == nCurSel)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("请正确选择操作类型!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Please chose operation type correctly!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
m_edOldPass.Empty();
|
||||
m_edNewPass.Empty();
|
||||
m_edConfirmPass.Empty();
|
||||
UpdateData(FALSE);
|
||||
ShowPasswordInfo(nCurSel);
|
||||
}
|
||||
|
||||
BOOL CPasswordMng::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
// TODO: Add extra initialization here
|
||||
m_mapPasswordMng.clear();
|
||||
theApp.GetPasswordPtr(m_mapPasswordMng);
|
||||
|
||||
//get online device
|
||||
CPtrArray olDevList;
|
||||
CDevice* pDev = NULL;
|
||||
olDevList.RemoveAll();
|
||||
theApp.m_pDevManager->GetOLDevList(&olDevList);
|
||||
int iIndex = (int)VAL_ZERO;
|
||||
m_cmbMachineID.Clear();
|
||||
while (iIndex < olDevList.GetSize())
|
||||
{
|
||||
pDev = NULL;
|
||||
pDev = (CDevice*)olDevList.GetAt(iIndex);
|
||||
if (PZ_STATE_NEW != pDev->m_uState)
|
||||
{
|
||||
m_cmbMachineID.AddString(pDev->m_szDevSN);
|
||||
m_cmbMachineID.SetItemDataPtr(m_cmbMachineID.GetCount() - 1, pDev);
|
||||
}
|
||||
iIndex++;
|
||||
}
|
||||
m_cmbMachineID.SetCurSel(0);
|
||||
|
||||
//set machine type info
|
||||
m_cmbMachineType.Clear();
|
||||
m_cmbMachineType.AddString(_T("Geomative"));
|
||||
m_cmbMachineType.AddString(_T("GD-20"));
|
||||
m_cmbMachineType.SetCurSel(0);
|
||||
|
||||
//set operation type
|
||||
m_cmbOperType.Clear();
|
||||
m_cmbOperType.AddString(_T("Create Password"));
|
||||
m_cmbOperType.AddString(_T("Modify Password"));
|
||||
m_cmbOperType.AddString(_T("Delete Password"));
|
||||
m_cmbOperType.SetCurSel(0);
|
||||
|
||||
//disable gd10 devcie_name infomation
|
||||
m_cmbMachineID.EnableWindow(FALSE);
|
||||
|
||||
UpdateData(FALSE);
|
||||
ShowPasswordInfo(0);
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
||||
//DEL void CPasswordMng::GetDBPasswordInfo()
|
||||
//DEL {
|
||||
//DEL _RecordsetPtr pRecInfo= NULL;
|
||||
//DEL pRecInfo.CreateInstance(_uuidof(Recordset));
|
||||
//DEL m_mapPasswordMng.clear();
|
||||
//DEL CString strDevName;
|
||||
//DEL CString strGeoName = _T("Geomative");
|
||||
//DEL try
|
||||
//DEL {
|
||||
//DEL pRecInfo->Open(_T("select * from password_info"), _variant_t((IDispatch*)m_pConnection, true),
|
||||
//DEL adOpenStatic, adLockOptimistic, adCmdText);
|
||||
//DEL bool bFirstGeo = false;
|
||||
//DEL STDBPasswordInfo stDBPassInfo;
|
||||
//DEL while ((short)VAL_ZERO == pRecInfo->adoEOF)
|
||||
//DEL {
|
||||
//DEL //只获取第一个Geomative的密码
|
||||
//DEL if (!bFirstGeo && (1 == pRecInfo->GetCollect(_T("DevType")).iVal) )
|
||||
//DEL {
|
||||
//DEL stDBPassInfo.nTableID = (int)(pRecInfo->GetCollect(_T("ID")).iVal);
|
||||
//DEL stDBPassInfo.strPassword.Empty();
|
||||
//DEL stDBPassInfo.strPassword = (CString)(LPCTSTR)(_bstr_t)pRecInfo->GetCollect(_T("Password"));
|
||||
//DEL bFirstGeo = true;
|
||||
//DEL m_mapPasswordMng.insert(std::make_pair(strGeoName,stDBPassInfo));
|
||||
//DEL }
|
||||
//DEL
|
||||
//DEL //获取GD10主机的密码,如果这里存在相同的主机名,则只获取第一个主机的密码
|
||||
//DEL if (2 == pRecInfo->GetCollect(_T("DevType")).iVal)
|
||||
//DEL {
|
||||
//DEL stDBPassInfo.strPassword.Empty();
|
||||
//DEL strDevName.Empty();
|
||||
//DEL stDBPassInfo.nTableID = (int)(pRecInfo->GetCollect(_T("ID")).iVal);
|
||||
//DEL strDevName = (CString)(LPCTSTR)(_bstr_t)pRecInfo->GetCollect(_T("DevName"));
|
||||
//DEL stDBPassInfo.strPassword = (CString)(LPCTSTR)(_bstr_t)pRecInfo->GetCollect(_T("Password"));
|
||||
//DEL m_mapPasswordMng.insert(std::make_pair(strDevName,stDBPassInfo));
|
||||
//DEL }
|
||||
//DEL pRecInfo->MoveNext();
|
||||
//DEL }
|
||||
//DEL
|
||||
//DEL }
|
||||
//DEL catch (_com_error e)
|
||||
//DEL {
|
||||
//DEL hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
|
||||
//DEL AfxMessageBox(e.Description());
|
||||
//DEL m_pConnection->RollbackTrans();
|
||||
//DEL }
|
||||
//DEL pRecInfo->Close();
|
||||
//DEL return;
|
||||
//DEL
|
||||
//DEL }
|
||||
|
||||
void CPasswordMng::OnSelchangeComboMachineType()
|
||||
{
|
||||
// TODO: Add your control notification handler code here
|
||||
int nCurSel = m_cmbMachineType.GetCurSel()+1;
|
||||
if (enGeomativeType == nCurSel)
|
||||
{
|
||||
m_cmbMachineID.EnableWindow(FALSE);
|
||||
}
|
||||
else if (enGD10Type == nCurSel)
|
||||
{
|
||||
m_cmbMachineID.EnableWindow(TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("不支持设备类型"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Not Support Machine-type!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool CPasswordMng::OperatePassword(int nOperateType, STOperDBPassword stOperDB, CString strOldPassword)
|
||||
{
|
||||
CString strSql = _T("");
|
||||
CString strErr = _T("");
|
||||
switch(nOperateType)
|
||||
{
|
||||
case enCreatePassword:
|
||||
if (1 == stOperDB.nDevType)
|
||||
{
|
||||
strSql.Format(_T("insert into password_info(DevType, DevPassword) values(%d, '%s')"),
|
||||
stOperDB.nDevType, stOperDB.strPassword);
|
||||
}
|
||||
else if(2 == stOperDB.nDevType)
|
||||
{
|
||||
strSql.Format(_T("insert into password_info(DevType,DevPassword,DevName) values(%d,'%s','%s')"),
|
||||
stOperDB.nDevType, stOperDB.strPassword,stOperDB.strDevName);
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Empty();
|
||||
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strErr.Format(_T("不支持设备类型%d"), stOperDB.nDevType);
|
||||
AfxMessageBox(strErr.GetBuffer(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Format(_T("Not support device_type = %d"), stOperDB.nDevType);
|
||||
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case enModifyPassword:
|
||||
strSql.Format(_T("update password_info set DevPassword = '%s' where ID = %d"),
|
||||
stOperDB.strPassword, stOperDB.nTableID);
|
||||
break;
|
||||
|
||||
case enDeletePassword:
|
||||
strSql.Format(_T("delete from password_info where ID = %d"),stOperDB.nTableID);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strErr.Format(_T("不支持操作数据库类型%d"), stOperDB.nDevType);
|
||||
AfxMessageBox(strErr.GetBuffer(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Format(_T("Not support operation_db_type = %d"), nOperateType);
|
||||
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
_CommandPtr pCmdPro = NULL;
|
||||
pCmdPro.CreateInstance(_uuidof(Command));
|
||||
pCmdPro->ActiveConnection = m_pConnection;
|
||||
try
|
||||
{
|
||||
CString szOrder=_T("");
|
||||
CString szResBuff = _T("");
|
||||
CString szRes = _T("");
|
||||
CString strShowInfo = _T("");
|
||||
//如果这个时候是GD10,则下发相应的命令给GD10,
|
||||
CDevice *pDev = NULL;
|
||||
//如果是GD10的设备,首先进行密码的校验
|
||||
if (enGD10Type == (m_cmbMachineType.GetCurSel()+1))
|
||||
{
|
||||
pDev = (CDevice*)(m_cmbMachineID.GetItemDataPtr(m_cmbMachineID.GetCurSel()));
|
||||
if (NULL == pDev)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
AfxMessageBox(_T("获取设备指针为空"));
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBoxEx(NULL, _T("Get Device-Ptr Failed!!!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
szOrder.Format(_T("check_password(\"%s\")\r\n"),strOldPassword);
|
||||
if (!pDev->ExecuteOrder(szOrder, ">", &szResBuff))
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strShowInfo.Format(_T("执行命令 %s 失败!!!"), szOrder);
|
||||
AfxMessageBox(strShowInfo.GetBuffer(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
strShowInfo.Format(_T("Excute cmd %s failed!!!"), szOrder);
|
||||
MessageBoxEx(NULL, strShowInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (-1 == szResBuff.Find("]"))
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("此功能在设备中不支持,请检查您的gd-20版本!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("This function is not supported in device, please check your gd-20 version!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
GetSubStringInHeadAndTail(szResBuff, szRes, _T("["), _T("]"));
|
||||
if (_T("1") != szRes)
|
||||
{
|
||||
//strShowInfo.Empty();
|
||||
//strShowInfo.Format(_T("check old password error in gd-10"));
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("检查旧密码错误在gd-10"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Check old password error in gd-10"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_pConnection->BeginTrans();
|
||||
/* strSql=_T("select * from password_info");*/
|
||||
pCmdPro->CommandText = strSql.AllocSysString();
|
||||
pCmdPro->Execute(NULL, NULL, adCmdText);
|
||||
|
||||
if (enGD10Type == (m_cmbMachineType.GetCurSel()+1))
|
||||
{
|
||||
szOrder.Empty();
|
||||
szResBuff.Empty();
|
||||
szRes.Empty();
|
||||
pDev = (CDevice*)(m_cmbMachineID.GetItemDataPtr(m_cmbMachineID.GetCurSel()));
|
||||
//如果新设置的密码为空,则表示无密码,底下没有密码的时候设置一个空格字符即可
|
||||
CString strDevPass = stOperDB.strPassword.IsEmpty() ? _T(" ") : stOperDB.strPassword;
|
||||
szOrder.Format(_T("set_param(\"password,%s;\")\r\n"),strDevPass);
|
||||
if (!pDev->ExecuteOrder(szOrder, "]", &szResBuff))
|
||||
{
|
||||
strShowInfo.Empty();
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strShowInfo.Format(_T("执行命令 %s 错误!!!"), szOrder);
|
||||
AfxMessageBox(strShowInfo.GetBuffer(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
strShowInfo.Format(_T("Excute cmd %s failed!!!"), szOrder);
|
||||
MessageBoxEx(NULL, strShowInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
GetSubStringInHeadAndTail(szResBuff, szRes, _T("["), _T("]"));
|
||||
if (_T("1") != szRes)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("GD-10设备设置密码错误"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Set password error in gd-10!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
m_pConnection->RollbackTrans();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_pConnection->CommitTrans();
|
||||
return true;
|
||||
|
||||
}
|
||||
catch (_com_error e)
|
||||
{
|
||||
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
|
||||
AfxMessageBox(e.Description());
|
||||
m_pConnection->RollbackTrans();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPasswordMng::OnOK()
|
||||
{
|
||||
// TODO: Add extra validation here
|
||||
if (!UpdateData(TRUE))
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("数据输入错误"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Data input error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
|
||||
//在这里需要加个对密码的校验判断的功能,不能出现特殊字符
|
||||
|
||||
|
||||
|
||||
STOperDBPassword stOperDBPass;
|
||||
|
||||
stOperDBPass.nDevType = m_cmbMachineType.GetCurSel()+1;
|
||||
//如果选择的是GD10,则获取设备名称
|
||||
if (enGD10Type == stOperDBPass.nDevType)
|
||||
{
|
||||
if ((m_cmbMachineID.GetCount() < 1) || (CB_ERR == m_cmbMachineID.GetCurSel()))
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("设备类型信息错误"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Machine_type information error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return ;
|
||||
}
|
||||
m_cmbMachineID.GetLBText(m_cmbMachineID.GetCurSel(),stOperDBPass.strDevName);
|
||||
}
|
||||
|
||||
CString strKey = (enGD10Type == stOperDBPass.nDevType) ? stOperDBPass.strDevName : _T("Geomative");
|
||||
std::map<CString,STDBPasswordInfo>::iterator iter = m_mapPasswordMng.find(strKey);
|
||||
int nOperTypeSel = m_cmbOperType.GetCurSel();
|
||||
CString strOldSetPass = _T("");
|
||||
switch (nOperTypeSel)
|
||||
{
|
||||
case enCreatePassword:
|
||||
if (m_edNewPass.IsEmpty())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("新密码不能为空!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("New password can not be empty!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
if (iter != m_mapPasswordMng.end())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("设备已设置密码!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("There is already set password for device!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
if (!VerifyPassword(m_edNewPass))
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("输入新密码无效,密码必须由数字和字母组成!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Input new password illeagal,password must be compose of number and letter!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
stOperDBPass.strPassword = m_edNewPass;
|
||||
break;
|
||||
|
||||
case enModifyPassword:
|
||||
if (iter == m_mapPasswordMng.end())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("设备密码未设置,无需修改!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("The password have not be set for device,no need to modify!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
if (m_edNewPass.IsEmpty() || m_edOldPass.IsEmpty() || m_edConfirmPass.IsEmpty())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("设置密码错误,请检查!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Set password error,please check!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
if (m_edNewPass != m_edConfirmPass)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("请确保新密码等于确认密码!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Plase ensure new password equal to confirm password!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
if (!VerifyPassword(m_edNewPass))
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("输入新密码无效,密码必须由数字和字母组成!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Input new password illeagal,password must be compose of number and letter!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
if (m_edOldPass != iter->second.strPassword)
|
||||
{
|
||||
//如果此时和数据库的密码对不上,如果是GD10,还需要对和GD10主机去校验密码
|
||||
//如果GD10主机密码通过,则认为校验密码通过
|
||||
if (enGeomativeType == (m_cmbMachineType.GetCurSel()+1))
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("旧密码错误"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Old password error!!!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
stOperDBPass.nTableID = iter->second.nTableID;
|
||||
stOperDBPass.strPassword = m_edNewPass;
|
||||
strOldSetPass = m_edOldPass;
|
||||
break;
|
||||
|
||||
case enDeletePassword:
|
||||
if (iter == m_mapPasswordMng.end())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("设备密码未设置,无需删除!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("The password have not be set for device,no need to delete!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
//在这里为什么使用m_edNewPass的原因参考ShowPasswordInfo中的注释
|
||||
if (m_edNewPass != iter->second.strPassword)
|
||||
{
|
||||
if (enGeomativeType == (m_cmbMachineType.GetCurSel()+1))
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("旧密码错误"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Old password error!!!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
}
|
||||
//如果是删除的话,只需要获取该条记录的ID即可
|
||||
stOperDBPass.nTableID = iter->second.nTableID;
|
||||
strOldSetPass = m_edNewPass;
|
||||
break;
|
||||
default:
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("不支持操作类型"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Not support operation-type"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
if (!OperatePassword(nOperTypeSel,stOperDBPass,strOldSetPass))
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("操作失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Operation failed!!!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("操作成功"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Operation success!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
CDialog::OnOK();
|
||||
}
|
||||
|
||||
bool CPasswordMng::VerifyPassword(CString strPass)
|
||||
{
|
||||
int nLen = strPass.GetLength();
|
||||
char chInfo;
|
||||
for (int i = 0; i < nLen; i++)
|
||||
{
|
||||
chInfo = strPass[i];
|
||||
if (!((chInfo >= '0' && chInfo <= '9') || (chInfo >= 'a' && chInfo <= 'z') || (chInfo >= 'A' && chInfo <= 'Z')))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPasswordMng::ShowPasswordInfo(int nOperType)
|
||||
{
|
||||
switch (nOperType)
|
||||
{
|
||||
case enCreatePassword:
|
||||
GetDlgItem(IDC_STATIC_NEW_PASS)->SetWindowText(_T("New Password:"));
|
||||
|
||||
GetDlgItem(IDC_EDIT_OLD_PASS)->ShowWindow(SW_HIDE);
|
||||
GetDlgItem(IDC_EDIT_CONFIRM_PASS)->ShowWindow(SW_HIDE);
|
||||
GetDlgItem(IDC_STATIC_OLD_PASS)->ShowWindow(SW_HIDE);
|
||||
GetDlgItem(IDC_STATIC_CONFIRM_PASS)->ShowWindow(SW_HIDE);
|
||||
|
||||
GetDlgItem(IDC_EDIT_NEW_PASS)->ShowWindow(SW_SHOW);
|
||||
GetDlgItem(IDC_STATIC_NEW_PASS)->ShowWindow(SW_SHOW);
|
||||
break;
|
||||
|
||||
case enModifyPassword:
|
||||
GetDlgItem(IDC_STATIC_NEW_PASS)->SetWindowText(_T("New Password:"));
|
||||
GetDlgItem(IDC_EDIT_OLD_PASS)->ShowWindow(SW_SHOW);
|
||||
GetDlgItem(IDC_EDIT_CONFIRM_PASS)->ShowWindow(SW_SHOW);
|
||||
GetDlgItem(IDC_STATIC_OLD_PASS)->ShowWindow(SW_SHOW);
|
||||
GetDlgItem(IDC_STATIC_CONFIRM_PASS)->ShowWindow(SW_SHOW);
|
||||
GetDlgItem(IDC_EDIT_NEW_PASS)->ShowWindow(SW_SHOW);
|
||||
GetDlgItem(IDC_STATIC_NEW_PASS)->ShowWindow(SW_SHOW);
|
||||
break;
|
||||
|
||||
case enDeletePassword:
|
||||
//为了界面的没关,在这里只显示中间的密码控件
|
||||
//同时将界面上的提示由New Password 改为 Old Password
|
||||
//但是在转换为其它的操作方式适合需要改回去,那么在删除密码时获取的密码内容实际是来自于m_edNewPass
|
||||
GetDlgItem(IDC_STATIC_NEW_PASS)->SetWindowText(_T("Old Password:"));
|
||||
|
||||
GetDlgItem(IDC_EDIT_OLD_PASS)->ShowWindow(SW_HIDE);
|
||||
GetDlgItem(IDC_EDIT_CONFIRM_PASS)->ShowWindow(SW_HIDE);
|
||||
GetDlgItem(IDC_STATIC_OLD_PASS)->ShowWindow(SW_HIDE);
|
||||
GetDlgItem(IDC_STATIC_CONFIRM_PASS)->ShowWindow(SW_HIDE);
|
||||
|
||||
GetDlgItem(IDC_EDIT_NEW_PASS)->ShowWindow(SW_SHOW);
|
||||
GetDlgItem(IDC_STATIC_NEW_PASS)->ShowWindow(SW_SHOW);
|
||||
break;
|
||||
|
||||
default:
|
||||
CString strErr = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strErr.Format(_T("不支持操作数据库类型 = %d"), nOperType);
|
||||
AfxMessageBox(strErr.GetBuffer(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Format(_T("Not support operation_db_type = %d"), nOperType);
|
||||
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
// TestManager.cpp: implementation of the CTestManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "TestManager.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CTestManager::CTestManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CTestManager::~CTestManager()
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user