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

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


// CDialogNumInput 对话框

IMPLEMENT_DYNAMIC(CDialogNumInput, CDialogEx)

CDialogNumInput::CDialogNumInput(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDialogNumInput::IDD, pParent)
	, x(0)
	, y(0)
{
	m_i32Type = 0;
	m_csNum = _T("0");
	m_i32Start=1;
	m_pStaticTitle = new CColorText_Static();
	m_pStaticText = new CColorText_Static();
}

CDialogNumInput::~CDialogNumInput()
{
	delete m_pStaticText;
	delete m_pStaticTitle;
}

void CDialogNumInput::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_BUTTON_DOT, CButtonDot);
	DDX_Control(pDX, IDC_BUTTON_SYMBOL, CButtonSymbol);
}


BEGIN_MESSAGE_MAP(CDialogNumInput, CDialogEx)
	ON_BN_CLICKED(IDOK, &CDialogNumInput::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON_NUM_INPUT_1, &CDialogNumInput::OnBnClickedButtonNumInput1)
	ON_BN_CLICKED(IDC_BUTTON_NUM_INPUT_2, &CDialogNumInput::OnBnClickedButtonNumInput2)
	ON_BN_CLICKED(IDC_BUTTON_NUM_INPUT_3, &CDialogNumInput::OnBnClickedButtonNumInput3)
	ON_BN_CLICKED(IDC_BUTTON_NUM_INPUT_4, &CDialogNumInput::OnBnClickedButtonNumInput4)
	ON_BN_CLICKED(IDC_BUTTON5, &CDialogNumInput::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CDialogNumInput::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON7, &CDialogNumInput::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON8, &CDialogNumInput::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON9, &CDialogNumInput::OnBnClickedButton9)
	ON_BN_CLICKED(IDC_BUTTON10, &CDialogNumInput::OnBnClickedButton10)
	ON_BN_CLICKED(IDC_BUTTON_DOT, &CDialogNumInput::OnBnClickedButtonDot)
	ON_BN_CLICKED(IDC_BUTTON1_DEL, &CDialogNumInput::OnBnClickedButton1Del)
	ON_BN_CLICKED(IDC_BUTTON14, &CDialogNumInput::OnBnClickedButton14)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON_SYMBOL, &CDialogNumInput::OnBnClickedButtonSymbol)
END_MESSAGE_MAP()


// CDialogNumInput 消息处理程序


void CDialogNumInput::OnBnClickedOk()
{
	// TODO:  在此添加控件通知处理程序代码
	//m_CEdit->SetWindowTextW(m_csNum);
	CDialogEx::OnOK();
}


BOOL CDialogNumInput::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	CRect     rect;
	GetWindowRect(&rect);


	
	m_pStaticTitle->Create(_T("0"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
		CRect(2, 2, rect.Width() - 4, 20), this, 0);
	m_pStaticTitle->SetWindowTextW(m_csTitle);
	m_pStaticTitle->Set_TextColor(RGB(255, 150, 40));
	m_pStaticTitle->Set_BackColor(RGB(255, 255, 155));
	m_pStaticTitle->SetFont(140, _T("宋体"));
	

	
	m_pStaticText->Create(_T("0"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
		CRect(2, 22, rect.Width() - 4, 42), this, 0);
	m_pStaticText->Set_TextColor(RGB(0, 0, 0));
	m_pStaticText->Set_BackColor(RGB(127, 225, 225));
	m_pStaticText->SetFont(160, _T("宋体"));

	if (m_i32NumFlag == 1)
	{
		m_pStaticText->SetWindowTextW(_T("-") + m_csNum);
	}
	else
	{
		m_pStaticText->SetWindowTextW(m_csNum);
	}

	if (!(m_i32Type&NUM_INPUT_DOT))
	{
		CButtonDot.EnableWindow(FALSE);
	}
	if (!(m_i32Type&NUM_INPUT_SYMBOL))
	{
		CButtonSymbol.EnableWindow(FALSE);
	}
	// TODO:  在此添加额外的初始化
	MoveWindow(x - rect.Width()-100, y, rect.Width(), rect.Height());
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常:  OCX 属性页应返回 FALSE
}


void CDialogNumInput::input_num(CString &cs)
{
	if (m_i32Start)
	{
		m_csNum = cs;
		m_i32Start = 0;
		m_i32Num++;
	}
	else
	{
		if (m_i32Num <= 12)
		{
			if (m_csNum[0] == '0')
			{
				if ((m_i32Num >= 2) && (m_csNum[1] == '.'))
				{
					m_csNum += cs;
					m_i32Num++;
				}
				else
				{
					m_csNum = cs;
					m_i32Num = 1;
				}
			}
			else
			{
				m_csNum += cs;
				m_i32Num++;
			}
		}

	}
	if (m_i32NumFlag == 1)
	{
		m_pStaticText->SetWindowTextW(_T("-") + m_csNum);
	}
	else
	{
		m_pStaticText->SetWindowTextW(m_csNum);
	}

}

void CDialogNumInput::set_pos(int x, int y)
{
	this->x = x ;
	this->y = y;
}

void CDialogNumInput::set_edit(CEdit *a)
{
	m_CEdit = a;
}

void CDialogNumInput::set_title(CString & cs)
{

	m_csTitle = cs;
}
void CDialogNumInput::set_result(CString & cs)
{
	if (cs[0] == '-')
	{
		m_i32Start = 0;
		m_i32NumFlag = 1;
		m_i32Num = cs.GetLength()-1;
		m_csNum = cs.Mid(1, m_i32Num);
	}
	else
	{
		m_i32Start = 0;
		m_i32NumFlag = 0;
		m_i32Num = cs.GetLength();
		m_csNum = cs.Mid(0, m_i32Num);
	}
	
}
void CDialogNumInput::get_result(CString & cs)
{
	if (m_i32NumFlag)
	{
		cs = _T('-') + m_csNum;
	}
	else
	{
		cs = m_csNum;
	}
}


void CDialogNumInput::set_type(int a)
{
	m_i32Type = a;

}
void CDialogNumInput::OnBnClickedButtonNumInput1()
{
	// TODO:  在此添加控件通知处理程序代码
	input_num(CString(_T("1")));
}


void CDialogNumInput::OnBnClickedButtonNumInput2()
{
	// TODO:  在此添加控件通知处理程序代码
	input_num(CString(_T("2")));
}


void CDialogNumInput::OnBnClickedButtonNumInput3()
{
	// TODO:  在此添加控件通知处理程序代码
	input_num(CString(_T("3")));
}


void CDialogNumInput::OnBnClickedButtonNumInput4()
{
	// TODO:  在此添加控件通知处理程序代码
	input_num(CString(_T("4")));
}


void CDialogNumInput::OnBnClickedButton5()
{
	// TODO:  在此添加控件通知处理程序代码
	input_num(CString(_T("5")));
}


void CDialogNumInput::OnBnClickedButton6()
{
	// TODO:  在此添加控件通知处理程序代码
	input_num(CString(_T("6")));
}


void CDialogNumInput::OnBnClickedButton7()
{
	// TODO:  在此添加控件通知处理程序代码
	input_num(CString(_T("7")));
}


void CDialogNumInput::OnBnClickedButton8()
{
	// TODO:  在此添加控件通知处理程序代码
	input_num(CString(_T("8")));
}


void CDialogNumInput::OnBnClickedButton9()
{
	// TODO:  在此添加控件通知处理程序代码
	input_num(CString(_T("9")));
}


void CDialogNumInput::OnBnClickedButton10()
{
	// TODO:  在此添加控件通知处理程序代码
	int i = 0;
	if (m_i32Start)
	{
		m_csNum = _T("0");
		m_i32Start = 0;
		m_i32Num = 1;
	}
	else
	{
		if (m_i32Num <= 12)
		{
			if (m_csNum[0] == '0')
			{
				if (m_csNum[1] == '.')
				{
					m_csNum += _T("0");
					m_i32Num++;
				}
				else
				{
					m_csNum = _T("0");
					m_i32Num = 1;
				}
				
			}
			else
			{
				m_csNum += _T("0");
				m_i32Num++;
			}
		}

	}
	if (m_i32NumFlag == 1)
	{
		m_pStaticText->SetWindowTextW(_T("-") + m_csNum);
	}
	else
	{
		m_pStaticText->SetWindowTextW(m_csNum);
	}
}


void CDialogNumInput::OnBnClickedButtonDot()
{
	// TODO:  在此添加控件通知处理程序代码
	int i = 0;
	if (m_i32Start)
	{
		m_csNum = _T("0.");
		m_i32Start = 0;
		m_i32Num = 2;
	}
	else
	{
		if (m_i32Num <= 12)
		{
			for (i = 0; i < m_i32Num;i++)
			{
				if (m_csNum[i] == '.')
					break;
			}
			if (i>=m_i32Num)
			{
				m_csNum += _T(".");
				m_i32Num++;
			}
		}

	}
	if (m_i32NumFlag == 1)
	{
		m_pStaticText->SetWindowTextW(_T("-") + m_csNum);
	}
	else
	{
		m_pStaticText->SetWindowTextW(m_csNum);
	}
}


void CDialogNumInput::OnBnClickedButton1Del()
{
	// TODO:  在此添加控件通知处理程序代码
	
	
		if (m_i32Num == 1 || m_i32Num == 0)
		{
			m_csNum = _T("0");
			m_i32Start = 1;
			m_i32Num = 0;
			m_i32NumFlag = 0;
		}
		else
		{
			m_csNum = m_csNum.Mid(0, m_i32Num - 1);
			m_i32Num--;
		}
		
	
	if (m_i32NumFlag == 1)
	{
		m_pStaticText->SetWindowTextW(_T("-") + m_csNum);
	}
	else
	{
		m_pStaticText->SetWindowTextW(m_csNum);
	}
}


int check_input(CString cs, int a)
{
	return 0;

}

void CDialogNumInput::OnBnClickedButton14()
{
	// TODO:  在此添加控件通知处理程序代码
	m_csNum = _T("0");
	m_i32Start = 1;
	m_i32Num = 0;
	m_i32NumFlag = 0;
	m_pStaticText->SetWindowTextW(m_csNum);
}


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

	// TODO:  在此处添加消息处理程序代码
//	m_pStaticTitle->DestroyWindow();
//	m_pStaticText->DestroyWindow();
}


void CDialogNumInput::OnBnClickedButtonSymbol()
{
	// TODO:  在此添加控件通知处理程序代码
	if (m_i32NumFlag == 0)
	{
		m_i32NumFlag = 1;
		m_pStaticText->SetWindowTextW(_T("-")+m_csNum);
	}
	else
	{
		m_i32NumFlag = 0;
		m_pStaticText->SetWindowTextW(m_csNum);
	}

}
