// ClientDemo5Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "ClientDemo5.h"
#include "ClientDemo5Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
	// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA
	
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL
	
	// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClientDemo5Dlg dialog

CClientDemo5Dlg::CClientDemo5Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CClientDemo5Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CClientDemo5Dlg)
	m_nPort = 34567;
	m_strUserName = _T("admin");
	m_strPwd = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_LoginID = 0;
	m_dlgDeviceType = NULL;
	m_nprotolV4 = 0;
	m_userManager=NULL;
	AlarmCfg_RB=FALSE;
	AlarmExp_RB=FALSE;
	AlarmCfg_SC=FALSE;
	AlarmExp_SC=FALSE;
	memset(&m_DeviceInfo,0,sizeof(m_DeviceInfo));
	memset(&m_searchfunc,0,sizeof(m_searchfunc));
}

void CClientDemo5Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CClientDemo5Dlg)
	DDX_Control(pDX, IDC_TAB_MAIN, m_ctlMainTab);
	DDX_Control(pDX, IDC_IPADDRESS_DVRIP, m_ctlDvrIP);
	DDX_Text(pDX, IDC_EDIT_PORT, m_nPort);
	DDX_Text(pDX, IDC_EDIT_USERNAME, m_strUserName);
	DDX_Text(pDX, IDC_EDIT_DVRPWD, m_strPwd);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CClientDemo5Dlg, CDialog)
//{{AFX_MSG_MAP(CClientDemo5Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_LOGIN, OnBtnLogin)
ON_BN_CLICKED(IDC_BTN_LOGOUT, OnBtnLogout)
ON_WM_DESTROY()
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_MAIN, OnSelchangeTabMain)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClientDemo5Dlg message handlers

BOOL CClientDemo5Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	_CWndCS(this);
	// Add "About..." menu item to system menu.
	
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	//Device default IP
	m_ctlDvrIP.SetAddress(192,168,1,230);
	//Initialize TabControl control
	InitTabControl();
	//Initialize SDK
	InitNetSDK();
	
	m_nAlarmOutNum = 0;
	m_nChannelNum = 0;
	m_nAlarmInNum = 0;
	m_nbyChanNum=0;
	m_niDigChannel = 0;
	//	SetTimer(1, 10000, NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CClientDemo5Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CClientDemo5Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting
		
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
		
		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		
		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CClientDemo5Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
BOOL CClientDemo5Dlg::AddPage(CString strTitle, CDialog* dlgPage, UINT uID)
{
	if(NULL == dlgPage)
	{
		return FALSE;
	}
	
	DeletePage();
	
	m_dlgDeviceType = dlgPage;
	
	CRect childRect;
	m_ctlMainTab.GetClientRect(childRect);
	childRect.top += 20;
	childRect.bottom -= 4;
	childRect.left += 4;
	childRect.right -= 4;
	
	m_dlgDeviceType->Create(uID, &m_ctlMainTab);
	m_dlgDeviceType->MoveWindow(childRect);
	m_ctlMainTab.InsertItem(8, strTitle);
	
	return TRUE;
}
BOOL CClientDemo5Dlg::DeletePage()
{
	if(NULL != m_dlgDeviceType)
	{
		int nSel = m_ctlMainTab.GetCurSel();
		m_dlgDeviceType->ShowWindow(FALSE);
		m_dlgDeviceType->CloseWindow();
		m_ctlMainTab.DeleteItem(8);
		delete m_dlgDeviceType;
		m_dlgDeviceType = NULL;
		
		if(nSel == 9)
		{
			m_ctlMainTab.SetCurSel(8);
			DoTab(8);
		}
		else
		{
			DoTab(nSel);
		}
		Invalidate(TRUE);
		return TRUE;
	}
	
	return FALSE;
}

//Register user to device 
#define TYPEMAP(a,b) case a:return (b)

void CClientDemo5Dlg::OnBtnLogin() 
{
	// TODO: Add your control notification handler code here
	BOOL bValid = UpdateData(TRUE);
	if(bValid)
	{
		int err=0;	//Stroage the returned error value
		char *pchDVRIP;
		m_strDvrIP = GetDvrIP();
		pchDVRIP = (LPSTR)(LPCSTR)m_strDvrIP;
		WORD wDVRPort=(WORD)m_nPort;
		char *pchUserName=(LPSTR)(LPCSTR)m_strUserName;
		char *pchPassword=(LPSTR)(LPCSTR)m_strPwd;
		//Device informaiton
		NET_SDK_DEVICEINFO deviceInfo;
		//Call log in interface
		//设置连接次数
		NET_SDK_SetConnectTime(3000, 1);//设置尝试连接1次，等待时间3s
		long lRet = NET_SDK_Login(pchDVRIP,wDVRPort,pchUserName,pchPassword,&deviceInfo,1,&err);
		memcpy(&m_DeviceInfo,&deviceInfo,sizeof(NET_SDK_DEVICEINFO));
		if(0 != lRet)
		{
			m_LoginID = lRet;
			memcpy(&m_DevAttribute.deviveInfo,&deviceInfo,sizeof(deviceInfo));
			
			GetDlgItem(IDC_BTN_LOGIN)->EnableWindow(FALSE);
			GetDlgItem(IDC_BTN_LOGOUT)->EnableWindow(TRUE);
			
			m_nChannelNum = deviceInfo.byChanNum+deviceInfo.iDigChannel;
			m_nAlarmInNum = deviceInfo.byAlarmInPortNum;
			m_nAlarmOutNum = deviceInfo.byAlarmOutPortNum;
			m_nbyChanNum =deviceInfo.byChanNum;
			m_niDigChannel = deviceInfo.iDigChannel;
			//Device property 
			GetDeviceConfigInfo();	

			GetAlarmConfigInfo();

		}
		else
		{
			m_LoginID = 0;
			//Display log in failure reason 
			ShowLoginErrorReason(err);
		}
	}
}

//Logout device user 
void CClientDemo5Dlg::OnBtnLogout() 
{
	// TODO: Add your control notification handler code here
	DeletePage();
	BOOL bRet = NET_SDK_Logout(m_LoginID);
	//Clear handle as o after logout 
	if(bRet)
	{
		m_LoginID=0;
		GetDlgItem(IDC_BTN_LOGIN)->EnableWindow(TRUE);
		GetDlgItem(IDC_BTN_LOGOUT)->EnableWindow(FALSE);
		//Device property 
		m_serverDlg.CleanAll();
		//Video channel property 
		m_channelDlg.CleanAll();
		//COM property 
		m_commDlg.CleanAll();
		//Record configuration 
		m_recordDlg.CleanAll();
		//Network configuration 
		m_networkDlg.CleanAll();
		//Alarm property 
		m_alarmDlg.CleanAll();
		//Ptz
		m_Ptz.CleanAll();
		//Camera Parameters
		m_SysCamera.CleanAll();
		m_channelNS.CleanAll();
		//m_vehicleDlg.CleanAll();
		
	}
}

//message callback function
bool __stdcall MessCallBack(long lLoginID, char *pBuf,
							unsigned long dwBufLen, long dwUser)
{
	CClientDemo5Dlg* pThis = (CClientDemo5Dlg*)dwUser;
	
	return TRUE;
}

//device disconnect callback
void __stdcall DisConnectBackCallFunc(LONG lLoginID, char *pchDVRIP, 
									  LONG nDVRPort, DWORD dwUser)
{
	CClientDemo5Dlg* pThis = (CClientDemo5Dlg*)dwUser;
	if (pThis == NULL)
	{
		ASSERT( FALSE );
		return ;
	}
}

//Initialize SDK
BOOL CClientDemo5Dlg::InitNetSDK()
{
	//initialize
	BOOL bResult = NET_SDK_Init((fNetDisConnect)DisConnectBackCallFunc,(DWORD)this);
	
	//he messages received in SDK from DVR which need to upload， such as alarm information，diary information，may do through callback function
	NET_SDK_SetDVRMessCallBack(MessCallBack,(DWORD)this);
	NET_SDK_SetConnectTime(5000, 3);
	
	return bResult;
}

void CClientDemo5Dlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	// Logout 
	if(0 != m_LoginID)
	{
		DeletePage();
		BOOL bLogout = NET_SDK_Logout(m_LoginID);
	}
	//Clear SDK, release resources  
	if(m_userManager)
	{
		delete m_userManager;
	}
	ExitSDk();
}

//Get DVR IP
CString CClientDemo5Dlg::GetDvrIP()
{
	CString strRet="";
	BYTE nField0,nField1,nField2,nField3;
	m_ctlDvrIP.GetAddress(nField0,nField1,nField2,nField3);
	strRet.Format("%d.%d.%d.%d",nField0,nField1,nField2,nField3);
	return strRet;
}

//Display log in failure reason 
void CClientDemo5Dlg::ShowLoginErrorReason(int nError)
{
}

//Initialize TabControl control
void CClientDemo5Dlg::InitTabControl()
{
	CRect childRect;
	m_ctlMainTab.GetClientRect(childRect);
	childRect.top += 20;
	childRect.bottom -= 4;
	childRect.left += 4;
	childRect.right -= 4;
	
	//Create non-mode dialogue box. Specified tag is non-mode dialogue box father window.
	m_serverDlg.Create(IDD_CONFIG_SERVER, &m_ctlMainTab);
	m_serverDlg.MoveWindow(childRect);
	
	m_channelDlg.Create(IDD_CONFIG_CHANNEL, &m_ctlMainTab);
	m_channelDlg.MoveWindow(childRect);
	m_commDlg.Create(IDD_CONFIG_COMM, &m_ctlMainTab);
	m_commDlg.MoveWindow(childRect);
	m_alarmDlg.Create(IDD_CONFIG_ALARM, &m_ctlMainTab);
	m_alarmDlg.MoveWindow(childRect);
	m_recordDlg.Create(IDD_CONFIG_RECORD, &m_ctlMainTab);
	m_recordDlg.MoveWindow(childRect);
	m_networkDlg.Create(IDD_CONFIG_NETWORK, &m_ctlMainTab);
	m_networkDlg.MoveWindow(childRect);
	m_Ptz.Create(IDD_DLG_SYS_PTZ,&m_ctlMainTab);
	m_Ptz.MoveWindow(childRect);
	m_SysCamera.Create(IDD_DLG_CAMERAPARA, &m_ctlMainTab);
	m_SysCamera.MoveWindow(childRect);
	m_userManager=new  CSysSettingUserManager();
 	m_userManager->Create(IDD_DLG_USER_MANAGER, &m_ctlMainTab);
 	m_userManager->MoveWindow(childRect);
	
	m_channelNS.Create(IDD_CHANNELNAME,&m_ctlMainTab);
	m_channelNS.MoveWindow(childRect);
	m_DigChannelDlg.Create(IDD_DLG_DIGITALCHANNEL, &m_ctlMainTab);
	m_DigChannelDlg.MoveWindow(childRect);
	

	m_ctlMainTab.InsertItem(0, _CS("Title.GeneralConfig"));
	m_ctlMainTab.InsertItem(1, _CS("Title.EncodeConfig"));
	m_ctlMainTab.InsertItem(2, _CS("Title.CommConfig"));
	m_ctlMainTab.InsertItem(3, _CS("Title.RecordConfig"));
	m_ctlMainTab.InsertItem(4, _CS("Title.NetCommonConfig"));
	m_ctlMainTab.InsertItem(5, _CS("Title.AlarmConfig"));
	m_ctlMainTab.InsertItem(6,_CS("Title.PtzConfig"));
	m_ctlMainTab.InsertItem(7, _CS("Title.CameraPara"));
	m_ctlMainTab.InsertItem(8, _CS("Title.UserManager"));
	m_ctlMainTab.InsertItem(9,_CS("Title.ChannelName"));
	//m_ctlMainTab.InsertItem(10,"车载功能");
	m_ctlMainTab.InsertItem(10,_CS("Title.DigitalChannel"));
	m_ctlMainTab.SetCurSel(0);
	DoTab(0);
}
void CClientDemo5Dlg::SetDlgState(CWnd *pWnd, BOOL bShow)
{
	if(bShow)
	{
		pWnd->ShowWindow(SW_SHOW);
	}
	else
	{
		pWnd->ShowWindow(SW_HIDE);
	}
}

void CClientDemo5Dlg::DoTab(int nTab)
{
	//Check nTab value is within the threshold
	if(nTab>12)
	{
		nTab=12;
	}
	if(nTab<0)
	{
		nTab=0;
	}
	
	BOOL bTab[13];
	bTab[0]=bTab[1]=bTab[2]=bTab[3]=bTab[4]=bTab[5]=bTab[6]=bTab[7]=bTab[8]=bTab[9]=bTab[10]=bTab[11]=bTab[12]=FALSE;
	bTab[nTab]=TRUE;
	if ( m_LoginID > 0 )
	{
		if ( nTab == 0)
		{
			GetDeviceConfigInfo();
		}else if ( nTab == 1)
		{
			GetChannelConfigInfo();
		}else if ( nTab == 2)
		{
			GetCommConfigInfo();
		}else if ( nTab == 3)
		{
			GetRecordConfigInfo();
		}
		else if ( nTab == 4)
		{
			GetNetWorkIPV6Config();
			GetNetWorkConfigInfo();
		}
		else if ( nTab == 5)
		{
			GetAlarmConfigInfo();
		}
		else if ( nTab == 6)
		{
			GetPTZConfigInfo();
		}
		else if ( nTab == 7 )
		{
			//摄象机参数
			
			GetCameraPara();
		}
		else if ( nTab == 8 )
		{
			//用户信息
			GetUserInfo();
		}
		else if (nTab ==9)
		{
			GetChannelNS();
			//
		}
		else if (nTab == 10)
		{
			m_DigChannelDlg.OnInitDialog();
			//
		}
	
	}
	
	//Display or hide dialogue box 
	
	SetDlgState(&m_serverDlg,bTab[0]);
	SetDlgState(&m_channelDlg,bTab[1]);
	SetDlgState(&m_commDlg,bTab[2]);
	SetDlgState(&m_recordDlg,bTab[3]);
	SetDlgState(&m_networkDlg,bTab[4]);
	SetDlgState(&m_alarmDlg,bTab[5]);
	SetDlgState(&m_Ptz,bTab[6]);
	SetDlgState(&m_SysCamera, bTab[7]);
	SetDlgState(m_userManager, bTab[8]);
	SetDlgState(&m_channelNS,bTab[9]);


	SetDlgState(&m_DigChannelDlg,bTab[10]);
	if(NULL != m_dlgDeviceType)
	{
		SetDlgState(m_dlgDeviceType,bTab[12]);
	}
}


void CClientDemo5Dlg::OnSelchangeTabMain(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int nSelect = m_ctlMainTab.GetCurSel();
	if(nSelect>=0)
	{
		DoTab(nSelect);
	}
	*pResult = 0;
}

BOOL g_bSignal = TRUE;
void CClientDemo5Dlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if (g_bSignal)
	{
		g_bSignal = FALSE;
	}
	else
	{
		g_bSignal = TRUE;
	}
	
	CDialog::OnTimer(nIDEvent);
}

BOOL CClientDemo5Dlg::ExitSDk()
{
	NET_SDK_Cleanup();
	
	return true;
}

void CClientDemo5Dlg::GetDeviceConfigInfo()
{
	if (0 != m_LoginID)
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		NET_SDK_CONFIG_NORMAL NormalConfig = {0};
		BOOL bSuccess = NET_SDK_GetDevConfig(m_LoginID, NET_SDK_CONFIG_SYSNORMAL ,0, 
			(char *)&NormalConfig ,sizeof(NET_SDK_CONFIG_NORMAL), &dwRetLen,nWaitTime);
		if ( bSuccess && dwRetLen == sizeof(NET_SDK_CONFIG_NORMAL))
		{
			//memcpy(&m_DevAttribute.NormalConfig, &NormalConfig,sizeof(SDK_CONFIG_NORMAL));
			m_DevAttribute.NormalConfig = NormalConfig;
			m_serverDlg.InitDlgInfo(&m_DevAttribute);
		}
	}else
	{
		MessageBox(_CS("Login.LoginFail"));
	}
}

void CClientDemo5Dlg::SetDeviceConfigInfo(DEV_ATTRIBUTE *pDevAttribute)
{
	DWORD dwRetLen = 0;
	int nWaitTime = 10000;
	if (0 != m_LoginID && pDevAttribute != NULL)
	{
		NET_SDK_CONFIG_NORMAL NormalConfig = {0};
		BOOL bSuccess = NET_SDK_GetDevConfig(m_LoginID, NET_SDK_CONFIG_SYSNORMAL ,0, 
			(char *)&NormalConfig ,sizeof(NET_SDK_CONFIG_NORMAL), &dwRetLen,nWaitTime);
		if ( bSuccess && dwRetLen == sizeof(NET_SDK_CONFIG_NORMAL))
		{
			NormalConfig.iLocalNo = pDevAttribute->NormalConfig.iLocalNo;
			NormalConfig.iOverWrite = pDevAttribute->NormalConfig.iOverWrite;
			NormalConfig.iAutoLogout = pDevAttribute->NormalConfig.iAutoLogout;
			NormalConfig.iVideoFormat = pDevAttribute->NormalConfig.iVideoFormat;
			NormalConfig.iDateFormat = pDevAttribute->NormalConfig.iDateFormat;
			NormalConfig.iDateSeparator = pDevAttribute->NormalConfig.iDateSeparator;
			NormalConfig.iTimeFormat = pDevAttribute->NormalConfig.iTimeFormat;
			strcpy(NormalConfig.sMachineName,pDevAttribute->NormalConfig.sMachineName);
			NormalConfig.iLanguage = pDevAttribute->NormalConfig.iLanguage;
			
			BOOL bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_SYSNORMAL,0,(char *)&NormalConfig,sizeof(NET_SDK_CONFIG_NORMAL),nWaitTime);
			if ( bSuccess == NET_SDK_OPT_REBOOT )
			{
				if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
				{
					bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
					if (bSuccess)
					{
						OnBtnLogout();
					}else
					{
						MessageBox(_CS("Error.RebootFail"));
					}
				}
			}else if ( bSuccess > 0)
			{
				MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
			}else{
				MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );
			}
		}
	}
}

void CClientDemo5Dlg::GetChannelConfigInfo()
{
	if (0 !=m_LoginID )
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		NET_SDK_CONFIG_NORMAL NormalConfig = {0};
		BOOL bSuccess = NET_SDK_GetDevConfig(m_LoginID, NET_SDK_CONFIG_SYSNORMAL ,0, 
			(char *)&NormalConfig ,sizeof(NET_SDK_CONFIG_NORMAL), &dwRetLen,nWaitTime);
		if ( bSuccess && dwRetLen == sizeof(NET_SDK_CONFIG_NORMAL))
		{
			NET_SDK_SystemFunction SysFunc;
			bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_ABILITY_SYSFUNC,0,
				(char *)&SysFunc,sizeof(NET_SDK_SystemFunction),&dwRetLen,nWaitTime);
			if (bSuccess && dwRetLen == sizeof(NET_SDK_SystemFunction))
			{
				NET_SDK_EncodeConfigAll CfgEncode = {0};
				bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_SYSENCODE, -1,
					(char *)&CfgEncode,sizeof(NET_SDK_EncodeConfigAll),&dwRetLen,nWaitTime);
				if (bSuccess && dwRetLen == sizeof(NET_SDK_EncodeConfigAll))
				{
					NET_SDK_CONFIG_EncodeAbility EncodeAbility = {0};
					bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_ABILTY_ENCODE,-1,
						(char *)&EncodeAbility,sizeof(NET_SDK_CONFIG_EncodeAbility),&dwRetLen,nWaitTime);
					if (bSuccess && dwRetLen == sizeof(NET_SDK_CONFIG_EncodeAbility))
					{
						NET_SDK_CombineEncodeConfigAll CombineEncodeCfg;
						bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_COMBINEENCODE,-1,
							(char*)&CombineEncodeCfg,sizeof(NET_SDK_CombineEncodeConfigAll),&dwRetLen,nWaitTime);
						if (bSuccess && dwRetLen == sizeof(NET_SDK_CombineEncodeConfigAll))
						{
							NET_SDK_CombEncodeModeAll CmbEncodeMode;
							bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_COMBINEENCODEMODE,-1,
								(char *)&CmbEncodeMode,sizeof(NET_SDK_CombEncodeModeAll),&dwRetLen,nWaitTime);
							if (bSuccess && dwRetLen == sizeof(NET_SDK_CombEncodeModeAll))
							{
								m_channelDlg.InitDlgInfo(m_nbyChanNum,&CfgEncode,&NormalConfig,&EncodeAbility,&CombineEncodeCfg,&SysFunc,&m_DevAttribute,&CmbEncodeMode);
							}
						}
					}
				}
			}
		}
	}
}

void CClientDemo5Dlg::SetChannelConfigInfo( NET_SDK_EncodeConfigAll *pEncodeCfg,
										   NET_SDK_CombineEncodeConfigAll *pCmbEncodeCfg,
										   NET_SDK_CombEncodeModeAll *pCmbEncodeMode)
{
	DWORD dwRetLen = 0;
	int nWaitTime = 10000;
	BOOL bReboot = FALSE;
	if (0 != m_LoginID)
	{
		BOOL bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_SYSENCODE,-1,
			(char *)pEncodeCfg,sizeof(NET_SDK_EncodeConfigAll),nWaitTime);
		if(bSuccess)
		{
			if ( bSuccess == NET_SDK_OPT_REBOOT)
			{
				bReboot = TRUE;
			}
			bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_COMBINEENCODE,-1,
				(char *)pCmbEncodeCfg,sizeof(NET_SDK_CombineEncodeConfigAll),nWaitTime);
			if (bSuccess)
			{
				if ( bSuccess == NET_SDK_OPT_REBOOT)
				{
					bReboot = TRUE;
				}
				bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_COMBINEENCODEMODE,-1,
					(char *)pCmbEncodeMode,sizeof(NET_SDK_CombEncodeModeAll),nWaitTime);
				if ( bSuccess == NET_SDK_OPT_REBOOT)
				{
					bReboot = TRUE;
				}
				if ( bReboot == TRUE)
				{
					if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
					{
						bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
						if (bSuccess)
						{
							OnBtnLogout();
						}else
						{
							MessageBox(_CS("Error.RebootFail"));
						}
					}
				}
				if ( bSuccess > 0)
				{
					MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
				}
				else if ( bSuccess < 0 && bSuccess != NET_SDK_OPT_REBOOT )
				{
					MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );
				}
			}
		}
	}
}

void CClientDemo5Dlg::GetCommConfigInfo()
{
	if ( 0 != m_LoginID)
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		NET_SDK_CommConfigAll CfgComm;
		BOOL bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_COMM,-1,
			(char *)&CfgComm,sizeof(NET_SDK_CommConfigAll),&dwRetLen,nWaitTime);
		if (bSuccess && dwRetLen == sizeof(NET_SDK_CommConfigAll))
		{
			NET_SDK_COMMFUNC CommFunc;
			bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_COMFIG_ABILITY_COMMPRO,0,
				(char *)&CommFunc,sizeof(NET_SDK_COMMFUNC),&dwRetLen,nWaitTime);
			if (bSuccess && dwRetLen == sizeof(NET_SDK_COMMFUNC))
			{
				m_commDlg.InitDlgInfo(&CfgComm,&CommFunc);
			}
		}
	}
}

void CClientDemo5Dlg::SetCommConfigInfo(NET_SDK_CommConfigAll *pCommCfg)
{
	int nWaitTime = 10000;
	if( 0 != m_LoginID && pCommCfg != NULL )
	{
		BOOL bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_COMM,-1,
			(char *)pCommCfg,sizeof(NET_SDK_CommConfigAll),nWaitTime);
		if (bSuccess == NET_SDK_OPT_REBOOT)
		{
			if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
			{
				bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
				if (bSuccess)
				{
					OnBtnLogout();
				}else
				{
					MessageBox(_CS("Error.RebootFail"));
				}
			}
		}else if ( bSuccess > 0 )
		{
			MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
		}
		else
		{
			MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );  
		}
	}
}

void CClientDemo5Dlg::GetRecordConfigInfo()
{
	if ( 0 != m_LoginID)
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		NET_SDK_RECORDCONFIG_ALL RecordCfgAll = {0};
		int i =0;
		for(;i<m_nChannelNum;i++)
		{
			BOOL bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_RECORD,i,
				(char *)&RecordCfgAll.vRecordConfigAll[i],sizeof(NET_SDK_RECORDCONFIG),&dwRetLen,nWaitTime);
			if (dwRetLen !=sizeof(NET_SDK_RECORDCONFIG) && !bSuccess)break;
		}
		if (i == m_nChannelNum)
		{
			m_recordDlg.InitDlgInfo(&RecordCfgAll,m_nChannelNum);
		}
	}
}

void CClientDemo5Dlg::SetRecordConfigInfo(NET_SDK_RECORDCONFIG_ALL *pRecordInfo)
{
	if (0 != m_LoginID && pRecordInfo != NULL)
	{
		int nWaitTime = 10000;
		int i = 0;
		BOOL bSuccess = FALSE;
		BOOL bReboot = FALSE;
		for (; i<m_nChannelNum;i++)
		{
			bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_RECORD,i,
				(char *)pRecordInfo,sizeof(NET_SDK_RECORDCONFIG),nWaitTime);
			if (!bSuccess)break;
			if ( bSuccess == NET_SDK_OPT_REBOOT)
			{
				bReboot =TRUE;
			}
		}
		if (i == m_nChannelNum && bReboot == TRUE)
		{
			if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
			{
				bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
				if (bSuccess)
				{
					OnBtnLogout();
				}else
				{
					MessageBox(_CS("Error.RebootFail"));
				}
			}
		}else if ( i == m_nChannelNum && bReboot == FALSE)
		{
			MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
		}else
		{
			MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );  
		}
	}
}
void CClientDemo5Dlg::GetNetWorkIPV6Config()
{
	if ( 0 !=m_LoginID)
	{
		DWORD dwRetLen = 0;
 		int nWaitTime = 10000;
		bool Enable;
		NET_SDK_SystemFunction nSystemFunction;
		NET_SDK_NetIPVersionConfig NetIPVersionCfg = {0};
		NET_SDK_NetCommonIPv6Config NetIPV6Cfg = {0};
		NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_ABILITY_SYSFUNC,-1,(char*)&nSystemFunction,sizeof(nSystemFunction),&dwRetLen,nWaitTime);
		if((nSystemFunction.vOtherFunction[NET_SDK_OTHER_SUPPORT_IPV6/32])&(1<<(NET_SDK_OTHER_SUPPORT_IPV6%32)))
		{
			Enable = true;
			
			BOOL bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_NETIPVERSION,0,
				(char *)&NetIPVersionCfg,sizeof(NetIPVersionCfg),&dwRetLen,nWaitTime);
			
			if (bSuccess )
			{
				
				bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_NETIPV6COMMON,0,
					(char *)&NetIPV6Cfg,sizeof(NetIPV6Cfg),&dwRetLen,nWaitTime);

			
					if (bSuccess)
					{
						m_networkDlg.InitDlgIPV6Info(&NetIPV6Cfg,&NetIPVersionCfg,Enable);
					}
				
			}
		}
		else
		{
			m_networkDlg.InitDlgIPV6Info(&NetIPV6Cfg,&NetIPVersionCfg,Enable);
		}
		
	}
	
}
void CClientDemo5Dlg::SetNetWorkIPV6Config(NET_SDK_NetIPVersionConfig *pNetIPVersion,NET_SDK_NetCommonIPv6Config *pNetIPV6Common)
{
	if (0 != m_LoginID && pNetIPVersion != NULL && pNetIPV6Common != NULL)
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		
		BOOL bReboot = FALSE;

			

		BOOL bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_NETIPVERSION,0,
			(char *)pNetIPVersion,sizeof(NET_SDK_NetIPVersionConfig),nWaitTime);
		if (bSuccess)
		{
			if (bSuccess == NET_SDK_OPT_REBOOT)
			{
				bReboot = TRUE;
			}
			bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_NETIPV6COMMON,0,
				(char *)pNetIPV6Common,sizeof(NET_SDK_NetCommonIPv6Config),nWaitTime);
		
			if (bSuccess)
			{
				if ( bSuccess == NET_SDK_OPT_REBOOT)
				{
					bReboot = TRUE;
				}
				if ( bReboot == TRUE )
				{
					if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
					{
						bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
						if (bSuccess)
						{
							OnBtnLogout();
						}else
						{
							MessageBox(_CS("Error.RebootFail"));
						}
					}
				}
				if ( bSuccess > 0)
				{
					MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
				}else if ( bSuccess < 0 && bSuccess != NET_SDK_OPT_REBOOT)
				{
					MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );
				}
			}
			
		}
	}


}
void CClientDemo5Dlg::GetNetWorkConfigInfo()
{
	if ( 0 !=m_LoginID)
	{
		DWORD dwRetLen = 0;
 		int nWaitTime = 10000;
		NET_SDK_CONFIG_NET_COMMON NetWorkCfg;
		BOOL bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_SYSNET,0,
			(char *)&NetWorkCfg,sizeof(NET_SDK_CONFIG_NET_COMMON),&dwRetLen,nWaitTime);
		long longtest=sizeof(NET_SDK_CONFIG_NET_COMMON);
		if (bSuccess && dwRetLen == sizeof(NET_SDK_CONFIG_NET_COMMON))
		{
			NET_SDK_NetDNSConfig NetDNSCfg;
			bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_NET_DNS,0,
				(char *)&NetDNSCfg,sizeof(NET_SDK_NetDNSConfig),&dwRetLen,nWaitTime);
			
			if (bSuccess && dwRetLen == sizeof(NET_SDK_NetDNSConfig))
			{
				NET_SDK_NetDHCPConfigAll NetDHPCfg;
				bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_NET_DHCP,0,
					(char *)&NetDHPCfg,sizeof(NET_SDK_NetDHCPConfigAll),&dwRetLen,nWaitTime);
				/*if (bSuccess && dwRetLen == sizeof(NET_SDK_NetDHCPConfigAll))
				{
					NET_SDK_NetOrderConfig NetOrder;
					bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_NET_ORDER,0,
						(char *)&NetOrder,sizeof(NET_SDK_NetOrderConfig),&dwRetLen,nWaitTime);
					if (bSuccess)//&& dwRetLen == sizeof(SDK_NetOrderConfig)
					{
						SDK_NetOrderFunction NetOrderFunc;
						bSuccess = NET_SDK_GetDevConfig(m_LoginID,E_SDK_CONFIG_ABILITY_NETORDER,0,
							(char *)&NetOrderFunc,sizeof(SDK_NetOrderFunction),&dwRetLen,nWaitTime);*/
					if (bSuccess)
					{
						m_networkDlg.InitDlgInfo(&NetWorkCfg,&NetDNSCfg,&NetDHPCfg);
					}
						
					
				
			}
		}
	}
}

void CClientDemo5Dlg::SetNetWorkConfigInfo(NET_SDK_CONFIG_NET_COMMON *pNetCommon, NET_SDK_NetDNSConfig *pNetDNS, NET_SDK_NetDHCPConfigAll *pNetDHCP)
{
	if (0 != m_LoginID && pNetCommon != NULL && pNetDNS != NULL && pNetDHCP != NULL)
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		NET_SDK_CONFIG_NET_COMMON NetWorkCfg;
		BOOL bReboot = FALSE;
		BOOL bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_SYSNET,0,
			(char *)&NetWorkCfg,sizeof(NET_SDK_CONFIG_NET_COMMON),&dwRetLen,nWaitTime);
		if (bSuccess && dwRetLen == sizeof (NET_SDK_CONFIG_NET_COMMON))
		{
			memcpy(&NetWorkCfg.HostIP,&pNetCommon->HostIP,sizeof(NET_SDK_CONFIG_IPAddress));
			memcpy(&NetWorkCfg.Gateway,&pNetCommon->Gateway,sizeof(NET_SDK_CONFIG_IPAddress));
			memcpy(&NetWorkCfg.Submask,&pNetCommon->Submask,sizeof(NET_SDK_CONFIG_IPAddress));
			NetWorkCfg.TCPPort = pNetCommon->TCPPort;
			NetWorkCfg.HttpPort = pNetCommon->HttpPort;
			strcpy(NetWorkCfg.sMac,pNetCommon->sMac);
			NetWorkCfg.bUseHSDownLoad = pNetCommon->bUseHSDownLoad;
			NetWorkCfg.TransferPlan = pNetCommon->TransferPlan;
			
			bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_SYSNET,0,
				(char *)&NetWorkCfg,sizeof(NET_SDK_CONFIG_NET_COMMON),nWaitTime);
			if (bSuccess)
			{
				if (bSuccess == NET_SDK_OPT_REBOOT)
				{
					bReboot = TRUE;
				}
				bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_NET_DNS,0,
					(char *)pNetDNS,sizeof(NET_SDK_NetDNSConfig),nWaitTime);
				if (bSuccess)
				{
					if ( bSuccess == NET_SDK_OPT_REBOOT)
					{
						bReboot = TRUE;
					}
					bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_NET_DHCP,0,
						(char *)pNetDHCP,sizeof(NET_SDK_NetDHCPConfigAll),nWaitTime);
					
					if (bSuccess)
					{
						if ( bSuccess == NET_SDK_OPT_REBOOT)
						{
							bReboot = TRUE;
						}
						if ( bReboot == TRUE )
						{
							if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
							{
								bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
								if (bSuccess)
								{
									OnBtnLogout();
								}else
								{
									MessageBox(_CS("Error.RebootFail"));
								}
							}
						}
						if ( bSuccess > 0)
						{
							MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
						}else if ( bSuccess < 0 && bSuccess != NET_SDK_OPT_REBOOT)
						{
							MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );
						}
					}
				}
			}
		}

	}
	
}
/*void CClientDemo5Dlg::SetNetWorkConfigInfo(NET_SDK_NetOrderConfig *pNetOrder)
{
	if (0 != m_LoginID &&pNetOrder!=NULL)
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		BOOL bReboot = FALSE;
		BOOL bSuccess = NET_SDK_SetDevConfig(m_LoginID,E_SDK_CONFIG_NET_ORDER,0,
			(char *)pNetOrder,sizeof(SDK_NetOrderConfig),nWaitTime);
		if (bSuccess)
		{
			if (bSuccess == NET_SDK_OPT_REBOOT)
			{
				bReboot = TRUE;
			}
			if ( bReboot == TRUE )
			{
				if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
				{
					bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
					if (bSuccess)
					{
						OnBtnLogout();
					}else
					{
						MessageBox(_CS("Error.RebootFail"));
					}
				}
			}
			if ( bSuccess > 0)
			{
				MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
			}else if ( bSuccess < 0 && bSuccess != NET_SDK_OPT_REBOOT)
			{
				MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );
			}
		}
	}
}*/
void CClientDemo5Dlg::GetAlarmConfigInfo()
{
	if ( 0 != m_LoginID)
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		ALARMCONFIGALL AlarmCfgAll;
		BOOL bSuccess = FALSE;
		int i;
		for ( i = 0;i  < m_nChannelNum; i++)
		{
			
			bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_MOTION,i,
			(char *)&AlarmCfgAll.MotionCfgAll.vMotionDetectAll[i],sizeof(NET_SDK_MOTIONCONFIG),&dwRetLen,nWaitTime);
			if ( (!bSuccess) && (dwRetLen != sizeof(NET_SDK_MOTIONCONFIG)) )break;
		}

		if ( i == m_nChannelNum )
		{
			for ( i = 0;i < m_nChannelNum; i++)
			{
				bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_SHELTER,i,
				(char *)&AlarmCfgAll.DectectCfgAll.vBlindDetectAll[i],sizeof(NET_SDK_BLINDDETECTCONFIG),&dwRetLen,nWaitTime);
				if ( (!bSuccess) && (dwRetLen != sizeof(NET_SDK_BLINDDETECTCONFIG)) )break;
			}

			if ( i== m_nChannelNum )
			{
				for ( i= 0; i < m_nChannelNum; i++)
				{
					bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_VIDEO_LOSS,i,
					(char *)&AlarmCfgAll.VideoLossCfgAll.vGenericEventConfig[i],sizeof(NET_SDK_VIDEOLOSSCONFIG),&dwRetLen,nWaitTime);
					if ( (!bSuccess) && (dwRetLen != sizeof(NET_SDK_VIDEOLOSSCONFIG)) )break;
				}

			
				if ( i == m_nChannelNum )
				{
					for ( i = 0; i < m_nAlarmInNum; i++)
					{	
						bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_ALARM_IN,i,
						(char *)&AlarmCfgAll.AlarmInCfgAll.vAlarmConfigAll[i],sizeof(NET_SDK_ALARM_INPUTCONFIG),&dwRetLen,nWaitTime);
						if ( (!bSuccess) && (dwRetLen != sizeof(NET_SDK_ALARM_INPUTCONFIG)) )break;
					}
				
					if ( i== m_nAlarmInNum )
					{
						NET_SDK_MotionDetectFunction MotionDectFuc;
						bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_ABILITY_MOTION_FUNC,0,
							(char *)&MotionDectFuc,sizeof(NET_SDK_MotionDetectFunction),&dwRetLen,nWaitTime);
						if (bSuccess && dwRetLen == sizeof(NET_SDK_MotionDetectFunction))
						{
							NET_SDK_AlarmOutConfigAll AlarmOutputConfig;
							bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_ALARM_OUT,-1,
							(char *)&AlarmOutputConfig,sizeof(NET_SDK_AlarmOutConfigAll),&dwRetLen,nWaitTime);
				

							if(bSuccess&&dwRetLen == sizeof(NET_SDK_AlarmOutConfigAll))
							{
								NET_SDK_SystemFunction SysFunc;
								bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_ABILITY_SYSFUNC,0,
									(char *)&SysFunc,sizeof(NET_SDK_SystemFunction),&dwRetLen,nWaitTime);
						
								
								if ( bSuccess && dwRetLen == sizeof(NET_SDK_SystemFunction))
								{
									m_alarmDlg.InitDlgInfo(&AlarmCfgAll,m_nChannelNum,m_nAlarmInNum,m_nAlarmOutNum,&MotionDectFuc,&SysFunc, &AlarmOutputConfig);
								}
							}
						}
					}
				}
			}
		}
	}
}

void CClientDemo5Dlg::SetAlarmConfigInfo(ALARMCONFIGALL *pAlarmCfgAll)
{
	if ( 0 != m_LoginID && pAlarmCfgAll != NULL)
	{
		int i = 0;
		int nWaitTime = 10000;
// 		BOOL bSuccess =FALSE;
// 		BOOL bReboot = FALSE;
		for (i = 0;i<m_nChannelNum;i++)
		{
			AlarmCfg_SC = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_MOTION,i,
				(char *)&pAlarmCfgAll->MotionCfgAll.vMotionDetectAll[i],sizeof(NET_SDK_MOTIONCONFIG),nWaitTime);
			if (!AlarmCfg_SC)break;
			if ( AlarmCfg_SC == NET_SDK_OPT_REBOOT)
			{
				AlarmCfg_RB = TRUE;
			}
		}
		if (i == m_nChannelNum)
		{
			for (i = 0;i<m_nAlarmInNum;i++)
			{
				
				AlarmCfg_SC = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_ALARM_IN,i,
					(char *)&pAlarmCfgAll->AlarmInCfgAll.vAlarmConfigAll[i],sizeof(NET_SDK_ALARM_INPUTCONFIG),nWaitTime);
				if (!AlarmCfg_SC)break;
				if ( AlarmCfg_SC == NET_SDK_OPT_REBOOT)
				{
					AlarmCfg_RB = TRUE;
				}
			}
			if ( i == m_nAlarmInNum)
			{
				for (i = 0;i<m_nChannelNum;i++)
				{
					AlarmCfg_SC = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_SHELTER,i,
						(char *)&pAlarmCfgAll->DectectCfgAll.vBlindDetectAll[i],sizeof(NET_SDK_BLINDDETECTCONFIG),nWaitTime);
					if (!AlarmCfg_SC)break;
					if ( AlarmCfg_SC == NET_SDK_OPT_REBOOT)
					{
						AlarmCfg_RB = TRUE;
					}
				}
				if (i == m_nChannelNum)
				{
					for (i = 0;i<m_nChannelNum;i++)
					{
						AlarmCfg_SC = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_VIDEO_LOSS,i,
							(char *)&pAlarmCfgAll->VideoLossCfgAll.vGenericEventConfig[i],sizeof(NET_SDK_VIDEOLOSSCONFIG),nWaitTime);
						if (!AlarmCfg_SC)break;
						if ( AlarmCfg_SC == NET_SDK_OPT_REBOOT)
						{
							AlarmCfg_RB = TRUE;
						}
					}

					AlarmCfg_SC = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_ALARM_OUT,-1,
						(char *)&pAlarmCfgAll->AlarmOutCfgAll,sizeof(NET_SDK_AlarmOutConfigAll),nWaitTime);
					if ( AlarmCfg_SC == NET_SDK_OPT_REBOOT)
					{
						AlarmCfg_RB = TRUE;
					}
				
					
					if ( AlarmCfg_RB == TRUE && AlarmExp_RB==TRUE &&i == m_nChannelNum)
					{
						if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
						{
							
							if (NET_SDK_ControlDVR(m_LoginID,0,nWaitTime))
							{
								OnBtnLogout();
							}else
							{
								MessageBox(_CS("Error.RebootFail"));
							}
						}
					}else if ( i == m_nChannelNum && AlarmCfg_RB == FALSE&&AlarmExp_RB==FALSE)
					{
						MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
					}else
					{
						MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );  
					}
				}
			}
		}
	}
}

void CClientDemo5Dlg::GetPTZConfigInfo()
{
	if ( 0 != m_LoginID)
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		BOOL bSuccess = FALSE;
		NET_SDK_STR_PTZCONFIG_ALL PtzCfgAll;
		
		bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_PTZ,-1,
			(char *)&PtzCfgAll,sizeof(NET_SDK_STR_PTZCONFIG_ALL),&dwRetLen,nWaitTime);
		if (bSuccess && dwRetLen == sizeof(NET_SDK_STR_PTZCONFIG_ALL))
		{
			NET_SDK_PTZPROTOCOLFUNC PtzProtocol;
			bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_ABILITY_PTZPRO,0,
				(char *)&PtzProtocol,sizeof(NET_SDK_PTZPROTOCOLFUNC),&dwRetLen,nWaitTime);
			if (bSuccess && dwRetLen == sizeof(NET_SDK_PTZPROTOCOLFUNC))
			{
				m_Ptz.InitDlgInfo(&PtzCfgAll,m_nChannelNum,&PtzProtocol);
			}
		}
	}
}

void CClientDemo5Dlg::SetPtzConfigInfo(NET_SDK_STR_PTZCONFIG_ALL *pPtzConfigAll)
{
	if ( 0 != m_LoginID && pPtzConfigAll != NULL)
	{
		int nWaitTime = 10000;
		BOOL bSuccess =FALSE;
		BOOL bReboot = FALSE;
		int i;
		for ( i = 0;i< m_nChannelNum;i++)
		{
			bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_PTZ,i,
				(char *)&pPtzConfigAll->ptzAll[i],sizeof(NET_SDK_STR_CONFIG_PTZ),nWaitTime);
			if (!bSuccess)break;
			if ( bSuccess == NET_SDK_OPT_REBOOT)
			{
				bReboot = TRUE;
			}
		}
		
		if ( i == m_nChannelNum && bReboot == TRUE )
		{
			if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
			{
				bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
				if (bSuccess)
				{
					OnBtnLogout();
				}else
				{
					MessageBox(_CS("Error.RebootFail"));
				}
			}
		}else if ( i == m_nChannelNum && bReboot == FALSE)
		{
			MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
		}else
		{
			MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );  
		}
	}
}

void CClientDemo5Dlg::GetCameraPara()
{
	if ( 0 != m_LoginID)
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		BOOL bSuccess = FALSE;
		int i = 0;
		NET_SDK_DEVICEINFO sysInfo;
		NET_SDK_CameraIspParamAll CameraParaISP;
		NET_SDK_CameraParamAllV2  CameraParaV2;
		NET_SDK_CameraParamAll CameraParaAll;
	
		bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_SYSINFO,-1,(char *)&sysInfo,sizeof(sysInfo),&dwRetLen, nWaitTime);
		if (bSuccess)
		{
			CString strTmp;
		
			strTmp.Format("%04d%02d%02d",sysInfo.tmBuildTime.year,sysInfo.tmBuildTime.month,sysInfo.tmBuildTime.day);

			if (!strTmp.IsEmpty() && strTmp >= "20180824")
			{
				m_bCameraV2 = TRUE;
			}
			else
			{
				m_bCameraV2 = FALSE;
			}
		}
		
		if (m_bCameraV2)
		{
			for ( ; i< m_nChannelNum; i++)
			{
				bSuccess = NET_SDK_GetDevConfig(m_LoginID, NET_SDK_CAMERAPARAM, i,
					(char *)&CameraParaV2.vCamGeneralParamAll[i], sizeof(NET_SDK_CameraParamV2), &dwRetLen, nWaitTime);
				if ( (!bSuccess) || (dwRetLen != sizeof(NET_SDK_CameraParamV2)) )
				{
					break;
				}
			
			}
			bSuccess = NET_SDK_GetDevConfig(m_LoginID, NET_SDK_CONFIG_ISP_CAMERA, -1, (char*)&CameraParaISP,sizeof(NET_SDK_CameraIspParamAll),&dwRetLen,nWaitTime);
			if ( i == m_nChannelNum )
			{
				m_SysCamera.InitDlgInfoV2(&CameraParaV2,&CameraParaISP,m_nChannelNum);
			}
		}
		else
		{
			for ( ; i< m_nChannelNum; i++)
			{
				bSuccess = NET_SDK_GetDevConfig(m_LoginID, NET_SDK_CAMERAPARAM, i,
					(char *)&CameraParaAll.vCameraParamAll[i], sizeof(NET_SDK_CameraParam), &dwRetLen, nWaitTime);
				if ( (!bSuccess) || (dwRetLen != sizeof(NET_SDK_CameraParam)) )
				{
					break;
				}
			}
			if ( i == m_nChannelNum )
			{
				m_SysCamera.InitDlgInfo(&CameraParaAll, m_nChannelNum);
			}
		}
		
		
	}
}
void CClientDemo5Dlg::GetCameraColor(int n_Channel)
{
	if ( 0 != m_LoginID)
	{
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		BOOL bSuccess = FALSE;
		int i = 0;
		NET_SDK_CONFIG_VIDEOCOLOR CameraColorAll;
	

		bSuccess = NET_SDK_GetDevConfig(m_LoginID, NET_SDK_VIDEOCOLOR, n_Channel,
				(char *)&CameraColorAll, sizeof(NET_SDK_CONFIG_VIDEOCOLOR), &dwRetLen, nWaitTime);

	
		if(bSuccess)
		{
			m_SysCamera.InitDlgInfoColor(&CameraColorAll, m_nChannelNum);
		}
		
		
		
	}
}

void CClientDemo5Dlg::SetCameraPara(NET_SDK_CameraParamAll* pCameraParaAll)
{
	if ( 0 != m_LoginID && pCameraParaAll != NULL)
	{
		int nWaitTime = 10000;
		BOOL bSuccess = FALSE;
		BOOL bReboot = FALSE;
		int i;
		for ( i = 0;i< m_nChannelNum;i++)
		{
			bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CAMERAPARAM,i,
				(char *)&pCameraParaAll->vCameraParamAll[i],sizeof(NET_SDK_CameraParam),nWaitTime);
			if (!bSuccess)break;
			if ( bSuccess == NET_SDK_OPT_REBOOT)
			{
				bReboot = TRUE;
			}

		}
		
		if ( i == m_nChannelNum && bReboot == TRUE )
		{
			if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
			{
				bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
				if (bSuccess)
				{
					OnBtnLogout();
				}else
				{
					MessageBox(_CS("Error.RebootFail"));
				}
			}
		}else if ( i == m_nChannelNum && bReboot == FALSE)
		{
			MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
		}else
		{
			MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );  
		}
	}
}
void CClientDemo5Dlg::SetCameraParaV2(NET_SDK_CameraParamAllV2*pCameraParaAll,NET_SDK_CameraIspParamAll*pCameraParaISP)
{
	if ( 0 != m_LoginID && pCameraParaAll != NULL)
	{
		int nWaitTime = 10000;
		BOOL bSuccess = FALSE;
		BOOL bReboot = FALSE;
		int i;
		for ( i = 0;i< m_nChannelNum;i++)
		{
			bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CAMERAPARAM,i,
				(char *)&pCameraParaAll->vCamGeneralParamAll[i],sizeof(NET_SDK_CameraParamV2),nWaitTime);
			if (!bSuccess)
				break;
			if ( bSuccess == NET_SDK_OPT_REBOOT)
			{
				bReboot = TRUE;
			}
			bSuccess = NET_SDK_SetDevConfig(m_LoginID, NET_SDK_CONFIG_ISP_CAMERA, i, (char*)&pCameraParaISP->vCamIspTotalParam[i],sizeof(NET_SDK_CameraIspTotalParam),nWaitTime);
			if (!bSuccess)
			{
				break;
			}
			if (bSuccess == NET_SDK_OPT_REBOOT)
			{
				bReboot = TRUE;
			}

		}

		if ( i == m_nChannelNum && bReboot == TRUE )
		{
			if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
			{
				bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
				if (bSuccess)
				{
					OnBtnLogout();
				}else
				{
					MessageBox(_CS("Error.RebootFail"));
				}
			}
		}else if ( i == m_nChannelNum && bReboot == FALSE)
		{
			MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
		}else
		{
			MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );  
		}
	}
}
void CClientDemo5Dlg::SetCameraColor(NET_SDK_CONFIG_VIDEOCOLOR* pCameraColor,int nChannel)
{
	if ( 0 != m_LoginID && pCameraColor != NULL)
	{
		int nWaitTime = 10000;
		BOOL bSuccess = FALSE;
		BOOL bReboot = FALSE;
		int i;
	
		bSuccess = NET_SDK_SetDevConfig(m_LoginID,NET_SDK_VIDEOCOLOR,nChannel,
				(char *)pCameraColor,sizeof(NET_SDK_CONFIG_VIDEOCOLOR),nWaitTime);
		if ( bSuccess == NET_SDK_OPT_REBOOT)
		{
			bReboot = TRUE;
		}

		

		if (bReboot == TRUE )
		{
			if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
			{
				bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
				if (bSuccess)
				{
					OnBtnLogout();
				}else
				{
					MessageBox(_CS("Error.RebootFail"));
				}
			}
		}else if ( bSuccess>0 && bReboot == FALSE)
		{
			MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
		}else
		{
			MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );  
		}
	}
}
void CClientDemo5Dlg::GetUserInfo()
{
	if ( 0 != m_LoginID&&m_userManager)
	{		
		m_userManager->m_LoginID=m_LoginID;
	}
}


void CClientDemo5Dlg:: GetChannelNS()
{
	if (0!=m_LoginID)
	{
		NET_SDK_ChannelNameConfigAll pChannelName;
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		BOOL bSuccess = FALSE;

		bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_CHANNEL_NAME,-1,
				(char *)&pChannelName,sizeof(NET_SDK_ChannelNameConfigAll),&dwRetLen,nWaitTime	);
		/*	if ((!bSuccess)||dwRetLen!=sizeof(SDK_ChannelNameConfigAll))break;	*/	
		if (bSuccess&&dwRetLen==sizeof(NET_SDK_ChannelNameConfigAll))
		{
			m_channelNS.InitDlgInfo(&pChannelName,m_nbyChanNum);
		}
			
		
	}
}
void CClientDemo5Dlg::setChannelNS(NET_SDK_ChannelNameConfigAll *pChannelName)
{
	if (0!=m_LoginID)
	{
		int nWaitTime = 10000;
		BOOL bSuccess =FALSE;
		BOOL bReboot = FALSE;
		bSuccess =NET_SDK_SetDevConfig(m_LoginID,NET_SDK_CONFIG_CHANNEL_NAME,-1,
			(char *)pChannelName,sizeof(NET_SDK_ChannelNameConfigAll),nWaitTime);
		if (bSuccess == NET_SDK_OPT_REBOOT)
		{
			bReboot = TRUE;
		}
		if (bReboot == TRUE )
		{
			if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
			{
				bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
				if (bSuccess)
				{
					OnBtnLogout();
				}else
				{
					MessageBox(_CS("Error.RebootFail"));
				}
			}
		}else if ( bReboot == FALSE)
		{
			MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
		}else
		{
			MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );  
		}
	}
}

		
	



/*void CClientDemo5Dlg::GetNetDecorderCfg()
{
	m_niDigChannel;
	if (0!=m_LoginID)
	{
		CString strTmp;
		strTmp.Format("%04d%02d%02d",m_DeviceInfo.tmBuildTime.year,m_DeviceInfo.tmBuildTime.month,m_DeviceInfo.tmBuildTime.day);

		if(strTmp.Compare("20161221")>=0)
		{
			m_nprotolV4 = 1;

		}
		NET_SDK_NetDecorderConfigAll pNetDigitChnConfig;
		NET_SDK_NetDecorderConfigAll_V4 pNetDigitChnConfig_V4;
		NET_SDK_NetDecoderConfigAll_V1 pNetDec;
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		BOOL bSuccess = FALSE;
		int i;
		int nRet = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_NET_DECODER,-1, (char *)&pNetDec, sizeof(NET_SDK_NetDecoderConfigAll_V1), &dwRetLen, nWaitTime);

		
		
			if (m_nprotolV4 == 0)
			{
				bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_NETDECORDER,i,
				(char *)&pNetDigitChnConfig,sizeof(NET_SDK_NetDecorderConfigAll),&dwRetLen,nWaitTime);
			
			}
			else
			{
				bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_NETDECORDER_V4,-1,
					(char *)&pNetDigitChnConfig_V4,sizeof(NET_SDK_NetDecorderConfigAll_V4),&dwRetLen,nWaitTime);
			
			}	
			

	}

}*/

void CClientDemo5Dlg::GetNetCommon()
{

	if (0!=m_LoginID)
	{
		NET_SDK_CONFIG_NET_COMMON pNetCommon;
		DWORD dwRetLen = 0;
		int nWaitTime = 10000;
		BOOL bSuccess = FALSE;
		bSuccess = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_SYSNET,-1,
				(char *)&pNetCommon,sizeof(NET_SDK_CONFIG_NET_COMMON),&dwRetLen,nWaitTime);

			
	}

}
/*BOOL CClientDemo5Dlg::SetNetDecorderCfg(NET_SDK_NetDigitChnConfig_V4 *pNetDigitChnConfig,int nDigChannelNum)
{
	if (0!=m_LoginID)
	{
		int nWaitTime = 10000;
		BOOL bSuccess =FALSE;
		BOOL bReboot = FALSE;
		bSuccess =NET_SDK_SetDevConfig(m_LoginID,NET_SDK_NETDECORDER_V4,nDigChannelNum,
			(char *)pNetDigitChnConfig,sizeof(NET_SDK_NetDigitChnConfig_V4),nWaitTime);
		if (bSuccess == NET_SDK_OPT_REBOOT)
		{
			bReboot = TRUE;
		}
		if (bReboot == TRUE )
		{
			if ( MessageBox(_CS("ConfigNet.NeedReboot"), _CS("OneClick.Prompt"), MB_YESNO | MB_ICONQUESTION ) == IDYES)
			{
				bSuccess = NET_SDK_ControlDVR(m_LoginID,0,nWaitTime);
				if (bSuccess)
				{
					OnBtnLogout();
				}else
				{
					MessageBox(_CS("Error.RebootFail"));
				}
			}
		}else if ( bReboot == FALSE && bSuccess )
		{
			//MessageBox(_CS("Error.SaveSuccess"), _CS("OneClick.Prompt") );
			return true;
		}else
		{
			MessageBox(_CS("Error.SetConfigFail"), _CS("OneClick.Prompt") );  
			return false;
		}
		return false;
	}
	return false;
}*/
NET_SDK_SEARCHPROTOCOLFUNC* CClientDemo5Dlg::GetSearchProtocol()
{
	DWORD dwRetLen = 0;
	int nRet = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_ABILITY_SEARCHPRO, -1,(char *)&m_searchfunc, sizeof(m_searchfunc), &dwRetLen, 10000);	
	return &m_searchfunc;
}
NET_SDK_DEVICEINFO *CClientDemo5Dlg::GetSysInfo()
{
	DWORD dwRetLen = 0;
	int nRet = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_SYSINFO, -1,(char *)&m_sysInfo, sizeof(m_sysInfo), &dwRetLen, 10000);	
	return &m_sysInfo;
}

int CClientDemo5Dlg::GetNetDecorderConfig(NET_SDK_NetDecorderConfigAll_V4* netdeccallV4)
{
	DWORD dwRetLen = 0;
	int nRet = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_NETDECORDER_V4, -1,(char *)netdeccallV4, sizeof(NET_SDK_NetDecorderConfigAll_V4), &dwRetLen, 10000);	
	return nRet;
}
int CClientDemo5Dlg::GetNetDecorder(NET_SDK_NetDecoderConfigAll_V1 netDec)
{
	DWORD dwRetLen = 0;
	int nRet = NET_SDK_GetDevConfig(m_LoginID,NET_SDK_CONFIG_NET_DECODER, -1,(char *)&netDec, sizeof(NET_SDK_NetDecoderConfigAll_V1), &dwRetLen, 1000);	
	return nRet;
}

int CClientDemo5Dlg::SetNetDecorderConfig(NET_SDK_NetDigitChnConfig_V4 netdeccallV4,int channel)
{
	int nRet =NET_SDK_SetDevConfig(m_LoginID,NET_SDK_NETDECORDER_V4,channel,(char *)&netdeccallV4,sizeof(NET_SDK_NetDigitChnConfig_V4),1000);
	return nRet;
}