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

#include "stdafx.h"
#include "OGCAssistTool.h"
#include "DlgLogin.h"


// CDlgLogin 对话框

IMPLEMENT_DYNAMIC(CDlgLogin, CDialogEx)

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

}

CDlgLogin::~CDlgLogin()
{
}

void CDlgLogin::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CDlgLogin, CDialogEx)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDOK, &CDlgLogin::OnBnClickedOk)
	ON_BN_CLICKED(IDCANCEL, &CDlgLogin::OnBnClickedCancel)
END_MESSAGE_MAP()


// CDlgLogin 消息处理程序

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

	// TODO:  在此添加额外的初始化
	CFont font;
	VERIFY(font.CreateFont(
		19,                        // nHeight
		0,                         // nWidth
		0,                         // nEscapement
		0,                         // nOrientation
		FW_NORMAL,                 // nWeight
		FALSE,                     // bItalic
		FALSE,                     // bUnderline
		0,                         // cStrikeOut
		ANSI_CHARSET,              // nCharSet
		OUT_DEFAULT_PRECIS,        // nOutPrecision
		CLIP_DEFAULT_PRECIS,       // nClipPrecision
		DEFAULT_QUALITY,           // nQuality
		DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
		_T("Arial")));             
	SetFont(&font);
	//SetBackgroundColor(RGB(125,0,25));
	SetBackgroundImage(IDB_LOGO);

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

HBRUSH CDlgLogin::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何属性

	switch ( pWnd->GetDlgCtrlID() ) 
	{
	case CHECK_OFFLINE:
		{
#if 1 // 透明控件处理;
			pDC->SetBkMode(TRANSPARENT);

			CRect rc;
			pWnd->GetWindowRect(&rc);
			ScreenToClient(&rc);

			CDC* dc = GetDC();
			pDC->BitBlt(0,0,rc.Width(),rc.Height(),dc,rc.left,rc.top,SRCCOPY);  //把父窗口背景图片先画到按钮上

			ReleaseDC(dc);
			hbr = (HBRUSH) ::GetStockObject(NULL_BRUSH);
#endif
		}
		break;
	default:
		break; 
	}

	// TODO:  如果默认的不是所需画笔，则返回另一个画笔
	return hbr;
}

void CDlgLogin::OnBnClickedOk()
{
	return CDialogEx::OnOK();
	// TODO: 在此添加控件通知处理程序代码
	CString strAccount, strPassword, strLine;
	GetDlgItemText(EDIT_LINE, strLine);
	GetDlgItemText(EDIT_ACCOUNT, strAccount);
	GetDlgItemText(EDIT_PASSWORD, strPassword);

	if ( strAccount.IsEmpty() )
	{
		MessageBox(_T("请输入账号"), _T("提示"), MB_OK);
		return;
	}

	if ( strPassword.IsEmpty() )
	{
		MessageBox(_T("请输入密码"), _T("提示"), MB_OK);
		return;
	}

	if ( strLine.IsEmpty() )
	{
		MessageBox(_T("请输入线体"), _T("提示"), MB_OK);
		return;
	}

	GLOBAL::g_config.nOffline = ((CButton*)GetDlgItem(CHECK_OFFLINE))->GetCheck();

#pragma region 账号密码验证
	// 获取账号密码;
	// 默认账号密码：OGCAssist、OGC+当前PC日期年月日;
	if ( true )
	{
		if ( strAccount != _T("Assist") )
		{
			MessageBox(_T("账号错误"), _T("提示"), MB_OK);
			return;
		}

		CString strDynamicPassword;
		strDynamicPassword.Format(_T("OGC%s"), CTime::GetCurrentTime().Format(_T("%y%m%d")));
		if ( strPassword != strDynamicPassword )
		{
			MessageBox(_T("密码错误"), _T("提示"), MB_OK);
			return;
		}
	}
#pragma endregion

	CDialogEx::OnOK();
}

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


	CDialogEx::OnCancel();
}
