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

#include "stdafx.h"
#include "Verbpo.h"
#include "DialogECGSetST.h"
#include "afxdialogex.h"
#include "VerbpoDlg.h"
#include "Data.h"
// CDialogECGSetST 对话框

IMPLEMENT_DYNAMIC(CDialogECGSetST, CDialogEx)

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

CDialogECGSetST::~CDialogECGSetST()
{
	
}

void CDialogECGSetST::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO_ECG_ST_SW, m_ComboECGSTSw);
	DDX_Control(pDX, IDC_COMBO_ECG_ST_ALM_SW, m_ComboECGSTAlmSw);
	DDX_Control(pDX, IDC_COMBO_ECG_ST_ALM_LEVEL, m_ComboECGSTAlmLevel);
	DDX_Control(pDX, IDC_COMBO1_ECG_ST_ALM_REC, m_ComboECGSTAlmRec);
	DDX_Control(pDX, IDC_EDIT_ECG_ST_ALM_H, m_EditECGSTAlmH);
	DDX_Control(pDX, IDC_EDIT_ECG_ST_ALM_L, m_EditECGSTAlmL);
}


BEGIN_MESSAGE_MAP(CDialogECGSetST, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_ECG_ST_SET, &CDialogECGSetST::OnBnClickedButtonEcgStSet)
	ON_CBN_SELCHANGE(IDC_COMBO_ECG_ST_SW, &CDialogECGSetST::OnCbnSelchangeComboEcgStSw)
	ON_CBN_SELCHANGE(IDC_COMBO_ECG_ST_ALM_SW, &CDialogECGSetST::OnCbnSelchangeComboEcgStAlmSw)
	ON_CBN_SELCHANGE(IDC_COMBO_ECG_ST_ALM_LEVEL, &CDialogECGSetST::OnCbnSelchangeComboEcgStAlmLevel)
	ON_CBN_SELCHANGE(IDC_COMBO1_ECG_ST_ALM_REC, &CDialogECGSetST::OnCbnSelchangeCombo1EcgStAlmRec)
END_MESSAGE_MAP()


// CDialogECGSetST 消息处理程序


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


BOOL CDialogECGSetST::OnInitDialog()
{
	CString a_cs;
	float f;

	CDialogEx::OnInitDialog();

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

	m_ComboECGSTAlmSw.AddString(CString(_T("关")));
	m_ComboECGSTAlmSw.AddString(CString(_T("开")));
	m_ComboECGSTAlmSw.SetCurSel(theApp.m_Data->m_i32ParaECGST_ALM_SW);

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

	m_ComboECGSTAlmRec.AddString(CString(_T("关")));
	m_ComboECGSTAlmRec.AddString(CString(_T("开")));
	m_ComboECGSTAlmRec.SetCurSel(theApp.m_Data->m_i32ParaECGST_ALM_REC);

	f = theApp.m_Data->m_i32ParaECGST_ALM_H;
	f /= 100.f;
	a_cs.Format(_T("%2.1f"), f);
	m_EditECGSTAlmH.SetWindowTextW(a_cs);

	f = theApp.m_Data->m_i32ParaECGST_ALM_L;
	f /= 100.f;
	a_cs.Format(_T("%2.1f"), f);
	m_EditECGSTAlmL.SetWindowTextW(a_cs);
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常:  OCX 属性页应返回 FALSE
}


BOOL CDialogECGSetST::PreTranslateMessage(MSG* pMsg)
{
	// TODO:  在此添加专用代码和/或调用基类
	CRect     rect;
	int i = 0;
	float f = 0.0f;
	CString a_cs;
	// TODO:  在此添加专用代码和/或调用基类
	
	if (WM_LBUTTONDOWN == pMsg->message&& m_EditECGSTAlmH.GetSafeHwnd() == pMsg->hwnd)
	{

		m_EditECGSTAlmH.GetWindowTextW(a_cs);
		m_EditECGSTAlmH.GetWindowRect(&rect);       //获得文本框矩形,左上角坐标(0,0)   
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_type(NUM_INPUT_DOT | NUM_INPUT_SYMBOL);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_title(CString(_T("ST上限")));
		((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);
		i = a_cs.Find('.');
		if (i!=-1)
		{
			if (i == a_cs.GetLength()-1)
			{
				a_cs = a_cs.Mid(0, i);
			}
			else
			{
				a_cs = a_cs.Mid(0, i + 2);
			}
			
		}
		a_cs = input_STAlmH_check(a_cs);
		f = _ttof(a_cs);
		i = (int)(f*100.0f);
		theApp.m_Data->m_i32ParaECGST_ALM_H = i;
		theApp.m_Data->m_CParameterSet.set_ECGSTAlmH(i);
		m_EditECGSTAlmH.SetWindowTextW(a_cs);
		return TRUE;
	}
	else if (WM_LBUTTONDOWN == pMsg->message&& m_EditECGSTAlmL.GetSafeHwnd() == pMsg->hwnd)
	{

		m_EditECGSTAlmL.GetWindowTextW(a_cs);
		m_EditECGSTAlmL.GetWindowRect(&rect);       //获得文本框矩形,左上角坐标(0,0)   
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_type(NUM_INPUT_DOT | NUM_INPUT_SYMBOL);
		((CVerbpoDlg *)theApp.m_pMainWnd)->m_CDialogNumInput.set_title(CString(_T("ST下限")));
		((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_HRAlmL_check(a_cs);
		i = a_cs.Find('.');
		if (i != -1)
		{
			if (i == a_cs.GetLength() - 1)
			{
				a_cs = a_cs.Mid(0, i);
			}
			else
			{
				a_cs = a_cs.Mid(0, i + 2);
			}

		}
		a_cs = input_STAlmL_check(a_cs);
		f = _ttof(a_cs);
		i = (int)(f*100.0f);
		theApp.m_Data->m_i32ParaECGST_ALM_L = i;
		theApp.m_Data->m_CParameterSet.set_ECGSTAlmL(i);
		m_EditECGSTAlmL.SetWindowTextW(a_cs);
		return TRUE;
	}
	return CDialogEx::PreTranslateMessage(pMsg);
}

//检测ST报警上限阈值是否正确
CString CDialogECGSetST::input_STAlmH_check(CString & cs)
{
	int a = 0;
	float f = 0.0f;
	CString a_cs;
	f = _ttof(cs);
	a = (int)(f*100.0f);

	

	if (a>CData::m_i16STAlmHMax)
	{
		a = CData::m_i16STAlmHMax;
	}
	else if (a<CData::m_i16STAlmHMin)
	{
		a = CData::m_i16STAlmHMin;
	}


	if (a <= theApp.m_Data->m_i32ParaECGST_ALM_L)
	{
		a = theApp.m_Data->m_i32ParaECGST_ALM_L + 10;
	}

	
	f = a;
	f /= 100.0f;

	a_cs.Format(_T("%2.1f"), f);
	return a_cs;
}

//检测ST报警下限阈值是否正确
CString CDialogECGSetST::input_STAlmL_check(CString & cs)
{
	int a = 0;
	float f = 0.0f;
	CString a_cs;
	f = _ttof(cs);
	a = (int)(f*100.0f);

	if (a>CData::m_i16STAlmLMax)
	{
		a = CData::m_i16STAlmLMax;
	}
	else if (a < CData::m_i16STAlmLMin)
	{
		a = CData::m_i16STAlmLMin;
	}
	

	if (a >= theApp.m_Data->m_i32ParaECGST_ALM_H)
	{
		a = theApp.m_Data->m_i32ParaECGST_ALM_H - 10;
	}
	
	
	f = a;
	f /= 100.0f;

	a_cs.Format(_T("%2.1f"), f);
	return a_cs;
}


void CDialogECGSetST::OnCbnSelchangeComboEcgStSw()
{
	// TODO:  在此添加控件通知处理程序代码
	theApp.m_Data->m_i32ParaECGST_SW = m_ComboECGSTAlmSw.GetCurSel();
	theApp.m_Data->m_CParameterSet.set_ECGSTSw(theApp.m_Data->m_i32ParaECGST_SW);

	if (theApp.m_Data->m_i32ParaECGST_SW == 0)
	{
		//报警 从 开 到 关
		theApp.m_Data->Del_ECG_Alm_ALL(ALM_TYPE_ST, DEL_ALL);
	}
	else
	{
	}
}


void CDialogECGSetST::OnCbnSelchangeComboEcgStAlmSw()
{
	// TODO:  在此添加控件通知处理程序代码
	theApp.m_Data->m_i32ParaECGST_ALM_SW = m_ComboECGSTAlmSw.GetCurSel();
	theApp.m_Data->m_CParameterSet.set_ECGSTAlmSw(theApp.m_Data->m_i32ParaECGST_ALM_SW);

	if (theApp.m_Data->m_i32ParaECGST_ALM_SW == 0)
	{
		//报警 从 开 到 关
		theApp.m_Data->Del_ECG_Alm_ALL(ALM_TYPE_ST, DEL_ALL);
	}
	else
	{
	}
}


void CDialogECGSetST::OnCbnSelchangeComboEcgStAlmLevel()
{
	// TODO:  在此添加控件通知处理程序代码
	theApp.m_Data->m_i32ParaECGST_ALM_LEVEL = m_ComboECGSTAlmLevel.GetCurSel();
	theApp.m_Data->m_CParameterSet.set_ECGAlmLevel(theApp.m_Data->m_i32ParaECGST_ALM_LEVEL);
}


void CDialogECGSetST::OnCbnSelchangeCombo1EcgStAlmRec()
{
	// TODO:  在此添加控件通知处理程序代码
	theApp.m_Data->m_i32ParaECGST_ALM_REC = m_ComboECGSTAlmRec.GetCurSel();
	theApp.m_Data->m_CParameterSet.set_ECGAlmLevel(theApp.m_Data->m_i32ParaECGST_ALM_REC);
}
