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

#include "stdafx.h"
#include "Verbpo.h"
#include "DialogSysSet.h"
#include "afxdialogex.h"
#include "DialogNumInput.h"
#include "VerbpoDlg.h"

// CDialogSysSet 对话框

CString CDialogSysSet::m_csUserPass=_T("2568");
CString CDialogSysSet::m_csMFRPass = _T("7680");
CString CDialogSysSet::m_csDemoPass = _T("8192");


IMPLEMENT_DYNAMIC(CDialogSysSet, CDialogEx)

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

}

CDialogSysSet::~CDialogSysSet()
{
}

void CDialogSysSet::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_SYS_SET_USER, m_CEditUser);
	DDX_Control(pDX, IDC_EDIT_SYS_SET_MFR, m_CEditMFR);
	DDX_Control(pDX, IDC_EDIT_SYS_SET_DEMO, m_CEditDemo);
}

BOOL CDialogSysSet::OnInitDialog()
{
	CRect rect;
	CString a_cs;
	CDialogEx::OnInitDialog();

	m_i32UserPassOK = 0, m_i32MFRPassOK = 0, m_i32DemoPassOK = 0;
	m_CEditUser.SetWindowTextW(CString(_T("1234")));
	m_CEditMFR.SetWindowTextW(CString(_T("1234")));
	m_CEditDemo.SetWindowTextW(CString(_T("1234")));

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

}

void CDialogSysSet::OnDestroy()
{
	CDialogEx::OnDestroy();

	// TODO:  在此处添加消息处理程序代码
	m_i32UserPassOK = 0, m_i32MFRPassOK = 0, m_i32DemoPassOK = 0;
}

BOOL CDialogSysSet::PreTranslateMessage(MSG* pMsg)
{
	CRect     rect;
	CString a_cs;
	// TODO:  在此添加专用代码和/或调用基类

	if (WM_LBUTTONDOWN == pMsg->message&& m_CEditUser.GetSafeHwnd() == pMsg->hwnd)
	{

		m_CEditUser.GetWindowTextW(a_cs);
		m_CEditUser.GetWindowRect(&rect);       //获得文本框矩形,左上角坐标(0,0)   
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_type(NUM_INPUT_NO_DOT | NUM_INPUT_NO_SYMBOL);

		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_title(CString(_T("用户维护密码")));
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_result(a_cs);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_pos(rect.left, rect.top);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.DoModal();
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.get_result(a_cs);
		Check_User_Pass(a_cs);
		
		m_CEditUser.SetWindowTextW(a_cs);
		
		return TRUE;
	}
	else if (WM_LBUTTONDOWN == pMsg->message&& m_CEditMFR.GetSafeHwnd() == pMsg->hwnd)
	{

		m_CEditMFR.GetWindowTextW(a_cs);
		m_CEditMFR.GetWindowRect(&rect);       //获得文本框矩形,左上角坐标(0,0)   

		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_type(NUM_INPUT_NO_DOT | NUM_INPUT_NO_SYMBOL);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_title(CString(_T("厂家维护密码")));
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_result(a_cs);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_pos(rect.left, rect.top);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.DoModal();
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.get_result(a_cs);

		Check_MFR_Pass(a_cs);
		
		m_CEditMFR.SetWindowTextW(a_cs);
		
		return TRUE;
	}
	else if (WM_LBUTTONDOWN == pMsg->message&& m_CEditDemo.GetSafeHwnd() == pMsg->hwnd)
	{

		m_CEditDemo.GetWindowTextW(a_cs);
		m_CEditDemo.GetWindowRect(&rect);       //获得文本框矩形,左上角坐标(0,0)   
		//ScreenToClient(&rect);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_type(NUM_INPUT_NO_DOT | NUM_INPUT_NO_SYMBOL);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_title(CString(_T("演示模式密码")));
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_result(a_cs);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_pos(rect.left, rect.top);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.DoModal();
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.get_result(a_cs);

		Check_Demo_Pass(a_cs);

		m_CEditDemo.SetWindowTextW(a_cs);

		return TRUE;
	}
	return CDialogEx::PreTranslateMessage(pMsg);
}


INT CDialogSysSet::Check_User_Pass(CString & cs)
{
	if (cs.Compare(CDialogSysSet::m_csUserPass) == 0)
	{
		m_i32UserPassOK = 1;
		return 0;
	}
		
	else
		return 1;
}



INT CDialogSysSet::Check_MFR_Pass(CString & cs)
{
	if (cs.Compare(CDialogSysSet::m_csMFRPass) == 0)
	{
		m_i32MFRPassOK = 1;
		return 0;
	}
	else
		return 1;
}



INT CDialogSysSet::Check_Demo_Pass(CString & cs)
{
	if (cs.Compare(CDialogSysSet::m_csDemoPass) == 0)
	{
		m_i32DemoPassOK = 1;
		return 0;
	}
	else
		return 1;
}




BEGIN_MESSAGE_MAP(CDialogSysSet, CDialogEx)
	ON_BN_CLICKED(IDOK, &CDialogSysSet::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON_SYS_SET_USER, &CDialogSysSet::OnBnClickedButtonSysSetUser)
	ON_BN_CLICKED(IDC_BUTTON_SYS_SET_MFR, &CDialogSysSet::OnBnClickedButtonSysSetMfr)
	ON_BN_CLICKED(IDC_BUTTON_SYS_SET_DEMO, &CDialogSysSet::OnBnClickedButtonSysSetDemo)
	ON_BN_CLICKED(IDC_BUTTON_SYS_SET_PARA, &CDialogSysSet::OnBnClickedButtonSysSetPara)
	ON_BN_CLICKED(IDC_BUTTON_SYS_SET_INFO, &CDialogSysSet::OnBnClickedButtonSysSetInfo)
END_MESSAGE_MAP()


// CDialogSysSet 消息处理程序


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


void CDialogSysSet::OnBnClickedButtonSysSetUser()
{
	// TODO:  在此添加控件通知处理程序代码
}


void CDialogSysSet::OnBnClickedButtonSysSetMfr()
{
	// TODO:  在此添加控件通知处理程序代码
}


void CDialogSysSet::OnBnClickedButtonSysSetDemo()
{
	// TODO:  在此添加控件通知处理程序代码
}


void CDialogSysSet::OnBnClickedButtonSysSetPara()
{
	// TODO:  在此添加控件通知处理程序代码
	m_CDialogSysParaSet.DoModal();
}


void CDialogSysSet::OnBnClickedButtonSysSetInfo()
{
	// TODO:  在此添加控件通知处理程序代码
	m_CDialogInfo.DoModal();
}
