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

#include "stdafx.h"
#include "Verbpo.h"
#include "DialogAirOxySet.h"
#include "afxdialogex.h"
#include "VerbpoDlg.h"


UINT8 CDialogAirOxySet::m_u8AirOxy_AlmH=100;
UINT8 CDialogAirOxySet::m_u8AirOxy_AlmL=22;
// CDialogAirOxySet 对话框

IMPLEMENT_DYNAMIC(CDialogAirOxySet, CDialogEx)

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

}

CDialogAirOxySet::~CDialogAirOxySet()
{
}

void CDialogAirOxySet::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_AIROXY_ALM_H, m_CEditAirOxyH);
	DDX_Control(pDX, IDC_EDIT_AIROXY_ALM_L, m_CEditAirOxyL);
	DDX_Control(pDX, IDC_COMBO_AIROXY_ALM_SW, m_CEditAirOxyAlmSW);
	DDX_Control(pDX, IDC_COMBO_AIROXY_ALM_LEVEL, m_CEditAirOxyAlmLevel);
	DDX_Control(pDX, IDC_COMBO_AIROXY_ALM_REC, m_CEditAirOxyAlmRec);
}


BOOL CDialogAirOxySet::PreTranslateMessage(MSG* pMsg)
{
	// TODO:  在此添加专用代码和/或调用基类
	CRect     rect;
	CString a_cs;
	// TODO:  在此添加专用代码和/或调用基类
	if (WM_LBUTTONDOWN == pMsg->message&& m_CEditAirOxyH.GetSafeHwnd() == pMsg->hwnd)
	{

		m_CEditAirOxyH.GetWindowTextW(a_cs);
		m_CEditAirOxyH.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);
		a_cs = input_AirOxy_AlmH_check(a_cs);
		theApp.m_Data->m_i32ParaAirOxy_ALM_H = _ttoi(a_cs);
		theApp.m_Data->m_CParameterSet.set_AirOxyAlmH(_ttoi(a_cs));
		m_CEditAirOxyH.SetWindowTextW(a_cs);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_FAValueNormal->set_AirOxy_alm_H(theApp.m_Data->m_i32ParaAirOxy_ALM_H, 0);
		return TRUE;
	}
	else if (WM_LBUTTONDOWN == pMsg->message&& m_CEditAirOxyL.GetSafeHwnd() == pMsg->hwnd)
	{

		m_CEditAirOxyL.GetWindowTextW(a_cs);
		m_CEditAirOxyL.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);
		a_cs = input_AirOxy_AlmL_check(a_cs);
		theApp.m_Data->m_i32ParaAirOxy_ALM_L = _ttoi(a_cs);
		theApp.m_Data->m_CParameterSet.set_AirOxyAlmL(_ttoi(a_cs));
		m_CEditAirOxyL.SetWindowTextW(a_cs);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_FAValueNormal->set_AirOxy_alm_L(theApp.m_Data->m_i32ParaAirOxy_ALM_L, 0);
		return TRUE;
	}
	return CDialogEx::PreTranslateMessage(pMsg);
}



CString CDialogAirOxySet::input_AirOxy_AlmH_check(CString & cs)
{
	int a = 0;
	CString a_cs;

	a = _ttoi(cs);

	if (a > CData::m_i16AirOxyAlmHMax)
	{
		a = CData::m_i16AirOxyAlmHMax;
	}
	if (a<CData::m_i16AirOxyAlmHMin)
	{
		a = CData::m_i16AirOxyAlmHMin;
	}
	if (a <= theApp.m_Data->m_i32ParaAirOxy_ALM_L)
	{
		a = theApp.m_Data->m_i32ParaAirOxy_ALM_L + 1;
	}
	
	a_cs.Format(_T("%d"), a);

	return a_cs;
}

CString CDialogAirOxySet::input_AirOxy_AlmL_check(CString & cs)
{
	int a = 0;
	CString a_cs;

	a = _ttoi(cs);

	if (a > CData::m_i16AirOxyAlmLMax)
	{
		a = CData::m_i16AirOxyAlmLMax;
	}
	if (a<CData::m_i16AirOxyAlmLMin)
	{
		a = CData::m_i16AirOxyAlmLMin;
	}

	if (a >= theApp.m_Data->m_i32ParaAirOxy_ALM_H)
	{
		a = theApp.m_Data->m_i32ParaAirOxy_ALM_H - 1;
	}
	
	a_cs.Format(_T("%d"), a);

	return a_cs;
}



BOOL CDialogAirOxySet::OnInitDialog()
{
	CString a_cs;
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	m_CEditAirOxyAlmSW.AddString(CString(_T("关")));
	m_CEditAirOxyAlmSW.AddString(CString(_T("开")));
	m_CEditAirOxyAlmSW.SetCurSel(theApp.m_Data->m_i32ParaAirOxyALM_SW);

	m_CEditAirOxyAlmLevel.AddString(CString(_T("低")));
	m_CEditAirOxyAlmLevel.AddString(CString(_T("中")));
	m_CEditAirOxyAlmLevel.AddString(CString(_T("高")));
	m_CEditAirOxyAlmLevel.SetCurSel(theApp.m_Data->m_i32ParaAirOxyALM_LEVEL);

	m_CEditAirOxyAlmRec.AddString(CString(_T("关")));
	m_CEditAirOxyAlmRec.AddString(CString(_T("开")));
	m_CEditAirOxyAlmRec.SetCurSel(theApp.m_Data->m_i32ParaAirOxyALM_REC);



	a_cs.Format(_T("%d"), theApp.m_Data->m_i32ParaAirOxy_ALM_H);
	m_CEditAirOxyH.SetWindowTextW(a_cs);

	a_cs.Format(_T("%d"), theApp.m_Data->m_i32ParaAirOxy_ALM_L);
	m_CEditAirOxyL.SetWindowTextW(a_cs);

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



BEGIN_MESSAGE_MAP(CDialogAirOxySet, CDialogEx)
	ON_BN_CLICKED(IDOK, &CDialogAirOxySet::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON_AIROXY_DEFAULT, &CDialogAirOxySet::OnBnClickedButtonAiroxyDefault)
	ON_CBN_SELCHANGE(IDC_COMBO_AIROXY_ALM_SW, &CDialogAirOxySet::OnCbnSelchangeComboAiroxyAlmSw)
	ON_CBN_SELCHANGE(IDC_COMBO_AIROXY_ALM_LEVEL, &CDialogAirOxySet::OnCbnSelchangeComboAiroxyAlmLevel)
	ON_CBN_SELCHANGE(IDC_COMBO_AIROXY_ALM_REC, &CDialogAirOxySet::OnCbnSelchangeComboAiroxyAlmRec)
END_MESSAGE_MAP()


// CDialogAirOxySet 消息处理程序


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


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


void CDialogAirOxySet::OnCbnSelchangeComboAiroxyAlmSw()
{
	// TODO:  在此添加控件通知处理程序代码
	theApp.m_Data->m_i32ParaAirOxyALM_SW = m_CEditAirOxyAlmSW.GetCurSel();
	theApp.m_Data->m_CParameterSet.set_AirOxyAlmSw(theApp.m_Data->m_i32ParaAirOxyALM_SW);
	((CVerbpoDlg *)theApp.m_pMainWnd)->m_FAValueNormal->Set_AlmFlag(theApp.m_Data->m_i32ParaAirOxyALM_SW, 0);
	if (theApp.m_Data->m_i32ParaAirOxyALM_SW == 0)
	{
		//报警 从 开 到 关
		theApp.m_Data->Del_AirOxy_Alm_ALL(ALM_TYPE_AIROXY, DEL_ALL);
	}
	else
	{
	}
}


void CDialogAirOxySet::OnCbnSelchangeComboAiroxyAlmLevel()
{
	// TODO:  在此添加控件通知处理程序代码
	theApp.m_Data->m_i32ParaAirOxyALM_LEVEL = m_CEditAirOxyAlmLevel.GetCurSel();
	theApp.m_Data->m_CParameterSet.set_AirOxyAlmLevel(theApp.m_Data->m_i32ParaAirOxyALM_LEVEL);
}


void CDialogAirOxySet::OnCbnSelchangeComboAiroxyAlmRec()
{
	// TODO:  在此添加控件通知处理程序代码
	theApp.m_Data->m_i32ParaAirOxyALM_REC = m_CEditAirOxyAlmRec.GetCurSel();
	theApp.m_Data->m_CParameterSet.set_AirOxyAlmRec(theApp.m_Data->m_i32ParaAirOxyALM_REC);
}
