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

#include "stdafx.h"
#include "demoJoinConfByLinkDlg.h"
#include "afxdialogex.h"
#include "HwmSdkAgent.h"
#include "demoTools.h"

// demoJoinConfByLinkDlg 对话框

IMPLEMENT_DYNAMIC(demoJoinConfByLinkDlg, CDialogEx)

demoJoinConfByLinkDlg::demoJoinConfByLinkDlg(CWnd* pParent /*=NULL*/)
    : CDialogEx(demoJoinConfByLinkDlg::IDD, pParent)
{

}

demoJoinConfByLinkDlg::~demoJoinConfByLinkDlg()
{
}

void demoJoinConfByLinkDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_EDIT_RANDOM, m_editRandom);
    DDX_Control(pDX, IDC_EDIT_SITE_URL, m_editUrl);
    DDX_Control(pDX, IDC_EDIT_NICK_NAME, m_editName);
    DDX_Control(pDX, IDC_EDIT_ALIAS_CN, m_aliasCN);
    DDX_Control(pDX, IDC_EDIT_ALIAS_EN, m_aliasEN);
}


BEGIN_MESSAGE_MAP(demoJoinConfByLinkDlg, CDialogEx)
    ON_BN_CLICKED(IDC_BUTTON_JOIN, &demoJoinConfByLinkDlg::OnBnClickedButtonJoin)
    ON_BN_CLICKED(IDC_BUTTON_JOIN_CANCEL, &demoJoinConfByLinkDlg::OnBnClickedButtonCancel)
END_MESSAGE_MAP()


// demoJoinConfByLinkDlg 消息处理程序


void demoJoinConfByLinkDlg::OnBnClickedButtonJoin()
{
    CString random("");
    m_editRandom.GetWindowText(random);
    CString siteUrl("");
    m_editUrl.GetWindowText(siteUrl);
    CString nickName("");
    m_editName.GetWindowText(nickName);
    CString aliasCN("");
    m_aliasCN.GetWindowText(aliasCN);
    CString aliasEN("");
    m_aliasEN.GetWindowText(aliasEN);

    //转换数据类型
    string strRandom = CTools::UNICODE2UTF(random.GetString());
    string strSiteUrl = CTools::UNICODE2UTF(siteUrl.GetString());
    string strName = CTools::UNICODE2UTF(nickName.GetString());
    string strAliasCN = CTools::UNICODE2UTF(aliasCN.GetString());
    string strAliasEN = CTools::UNICODE2UTF(aliasEN.GetString());

    hwmsdkagent::HwmJoinConfByLinkInfo info;
    memset(&info, 0, sizeof(info));
    strncpy_s(info.random, strRandom.c_str(), HWM_MAX_CONF_PASSWORD_LEN);
    strncpy_s(info.siteUrl, strSiteUrl.c_str(), HWM_MAX_URL_LEN);
    strncpy_s(info.name, strName.c_str(), HWM_MAX_DISPLAY_NAME_LEN);
    strncpy_s(info.aliasCN, strAliasCN.c_str(), HWM_MAX_DISPLAY_NAME_LEN);
    strncpy_s(info.aliasEN, strAliasEN.c_str(), HWM_MAX_DISPLAY_NAME_LEN);

    int ret = hwmsdkagent::JoinConfByLink(&info);
    if (hwmsdk::HWM_COMMON_SUCCESS != ret)
    {
        CTools::OutputRetStr("JoinConfByLink error");
    }
    else
    {
        //接口调用成功关闭窗口
        CDialogEx::OnOK();
    }
}


void demoJoinConfByLinkDlg::OnBnClickedButtonCancel()
{
    // TODO: 在此添加控件通知处理程序代码
    CDialogEx::OnCancel();
}
