DialogConfig.cpp 3.4 KB
// DialogConfig.cpp : 实现文件
//

#include "stdafx.h"
#include "DialogConfig.h"
#include "afxdialogex.h"
#include "etradeclient/utility/application_config.h"
#include "resource.h"

const int CLIENT_HEIGHT = 200;
const int CLIENT_WIDTH = 300;

const int CLIENT_SPACE = 10;

const int STATIC_HEIGHT = 20;
const int STATIC_WIDTH = 60;

const int EDIT_HEIGHT = 18;
const int EDIT_WIDTH = 60;

const int BUTTON_HEIGHT = 30;
const int BUTTON_WIDTH = 80;

// CDialogConfig 对话框

IMPLEMENT_DYNAMIC(CDialogConfig, CDialogEx)

CDialogConfig::CDialogConfig(CWnd* pParent /*=NULL*/)
: CDialogEx(CDialogConfig::IDD, pParent),
m_iPinPadPWLen(0), m_iPinPadTimeout(0)
{
}

CDialogConfig::~CDialogConfig()
{
}

void CDialogConfig::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);

	const int kMinTimeoutSeconds = 1, kMaxTimeoutSeconds = 10;
	const int kMinPwdLen = 6, kMaxPwdLen = 32;

	DDX_Text(pDX, IDC_EDIT_PIN_PAD_LEN, m_iPinPadPWLen);
	DDV_MinMaxInt(pDX, m_iPinPadPWLen, kMinPwdLen, kMaxPwdLen);

	DDX_Text(pDX, IDC_EDIT_PIN_PAD_TIMEOUT, m_iPinPadTimeout);
	DDV_MinMaxInt(pDX, m_iPinPadTimeout, kMinTimeoutSeconds, kMaxTimeoutSeconds);
}

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


// CDialogConfig 消息处理程序


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

	CRect rtClient;
	GetWindowRect(&rtClient);
	MoveWindow(rtClient.left, rtClient.top, CLIENT_WIDTH, CLIENT_HEIGHT);

	GetClientRect(&rtClient);
	GetDlgItem(IDC_STATIC_PINPAD)->MoveWindow(rtClient.left + CLIENT_SPACE, rtClient.top + CLIENT_SPACE, 
		rtClient.Width() - CLIENT_SPACE * 2, rtClient.Height() - CLIENT_SPACE * 2 - BUTTON_HEIGHT);

	GetDlgItem(IDC_STATIC_LEN)->MoveWindow(rtClient.left + CLIENT_SPACE * 5,
		rtClient.top + CLIENT_SPACE * 4 + 2,
		STATIC_WIDTH, STATIC_HEIGHT);
	GetDlgItem(IDC_EDIT_PIN_PAD_LEN)->MoveWindow(rtClient.left + CLIENT_SPACE * 5 + STATIC_WIDTH,
		rtClient.top + CLIENT_SPACE * 4,
		EDIT_WIDTH, EDIT_HEIGHT);

	GetDlgItem(IDC_STATIC_TIMEOUT)->MoveWindow(rtClient.left + CLIENT_SPACE * 5,
		rtClient.top + CLIENT_SPACE * 5 + STATIC_HEIGHT + 2,
		STATIC_WIDTH, STATIC_HEIGHT);
	GetDlgItem(IDC_EDIT_PIN_PAD_TIMEOUT)->MoveWindow(rtClient.left + CLIENT_SPACE * 5 + STATIC_WIDTH,
		rtClient.top + CLIENT_SPACE * 5 + STATIC_HEIGHT,
		EDIT_WIDTH, EDIT_HEIGHT);
	GetDlgItem(IDC_STATIC_SECOND)->MoveWindow(rtClient.left + CLIENT_SPACE * 6 + STATIC_WIDTH + EDIT_WIDTH,
		rtClient.top + CLIENT_SPACE * 5 + STATIC_HEIGHT + 2,
		STATIC_WIDTH, STATIC_HEIGHT);

	GetDlgItem(IDCANCEL)->MoveWindow(rtClient.right - BUTTON_WIDTH, rtClient.bottom - BUTTON_HEIGHT,
		BUTTON_WIDTH, BUTTON_HEIGHT);
	GetDlgItem(IDOK)->MoveWindow(rtClient.right - BUTTON_WIDTH * 2 - CLIENT_SPACE,
		rtClient.bottom - BUTTON_HEIGHT,
		BUTTON_WIDTH, BUTTON_HEIGHT);

	const ApplicationConfig& app_config = ApplicationConfig::Instance();

	m_iPinPadPWLen = app_config.PINPadPWDLen();
	m_iPinPadTimeout = app_config.PINPadTimeout();

	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常:  OCX 属性页应返回 FALSE
}


void CDialogConfig::OnBnClickedOk()
{
	UpdateData(TRUE);

	const ApplicationConfig& app_config = ApplicationConfig::Instance();
	ApplicationConfig::Instance().ModifyCfg(
		app_config.MsgCountQueryInterval(),
		app_config.PWDMachineIP(),
		app_config.PWDMachinePort(),
		app_config.PWDMachineTimeout(),
		m_iPinPadPWLen,
		m_iPinPadTimeout);

	CDialogEx::OnOK();
}