// demoSetNetworkModeDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "resource.h"
#include "demoSetNetworkModeDlg.h"
#include "afxdialogex.h"
#include "demoTools.h"
#include "HwmSdkAgent.h"
#include <iostream>
#include <Iphlpapi.h>

#pragma comment(lib,"Iphlpapi.lib") //需要添加Iphlpapi.lib库

// demoSetNetworkModeDlg 对话框

hwmsdkagent::HwmNetworkAccessType demoSetNetworkModeDlg::m_currBtn = hwmsdkagent::HwmNetworkAccessType::ACCESS_TYPE_AUTO;;

IMPLEMENT_DYNAMIC(demoSetNetworkModeDlg, CDialogEx)

demoSetNetworkModeDlg::demoSetNetworkModeDlg(CWnd* pParent /*=NULL*/)
    : CDialogEx(IDD_SET_NETWORK_MODE_DIALOG, pParent)
{

}

demoSetNetworkModeDlg::~demoSetNetworkModeDlg()
{
}

void demoSetNetworkModeDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_RADIO_DEFAULT, m_defaultSet);
    DDX_Control(pDX, IDC_RADIO_INNER, m_innerSet);
    DDX_Control(pDX, IDC_RADIO_OUTER, m_outerSet);
}


// demoLoginDlg 消息处理程序

BOOL demoSetNetworkModeDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    switch (m_currBtn)
    {
        case hwmsdkagent::HwmNetworkAccessType::ACCESS_TYPE_INNER:
            m_innerSet.SetCheck(1);
            break;
        case hwmsdkagent::HwmNetworkAccessType::ACCESS_TYPE_OUTER:
            m_outerSet.SetCheck(1);
            break;
        case hwmsdkagent::HwmNetworkAccessType::ACCESS_TYPE_AUTO:
        default:
            m_defaultSet.SetCheck(1);
            break;
    }

    return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

BEGIN_MESSAGE_MAP(demoSetNetworkModeDlg, CDialogEx)
    ON_BN_CLICKED(IDOK, &demoSetNetworkModeDlg::OnBnClickedOk)
END_MESSAGE_MAP()

void demoSetNetworkModeDlg::OnBnClickedOk()
{
    hwmsdkagent::HwmNetWorkModeInfo networkMode{};
    if (m_defaultSet.GetCheck()) {
        m_currBtn = hwmsdkagent::HwmNetworkAccessType::ACCESS_TYPE_AUTO;
    }
    else if (m_innerSet.GetCheck()) {
        m_currBtn = hwmsdkagent::HwmNetworkAccessType::ACCESS_TYPE_INNER;
    }
    else if (m_outerSet.GetCheck()) {
        m_currBtn = hwmsdkagent::HwmNetworkAccessType::ACCESS_TYPE_OUTER;
    }

    networkMode.accessType = m_currBtn;
    hwmsdkagent::SetNetworkMode(&networkMode);

    CDialogEx::OnOK();
}