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

#include "stdafx.h"
#include "YAServer.h"
#include "SysSetting.h"
#include "afxdialogex.h"
#include "Functions/Functions.h"

// CSysSetting 对话框

IMPLEMENT_DYNAMIC(CSysSetting, CDialogEx)

	CSysSetting::CSysSetting(CWnd* pParent /*=NULL*/)
	: CDialogEx(CSysSetting::IDD, pParent)
	, m_host_master(_T(""))
	, m_recon_server(0)
	, m_host_slave(_T(""))
	, m_recon_db(0)
	, m_reader_lost(0)
	, m_card_lost(0)
	, m_timing_interval(0)
	, m_coor_error(0)
	, m_ranging_error(0)
	, m_move_error(0)
	, m_sampling_interval(0)
	, m_use_filter(FALSE)
	, m_db_z_offset(0)
{
	m_host_master = CFunctions::c2wc(theApp.ws_url.c_str());
	m_host_slave = CFunctions::c2wc(theApp.ws_url_bk.c_str());
	m_recon_db = theApp.recon_db;
	m_recon_server = theApp.recon_server;
	m_reader_lost = theApp.reader_lost;
	m_card_lost = theApp.card_lost;
	m_timing_interval = theApp.timing_interval;
	m_sampling_interval = theApp.sampling_interval;
	m_coor_error = theApp.coor_error;
	m_ranging_error = theApp.ranging_error;
	m_move_error = theApp.move_error;
	m_use_filter = theApp.use_filter;
	m_db_z_offset = theApp.z_offset;
}

CSysSetting::~CSysSetting()
{
}

void CSysSetting::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_host_master);
	DDV_MaxChars(pDX, m_host_master, 255);
	DDX_Text(pDX, IDC_EDIT15, m_recon_server);
	DDX_Text(pDX, IDC_EDIT5, m_host_slave);
	DDX_Text(pDX, IDC_EDIT13, m_recon_db);
	DDX_Text(pDX, IDC_EDIT8, m_reader_lost);
	//DDV_MinMaxInt(pDX, m_reader_lost, 15, 7200);
	DDX_Text(pDX, IDC_EDIT10, m_card_lost);
	DDX_Text(pDX, IDC_EDIT11, m_timing_interval);
	DDX_Text(pDX, IDC_EDIT9, m_coor_error);
	DDX_Text(pDX, IDC_EDIT14, m_ranging_error);
	DDX_Text(pDX, IDC_EDIT7, m_move_error);
	DDX_Text(pDX, IDC_EDIT12, m_sampling_interval);
	DDX_Check(pDX, IDC_ENABLE_FILTER, m_use_filter);
	DDX_Text(pDX, IDC_EDIT16, m_db_z_offset);	
}


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

BOOL CSysSetting::OnInitDialog()
{
	CDialog::OnInitDialog();

	m_use_filter = theApp.use_filter;
	((CButton*)GetDlgItem(IDC_ENABLE_FILTER))->SetCheck(m_use_filter);

	return TRUE;
}


// CSysSetting 消息处理程序

/*
 * 保存系统参数设置
 *
 * param
 *		无
 *
 * return
 *		无
*/
void CSysSetting::OnBnClickedOk()
{
	UpdateData();

	//滤波器是否开启
	m_use_filter = ((CButton*)GetDlgItem(IDC_ENABLE_FILTER))->GetCheck();

	theApp.ws_url = CFunctions::wc2c(m_host_master);
	theApp.ws_url_bk = CFunctions::wc2c(m_host_slave);
	theApp.recon_db = m_recon_db;
	theApp.recon_server = m_recon_server;
	theApp.reader_lost = m_reader_lost;
	theApp.card_lost = m_card_lost;
	theApp.timing_interval = m_timing_interval;
	theApp.sampling_interval = m_sampling_interval;
	theApp.coor_error = m_coor_error;
	theApp.ranging_error = m_ranging_error;
	theApp.move_error = m_move_error;
	theApp.use_filter = m_use_filter;
	theApp.z_offset = m_db_z_offset;

	//将参数写入到配置文件中
	theApp.save_sys_conf();
	CDialogEx::OnOK();
}
