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

#include "stdafx.h"
#include "Verbpo.h"
#include "DialogDataRec.h"
#include "afxdialogex.h"
#include "CStaticWave/DataRecWave.h"
#include "ThreadDataAlmRec.h"
#include "VerbpoDlg.h"

// CDialogDataRec 对话框

IMPLEMENT_DYNAMIC(CDialogDataRec, CDialogEx)

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

CDialogDataRec::~CDialogDataRec()
{
}

void CDialogDataRec::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_DATA_REC_NAME, m_CStaticName);
	DDX_Control(pDX, IDC_STATIC_DATA_REC_TIME, m_CStaticTime);
	DDX_Control(pDX, IDC_STATIC_DATA_REC_HR, m_CStaticHR);
	DDX_Control(pDX, IDC_STATIC_DATA_REC_ST1, m_CStaticST1);
	DDX_Control(pDX, IDC_STATIC_DATA_REC_ST2, m_CStaticST2);
	DDX_Control(pDX, IDC_STATIC_DATA_REC_RR, m_CStaticRR);
	DDX_Control(pDX, IDC_STATIC_DATA_REC_SPO2, m_CStaticSpo2);
	DDX_Control(pDX, IDC_STATIC_DATA_REC_PR, m_CStaticPR);
	DDX_Control(pDX, IDC_STATIC_DATA_REC_TEMP, m_CStaticTemp);
	DDX_Control(pDX, IDC_STATIC_ALM_REC_AIROXY, m_CStaticAirOxy);
}


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

	GetWindowRect(&rect);

	//MoveWindow(((CVerbpoDlg *)theApp.m_pMainWnd)->m_i32X, ((CVerbpoDlg *)theApp.m_pMainWnd)->m_i32Y,
	//	((CVerbpoDlg *)theApp.m_pMainWnd)->m_i32X + rect.Width(), ((CVerbpoDlg *)theApp.m_pMainWnd)->m_i32Y + rect.Height());

	font.CreateFont(16,                                          //   nHeight     
		0,                                                   //   nWidth     
		0,                                                   //   nEscapement   
		0,                                                   //   nOrientation     
		FW_NORMAL,                                   //   nWeight     
		TRUE,                                           //   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("宋体"));


	m_CStaticName.SetFont(&font);
	m_CStaticTime.SetFont(&font);
	m_CStaticHR.SetFont(&font);
	m_CStaticST1.SetFont(&font);
	m_CStaticST2.SetFont(&font);
	m_CStaticRR.SetFont(&font);
	m_CStaticSpo2.SetFont(&font);
	m_CStaticPR.SetFont(&font);
	m_CStaticTemp.SetFont(&font);
	m_CStaticAirOxy.SetFont(&font);
	
	((CButton *)GetDlgItem(IDC_RADIO_DATA_REC_2SEC))->SetCheck(TRUE);

	m_stSAVE_DATA.pECGData[0] = new UINT16[1000];
	m_stSAVE_DATA.pECGData[1] = new UINT16[1000];
	m_stSAVE_DATA.pECGData[2] = new UINT16[1000];
	m_stSAVE_DATA.pRespData = new UINT8[250];
	m_stSAVE_DATA.pPlethData = new UINT8[250];

	m_pCDataRecWave = new CDataRecWave;
	m_pCDataRecWave->Create(NULL, WS_CHILD | WS_VISIBLE | SS_NOTIFY, CRect(5, 90, CDataRecWave::m_i32Width+5, CDataRecWave::m_i32Height+90), this, 123);
	m_pCDataRecWave->ShowWindow(SW_SHOW);
	m_pCDataRecWave->Draw_Wave();
	m_pCDataRecWave->Invalidate(TRUE);

	m_stSAVE_DATA.i32dir = REC_CURRENT;
	m_stSAVE_DATA.wnd = this;
	m_stSAVE_DATA.i32time = 1;
	((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Get_Data(&m_stSAVE_DATA);

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


INT CDialogDataRec::Get_Time()
{
	INT a_i32Sec = 0;
	if (((CButton *)GetDlgItem(IDC_RADIO_DATA_REC_2SEC))->GetCheck())
	{
		a_i32Sec = 1;
	}
	else if (((CButton *)GetDlgItem(IDC_RADIO_DATA_REC_1MIN))->GetCheck())
	{
		a_i32Sec = 30;
	}
	else if (((CButton *)GetDlgItem(IDC_RADIO_DATA_REC_10MIN))->GetCheck())
	{
		a_i32Sec = 300;
	}
	else if (((CButton *)GetDlgItem(IDC_RADIO_DATA_REC_30MIN))->GetCheck())
	{
		a_i32Sec = 900;
	}
	else if (((CButton *)GetDlgItem(IDC_RADIO_DATA_REC_60MIN))->GetCheck())
	{
		a_i32Sec = 1800;
	}

	return a_i32Sec;
}



BEGIN_MESSAGE_MAP(CDialogDataRec, CDialogEx)
	ON_MESSAGE(WM_MONITOR_STATUS, OnMonitorStatus)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDOK, &CDialogDataRec::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON_DATA_REC_PRE, &CDialogDataRec::OnBnClickedButtonDataRecPre)
	ON_BN_CLICKED(IDC_BUTTON__DATA_REC_NEXT, &CDialogDataRec::OnBnClickedButton)
	ON_BN_CLICKED(IDC_BUTTON_DATA_REC_CHANGE, &CDialogDataRec::OnBnClickedButtonDataRecChange)
END_MESSAGE_MAP()


// CDialogDataRec 消息处理程序


LRESULT  CDialogDataRec::OnMonitorStatus(WPARAM wPara, LPARAM lPara)
{
	switch (wPara)
	{
	case WM_REC_GET_OK:
		Show_Result();

		break;
	}

	return 0;
}


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

	// TODO:  在此处添加消息处理程序代码
	m_pCDataRecWave->DestroyWindow();
	delete m_pCDataRecWave;
	font.DeleteObject();
	delete m_stSAVE_DATA.pECGData[0];
	delete m_stSAVE_DATA.pECGData[1];
	delete m_stSAVE_DATA.pECGData[2];
	delete m_stSAVE_DATA.pRespData;
	delete m_stSAVE_DATA.pPlethData;
}



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


void CDialogDataRec::OnBnClickedButtonDataRecPre()
{
	// TODO:  在此添加控件通知处理程序代码
	m_stSAVE_DATA.i32dir = REC_FORWARD;
	m_stSAVE_DATA.wnd = this;
	m_stSAVE_DATA.i32time = Get_Time();
	((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Get_Data(&m_stSAVE_DATA);
}


void CDialogDataRec::OnBnClickedButton()
{
	// TODO:  在此添加控件通知处理程序代码
	m_stSAVE_DATA.i32dir = REC_BACKWARD;
	m_stSAVE_DATA.wnd = this;
	m_stSAVE_DATA.i32time = Get_Time();
	((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Get_Data(&m_stSAVE_DATA);
}


void CDialogDataRec::Show_Result()
{
	CString a_cs;
	float a_fTemp=0.0f;

	m_CStaticName.SetWindowTextW(m_stSAVE_DATA.stPara.cName);
	m_CStaticTime.SetWindowTextW(m_stSAVE_DATA.stPara.cTime);


	if (m_stSAVE_DATA.stPara.i16HR == CData::m_i16HRInvalidValue)
	{
		a_cs = _T("未测出");
	}
	else
	{
		a_cs.Format(_T("%d bpm"), m_stSAVE_DATA.stPara.i16HR);
	}
	m_CStaticHR.SetWindowTextW(a_cs);


	if (m_stSAVE_DATA.stPara.i16ST1 == CData::m_i16STInvalidValue)
	{
		a_cs = _T("未测出");
	}
	else
	{
		a_fTemp = m_stSAVE_DATA.stPara.i16ST1;
		a_fTemp = a_fTemp / 100.0f;
		a_cs.Format(_T("%0.2f "), a_fTemp);
	}
	m_CStaticST1.SetWindowTextW(a_cs);

	
	if (m_stSAVE_DATA.stPara.i16ST2 == CData::m_i16STInvalidValue)
	{
		a_cs = _T("未测出");
	}
	else
	{
		a_fTemp = m_stSAVE_DATA.stPara.i16ST2;
		a_fTemp = a_fTemp / 100.0f;
		a_cs.Format(_T("%0.2f "), a_fTemp);
	}
	m_CStaticST2.SetWindowTextW(a_cs);


	if (m_stSAVE_DATA.stPara.i16RR == CData::m_i16RRInvalidValue)
	{
		a_cs = _T("未测出");
	}
	else
	{
		a_cs.Format(_T("%d rpm"), m_stSAVE_DATA.stPara.i16RR);
	}
	m_CStaticRR.SetWindowTextW(a_cs);

	if (m_stSAVE_DATA.stPara.i16Spo2 == CData::m_i16Spo2InvalidValue)
	{
		a_cs = _T("未测出");
	}
	else
	{
		a_cs.Format(_T("%d %s"), m_stSAVE_DATA.stPara.i16Spo2,_T("%"));
	}
	m_CStaticSpo2.SetWindowTextW(a_cs);

	if (m_stSAVE_DATA.stPara.i16PR == CData::m_i16PRInvalidValue)
	{
		a_cs = _T("未测出");
	}
	else
	{
		a_cs.Format(_T("%d bpm"), m_stSAVE_DATA.stPara.i16PR);
	}
	m_CStaticPR.SetWindowTextW(a_cs);

	
	if (m_stSAVE_DATA.stPara.i16Temp == CData::m_i16TempInvalidValue)
	{
		a_cs = _T("未测出");
	}
	else
	{
		a_fTemp = m_stSAVE_DATA.stPara.i16Temp;
		a_fTemp = a_fTemp / 10.0f;
		a_cs.Format(_T("%0.1f C"), a_fTemp);
	}
	m_CStaticTemp.SetWindowTextW(a_cs);

	if (m_stSAVE_DATA.stPara.i8AirOxy == CData::m_i16AirOxyInvalidValue)
	{
		a_cs = _T("未测出");
	}
	else
	{
		a_cs.Format(_T("%d %s"), m_stSAVE_DATA.stPara.i8AirOxy, _T("%"));
	}
	m_CStaticAirOxy.SetWindowTextW(a_cs);

	m_pCDataRecWave->copy_data(&m_stSAVE_DATA);
	m_pCDataRecWave->Draw_Wave();
}

void CDialogDataRec::OnBnClickedButtonDataRecChange()
{
	// TODO:  在此添加控件通知处理程序代码
	m_pCDataRecWave->show_change();
	m_pCDataRecWave->Draw_Wave();
}
