#include "stdafx.h"
#include "Data.h"
#include "Verbpo.h"
#include "ThreadDataAlmRec.h"
#include "VerbpoDlg.h"

const TCHAR n_ECG_ALM_INFO[24][32] = { _T(""), _T("心律过低"), _T("心律过高"), _T("LL导联脱落"), _T("LA导联脱落"), _T("RA导联脱落"), _T("V导联脱落"), _T("导联脱落"),
};

const TCHAR n_ST_ALM_INFO[24][32] = { _T(""), _T("ST1过低"), _T("ST1过高"), _T("ST2过低"), _T("ST2过高")
};


const TCHAR n_ARRA_ALM_INFO[24][32] = { _T(""), _T("二联律"), _T("三联律"), _T("心电过缓"), _T("心电过速"), _T("室早"), _T("室速"), _T("室早成对"), _T("停搏"),

};


const TCHAR n_RESP_ALM_INFO[12][32] = { _T(""), _T("呼吸率过低"), _T("呼吸率过高"),
_T("呼吸窒息")
};


const TCHAR n_OXY_ALM_INFO[12][32] = { _T(""), _T("血氧饱和度过低"), _T("血氧饱和度过高"),
_T("脉率过低"), _T("脉率过高"),
_T("血氧手指脱落"), _T("血氧探头脱落")
};

const TCHAR n_TEMP_ALM_INFO[12][32] = { _T(""), _T("体温过低"), _T("体温过高"),
_T("体温探头脱落")
};

const TCHAR n_NIBP_ALM_INFO[12][32] = { _T(""), _T("收缩压过低"), _T("收缩压过高"),
_T("舒张压过低"), _T("舒张压过高"),
};

const TCHAR n_AirOxy_ALM_INFO[12][32] = { _T(""), _T("氧浓度过低"), _T("氧浓度过高"),
_T("氧浓度探头脱落")
};

int CData::m_i32AlmSWOn = 1;
int CData::m_i32AlmSWOff = 0;
int CData::m_i32AlmLevelH = 2;
int CData::m_i32AlmLevelM = 1;
int CData::m_i32AlmLevelL = 0;
int CData::m_i32AlmRecOn = 1;
int CData::m_i32AlmRecOff = 0;



INT16 CData::m_i16HRAlmHMin = 25; INT16 CData::m_i16HRAlmHMax = 350;
INT16 CData::m_i16HRAlmLMin=7; INT16 CData::m_i16HRAlmLMax=250;
INT CData::m_i32HRFromECG=0; INT CData::m_i32HRFromPR=1;
INT CData::m_i32ECGHRLeadI=0; INT CData::m_i32ECGHRLeadII=1;
INT CData::m_i32ECGLeadMode5=0; INT CData::m_i32ECGLeadMode3;
INT CData::m_i32ECGTrapOn = 1; INT CData::m_i32ECGTrapOff=0;
INT CData::m_i32ECGPaceOn = 1; INT CData::m_i32ECGPaceOff = 0;
INT16 CData::m_i16ECGSpeed25=0; INT16 CData::m_i16ECGSpeed50=1;
INT16 CData::m_i16ECGGain1_2 = 0; INT16 CData::m_i16ECGGain1_1 = 1; INT16 CData::m_i16ECGGain2_1 = 2;
//心搏音 的定义
INT  CData::m_i32BeatVol0 = 0; INT  CData::m_i32BeatVol1 = 1; INT  CData::m_i32BeatVol2 = 2; INT  CData::m_i32BeatVol3 = 3;

INT CData::m_i32STOn = 1; INT CData::m_i32STOff = 0;
INT CData::m_i32STMin=0; INT CData::m_i32STMax=100;
INT CData::m_i32ISOMin=0; INT CData::m_i32ISOMax = 100;
INT16 CData::m_i16STAlmHMin = -100; INT16 CData::m_i16STAlmHMax = 200;
INT16 CData::m_i16STAlmLMin = -200; INT16 CData::m_i16STAlmLMax = 100;

INT16 CData::m_i16PVCsAlmHMin=1; INT16 CData::m_i16PVCsAlmHMax=10;

INT16 CData::m_i16Spo2AlmHMin=80; INT16 CData::m_i16Spo2AlmHMax=100;
INT16 CData::m_i16Spo2AlmLMin=70; INT16 CData::m_i16Spo2AlmLMax=90;

INT16 CData::m_i16PRAlmHMin=30; INT16 CData::m_i16PRAlmHMax=300;
INT16 CData::m_i16PRAlmLMin=10; INT16 CData::m_i16PRAlmLMax=250;
INT16 CData::m_i16PlethSpeed12=0; INT16 CData::m_i16PlethSpeed25=1;

INT16 CData::m_i16RRAlmHMin=30; INT16 CData::m_i16RRAlmHMax=120;
INT16 CData::m_i16RRAlmLMin=7; INT16 CData::m_i16RRAlmLMax=100;
INT16 CData::m_i16APNEATime0Sec=0; INT16 CData::m_i16APNEATime10Sec=1; 
INT16 CData::m_i16APNEATime20Sec=2; INT16 CData::m_i16APNEATime30Sec=3;
INT16 CData::m_i16RespSpeed12=0; INT16 CData::m_i16RespSpeed25=1;
INT16 CData::m_i16RespGain1_4 = 0; INT16 CData::m_i16RespGain1_2 = 1; 
INT16 CData::m_i16RespGain1_1 = 2; INT16 CData::m_i16RespGain2_1 = 3; INT16 CData::m_i16RespGain4_1 = 4;


INT16 CData::m_i16TempAlmHMin=360; INT16 CData::m_i16TempAlmHMax=430;
INT16 CData::m_i16TempAlmLMin=330; INT16 CData::m_i16TempAlmLMax=390;

INT16 CData::m_i16SBPAlmHMin=60; INT16 CData::m_i16SBPAlmHMax=120;
INT16 CData::m_i16SBPAlmLMin=40; INT16 CData::m_i16SBPAlmLMax=100;

INT16 CData::m_i16DBPAlmHMin=40; INT16 CData::m_i16DBPAlmHMax=100;
INT16 CData::m_i16DBPAlmLMin=30; INT16 CData::m_i16DBPAlmLMax=80;

INT16 CData::m_i16AirOxyAlmHMin=50; INT16 CData::m_i16AirOxyAlmHMax=100;
INT16 CData::m_i16AirOxyAlmLMin=20; INT16 CData::m_i16AirOxyAlmLMax=80;



//报警静音时间 的定义
INT CData::m_i32AlmTime1 = 60; INT CData::m_i32AlmTime2 = 120;
//报警音 的定义
INT CData::m_i32AlmVol1_5 = 0; INT CData::m_i32AlmVol1_2 = 1; INT CData::m_i32AlmVol4_5 = 2; INT CData::m_i32AlmVol1_1 = 3;

INT CData::m_i32SaveDataECGWaveL = 1000;
INT CData::m_i32SaveDataRespWaveL = 250;
INT CData::m_i32SaveDataPlethWaveL = 250;



INT16 CData::m_i16HRInvalidValue = -100;
INT16 CData::m_i16STInvalidValue = -10000;
INT16 CData::m_i16PVCsInvalidValue = -100;
INT16 CData::m_i16RRInvalidValue = -100;
INT16 CData::m_i16TempInvalidValue = -100;
INT16 CData::m_i16Spo2InvalidValue = -100;
INT16 CData::m_i16PRInvalidValue = -100;
INT16 CData::m_i16AirOxyInvalidValue = -100;
INT16 CData::m_i16SBPInvalidValue = -100;
INT16 CData::m_i16DBPInvalidValue = -100;
COLORREF CData::m_rgbECGWave = RGB(0, 255, 0);
COLORREF CData::m_rgbRespWave = RGB(0xEE, 0xEE, 0x62);
COLORREF CData::m_rgbPlethWave = RGB(0x80, 0xCD, 0xFF);


CData::CData()
{
	int i;

	m_i32ParaECGALM_SW = m_CParameterSet.get_ECGAlmSw();
	m_i32ParaECGALM_LEVEL = m_CParameterSet.get_ECGAlmLevel();
	m_i32ParaECGALM_REC = m_CParameterSet.get_ECGAlmRec();
	m_i32ParaECGHR_FORM = m_CParameterSet.get_ECGHRFrom();
	m_i32ParaECGHR_LEAD = m_CParameterSet.get_ECGHRLead();
	m_i32ParaECGLEAD_MODE = m_CParameterSet.get_ECGLeadMode();
	m_i32ParaECGHR_ALM_H = m_CParameterSet.get_ECGHRAlmH();
	m_i32ParaECGHR_ALM_L = m_CParameterSet.get_ECGHRAlmL();
	m_i32ParaECGECG_TRAP = m_CParameterSet.get_ECGTrap();
	m_i32ParaECGPACE_SW = m_CParameterSet.get_ECGPaceSw();
	m_i32ParaECGWAVE_SPEED = m_CParameterSet.get_ECGWaveSpeed();
	m_i32ParaECGWAVE_GAIN = m_CParameterSet.get_ECGWaveGain();
	m_i32ParaECGWAVE_Filter = m_CParameterSet.get_ECGWaveFilter();
	m_i32ParaECGBEAT_VOL = m_CParameterSet.get_ECGBeatVol();
	
	m_i32ParaECGST_SW = m_CParameterSet.get_ECGSTSw();
	m_i32ParaECGST_ALM_SW = m_CParameterSet.get_ECGSTAlmSw();
	m_i32ParaECGST_ALM_LEVEL = m_CParameterSet.get_ECGSTAlmLevel();
	m_i32ParaECGST_ALM_REC = m_CParameterSet.get_ECGSTAlmRec();
	m_i32ParaECGST_ALM_H = m_CParameterSet.get_ECGSTAlmH();
	m_i32ParaECGST_ALM_L = m_CParameterSet.get_ECGSTAlmL();
	m_i32ParaECGISO = m_CParameterSet.get_ECGISO();
	m_i32ParaECGST = m_CParameterSet.get_ECGST();
	m_i32ParaECGARRASW = m_CParameterSet.get_ECGARRASW();
	m_i32ParaECGARRA_ALM_SW = m_CParameterSet.get_ECGARRAAlmSw();
	m_i32ParaECGARRA_ALM_LEVEL = m_CParameterSet.get_ECGARRAAlmLevel();
	m_i32ParaECGARRA_ALM_REC = m_CParameterSet.get_ECGARRAAlmRec();
	m_i32ParaECGARRA_PVCS_ALM_H = m_CParameterSet.get_ECGARRAPVCsH();


	m_i32ShowNormalECGChannel1Type = ECG_WAVE_II, m_i32ShowNormalECGChannel2Type = ECG_WAVE_I;

	m_i32ParaRespALM_SW = m_CParameterSet.get_RespAlmSw();
	m_i32ParaRespALM_LEVEL = m_CParameterSet.get_RespAlmLevel();
	m_i32ParaRespALM_REC = m_CParameterSet.get_RespAlmRec();
	m_i32ParaRespAPNEA_TIME = m_CParameterSet.get_RespAPNEATime();
	m_i32ParaRespRR_ALM_H = m_CParameterSet.get_RespRRAlmH();
	m_i32ParaRespRR_ALM_L = m_CParameterSet.get_RespRRAlmL();
	m_i32ParaRespGain = 0;
	m_i32ParaRespSpeed = 0;

	m_i32ParaTempALM_SW = m_CParameterSet.get_TempAlmSw();
	m_i32ParaTempALM_LEVEL = m_CParameterSet.get_TempAlmLevel();
	m_i32ParaTempALM_REC = m_CParameterSet.get_TempAlmRec();
	m_i32ParaTempTEMP_ALM_H = m_CParameterSet.get_TempAlmH();
	m_i32ParaTempTEMP_ALM_L = m_CParameterSet.get_TempAlmL();


	m_i32ParaOxyALM_SW = m_CParameterSet.get_OxyAlmSw();
	m_i32ParaOxyALM_LEVEL = m_CParameterSet.get_OxyAlmLevel();
	m_i32ParaOxyALM_REC = m_CParameterSet.get_OxyAlmRec();
	m_i32ParaOxyOXY_ALM_H = m_CParameterSet.get_OxyAlmH();
	m_i32ParaOxyOXY_ALM_L = m_CParameterSet.get_OxyAlmL();
	m_i32ParaOxyOXY_PR_ALM_H = m_CParameterSet.get_OxyPRAlmH();
	m_i32ParaOxyOXY_PR_ALM_L = m_CParameterSet.get_OxyPRAlmL();
	m_i32PlethSpeed = 0;

	m_i32ParaBPALM_SW = m_CParameterSet.get_BPAlmSw();
	m_i32ParaBPALM_LEVEL = m_CParameterSet.get_BPAlmLevel();
	m_i32ParaBPALM_REC = m_CParameterSet.get_BPAlmRec();
	m_i32ParaBPSBP_ALM_H = m_CParameterSet.get_BPSBPAlmH();
	m_i32ParaBPSBP_ALM_L = m_CParameterSet.get_BPSBPAlmL();
	m_i32ParaBPDBP_ALM_H = m_CParameterSet.get_BPDBPAlmH();
	m_i32ParaBPDBP_ALM_L = m_CParameterSet.get_BPDBPAlmL();
	m_i32ParaBPPress = m_CParameterSet.get_Press();

	m_i32ParaAirOxyALM_SW = m_CParameterSet.get_AirOxyAlmSw();
	m_i32ParaAirOxyALM_LEVEL = m_CParameterSet.get_AirOxyAlmLevel();
	m_i32ParaAirOxyALM_REC = m_CParameterSet.get_AirOxyAlmRec();
	m_i32ParaAirOxy_ALM_H = m_CParameterSet.get_AirOxyAlmH();
	m_i32ParaAirOxy_ALM_L = m_CParameterSet.get_AirOxyAlmL();

	m_i32ParaAlmTime = m_CParameterSet.get_AlmTime();
	m_i32ParaAlmVol = m_CParameterSet.get_AlmVol();

	


	m_CParameterSet.get_DataSaveFileName(theApp.m_csSaveDataFileName);
	m_CParameterSet.get_NIBPSaveFileName(theApp.m_csSaveNIBPFileName);
	m_CParameterSet.get_AlmSaveFileName(theApp.m_csSaveAlmPFileName);
	m_CParameterSet.get_SysSaveFileName(theApp.m_csSaveSysPFileName);

	for (i = 0; i < 7; i++)
	{
		m_u16ECGData[i] = new UINT16[SHOW_BUFF_LENGTH];
		m_i32ECGDateW = 0, m_i32ECGDateR = 0, m_i32ECGDateLength = 0;

		m_stGET_ECG_DATA.pECGData[i] = new int[ECG_DATA_SAVE_TIME*ECG_SAMPLE_RATE];

		m_u16ECGSaveData[i] = new UINT16[SHOW_BUFF_LENGTH];
		m_i32ECGSaveDateW = 0, m_i32ECGSaveDateR = 0, m_i32ECGSaveDateLength = 0;
	}
	m_i32PrintDateW = 0, m_i32PrintDateR = 0, m_i32PrintDateLength = 0;

	m_u8RespData = new UINT8[SHOW_BUFF_LENGTH];
	m_i32RespDateW = 0, m_i32RespDateR = 0, m_i32RespDateLength = 0;

	m_u8RespSaveData = new UINT8[SHOW_BUFF_LENGTH];
	m_i32RespSaveDateW = 0, m_i32RespSaveDateR = 0, m_i32RespSaveDateLength = 0;

	m_u8PlethData = new UINT8[SHOW_BUFF_LENGTH];
	m_i32PlethDataW = 0, m_i32PlethDateR = 0, m_i32PlethDateLength = 0;

	m_u8PlethSaveData = new UINT8[SHOW_BUFF_LENGTH];
	m_i32PlethSaveDataW = 0, m_i32PlethSaveDateR = 0, m_i32PlethSaveDateLength = 0;


	m_stSaveData.pECGData[0] = new UINT16[CData::m_i32SaveDataECGWaveL];
	m_stSaveData.pECGData[1] = new UINT16[CData::m_i32SaveDataECGWaveL];
	m_stSaveData.pECGData[2] = new UINT16[CData::m_i32SaveDataECGWaveL];
	m_stSaveData.pRespData = new UINT8[CData::m_i32SaveDataRespWaveL];
	m_stSaveData.pPlethData = new UINT8[CData::m_i32SaveDataPlethWaveL];


	m_i16HR = CData::m_i16HRInvalidValue;
	m_i16ST1 = CData::m_i16STInvalidValue, m_i16ST2 = CData::m_i16STInvalidValue;
	m_i32LeadOff, m_i32LeadOverLoad;
	m_i16PVCs = CData::m_i16PVCsInvalidValue;
	m_i32Beat = 0;
	m_u8ARRA = 0;

	m_i16RR = CData::m_i16RRInvalidValue;
	m_u8APNEA = 0;


	m_i16Spo2 = CData::m_i16Spo2InvalidValue;
	m_i16PR = CData::m_i16PRInvalidValue;
	u16Finger = 0;
	u16Beat = 0;
	u16Search = 0;
	u16Probe = 0;
	u8Bar = 0;
	u16Signal = 0;

	m_u8TempProbe = 0;
	m_i16Temp = CData::m_i16TempInvalidValue;

	m_i16SBP = CData::m_i16SBPInvalidValue;
	m_i16DBP = CData::m_i16DBPInvalidValue;

	m_i8AirOxy = 0;
	m_u8AirOxySTS = 0;

	m_i32ECGAlmShowIndex = 0;
	m_i32RespTempAlmShowIndex = 0;
	m_i32OxyNIBPAlmShowIndex = 0;
	m_i32AirOxyAlmShowIndex = 0;

	for (i = 0; i < 16; i++)
	{
		m_u8ECGTrigger[i] = 0;
		m_u8STTrigger[i] = 0;
		m_u8ARRATrigger[i] = 0;
		m_u8RespTrigger[i] = 0;
		m_u8OxyTrigger[i] = 0;
		m_u8TempTrigger[i] = 0;
		m_u8NIBPTrigger[i] = 0;
		m_u8AirOxyTrigger[i] = 0;

		m_u8ECGAlm[i] = 0;
		m_u8STAlm[i] = 0;
		m_u8ARRAAlm[i] = 0;
		m_u8RespAlm[i] = 0;
		m_u8OxyAlm[i] = 0;
		m_u8TempAlm[i] = 0;
		m_u8NIBPAlm[i] = 0;
		m_u8AirOxyAlm[i] = 0;
	}

	m_stSAVE_ALM.pECGData[0] = new UINT16[CThreadDataAlmRec::m_i32SaveAlmECGWaveLength];
	m_stSAVE_ALM.pECGData[1] = new UINT16[CThreadDataAlmRec::m_i32SaveAlmECGWaveLength];
	m_stSAVE_ALM.pECGData[2] = new UINT16[CThreadDataAlmRec::m_i32SaveAlmECGWaveLength];

	m_stSAVE_ALM.pPlethData = new UINT8[CThreadDataAlmRec::m_i32SaveAlmPlethWaveLength];
	m_stSAVE_ALM.pRespData = new UINT8[CThreadDataAlmRec::m_i32SaveAlmRespWaveLength];

	m_u32Status = (1 << STATUS_TIME_DELAY);

	Check_Set_Para();
}


CData::~CData()
{
	int i;
	for (i = 0; i < 7; i++)
	{
		delete m_u16ECGData[i];
		delete m_u16ECGSaveData[i];
		delete m_stGET_ECG_DATA.pECGData[i];
	}
	delete m_u8RespData;
	delete m_u8RespSaveData;
	delete m_u8PlethData;
	delete m_u8PlethSaveData;

	delete m_stSaveData.pECGData[0];
	delete m_stSaveData.pECGData[1];
	delete m_stSaveData.pECGData[2];
	delete m_stSaveData.pRespData;
	delete m_stSaveData.pPlethData;

	delete m_stSAVE_ALM.pECGData[0] ;
	delete m_stSAVE_ALM.pECGData[1] ;
	delete m_stSAVE_ALM.pECGData[2] ;

	delete m_stSAVE_ALM.pPlethData ;
	delete m_stSAVE_ALM.pRespData ;
}


//检查设置参数 是否正确，如果错误，更改
INT CData::Check_Set_Para()
{
	//检查心电设置参数 是否正确，如果错误，更改
	Check_ECG_Set_Para();
	//检查呼吸设置参数 是否正确，如果错误，更改
	Check_Resp_Set_Para();
	//检查血氧设置参数 是否正确，如果错误，更改
	Check_Spo2_Set_Para();
	//检查体温设置参数 是否正确，如果错误，更改
	Check_Temp_Set_Para();
	//检查血压设置参数 是否正确，如果错误，更改
	Check_NIBP_Set_Para();
	//检查空氧设置参数 是否正确，如果错误，更改
	Check_AirOxy_Set_Para();
	//检查系统设置参数 是否正确，如果错误，更改
	Check_Sys_Set_Para();
	return 0;
}

//检查心电设置参数 是否正确，如果错误，更改
INT CData::Check_ECG_Set_Para()
{
	if ((m_i32ParaECGALM_SW != CData::m_i32AlmSWOn) && (m_i32ParaECGALM_SW != CData::m_i32AlmSWOff))
	{
		m_i32ParaECGALM_SW = CData::m_i32AlmSWOn;
	}

	if ((m_i32ParaECGALM_LEVEL != CData::m_i32AlmLevelH) && (m_i32ParaECGALM_LEVEL != CData::m_i32AlmLevelM) && (m_i32ParaECGALM_LEVEL != CData::m_i32AlmLevelL))
	{
		m_i32ParaECGALM_LEVEL = CData::m_i32AlmLevelH;
	}

	if ((m_i32ParaECGALM_REC != CData::m_i32AlmRecOn) && (m_i32ParaECGALM_REC != CData::m_i32AlmRecOff))
	{
		m_i32ParaECGALM_REC = CData::m_i32AlmRecOff;
	}

	if ((m_i32ParaECGHR_FORM != CData::m_i32HRFromECG) && (m_i32ParaECGHR_FORM != CData::m_i32HRFromPR))
	{
		m_i32ParaECGHR_FORM = CData::m_i32HRFromECG;
	}

	if ((m_i32ParaECGHR_LEAD != CData::m_i32ECGHRLeadI) && (m_i32ParaECGHR_LEAD != CData::m_i32ECGHRLeadII))
	{
		m_i32ParaECGHR_LEAD = CData::m_i32ECGHRLeadI;
	}

	if ((m_i32ParaECGLEAD_MODE != CData::m_i32ECGLeadMode5) && (m_i32ParaECGLEAD_MODE != CData::m_i32ECGLeadMode3))
	{
		m_i32ParaECGLEAD_MODE = CData::m_i32ECGLeadMode5;
	}

	if ((m_i32ParaECGECG_TRAP != CData::m_i32ECGTrapOn) && (m_i32ParaECGECG_TRAP != CData::m_i32ECGTrapOff))
	{
		m_i32ParaECGECG_TRAP = CData::m_i32ECGTrapOn;
	}

	if ((m_i32ParaECGWAVE_SPEED != CData::m_i16ECGSpeed25) && (m_i32ParaECGWAVE_SPEED != CData::m_i16ECGSpeed50))
	{
		m_i32ParaECGWAVE_SPEED = CData::m_i16ECGSpeed25;
	}

	if ((m_i32ParaECGWAVE_GAIN != CData::m_i16ECGGain1_2)
		&& (m_i32ParaECGWAVE_GAIN != CData::m_i16ECGGain1_1)
		&& (m_i32ParaECGWAVE_GAIN != CData::m_i16ECGGain2_1))
	{
		m_i32ParaECGWAVE_GAIN = CData::m_i16ECGGain1_1;
	}

	if ((m_i32ParaECGBEAT_VOL != CData::m_i32BeatVol0)
		&& (m_i32ParaECGBEAT_VOL != CData::m_i32BeatVol1)
		&& (m_i32ParaECGBEAT_VOL != CData::m_i32BeatVol2)
		&& (m_i32ParaECGBEAT_VOL != CData::m_i32BeatVol3))
	{
		m_i32ParaECGBEAT_VOL = CData::m_i32BeatVol0;
	}
	switch (m_i32ParaECGBEAT_VOL)
	{
	case 0:
		m_i32BeatVol = -10000;
		break;

	case 1:
		m_i32BeatVol = -1398;
		break;

	case 2:
		m_i32BeatVol = -444;
		break;

	case 3:
		m_i32BeatVol = 0;
		break;
	}
	

	//心律 报警阈值检查，如果错误，更改
	if (m_i32ParaECGHR_ALM_H > m_i16HRAlmHMax)
	{
		m_i32ParaECGHR_ALM_H = m_i16HRAlmHMax;
	}
	else if (m_i32ParaECGHR_ALM_H<m_i16HRAlmHMin)
	{
		m_i32ParaECGHR_ALM_H = m_i16HRAlmHMin;
	}

	if (m_i32ParaECGHR_ALM_L>m_i16HRAlmLMax)
	{
		m_i32ParaECGHR_ALM_L = m_i16HRAlmLMax;
	}
	else if (m_i32ParaECGHR_ALM_L < m_i16HRAlmLMin)
	{
		m_i32ParaECGHR_ALM_L = m_i16HRAlmLMin;
	}

	if (m_i32ParaECGHR_ALM_H <= m_i32ParaECGHR_ALM_L)
	{
		m_i32ParaECGHR_ALM_H = m_i32ParaECGHR_ALM_L + 3;
	}




	//ST 参数检查
	if ((m_i32ParaECGST_SW != CData::m_i32STOn) && (m_i32ParaECGST_SW != CData::m_i32STOff))
	{
		m_i32ParaECGST_SW = CData::m_i32STOff;
	}

	if ((m_i32ParaECGST_ALM_SW != CData::m_i32AlmSWOn) && (m_i32ParaECGST_ALM_SW != CData::m_i32AlmSWOff))
	{
		m_i32ParaECGST_ALM_SW = CData::m_i32AlmSWOn;
	}

	if ((m_i32ParaECGST_ALM_LEVEL != CData::m_i32AlmLevelH) && (m_i32ParaECGST_ALM_LEVEL != CData::m_i32AlmLevelM) && (m_i32ParaECGST_ALM_LEVEL != CData::m_i32AlmLevelL))
	{
		m_i32ParaECGST_ALM_LEVEL = CData::m_i32AlmLevelH;
	}

	if ((m_i32ParaECGST_ALM_REC != CData::m_i32AlmRecOn) && (m_i32ParaECGST_ALM_REC != CData::m_i32AlmRecOff))
	{
		m_i32ParaECGST_ALM_REC = CData::m_i32AlmRecOff;
	}

	if (m_i32ParaECGST > m_i32STMax)
	{
		m_i32ParaECGST = m_i32STMax;
	}
	else if (m_i32ParaECGST<m_i32STMin)
	{
		m_i32ParaECGST = m_i32STMin;
	}

	if (m_i32ParaECGISO > m_i32ISOMax)
	{
		m_i32ParaECGISO = m_i32ISOMax;
	}
	else if (m_i32ParaECGISO<m_i32ISOMin)
	{
		m_i32ParaECGISO = m_i32ISOMin;
	}

	//ST 报警阈值检查，如果错误，更改
	if (m_i32ParaECGST_ALM_H>m_i16STAlmHMax)
	{
		m_i32ParaECGST_ALM_H = m_i16STAlmHMax;
	}
	else if (m_i32ParaECGST_ALM_H<m_i16STAlmHMin)
	{
		m_i32ParaECGST_ALM_H = m_i16STAlmHMin;
	}

	if (m_i32ParaECGST_ALM_L>m_i16STAlmLMax)
	{
		m_i32ParaECGST_ALM_L = m_i16STAlmLMax;
	}
	else if (m_i32ParaECGST_ALM_L < m_i16STAlmLMin)
	{
		m_i32ParaECGST_ALM_L = m_i16STAlmLMin;
	}

	if (m_i32ParaECGST_ALM_H <= m_i32ParaECGST_ALM_L)
	{
		m_i32ParaECGST_ALM_H = m_i32ParaECGST_ALM_L + 10;
	}


	//心律异常分析 报警阈值检查，如果错误，更改
	if ((m_i32ParaECGARRA_ALM_SW != CData::m_i32AlmSWOn) && (m_i32ParaECGARRA_ALM_SW != CData::m_i32AlmSWOff))
	{
		m_i32ParaECGARRA_ALM_SW = CData::m_i32AlmSWOn;
	}

	if ((m_i32ParaECGARRA_ALM_LEVEL != CData::m_i32AlmLevelH) && (m_i32ParaECGARRA_ALM_LEVEL != CData::m_i32AlmLevelM) && (m_i32ParaECGARRA_ALM_LEVEL != CData::m_i32AlmLevelL))
	{
		m_i32ParaECGARRA_ALM_LEVEL = CData::m_i32AlmLevelH;
	}

	if ((m_i32ParaECGARRA_ALM_REC != CData::m_i32AlmRecOn) && (m_i32ParaECGARRA_ALM_REC != CData::m_i32AlmRecOff))
	{
		m_i32ParaECGARRA_ALM_REC = CData::m_i32AlmRecOff;
	}
	//心律异常分析 报警阈值检查，如果错误，更改
	if (m_i32ParaECGARRA_PVCS_ALM_H > m_i16PVCsAlmHMax)
	{
		m_i32ParaECGARRA_PVCS_ALM_H = m_i16PVCsAlmHMax;
	}
	else if (m_i32ParaECGST_ALM_H < m_i16PVCsAlmHMin)
	{
		m_i32ParaECGARRA_PVCS_ALM_H = m_i16PVCsAlmHMin;
	}
	
	return 0;
}

//检查呼吸设置参数 是否正确，如果错误，更改
INT CData::Check_Resp_Set_Para()
{
	if ((m_i32ParaRespALM_SW != CData::m_i32AlmSWOn) && (m_i32ParaRespALM_SW != CData::m_i32AlmSWOff))
	{
		m_i32ParaRespALM_SW = CData::m_i32AlmSWOn;
	}

	if ((m_i32ParaRespALM_LEVEL != CData::m_i32AlmLevelH) && (m_i32ParaRespALM_LEVEL != CData::m_i32AlmLevelM) && (m_i32ParaRespALM_LEVEL != CData::m_i32AlmLevelL))
	{
		m_i32ParaRespALM_LEVEL = CData::m_i32AlmLevelH;
	}

	if ((m_i32ParaRespALM_REC != CData::m_i32AlmRecOn) && (m_i32ParaRespALM_REC != CData::m_i32AlmRecOff))
	{
		m_i32ParaRespALM_REC = CData::m_i32AlmRecOff;
	}


	if (m_i32ParaRespRR_ALM_H > m_i16RRAlmHMax)
	{
		m_i32ParaRespRR_ALM_H = m_i16RRAlmHMax;
	}
	else if (m_i32ParaRespRR_ALM_H<m_i16RRAlmHMin)
	{
		m_i32ParaRespRR_ALM_H = m_i16RRAlmHMin;
	}

	if (m_i32ParaRespRR_ALM_L>m_i16RRAlmLMax)
	{
		m_i32ParaRespRR_ALM_L = m_i16RRAlmLMax;
	}
	else if (m_i32ParaRespRR_ALM_L < m_i16RRAlmLMin)
	{
		m_i32ParaRespRR_ALM_L = m_i16RRAlmLMin;
	}
	if (m_i32ParaRespRR_ALM_H <= m_i32ParaRespRR_ALM_L)
	{
		m_i32ParaRespRR_ALM_H = m_i32ParaRespRR_ALM_L + 3;
	}

	if ((m_i32ParaRespAPNEA_TIME != CData::m_i16APNEATime0Sec)
		&& (m_i32ParaRespAPNEA_TIME != CData::m_i16APNEATime10Sec)
		&& (m_i32ParaRespAPNEA_TIME != CData::m_i16APNEATime20Sec)
		&& (m_i32ParaRespAPNEA_TIME != CData::m_i16APNEATime30Sec))
	{
		m_i32ParaRespAPNEA_TIME = CData::m_i16APNEATime10Sec;
	}

	if ((m_i32ParaRespSpeed != CData::m_i16RespSpeed12) && (m_i32ParaRespSpeed != CData::m_i16RespSpeed25))
	{
		m_i32ParaRespSpeed = CData::m_i16RespSpeed25;
	}

	if ((m_i32ParaRespGain != CData::m_i16RespGain1_4)
		&& (m_i32ParaRespGain != CData::m_i16RespGain1_2)
		&& (m_i32ParaRespGain != CData::m_i16RespGain1_1)
		&& (m_i32ParaRespGain != CData::m_i16RespGain2_1)
		&& (m_i32ParaRespGain != CData::m_i16RespGain4_1))
	{
		m_i32ParaRespGain = CData::m_i16RespGain1_1;
	}

	return 0;
}

//检查血氧设置参数 是否正确，如果错误，更改
INT CData::Check_Spo2_Set_Para()
{
	if ((m_i32ParaOxyALM_SW != CData::m_i32AlmSWOn) && (m_i32ParaOxyALM_SW != CData::m_i32AlmSWOff))
	{
		m_i32ParaOxyALM_SW = CData::m_i32AlmSWOn;
	}

	if ((m_i32ParaOxyALM_LEVEL != CData::m_i32AlmLevelH) && (m_i32ParaOxyALM_LEVEL != CData::m_i32AlmLevelM) && (m_i32ParaOxyALM_LEVEL != CData::m_i32AlmLevelL))
	{
		m_i32ParaOxyALM_LEVEL = CData::m_i32AlmLevelH;
	}

	if ((m_i32ParaOxyALM_REC != CData::m_i32AlmRecOn) && (m_i32ParaOxyALM_REC != CData::m_i32AlmRecOff))
	{
		m_i32ParaOxyALM_REC = CData::m_i32AlmRecOff;
	}


	if (m_i32ParaOxyOXY_ALM_H > m_i16Spo2AlmHMax)
	{
		m_i32ParaOxyOXY_ALM_H = m_i16Spo2AlmHMax;
	}
	else if (m_i32ParaOxyOXY_ALM_H<m_i16Spo2AlmHMin)
	{
		m_i32ParaOxyOXY_ALM_H = m_i16Spo2AlmHMin;
	}

	if (m_i32ParaOxyOXY_ALM_L>m_i16Spo2AlmLMax)
	{
		m_i32ParaOxyOXY_ALM_L = m_i16Spo2AlmLMax;
	}
	else if (m_i32ParaOxyOXY_ALM_L < m_i16Spo2AlmLMin)
	{
		m_i32ParaOxyOXY_ALM_L = m_i16Spo2AlmLMin;
	}
	if (m_i32ParaOxyOXY_ALM_H <= m_i32ParaOxyOXY_ALM_L)
	{
		m_i32ParaOxyOXY_ALM_H = m_i32ParaOxyOXY_ALM_L + 3;
	}

	if (m_i32ParaOxyOXY_PR_ALM_H > m_i16PRAlmHMax)
	{
		m_i32ParaOxyOXY_PR_ALM_H = m_i16PRAlmHMax;
	}
	else if (m_i32ParaOxyOXY_PR_ALM_H<m_i16PRAlmHMin)
	{
		m_i32ParaOxyOXY_PR_ALM_H = m_i16PRAlmHMin;
	}

	if (m_i32ParaOxyOXY_PR_ALM_L>m_i16PRAlmLMax)
	{
		m_i32ParaOxyOXY_PR_ALM_L = m_i16PRAlmLMax;
	}
	else if (m_i32ParaOxyOXY_PR_ALM_L < m_i16PRAlmLMin)
	{
		m_i32ParaOxyOXY_PR_ALM_L = m_i16PRAlmLMin;
	}
	if (m_i32ParaOxyOXY_PR_ALM_H <= m_i32ParaOxyOXY_PR_ALM_L)
	{
		m_i32ParaOxyOXY_PR_ALM_H = m_i32ParaOxyOXY_PR_ALM_L + 3;
	}

	if ((m_i32PlethSpeed != CData::m_i16PlethSpeed12) && (m_i32PlethSpeed != CData::m_i16PlethSpeed25))
	{
		m_i32PlethSpeed = CData::m_i16PlethSpeed25;
	}
	

	return 0;
}

//检查体温设置参数 是否正确，如果错误，更改
INT CData::Check_Temp_Set_Para()
{
	if ((m_i32ParaTempALM_SW != CData::m_i32AlmSWOn) && (m_i32ParaTempALM_SW != CData::m_i32AlmSWOff))
	{
		m_i32ParaTempALM_SW = CData::m_i32AlmSWOn;
	}

	if ((m_i32ParaTempALM_LEVEL != CData::m_i32AlmLevelH) && (m_i32ParaTempALM_LEVEL != CData::m_i32AlmLevelM) && (m_i32ParaTempALM_LEVEL != CData::m_i32AlmLevelL))
	{
		m_i32ParaTempALM_LEVEL = CData::m_i32AlmLevelH;
	}

	if ((m_i32ParaTempALM_REC != CData::m_i32AlmRecOn) && (m_i32ParaTempALM_REC != CData::m_i32AlmRecOff))
	{
		m_i32ParaTempALM_REC = CData::m_i32AlmRecOff;
	}


	if (m_i32ParaTempTEMP_ALM_H > m_i16TempAlmHMax)
	{
		m_i32ParaTempTEMP_ALM_H = m_i16TempAlmHMax;
	}
	else if (m_i32ParaTempTEMP_ALM_H<m_i16TempAlmHMin)
	{
		m_i32ParaTempTEMP_ALM_H = m_i16TempAlmHMin;
	}

	if (m_i32ParaTempTEMP_ALM_L>m_i16TempAlmLMax)
	{
		m_i32ParaTempTEMP_ALM_L = m_i16TempAlmLMax;
	}
	else if (m_i32ParaTempTEMP_ALM_L < m_i16TempAlmLMin)
	{
		m_i32ParaTempTEMP_ALM_L = m_i16TempAlmLMin;
	}
	if (m_i32ParaTempTEMP_ALM_H <= m_i32ParaTempTEMP_ALM_L)
	{
		m_i32ParaTempTEMP_ALM_H = m_i32ParaTempTEMP_ALM_L + 5;
	}
	return 0;
}

//检查血压设置参数 是否正确，如果错误，更改
INT CData::Check_NIBP_Set_Para()
{
	if ((m_i32ParaBPALM_SW != CData::m_i32AlmSWOn) && (m_i32ParaBPALM_SW != CData::m_i32AlmSWOff))
	{
		m_i32ParaBPALM_SW = CData::m_i32AlmSWOn;
	}

	if ((m_i32ParaBPALM_LEVEL != CData::m_i32AlmLevelH) && (m_i32ParaBPALM_LEVEL != CData::m_i32AlmLevelM) && (m_i32ParaBPALM_LEVEL != CData::m_i32AlmLevelL))
	{
		m_i32ParaBPALM_LEVEL = CData::m_i32AlmLevelH;
	}

	if ((m_i32ParaBPALM_REC != CData::m_i32AlmRecOn) && (m_i32ParaBPALM_REC != CData::m_i32AlmRecOff))
	{
		m_i32ParaBPALM_REC = CData::m_i32AlmRecOff;
	}


	if (m_i32ParaBPSBP_ALM_H > m_i16SBPAlmHMax)
	{
		m_i32ParaBPSBP_ALM_H = m_i16SBPAlmHMax;
	}
	else if (m_i32ParaBPSBP_ALM_H<m_i16SBPAlmHMin)
	{
		m_i32ParaBPSBP_ALM_H = m_i16SBPAlmHMin;
	}

	if (m_i32ParaBPSBP_ALM_L>m_i16SBPAlmLMax)
	{
		m_i32ParaBPSBP_ALM_L = m_i16SBPAlmLMax;
	}
	else if (m_i32ParaBPSBP_ALM_L < m_i16SBPAlmLMin)
	{
		m_i32ParaBPSBP_ALM_L = m_i16SBPAlmLMin;
	}

	if (m_i32ParaBPSBP_ALM_H <= m_i32ParaBPSBP_ALM_L)
	{
		m_i32ParaBPSBP_ALM_H = m_i32ParaBPSBP_ALM_L + 3;
	}
	

	if (m_i32ParaBPDBP_ALM_H > m_i16DBPAlmHMax)
	{
		m_i32ParaBPDBP_ALM_H = m_i16DBPAlmHMax;
	}
	else if (m_i32ParaBPDBP_ALM_H<m_i16DBPAlmHMin)
	{
		m_i32ParaBPDBP_ALM_H = m_i16DBPAlmHMin;
	}

	if (m_i32ParaBPDBP_ALM_L>m_i16DBPAlmLMax)
	{
		m_i32ParaBPDBP_ALM_L = m_i16DBPAlmLMax;
	}
	else if (m_i32ParaBPDBP_ALM_L < m_i16DBPAlmLMin)
	{
		m_i32ParaBPDBP_ALM_L = m_i16DBPAlmLMin;
	}

	if (m_i32ParaBPDBP_ALM_H <= m_i32ParaBPDBP_ALM_L)
	{
		m_i32ParaBPDBP_ALM_H = m_i32ParaBPDBP_ALM_L + 3;
	}
	if (m_i32ParaBPSBP_ALM_H <= m_i32ParaBPDBP_ALM_H)
	{
		m_i32ParaBPSBP_ALM_H = m_i32ParaBPDBP_ALM_H + 3;
	}
	if (m_i32ParaBPDBP_ALM_H >=m_i32ParaBPSBP_ALM_L)
	{
		m_i32ParaBPDBP_ALM_H = m_i32ParaBPSBP_ALM_L - 3;
	}

	return 0;
}

//检查空氧设置参数 是否正确，如果错误，更改
INT CData::Check_AirOxy_Set_Para()
{
	if ((m_i32ParaAirOxyALM_SW != CData::m_i32AlmSWOn) && (m_i32ParaAirOxyALM_SW != CData::m_i32AlmSWOff))
	{
		m_i32ParaAirOxyALM_SW = CData::m_i32AlmSWOn;
	}

	if ((m_i32ParaAirOxyALM_LEVEL != CData::m_i32AlmLevelH) && (m_i32ParaAirOxyALM_LEVEL != CData::m_i32AlmLevelM) && (m_i32ParaAirOxyALM_LEVEL != CData::m_i32AlmLevelL))
	{
		m_i32ParaAirOxyALM_LEVEL = CData::m_i32AlmLevelH;
	}

	if ((m_i32ParaAirOxyALM_REC != CData::m_i32AlmRecOn) && (m_i32ParaAirOxyALM_REC != CData::m_i32AlmRecOff))
	{
		m_i32ParaAirOxyALM_REC = CData::m_i32AlmRecOff;
	}


	if (m_i32ParaAirOxy_ALM_H > m_i16AirOxyAlmHMax)
	{
		m_i32ParaAirOxy_ALM_H = m_i16AirOxyAlmHMax;
	}
	else if (m_i32ParaAirOxy_ALM_H<m_i16AirOxyAlmHMin)
	{
		m_i32ParaAirOxy_ALM_H = m_i16AirOxyAlmHMin;
	}

	if (m_i32ParaAirOxy_ALM_L>m_i16AirOxyAlmLMax)
	{
		m_i32ParaAirOxy_ALM_L = m_i16AirOxyAlmLMax;
	}
	else if (m_i32ParaAirOxy_ALM_L < m_i16AirOxyAlmLMin)
	{
		m_i32ParaAirOxy_ALM_L = m_i16AirOxyAlmLMin;
	}
	return 0;
}

//检查系统设置参数 是否正确，如果错误，更改
INT CData::Check_Sys_Set_Para()
{
	if ((m_i32ParaAlmTime != CData::m_i32AlmTime1)
		&& (m_i32ParaAlmTime != CData::m_i32AlmTime2))
	{
		m_i32ParaAlmTime = CData::m_i32AlmTime1;
	}

	if ((m_i32ParaAlmVol != CData::m_i32AlmVol1_5)
		&& (m_i32ParaAlmVol != CData::m_i32AlmVol1_2)
		&& (m_i32ParaAlmVol != CData::m_i32AlmVol4_5)
		&& (m_i32ParaAlmVol != CData::m_i32AlmVol1_1))
	{
		m_i32ParaAlmVol = CData::m_i32BeatVol0;
	}
	switch (m_i32ParaAlmVol)
	{
		
	case 0:
		m_i32AlmVol = -1398;
		break;

	case 1:
		m_i32AlmVol = -602;
		break;

	case 2:
		m_i32AlmVol = -194;
		break;

	case 3:
		m_i32AlmVol = 0;
		break;
		
	}

	return 0;
}

void CData::Set_Pat(CPatient & pat)
{
	g_CSPat.Lock();
	m_CPat.set_pat(pat);
	g_CSPat.Unlock();
}


void CData::Get_Pat(CPatient & pat)
{
	g_CSPat.Lock();
	m_CPat.get_pat(pat);
	g_CSPat.Unlock();

}

INT CData::AddECGWave(UINT16 *data)
{
	int i = 0, t = 0;


	for (i = 0; i < 3; i++)
	{
		for (t = 0; t < 7; t++)
		{
			m_u16ECGData[t][m_i32ECGDateW] = data[7 * i + t];
		}
		m_i32ECGDateW = (m_i32ECGDateW + 1) % SHOW_BUFF_LENGTH;
	}
	g_CSECGData.Lock();
	if (m_i32ECGDateLength < SHOW_BUFF_LENGTH)
	{
		m_i32ECGDateLength += 3;
	}
	g_CSECGData.Unlock();
	return 0;
}


INT CData::GetECGWave(struct ECG_DATA *st)
{
	int i = 0, j = 0, t = 0;


	g_CSECGData.Lock();
	//获得每个通道要保存的数据长度
	j = m_i32ECGDateLength;
	if (j >= st->i32Length)
		j = st->i32Length;

	//复制数据
	for (t = 0; t < 7; t++)
	{
		for (i = 0; i < j; i++)
		{
			st->pECGData[t][i] = m_u16ECGData[t][(m_i32ECGDateR + i) % SHOW_BUFF_LENGTH];
		}
	}
	st->i32DataLength = j;
	//调节读和长度
	m_i32ECGDateLength -= j;

	st->i16HR = m_i16HR;
	st->i16ST1 = m_i16ST1;
	st->i16ST2 = m_i16ST2;
	st->m_u8LeadOff = m_i32LeadOff, st->m_u8LeadOverLoad = m_i32LeadOverLoad;
	st->m_i16PVCs = m_i16PVCs;


	g_CSECGData.Unlock();
	m_i32ECGDateR = (m_i32ECGDateR + j) % SHOW_BUFF_LENGTH;

	return 0;
}


INT CData::AddRespWave(UINT8 * data)
{
	int i = 0;

	for (i = 0; i < 3; i++)
	{
		m_u8RespData[m_i32RespDateW] = data[i];
		m_i32RespDateW = (m_i32RespDateW + 1) % SHOW_BUFF_LENGTH;
	}
	g_CSRespData.Lock();
	if (m_i32RespDateLength < SHOW_BUFF_LENGTH)
	{
		m_i32RespDateLength += 3;
	}
	g_CSRespData.Unlock();
	return 0;
}


INT CData::GetRespWave(struct RESP_DATA *st)
{
	int i = 0, j = 0, t = 0;

	g_CSRespData.Lock();
	j = m_i32RespDateLength;
	if (j >= st->i32Length)
		j = st->i32Length;

	//复制数据
	for (i = 0; i < j; i++)
	{
		st->pRespData[i] = m_u8RespData[(m_i32RespDateR + i) % SHOW_BUFF_LENGTH];
	}
	st->i32DataLength = j;

	//调节读和长度
	m_i32RespDateLength -= j;

	st->i16RR = m_i16RR;
	g_CSRespData.Unlock();
	m_i32RespDateR = (m_i32RespDateR + j) % SHOW_BUFF_LENGTH;

	return 0;
}



INT CData::AddOxyWave(UINT8 *data)
{
	int i = 0;

	for (i = 0; i < 3; i++)
	{
		m_u8PlethData[m_i32PlethDataW] = data[i];
		m_i32PlethDataW = (m_i32PlethDataW + 1) % SHOW_BUFF_LENGTH;
	}
	g_CSOxyData.Lock();
	if (m_i32PlethDateLength < SHOW_BUFF_LENGTH)
	{
		m_i32PlethDateLength += 3;
	}
	g_CSOxyData.Unlock();
	return 0;
}

INT CData::Add_OxyBar(UINT8 data)
{
	g_CSOxyData.Lock();
	u8Bar = data;
	g_CSOxyData.Unlock();
	return 0;
}

INT CData::Add_OxyAlm(UINT8 data)
{
	g_CSOxyData.Lock();
	if (data&0x80)
	{
		u16Finger = 1;
	} 
	else
	{
		u16Finger = 0;
	}
	if (data & 0x10)
	{
		u16Probe = 1;
	}
	else
	{
		u16Probe = 0;
	}
	g_CSOxyData.Unlock();
	return 0;
}


INT CData::GetOxyWave(struct OXY_DATA *st)
{
	int i = 0, j = 0, t = 0;

	g_CSOxyData.Lock();
	j = m_i32PlethDateLength;
	if (j >= st->i32Length)
		j = st->i32Length;

	//复制数据
	for (i = 0; i < j; i++)
	{
		st->pPlethData[i] = m_u8PlethData[(m_i32PlethDateR + i) % SHOW_BUFF_LENGTH];
	}
	st->i32DataLength = j;
	//调节读和长度
	m_i32PlethDateLength -= j;

	st->i16Spo2 = m_i16Spo2;
	st->i16PR = m_i16PR;
	st->u8Finger;
	st->u8Beat;
	st->u8Search;
	st->u8Probe;
	st->u8Bar = u8Bar;
	st->u8Signal;
	g_CSOxyData.Unlock();

	m_i32PlethDateR = (m_i32PlethDateR + j) % SHOW_BUFF_LENGTH;
	return 0;
}

INT CData::AddECGWaveSaveData(UINT16 *data)
{
	int i = 0, t = 0;


	for (i = 0; i < 3; i++)
	{
		for (t = 0; t < 7; t++)
		{
			m_u16ECGSaveData[t][m_i32ECGSaveDateW] = data[7 * i + t];
		}

		m_i32ECGSaveDateW = (m_i32ECGSaveDateW + 1) % SHOW_BUFF_LENGTH;


	}
	g_CSECGDataSave.Lock();
	if (m_i32ECGSaveDateLength < SHOW_BUFF_LENGTH)
	{
		m_i32ECGSaveDateLength += 3;
	}
	g_CSECGDataSave.Unlock();

	return 0;
}

INT CData::AddRespWaveSaveData(UINT8 *data)
{
	int i = 0;

	for (i = 0; i < 3; i++)
	{
		m_u8RespSaveData[m_i32RespSaveDateW] = data[i];
		m_i32RespSaveDateW = (m_i32RespSaveDateW + 1) % SHOW_BUFF_LENGTH;
	}
	g_CSRespData.Lock();
	if (m_i32RespSaveDateLength < SHOW_BUFF_LENGTH)
	{
		m_i32RespSaveDateLength += 3;
	}
	g_CSRespData.Unlock();
	return 0;
}


INT CData::AddPlethWaveSaveData(UINT8 *data)
{
	int i = 0;

	for (i = 0; i < 3; i++)
	{
		m_u8PlethSaveData[m_i32PlethSaveDataW] = data[i];
		m_i32PlethSaveDataW = (m_i32PlethSaveDataW + 1) % SHOW_BUFF_LENGTH;
	}
	g_CSOxyData.Lock();
	if (m_i32PlethSaveDateLength < SHOW_BUFF_LENGTH)
	{
		m_i32PlethSaveDateLength += 3;
	}
	g_CSOxyData.Unlock();
	return 0;
}

INT CData::SaveData()
{
	CPatient a_CPatient;
	int a_i32ECGSaveDateLength, i = 0, a_i32RespDateR, a_i32PlethDateR;

	g_CSECGDataSave.Lock();
	a_i32ECGSaveDateLength = m_i32ECGSaveDateLength;
	g_CSECGDataSave.Unlock();


	if (a_i32ECGSaveDateLength > 1000)
	{
		g_CSRespData.Lock();
		a_i32RespDateR = (m_i32RespDateW + SHOW_BUFF_LENGTH - 300) % SHOW_BUFF_LENGTH;
		g_CSRespData.Unlock();


		g_CSOxyData.Lock();
		a_i32PlethDateR = (m_i32PlethDataW + SHOW_BUFF_LENGTH - 300) % SHOW_BUFF_LENGTH;
		g_CSOxyData.Unlock();

		for (i = 0; i < 1000; i++)
		{
			m_stSaveData.pECGData[0][i] = m_u16ECGSaveData[ECG_I_LEAD][(m_i32ECGSaveDateR + i) % SHOW_BUFF_LENGTH];
			m_stSaveData.pECGData[1][i] = m_u16ECGSaveData[ECG_II_LEAD][(m_i32ECGSaveDateR + i) % SHOW_BUFF_LENGTH];
			m_stSaveData.pECGData[2][i] = m_u16ECGSaveData[ECG_V1_LEAD][(m_i32ECGSaveDateR + i) % SHOW_BUFF_LENGTH];
		}
		m_i32ECGSaveDateR = (m_i32ECGSaveDateR + 1000) % SHOW_BUFF_LENGTH;

		for (i = 0; i < 250; i++)
		{
			m_stSaveData.pRespData[i] = m_u8RespSaveData[(a_i32RespDateR + i) % SHOW_BUFF_LENGTH];
			m_stSaveData.pPlethData[i] = m_u8PlethSaveData[(a_i32PlethDateR + i) % SHOW_BUFF_LENGTH];
		}


		theApp.m_Data->Get_Pat(a_CPatient);

		m_stSaveData.stPara.i16HR = m_i16HR;
		m_stSaveData.stPara.i16ST1 = m_i16ST1;
		m_stSaveData.stPara.i16ST2 = m_i16ST2;
		m_stSaveData.stPara.i16PVCs = m_i16PVCs;
		m_stSaveData.stPara.i16RR = m_i16RR;
		m_stSaveData.stPara.i16Spo2 = m_i16Spo2;
		m_stSaveData.stPara.i16PR = m_i16PR;
		m_stSaveData.stPara.i16SBP = m_i16SBP;
		m_stSaveData.stPara.i16DBP = m_i16DBP;
		m_stSaveData.stPara.i16MBP = m_i16MBP;
		m_stSaveData.stPara.i16Temp = m_i16Temp;
		m_stSaveData.stPara.i8AirOxy = m_i8AirOxy;
		wcscpy_s(m_stSaveData.stPara.cName, 9, a_CPatient.m_cName);

		g_CSECGDataSave.Lock();
		m_i32ECGSaveDateLength -= 1000;
		g_CSECGDataSave.Unlock();
		((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Save_Data(&m_stSaveData);
	}

	return 0;
}


int CData::AddPrintData(struct GET_ECG_DATA *st)
{
	//int i = 0, a_i32PrintDateR, t = 0;
	//CString strTime;

	//g_CSECGDataPrint.Lock();
	//a_i32PrintDateR = m_i32PrintDateW;
	//g_CSECGDataPrint.Unlock();

	//a_i32PrintDateR = (a_i32PrintDateR + SHOW_BUFF_LENGTH - ECG_FILE_DATA_LENGTH) % SHOW_BUFF_LENGTH;
	////复制数据
	//for (t = 0; t < 7; t++)
	//{
	//	for (i = 0; i < ECG_FILE_DATA_LENGTH; i++)
	//	{
	//		st->pECGData[t][i] = m_i16PrintData[t][(a_i32PrintDateR + i) % SHOW_BUFF_LENGTH];
	//	}
	//}
	//st->i32DataLength = ECG_FILE_DATA_LENGTH;
	//
	//if (theApp.m_i32Connect == 0)
	//{
	//	wcscpy_s(st->cID, 32, theApp.m_ECGFileOutput->m_stInputECGData.cID);
	//	wcscpy_s(st->cName, 9, theApp.m_ECGFileOutput->m_stInputECGData.cName);
	//	wcscpy_s(st->cSex, 8, theApp.m_ECGFileOutput->m_stInputECGData.cSex);
	//	wcscpy_s(st->cAge, 8, theApp.m_ECGFileOutput->m_stInputECGData.cAge);
	//	wcscpy_s(st->cWeight, 8, theApp.m_ECGFileOutput->m_stInputECGData.cWeight);
	//	wcscpy_s(st->cHeight, 8, theApp.m_ECGFileOutput->m_stInputECGData.cHeight);
	//	wcscpy_s(st->cTime, 20, theApp.m_ECGFileOutput->m_stInputECGData.cTime);
	//}
	//else
	//{
	//	COleDateTime tm = COleDateTime::GetCurrentTime();
	//	strTime.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tm.GetYear(), tm.GetMonth(), tm.GetDay(), tm.GetHour(), tm.GetMinute(), tm.GetSecond());
	//	wcscpy_s(st->cID, 32, theApp.m_Patient->cID);
	//	wcscpy_s(st->cName, 9, theApp.m_Patient->cName);
	//	wcscpy_s(st->cSex, 8, theApp.m_Patient->cSex);
	//	wcscpy_s(st->cAge, 8, theApp.m_Patient->cAge);
	//	wcscpy_s(st->cWeight, 8, theApp.m_Patient->cWeight);
	//	wcscpy_s(st->cHeight, 8, theApp.m_Patient->cHeight);

	//	wcscpy_s(st->cTime, 20, strTime);
	//}

	return 0;
}




//心电导联连接和信号信息
int CData::Add_Lead_STS(UINT8 leadoff, UINT8 overload)
{
	g_CSECGData.Lock();
	m_i32LeadOff = leadoff;
	m_i32LeadOverLoad = overload;
	g_CSECGData.Unlock();

	return 0;
}


int CData::Get_Lead_STS(UINT8 *leadoff, UINT8 *overload)
{
	g_CSECGData.Lock();
	*leadoff = m_i32LeadOff;
	*overload = m_i32LeadOverLoad;
	g_CSECGData.Unlock();
	return 0;
}


//心律
int CData::Add_HR(INT16 hr)
{
	g_CSECGData.Lock();
	m_i16HR = hr;
	g_CSECGData.Unlock();
	return 0;
}


int CData::Get_HR(INT16 *hr)
{
	g_CSECGData.Lock();
	*hr = m_i16HR;
	g_CSECGData.Unlock();
	return 0;
}

//心律
int CData::Add_Beat(int b)
{
	g_CSECGData.Lock();
	m_i32Beat = b;
	g_CSECGData.Unlock();

	return 0;
}

int CData::Get_Beat(int *b)
{
	g_CSECGData.Lock();
	*b = m_i32Beat;
	m_i32Beat = 0;
	g_CSECGData.Unlock();
	return 0;
}

//PVCs
int CData::Add_PVCs(UINT8 pvcs)
{
	g_CSECGData.Lock();
	m_i16PVCs = pvcs;
	g_CSECGData.Unlock();
	return 0;
}
int CData::Get_PVCs(UINT8 *pvcs)
{
	g_CSECGData.Lock();
	*pvcs = m_i16PVCs;
	g_CSECGData.Unlock();
	return 0;
}

//ARRA
int CData::Add_ARRA(UINT8 arra)
{
	g_CSECGData.Lock();
	m_u8ARRA = arra;
	g_CSECGData.Unlock();
	return 0;
}
int CData::Get_ARRA(UINT8 *arra)
{
	g_CSECGData.Lock();
	*arra = m_u8ARRA;
	g_CSECGData.Unlock();
	return 0;
}

//ST值
int CData::Add_ST(INT16 st1, INT16 st2)
{
	g_CSECGData.Lock();
	m_i16ST1 = st1;
	m_i16ST2 = st2;
	g_CSECGData.Unlock();
	return 0;
}


int CData::Get_ST(INT16 *st1, INT16 *st2)
{
	g_CSECGData.Lock();
	*st1 = m_i16ST1;
	*st2 = m_i16ST2;
	g_CSECGData.Unlock();
	return 0;
}


//ST 模板波形
int CData::Add_Pattern(struct ECG_PATTERN *st)
{

	return 0;
}


//呼吸率
int  CData::Add_RR(INT16 rr)
{
	g_CSRespData.Lock();
	m_i16RR = rr;
	g_CSRespData.Unlock();

	return 0;
}


int CData::Add_APNEA(UINT8 apnea)
{
	g_CSRespData.Lock();
	m_u8APNEA = apnea;
	g_CSRespData.Unlock();

	return 0;
}
//血氧饱和度
int CData::Add_Spo2(INT16 spo2)
{
	g_CSOxyData.Lock();
	m_i16Spo2 = spo2;
	g_CSOxyData.Unlock();

	return 0;

}
//脉率
int CData::Add_PR(INT16 pr)

{
	g_CSOxyData.Lock();
	m_i16PR = pr;
	g_CSOxyData.Unlock();

	return 0;

}

int CData::Add_Temp(INT16 t)
{
	g_CSTempData.Lock();
	m_i16Temp = t;
	g_CSTempData.Unlock();

	return 0;
}


int CData::Add_TempAlm(INT16 t)
{
	g_CSTempData.Lock();
	m_u8TempProbe = t;
	g_CSTempData.Unlock();

	return 0;
}

int CData::Get_Temp(INT16 *t)
{
	g_CSTempData.Lock();
	*t = m_i16Temp;
	g_CSTempData.Unlock();

	return 0;

}


int CData::Add_AirOxy(INT8 t)
{
	g_CSAirOxyData.Lock();
	m_i8AirOxy = t;
	g_CSAirOxyData.Unlock();
	return 0;
}

int CData::Add_AirOxyAlm(INT16 t)
{
	g_CSAirOxyData.Lock();
	m_u8AirOxySTS = t;
	g_CSAirOxyData.Unlock();
	return 0;
}

int CData::Get_AirOxy(INT8 *t)
{
	g_CSAirOxyData.Lock();
	*t = m_i8AirOxy;
	g_CSAirOxyData.Unlock();

	return 0;
}


int CData::Get_AirOxyAlm(UINT8 *t)
{
	g_CSAirOxyData.Lock();
	*t = m_u8AirOxySTS;
	g_CSAirOxyData.Unlock();
	return 0;
}


void CData::copy_print_data(struct GET_ECG_DATA *st, int length)
{
	/*int i = 0,j=0;
	int	l = length;
	if (l > ECG_WAVE_BUFF_LENGTH)
	l = ECG_WAVE_BUFF_LENGTH;

	for (i = 0; i < 7;i++)
	{
	memcpy(m_i32PrintData[i], st->pECGData[i], l * 2);
	}

	m_i32PrintDateW = (m_i32PrintDateW + l) % ECG_WAVE_BUFF_LENGTH;
	m_i32PrintDateLength += l;
	if (m_i32PrintDateLength > ECG_WAVE_BUFF_LENGTH)
	{
	m_i32PrintDateLength = ECG_WAVE_BUFF_LENGTH;
	}*/

}

int CData::ResetShowBuff()
{
	/*g_CSECGData.Lock();
	m_i32ShowDateW = 0, m_i32ShowDateR = 0, m_i32ShowDateLength = 0;
	g_CSECGData.Unlock();*/
	return 0;
}

int CData::ResetSaveBuff()
{
	/*g_CSECGDataSave.Lock();
	m_i32SaveDateW = 0, m_i32SaveDateR = 0, m_i32SaveDateLength = 0;
	g_CSECGDataSave.Unlock();*/

	return 0;
}

int CData::ResetPrintBuff()
{

	g_CSECGDataPrint.Lock();
	m_i32PrintDateW = 0, m_i32PrintDateR = 0, m_i32PrintDateLength = 0;
	g_CSECGDataPrint.Unlock();

	return 0;
}



//将心电报警项，添加到报警队列中
int CData::Add_ECG_Alm(INT	u8Type, INT	u8SubType, TCHAR * cTime, INT16 i16AlmThrd, INT16	i16Result)
{
	struct SHOW_ALM alm;
	list<struct SHOW_ALM>::iterator i;
	INT a_i32Flag = 0;

	if (u8Type == ALM_TYPE_ECG)
	{
		//设置为触发状态
		m_u8ECGAlm[u8SubType] = 1;
	}
	else if (u8Type == ALM_TYPE_ST)
	{
		//设置为触发状态
		m_u8STAlm[u8SubType] = 1;
	}
	else if (u8Type == ALM_TYPE_ARRA)
	{
		//设置为触发状态
		m_u8ARRAAlm[u8SubType] = 1;
	}

	if (theApp.m_i32AlmLock)
	{
		//栓锁状态
		for (i = m_ECGAlm.begin(); (i != m_ECGAlm.end()); i++)
		{	
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				//如果报警队列中，同一类型的报警项为 未触发 状态
				a_i32Flag = 1;
				if (i->u8Trigger == 0)
				{
					//删除此报警项
					m_ECGAlm.erase(i);
					a_i32Flag = 0;
					break;
				}
				else
				{
					return 1;
				}
			}
		}
		if (a_i32Flag == 0)
		{
			//如果报警队列中，同一类型的报警项为 未触发 状态
			//删除此报警项
			//后添加新的报警项
			if (u8Type == ALM_TYPE_ECG)
			{
				//设置为触发状态
				m_u8ECGTrigger[u8SubType] = 1;
			}
			else if (u8Type == ALM_TYPE_ST)
			{
				//设置为触发状态
				m_u8STTrigger[u8SubType] = 1;
			}
			else if (u8Type == ALM_TYPE_ARRA)
			{
				//设置为触发状态
				m_u8ARRATrigger[u8SubType] = 1;
			}

			//报警类型 
			alm.u8Type = u8Type;
			//报警子类型
			alm.u8SubType = u8SubType;
			//报警为 触发
			alm.u8Trigger = 1;
			//不显示报警时间
			alm.u8ShowTime = 0;

			if (u8Type == ALM_TYPE_ECG)
			{
				wcscpy_s(alm.cAlm, 16, n_ECG_ALM_INFO[u8SubType]);
			}
			else if (u8Type == ALM_TYPE_ST)
			{
				wcscpy_s(alm.cAlm, 16, n_ST_ALM_INFO[u8SubType]);
			}
			else
			{
				wcscpy_s(alm.cAlm, 16, n_ARRA_ALM_INFO[u8SubType]);
			}
			wcscpy_s(alm.cAlm, 16, n_ECG_ALM_INFO[u8SubType]);
			//报警发生的时间
			wcscpy_s(alm.cTime, 20, cTime);
			//报警阈值
			alm.i16AlmThrd = i16AlmThrd;
			alm.i16Result = i16Result;
			//新报警项，添加到队列尾部
			m_ECGAlm.push_back(alm);
		}
	}
	else
	{
		//非栓锁状态
		for (i = m_ECGAlm.begin(); (i != m_ECGAlm.end()); i++)
		{
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				a_i32Flag = 1;
				return 1;
			}
		}

		if (a_i32Flag == 0)
		{
			if (u8Type == ALM_TYPE_ECG)
			{
				//设置为触发状态
				m_u8ECGTrigger[u8SubType] = 1;
			}
			else if (u8Type == ALM_TYPE_ST)
			{
				//设置为触发状态
				m_u8STTrigger[u8SubType] = 1;
			}
			else if (u8Type == ALM_TYPE_ARRA)
			{
				//设置为触发状态
				m_u8ARRATrigger[u8SubType] = 1;
			}
			//报警类型 
			alm.u8Type = u8Type;
			//报警子类型
			alm.u8SubType = u8SubType;
			//报警为 触发
			alm.u8Trigger = 1;
			//不显示报警时间
			alm.u8ShowTime = 0;
			if (u8Type == ALM_TYPE_ECG)
			{
				wcscpy_s(alm.cAlm, 16, n_ECG_ALM_INFO[u8SubType]);
			}
			else if (u8Type == ALM_TYPE_ST)
			{
				wcscpy_s(alm.cAlm, 16, n_ST_ALM_INFO[u8SubType]);
			}
			else
			{
				wcscpy_s(alm.cAlm, 16, n_ARRA_ALM_INFO[u8SubType]);
			}
			//报警发送的时间
			wcscpy_s(alm.cTime, 20, cTime);
			//报警阈值
			alm.i16AlmThrd = i16AlmThrd;
			alm.i16Result = i16Result;
			//新报警项，添加到队列尾部
			m_ECGAlm.push_back(alm);
		}
	}

	return 0;
}

int CData::Get_ECG_Alm(struct SHOW_ALM *alm, INT num)
{
	INT j = 0;
	list<struct SHOW_ALM>::iterator i;
//	struct SHOW_ALM *a_alm;

	if (m_ECGAlm.size())
	{
		for (i = m_ECGAlm.begin(); (i != m_ECGAlm.end()) && (j <= num); i++)
		{
			if (j == num)
			{
				memcpy(alm, (struct SHOW_ALM *)(&(*i)), sizeof(struct SHOW_ALM));
				return 0;
			}
			j++;
		}
	}

	return 1;
}

//获得下一个要显示的报警项数据
//如果报警队列为空，返回1
int CData::Get_ECG_Alm_Show_Next(struct SHOW_ALM *alm)
{
	struct SHOW_ALM a_stSHOW_ALM;
	CString a_cs;
	INT a_i32Return = 0;

	if (m_ECGAlm.size())
	{
		a_i32Return = 0;
		//获得报警内容
		m_i32ECGAlmShowIndex = (m_i32ECGAlmShowIndex + 1) % m_ECGAlm.size();
		Get_ECG_Alm(&a_stSHOW_ALM, m_i32ECGAlmShowIndex);

		if ((a_stSHOW_ALM.u8Type == ALM_TYPE_ECG)
			|| (a_stSHOW_ALM.u8Type == ALM_TYPE_ST)
			|| (a_stSHOW_ALM.u8Type == ALM_TYPE_ARRA))
		{
			if (a_stSHOW_ALM.u8Type == ALM_TYPE_ECG)
			{
				a_stSHOW_ALM.u8Level = m_i32ParaECGALM_LEVEL;
			}
			else if (a_stSHOW_ALM.u8Type == ALM_TYPE_ST)
			{
				a_stSHOW_ALM.u8Level = m_i32ParaECGST_ALM_LEVEL;
			}
			else
			{
				a_stSHOW_ALM.u8Level = m_i32ParaECGARRA_ALM_LEVEL;
			}

			if (Get_Alm_Type(&a_stSHOW_ALM))
			{
				//技术报警
			}
			else
			{
				//生物报警 需要添加星号
				a_cs = a_stSHOW_ALM.cAlm;
				if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelH)
				{
					a_cs += _T("***");
				}
				else if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelM)
				{
					a_cs += _T("**");
				}
				else if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelL)
				{
					a_cs += _T("*");
				}
				wcscpy_s(a_stSHOW_ALM.cAlm, 16, a_cs);
			}

			if (theApp.m_i32AlmLock)
			{
				//报警栓锁
				//判断报警是否触发
				if (a_stSHOW_ALM.u8Trigger)
				{
					//报警触发
					a_stSHOW_ALM.u8ShowTime = 0;
				}
				else
				{
					//报警没触发
					a_stSHOW_ALM.u8ShowTime = 1;
				}
			}
			else
			{
				//非栓锁 ，不显示报警时间
				a_stSHOW_ALM.u8ShowTime = 0;
			}
		}
		memcpy(alm, &a_stSHOW_ALM, sizeof(struct SHOW_ALM));
	}
	else
	{
		a_i32Return = 1;
	}


	return a_i32Return;
}

//按照删除报警的要求，删除 心电报警队列 所有报警或者删除未触发的报警
int CData::Del_ECG_Alm_ALL(INT alm_type, INT del_type)
{
	INT j = 0, t = 0;;
	list<struct SHOW_ALM>::iterator i;

	//删除报警队列中 所有的 报警项
	if (del_type == DEL_ALL)
	{
	ECG_LOOP_DEL_ALL:
		j = 0;
		t = m_ECGAlm.size();
		if (t)
		{
			for (i = m_ECGAlm.begin(); (i != m_ECGAlm.end()); i++)
			{
				if ((i->u8Type == alm_type))
				{
					if (i->u8Type == ALM_TYPE_ECG)
					{
						//设置为触发状态
						m_u8ECGTrigger[i->u8SubType] = 0;
						m_u8ECGAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_ST)
					{
						//设置为触发状态
						m_u8STTrigger[i->u8SubType] = 0;
						m_u8STAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_ARRA)
					{
						//设置为触发状态
						m_u8ARRATrigger[i->u8SubType] = 0;
						m_u8ARRAAlm[i->u8SubType] = 0;
					}
					m_ECGAlm.erase(i);

					if ((j + 1) == t)
					{
						break;
					}
					else
						goto ECG_LOOP_DEL_ALL;
				}
			}
		}
	}
	//删除报警队列中 所有的 未触发的报警项
	else if (del_type == DEL_NOT_TRIGGER)
	{
	ECG_LOOP_DEL_NOT_TRIGGER:
		j = 0;
		t = m_ECGAlm.size();
		if (t)
		{
			for (i = m_ECGAlm.begin(); (i != m_ECGAlm.end()); i++, j++)
			{
				if ((i->u8Type == alm_type) && (i->u8Trigger == 0))
				{
					if (i->u8Type == ALM_TYPE_ECG)
					{
						//设置为触发状态
						m_u8ECGTrigger[i->u8SubType] = 0;
						m_u8ECGAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_ST)
					{
						//设置为触发状态
						m_u8STTrigger[i->u8SubType] = 0;
						m_u8STAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_ARRA)
					{
						//设置为触发状态
						m_u8ARRATrigger[i->u8SubType] = 0;
						m_u8ARRAAlm[i->u8SubType] = 0;
					}
					m_ECGAlm.erase(i);
					if ((j + 1) == t)
					{
						break;
					}
					else
						goto ECG_LOOP_DEL_NOT_TRIGGER;
				}
			}
		}
	}

	return 0;
}

int CData::Del_ECG_Alm(INT num)
{
	list<struct SHOW_ALM>::iterator i;
	int j = 0;
	if (m_ECGAlm.size())
	{
		for (i = m_ECGAlm.begin(); (i != m_ECGAlm.end()) && (j <= num); i++)
		{
			if (j == num)
			{
				m_ECGAlm.erase(i);
				return 0;
			}
			j++;
		}

	}

	return 1;
}
//报警为未触发
int CData::Del_ECG_Alm(INT	u8Type, INT	u8SubType)
{
	list<struct SHOW_ALM>::iterator i;
	INT j = 0;


	if (theApp.m_i32AlmLock)
	{
		//如果为栓锁
		for (i = m_ECGAlm.begin(); (i != m_ECGAlm.end()); i++, j++)
		{
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				//更新为非触发
				i->u8Trigger = 0;
				if (i->u8Type == ALM_TYPE_ECG)
				{
					//设置为触发状态
					m_u8ECGTrigger[i->u8SubType] = 0;
					m_u8ECGAlm[i->u8SubType] = 0;
				}
				else if (i->u8Type == ALM_TYPE_ST)
				{
					//设置为触发状态
					m_u8STTrigger[i->u8SubType] = 0;
					m_u8STAlm[i->u8SubType] = 0;
				}
				else if (i->u8Type == ALM_TYPE_ARRA)
				{
					//设置为触发状态
					m_u8ARRATrigger[i->u8SubType] = 0;
					m_u8ARRAAlm[i->u8SubType] = 0;
				}
				break;
			}
		}
	}
	else
	{
		//非栓锁状态
		//从报警队列中,去除报警项
		if (m_ECGAlm.size())
		{
			for (i = m_ECGAlm.begin(); (i != m_ECGAlm.end()); i++, j++)
			{
				if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
				{
					if (i->u8Type == ALM_TYPE_ECG)
					{
						//设置为触发状态
						m_u8ECGTrigger[i->u8SubType] = 0;
						m_u8ECGAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_ST)
					{
						//设置为触发状态
						m_u8STTrigger[i->u8SubType] = 0;
						m_u8STAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_ARRA)
					{
						//设置为触发状态
						m_u8ARRATrigger[i->u8SubType] = 0;
						m_u8ARRAAlm[i->u8SubType] = 0;
					}
					m_ECGAlm.erase(i);
					break;
				}
			}
			//更新报警轮显示的读取 位置
			if (j <= m_i32ECGAlmShowIndex)
			{
				--m_i32ECGAlmShowIndex;
			}
		}
	}


	return 0;
}


//将呼吸、体温报警项，添加到报警队列中
int CData::Add_Resp_Temp_Alm(INT	u8Type, INT	u8SubType, TCHAR * cTime, INT16 i16AlmThrd, INT16	i16Result)
{
	struct SHOW_ALM alm;
	list<struct SHOW_ALM>::iterator i;
	INT a_i32Flag = 0;

	if (u8Type == ALM_TYPE_RESP)
	{
		//设置为触发状态
		m_u8RespAlm[u8SubType] = 1;
	}
	else if (u8Type == ALM_TYPE_TEMP)
	{
		//设置为触发状态
		m_u8TempAlm[u8SubType] = 1;
	}

	if (theApp.m_i32AlmLock)
	{
		//栓锁状态
		for (i = m_RespTempAlm.begin(); (i != m_RespTempAlm.end()); i++)
		{
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				//如果报警队列中，同一类型的报警项为 未触发 状态
				a_i32Flag = 1;
				if (i->u8Trigger == 0)
				{
					//删除此报警项
					m_RespTempAlm.erase(i);
					a_i32Flag = 0;
					break;
				}
				else
					return 1;
			}
		}
		if (a_i32Flag == 0)
		{
			//如果报警队列中，同一类型的报警项为 未触发 状态
			//删除此报警项
			//后添加新的报警项
			if (u8Type == ALM_TYPE_RESP)
			{
				//设置为触发状态
				m_u8RespTrigger[u8SubType] = 1;
			}
			else if (u8Type == ALM_TYPE_TEMP)
			{
				//设置为触发状态
				m_u8TempTrigger[u8SubType] = 1;
			}
			//报警类型 
			alm.u8Type = u8Type;
			//报警子类型
			alm.u8SubType = u8SubType;
			//报警为 触发
			alm.u8Trigger = 1;
			//不显示报警时间
			alm.u8ShowTime = 0;
			if (u8Type == ALM_TYPE_TEMP)
			{
				wcscpy_s(alm.cAlm, 16, n_TEMP_ALM_INFO[u8SubType]);
			}
			else
			{
				wcscpy_s(alm.cAlm, 16, n_RESP_ALM_INFO[u8SubType]);
			}
			//报警发送的时间
			wcscpy_s(alm.cTime, 20, cTime);
			//报警阈值
			alm.i16AlmThrd = i16AlmThrd;
			alm.i16Result = i16Result;

			//新报警项，添加到队列尾部
			m_RespTempAlm.push_back(alm);
		}
	}
	else
	{
		//非栓锁状态
		for (i = m_RespTempAlm.begin(); (i != m_RespTempAlm.end()); i++)
		{
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				a_i32Flag = 1;
				return 1;
			}
		}

		if (a_i32Flag == 0)
		{
			if (u8Type == ALM_TYPE_RESP)
			{
				//设置为触发状态
				m_u8RespTrigger[u8SubType] = 1;
			}
			else if (u8Type == ALM_TYPE_TEMP)
			{
				//设置为触发状态
				m_u8TempTrigger[u8SubType] = 1;
			}
			//报警类型 
			alm.u8Type = u8Type;
			//报警子类型
			alm.u8SubType = u8SubType;
			//报警为 触发
			alm.u8Trigger = 1;
			//不显示报警时间
			alm.u8ShowTime = 0;
			if (u8Type == ALM_TYPE_TEMP)
			{
				wcscpy_s(alm.cAlm, 16, n_TEMP_ALM_INFO[u8SubType]);
			}
			else
			{
				wcscpy_s(alm.cAlm, 16, n_RESP_ALM_INFO[u8SubType]);
			}
			//报警发送的时间
			wcscpy_s(alm.cTime, 20, cTime);
			//报警阈值
			alm.i16AlmThrd = i16AlmThrd;
			alm.i16Result = i16Result;
			//新报警项，添加到队列尾部
			m_RespTempAlm.push_back(alm);
		}
	}


	return 0;
}

int CData::Get_Resp_Temp_Alm(struct SHOW_ALM *alm, INT num)
{
	INT j = 0;
	list<struct SHOW_ALM>::iterator i;
//	struct SHOW_ALM *a_alm;

	if (m_RespTempAlm.size())
	{
		for (i = m_RespTempAlm.begin(); (i != m_RespTempAlm.end()) && (j <= num); i++)
		{
			if (j == num)
			{
				memcpy(alm, (struct SHOW_ALM *)(&(*i)), sizeof(struct SHOW_ALM));
				return 0;
			}
			j++;
		}
	}


	return 1;
}

//获得呼吸、体温下一个要显示的报警项数据
//如果报警队列为空，返回1
int CData::Get_Resp_Temp_Alm_Show_Next(struct SHOW_ALM *alm)
{
	struct SHOW_ALM a_stSHOW_ALM;
	CString a_cs;
	INT a_i32Return = 0;

	if (m_RespTempAlm.size())
	{
		a_i32Return = 0;
		//获得报警内容
		m_i32RespTempAlmShowIndex = (m_i32RespTempAlmShowIndex + 1) % m_RespTempAlm.size();
		Get_Resp_Temp_Alm(&a_stSHOW_ALM, m_i32RespTempAlmShowIndex);

		if ((a_stSHOW_ALM.u8Type == ALM_TYPE_RESP) || (a_stSHOW_ALM.u8Type == ALM_TYPE_TEMP))
		{
			if (a_stSHOW_ALM.u8Type == ALM_TYPE_TEMP)
			{
				a_stSHOW_ALM.u8Level = m_i32ParaTempALM_LEVEL;
			}
			else
			{
				a_stSHOW_ALM.u8Level = m_i32ParaRespALM_LEVEL;
			}

			if (Get_Alm_Type(&a_stSHOW_ALM))
			{
				//技术报警
			}
			else
			{
				//生物报警
				a_cs = a_stSHOW_ALM.cAlm;
				if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelH)
				{
					a_cs += _T("***");
				}
				else if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelM)
				{
					a_cs += _T("**");
				}
				else if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelL)
				{
					a_cs += _T("*");
				}
				wcscpy_s(a_stSHOW_ALM.cAlm, 16, a_cs);
			}

			if (theApp.m_i32AlmLock)
			{
				//报警栓锁
				//判断报警是否触发
				if (a_stSHOW_ALM.u8Trigger)
				{
					//报警触发
					a_stSHOW_ALM.u8ShowTime = 0;
				}
				else
				{
					//报警没触发
					a_stSHOW_ALM.u8ShowTime = 1;
				}
			}
			else
			{
				//非栓锁 ，不显示报警时间
				a_stSHOW_ALM.u8ShowTime = 0;
			}
		}
		memcpy(alm, &a_stSHOW_ALM, sizeof(struct SHOW_ALM));
	}
	else
	{
		a_i32Return = 1;
	}


	return a_i32Return;
}

//按照删除报警的要求，删除 呼吸、体温报警队列 所有报警或者删除未触发的报警
int CData::Del_Resp_Temp_Alm_ALL(INT alm_type, INT del_type)
{
	INT j = 0, t = 0;;
	list<struct SHOW_ALM>::iterator i;

	//删除报警队列中 所有的 报警项
	if (del_type == DEL_ALL)
	{
	RESP_TEMP_LOOP_DEL_ALL:
		j = 0;
		t = m_RespTempAlm.size();
		if (t)
		{
			for (i = m_RespTempAlm.begin(); (i != m_RespTempAlm.end()); i++)
			{
				if ((i->u8Type == alm_type))
				{
					if (i->u8Type == ALM_TYPE_RESP)
					{
						//设置为触发状态
						m_u8RespTrigger[i->u8SubType] = 0;
						m_u8RespAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_TEMP)
					{
						//设置为触发状态
						m_u8TempTrigger[i->u8SubType] = 0;
						m_u8TempAlm[i->u8SubType] = 0;
					}
					m_RespTempAlm.erase(i);
					if ((j + 1) == t)
					{
						break;
					}
					else
						goto RESP_TEMP_LOOP_DEL_ALL;
				}
			}
		}
	}
	//删除报警队列中 所有的 未触发的报警项
	else if (del_type == DEL_NOT_TRIGGER)
	{
	RESP_TEMP_LOOP_DEL_NOT_TRIGGER:
		j = 0;
		t = m_RespTempAlm.size();
		if (t)
		{
			for (i = m_RespTempAlm.begin(); (i != m_RespTempAlm.end()); i++, j++)
			{
				if ((i->u8Type == alm_type) && (i->u8Trigger == 0))
				{
					if (i->u8Type == ALM_TYPE_RESP)
					{
						//设置为触发状态
						m_u8RespTrigger[i->u8SubType] = 0;
						m_u8RespAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_TEMP)
					{
						//设置为触发状态
						m_u8TempTrigger[i->u8SubType] = 0;
						m_u8TempAlm[i->u8SubType] = 0;
					}
					m_RespTempAlm.erase(i);
					if ((j + 1) == t)
					{
						break;
					}
					else
						goto RESP_TEMP_LOOP_DEL_NOT_TRIGGER;
				}
			}
		}
	}

	return 0;
}

int CData::Del_Resp_Temp_Alm(INT num)
{
	list<struct SHOW_ALM>::iterator i;
	int j = 0;
	if (m_RespTempAlm.size())
	{
		for (i = m_RespTempAlm.begin(); (i != m_RespTempAlm.end()) && (j <= num); i++)
		{
			if (j == num)
			{
				m_RespTempAlm.erase(i);
				return 0;
			}
			j++;
		}

	}

	return 1;
}

int CData::Del_Resp_Temp_Alm(INT	u8Type, INT	u8SubType)
{
	list<struct SHOW_ALM>::iterator i;
	INT j = 0;


	if (theApp.m_i32AlmLock)
	{
		//如果为栓锁
		for (i = m_RespTempAlm.begin(); (i != m_RespTempAlm.end()); i++, j++)
		{
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				//更新为非触发
				i->u8Trigger = 0;
				if (i->u8Type == ALM_TYPE_RESP)
				{
					//设置为触发状态
					m_u8RespTrigger[i->u8SubType] = 0;
					m_u8RespAlm[i->u8SubType] = 0;
				}
				else if (i->u8Type == ALM_TYPE_TEMP)
				{
					//设置为触发状态
					m_u8TempTrigger[i->u8SubType] = 0;
					m_u8TempAlm[i->u8SubType] = 0;
				}
				break;
			}
		}
	}
	else
	{
		//非栓锁状态
		//从报警队列中,去除报警项
		if (m_RespTempAlm.size())
		{
			for (i = m_RespTempAlm.begin(); (i != m_RespTempAlm.end()); i++, j++)
			{
				if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
				{
					if (i->u8Type == ALM_TYPE_RESP)
					{
						//设置为触发状态
						m_u8RespTrigger[i->u8SubType] = 0;
						m_u8RespAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_TEMP)
					{
						//设置为触发状态
						m_u8TempTrigger[i->u8SubType] = 0;
						m_u8TempAlm[i->u8SubType] = 0;
					}
					m_RespTempAlm.erase(i);
					break;
				}
			}
			//更新报警轮显示的读取 位置
			if (j <= m_i32RespTempAlmShowIndex)
			{
				--m_i32RespTempAlmShowIndex;
			}
		}
	}

	return 0;
}


//将血氧、血压报警项，添加到报警队列中
int CData::Add_Oxy_NIBP_Alm(INT	u8Type, INT	u8SubType, TCHAR * cTime, INT16 i16AlmThrd, INT16	i16Result)
{
	struct SHOW_ALM alm;
	list<struct SHOW_ALM>::iterator i;
	INT a_i32Flag = 0;
	
	if (u8Type == ALM_TYPE_OXY)
	{
		//设置为触发状态
		m_u8OxyAlm[u8SubType] = 1;
	}
	else if (u8Type == ALM_TYPE_NIBP)
	{
		//设置为触发状态
		m_u8NIBPAlm[u8SubType] = 1;
	}

	if (theApp.m_i32AlmLock)
	{
		//栓锁状态
		for (i = m_OxyNIBPAlm.begin(); (i != m_OxyNIBPAlm.end()); i++)
		{
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				//如果报警队列中，同一类型的报警项为 未触发 状态
				a_i32Flag = 1;
				if (i->u8Trigger == 0)
				{
					//删除此报警项
					m_OxyNIBPAlm.erase(i);
					a_i32Flag = 0;
					break;
				}
				else
					return 1;
			}
		}
		if (a_i32Flag == 0)
		{
			//如果报警队列中，同一类型的报警项为 未触发 状态
			//删除此报警项
			//后添加新的报警项
			if (u8Type == ALM_TYPE_OXY)
			{
				//设置为触发状态
				m_u8OxyTrigger[u8SubType] = 1;
			}
			else if (u8Type == ALM_TYPE_NIBP)
			{
				//设置为触发状态
				m_u8NIBPTrigger[u8SubType] = 1;
			}
			//报警类型 
			alm.u8Type = u8Type;
			//报警子类型
			alm.u8SubType = u8SubType;
			//报警为 触发
			alm.u8Trigger = 1;
			//不显示报警时间
			alm.u8ShowTime = 0;
			if (u8Type == ALM_TYPE_OXY)
			{
				wcscpy_s(alm.cAlm, 16, n_OXY_ALM_INFO[u8SubType]);
			}
			else
			{
				wcscpy_s(alm.cAlm, 16, n_NIBP_ALM_INFO[u8SubType]);
			}
			//报警发送的时间
			wcscpy_s(alm.cTime, 20, cTime);
			//报警阈值
			alm.i16AlmThrd = i16AlmThrd;
			alm.i16Result = i16Result;
			//新报警项，添加到队列尾部
			m_OxyNIBPAlm.push_back(alm);
		}
	}
	else
	{
		//非栓锁状态
		for (i = m_OxyNIBPAlm.begin(); (i != m_OxyNIBPAlm.end()); i++)
		{
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				a_i32Flag = 1;
				return 1;
			}
		}

		if (a_i32Flag == 0)
		{
			if (u8Type == ALM_TYPE_OXY)
			{
				//设置为触发状态
				m_u8OxyTrigger[u8SubType] = 1;
			}
			else if (u8Type == ALM_TYPE_NIBP)
			{
				//设置为触发状态
				m_u8NIBPTrigger[u8SubType] = 1;
			}
			//报警类型 
			alm.u8Type = u8Type;
			//报警子类型
			alm.u8SubType = u8SubType;
			//报警为 触发
			alm.u8Trigger = 1;
			//不显示报警时间
			alm.u8ShowTime = 0;
			if (u8Type == ALM_TYPE_OXY)
			{
				wcscpy_s(alm.cAlm, 16, n_OXY_ALM_INFO[u8SubType]);
			}
			else
			{
				wcscpy_s(alm.cAlm, 16, n_NIBP_ALM_INFO[u8SubType]);
			}
			//报警发送的时间
			wcscpy_s(alm.cTime, 20, cTime);
			//报警阈值
			alm.i16AlmThrd = i16AlmThrd;
			alm.i16Result = i16Result;
			//新报警项，添加到队列尾部
			m_OxyNIBPAlm.push_back(alm);
		}
	}

	return 0;
}

int CData::Get_Oxy_NIBP_Alm(struct SHOW_ALM *alm, INT num)
{
	INT j = 0;
	list<struct SHOW_ALM>::iterator i;
//	struct SHOW_ALM *a_alm;

	if (m_OxyNIBPAlm.size())
	{
		for (i = m_OxyNIBPAlm.begin(); (i != m_OxyNIBPAlm.end()) && (j <= num); i++)
		{
			if (j == num)
			{
				memcpy(alm, (struct SHOW_ALM *)(&(*i)), sizeof(struct SHOW_ALM));
				return 0;
			}
			j++;
		}
	}


	return 1;
}

//获得血氧、血压下一个要显示的报警项数据
//如果报警队列为空，返回1
int CData::Get_Oxy_NIBP_Alm_Show_Next(struct SHOW_ALM *alm)
{
	struct SHOW_ALM a_stSHOW_ALM;
	CString a_cs;
	INT a_i32Return = 0;

	if (m_OxyNIBPAlm.size())
	{
		a_i32Return = 0;
		//获得报警内容
		m_i32OxyNIBPAlmShowIndex = (m_i32OxyNIBPAlmShowIndex + 1) % m_OxyNIBPAlm.size();
		Get_Oxy_NIBP_Alm(&a_stSHOW_ALM, m_i32OxyNIBPAlmShowIndex);

		if ((a_stSHOW_ALM.u8Type == ALM_TYPE_OXY) || (a_stSHOW_ALM.u8Type == ALM_TYPE_NIBP))
		{
			if (a_stSHOW_ALM.u8Type == ALM_TYPE_OXY)
			{
				a_stSHOW_ALM.u8Level = m_i32ParaOxyALM_LEVEL;
			}
			else
			{
				a_stSHOW_ALM.u8Level = m_i32ParaBPALM_LEVEL;
			}

			if (Get_Alm_Type(&a_stSHOW_ALM))
			{
				//技术报警
			}
			else
			{
				//生物报警
				a_cs = a_stSHOW_ALM.cAlm;
				if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelH)
				{
					a_cs += _T("***");
				}
				else if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelM)
				{
					a_cs += _T("**");
				}
				else if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelL)
				{
					a_cs += _T("*");
				}
				wcscpy_s(a_stSHOW_ALM.cAlm, 16, a_cs);
			}

			if (theApp.m_i32AlmLock)
			{
				//报警栓锁
				//判断报警是否触发
				if (a_stSHOW_ALM.u8Trigger)
				{
					//报警触发
					a_stSHOW_ALM.u8ShowTime = 0;
				}
				else
				{
					//报警没触发
					a_stSHOW_ALM.u8ShowTime = 1;
				}
			}
			else
			{
				//非栓锁 ，不显示报警时间
				a_stSHOW_ALM.u8ShowTime = 0;
			}
		}
		memcpy(alm, &a_stSHOW_ALM, sizeof(struct SHOW_ALM));
	}
	else
	{
		a_i32Return = 1;
	}


	return a_i32Return;
}

//按照删除报警的要求，删除 血氧、血压报警队列 所有报警或者删除未触发的报警
int CData::Del_Oxy_NIBP_Alm_ALL(INT alm_type, INT del_type)
{
	INT j = 0, t = 0;;
	list<struct SHOW_ALM>::iterator i;

	//删除报警队列中 所有的 报警项
	if (del_type == DEL_ALL)
	{
	OXY_NIBP_LOOP_DEL_ALL:
		j = 0;
		t = m_OxyNIBPAlm.size();
		if (t)
		{
			for (i = m_OxyNIBPAlm.begin(); (i != m_OxyNIBPAlm.end()); i++)
			{
				if ((i->u8Type == alm_type))
				{
					if (i->u8Type == ALM_TYPE_OXY)
					{
						//设置为触发状态
						m_u8OxyTrigger[i->u8SubType] = 0;
						m_u8OxyAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_NIBP)
					{
						//设置为触发状态
						m_u8NIBPTrigger[i->u8SubType] = 0;
						m_u8NIBPAlm[i->u8SubType] = 0;
					}
					m_OxyNIBPAlm.erase(i);
					if ((j + 1) == t)
					{
						break;
					}
					else
						goto OXY_NIBP_LOOP_DEL_ALL;
				}
			}
		}
	}
	//删除报警队列中 所有的 未触发的报警项
	else if (del_type == DEL_NOT_TRIGGER)
	{
	OXY_NIBP_LOOP_DEL_NOT_TRIGGER:
		j = 0;
		t = m_OxyNIBPAlm.size();
		if (t)
		{
			for (i = m_OxyNIBPAlm.begin(); (i != m_OxyNIBPAlm.end()); i++, j++)
			{
				if ((i->u8Type == alm_type) && (i->u8Trigger == 0))
				{
					if (i->u8Type == ALM_TYPE_OXY)
					{
						//设置为触发状态
						m_u8OxyTrigger[i->u8SubType] = 0;
						m_u8OxyAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_NIBP)
					{
						//设置为触发状态
						m_u8NIBPTrigger[i->u8SubType] = 0;
						m_u8NIBPAlm[i->u8SubType] = 0;
					}
					m_OxyNIBPAlm.erase(i);
					if ((j + 1) == t)
					{
						break;
					}
					else
						goto OXY_NIBP_LOOP_DEL_NOT_TRIGGER;
				}
			}
		}
	}

	return 0;
}

int CData::Del_Oxy_NIBP_Alm(INT num)
{
	list<struct SHOW_ALM>::iterator i;
	int j = 0;
	if (m_OxyNIBPAlm.size())
	{
		for (i = m_OxyNIBPAlm.begin(); (i != m_OxyNIBPAlm.end()) && (j <= num); i++)
		{
			if (j == num)
			{
				m_OxyNIBPAlm.erase(i);
				return 0;
			}
			j++;
		}

	}

	return 1;
}

int CData::Del_Oxy_NIBP_Alm(INT	u8Type, INT	u8SubType)
{
	list<struct SHOW_ALM>::iterator i;
	INT j = 0;


	if (theApp.m_i32AlmLock)
	{
		//如果为栓锁
		for (i = m_OxyNIBPAlm.begin(); (i != m_OxyNIBPAlm.end()); i++, j++)
		{
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				//更新为非触发
				i->u8Trigger = 0;
				if (i->u8Type == ALM_TYPE_OXY)
				{
					//设置为触发状态
					m_u8OxyTrigger[i->u8SubType] = 0;
					m_u8OxyAlm[i->u8SubType] = 0;
				}
				else if (i->u8Type == ALM_TYPE_NIBP)
				{
					//设置为触发状态
					m_u8NIBPTrigger[i->u8SubType] = 0;
					m_u8NIBPAlm[i->u8SubType] = 0;
				}
				break;
			}
		}
	}
	else
	{
		//非栓锁状态
		//从报警队列中,去除报警项
		if (m_OxyNIBPAlm.size())
		{
			for (i = m_OxyNIBPAlm.begin(); (i != m_OxyNIBPAlm.end()); i++, j++)
			{
				if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
				{
					if (i->u8Type == ALM_TYPE_OXY)
					{
						//设置为触发状态
						m_u8OxyTrigger[i->u8SubType] = 0;
						m_u8OxyAlm[i->u8SubType] = 0;
					}
					else if (i->u8Type == ALM_TYPE_NIBP)
					{
						//设置为触发状态
						m_u8NIBPTrigger[i->u8SubType] = 0;
						m_u8NIBPAlm[i->u8SubType] = 0;
					}
					m_OxyNIBPAlm.erase(i);
					break;
				}
			}
			//更新报警轮显示的读取 位置
			if (j <= m_i32OxyNIBPAlmShowIndex)
			{
				--m_i32OxyNIBPAlmShowIndex;
			}
		}
	}

	return 0;
}


//将氧浓度报警项，添加到报警队列中
int CData::Add_AirOxy_Alm(INT	u8Type, INT	u8SubType, TCHAR * cTime, INT16 i16AlmThrd, INT16	i16Result)
{
	struct SHOW_ALM alm;
	list<struct SHOW_ALM>::iterator i;
	INT a_i32Flag = 0;

	m_u8AirOxyAlm[u8SubType] = 1;
	if (theApp.m_i32AlmLock)
	{
		//栓锁状态
		for (i = m_AirOxyAlm.begin(); (i != m_AirOxyAlm.end()); i++)
		{
			//如果报警队列中，同一类型的报警项为 未触发 状态
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				a_i32Flag = 1;
				if (i->u8Trigger == 0)
				{
					//删除此报警项
					m_AirOxyAlm.erase(i);
					a_i32Flag = 0;
					break;
				}
				else
					return 1;
			}
		}
		if (a_i32Flag == 0)
		{
			//如果报警队列中，同一类型的报警项为 未触发 状态
			//删除此报警项
			//后添加新的报警项
			if (u8Type == ALM_TYPE_AIROXY)
			{
				//设置为触发状态
				m_u8AirOxyTrigger[u8SubType] = 1;
			}

			//报警类型 
			alm.u8Type = u8Type;
			//报警子类型
			alm.u8SubType = u8SubType;
			//报警为 触发
			alm.u8Trigger = 1;
			//不显示报警时间
			alm.u8ShowTime = 0;
			wcscpy_s(alm.cAlm, 16, n_AirOxy_ALM_INFO[u8SubType]);
			//报警发送的时间
			wcscpy_s(alm.cTime, 20, cTime);
			//报警阈值
			alm.i16AlmThrd = i16AlmThrd;
			alm.i16Result = i16Result;
			//新报警项，添加到队列尾部
			m_AirOxyAlm.push_back(alm);
		}
	}
	else
	{
		//非栓锁状态
		for (i = m_AirOxyAlm.begin(); (i != m_AirOxyAlm.end()); i++)
		{
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				a_i32Flag = 1;
				return 1;
			}

		}

		if (a_i32Flag == 0)
		{
			if (u8Type == ALM_TYPE_AIROXY)
			{
				//设置为触发状态
				m_u8AirOxyTrigger[u8SubType] = 1;
			}
			//报警类型 
			alm.u8Type = u8Type;
			//报警子类型
			alm.u8SubType = u8SubType;
			//报警为 触发
			alm.u8Trigger = 1;
			//不显示报警时间
			alm.u8ShowTime = 0;
			wcscpy_s(alm.cAlm, 16, n_AirOxy_ALM_INFO[u8SubType]);
			//报警发送的时间
			wcscpy_s(alm.cTime, 20, cTime);
			//报警阈值
			alm.i16AlmThrd = i16AlmThrd;
			alm.i16Result = i16Result;
			//新报警项，添加到队列尾部
			m_AirOxyAlm.push_back(alm);
		}
	}

	return 0;
}

int CData::Get_AirOxy_Alm(struct SHOW_ALM *alm, INT num)
{
	INT j = 0;
	list<struct SHOW_ALM>::iterator i;
//	struct SHOW_ALM *a_alm;

	if (m_AirOxyAlm.size())
	{
		for (i = m_AirOxyAlm.begin(); (i != m_AirOxyAlm.end()) && (j <= num); i++)
		{
			if (j == num)
			{
				memcpy(alm, (struct SHOW_ALM *)(&(*i)), sizeof(struct SHOW_ALM));
				return 0;
			}
			j++;
		}
	}


	return 1;
}

//获得氧浓度下一个要显示的报警项数据
//如果报警队列为空，返回1
int CData::Get_AirOxy_Alm_Show_Next(struct SHOW_ALM *alm)
{
	struct SHOW_ALM a_stSHOW_ALM;
	CString a_cs;
	INT a_i32Return = 0;

	if (m_AirOxyAlm.size())
	{
		a_i32Return = 0;
		//获得报警内容
		m_i32AirOxyAlmShowIndex = (m_i32AirOxyAlmShowIndex + 1) % m_AirOxyAlm.size();
		Get_AirOxy_Alm(&a_stSHOW_ALM, m_i32AirOxyAlmShowIndex);

		if ((a_stSHOW_ALM.u8Type == ALM_TYPE_AIROXY))
		{
			if (a_stSHOW_ALM.u8Type == ALM_TYPE_AIROXY)
			{
				a_stSHOW_ALM.u8Level = m_i32ParaAirOxyALM_LEVEL;
			}


			if (Get_Alm_Type(&a_stSHOW_ALM))
			{
				//技术报警
			}
			else
			{
				//生物报警
				a_cs = a_stSHOW_ALM.cAlm;
				if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelH)
				{
					a_cs += _T("***");
				}
				else if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelM)
				{
					a_cs += _T("**");
				}
				else if (a_stSHOW_ALM.u8Level == CData::m_i32AlmLevelL)
				{
					a_cs += _T("*");
				}
				wcscpy_s(a_stSHOW_ALM.cAlm, 16, a_cs);
			}

			if (theApp.m_i32AlmLock)
			{
				//报警栓锁
				//判断报警是否触发
				if (a_stSHOW_ALM.u8Trigger)
				{
					//报警触发
					a_stSHOW_ALM.u8ShowTime = 0;
				}
				else
				{
					//报警没触发
					a_stSHOW_ALM.u8ShowTime = 1;
				}
			}
			else
			{
				//非栓锁 ，不显示报警时间
				a_stSHOW_ALM.u8ShowTime = 0;
			}
		}
		memcpy(alm, &a_stSHOW_ALM, sizeof(struct SHOW_ALM));
	}
	else
	{
		a_i32Return = 1;
	}


	return a_i32Return;
}

//按照删除报警的要求，删除 氧浓度报警队列 所有报警或者删除未触发的报警
int CData::Del_AirOxy_Alm_ALL(INT alm_type, INT del_type)
{
	INT j = 0, t = 0;;
	list<struct SHOW_ALM>::iterator i;

	//删除报警队列中 所有的 报警项
	if (del_type == DEL_ALL)
	{
	AIR_OXY_LOOP_DEL_ALL:
		j = 0;
		t = m_AirOxyAlm.size();
		if (t)
		{
			for (i = m_AirOxyAlm.begin(); (i != m_AirOxyAlm.end()); i++)
			{
				if ((i->u8Type == alm_type))
				{
					if (i->u8Type == ALM_TYPE_AIROXY)
					{
						//设置为触发状态
						m_u8AirOxyTrigger[i->u8SubType] = 0;
						m_u8AirOxyAlm[i->u8SubType] = 0;
					}
					m_AirOxyAlm.erase(i);
					if ((j + 1) == t)
					{
						break;
					}
					else
						goto AIR_OXY_LOOP_DEL_ALL;
				}
			}

		}
	}
	//删除报警队列中 所有的 未触发的报警项
	else if (del_type == DEL_NOT_TRIGGER)
	{
	AIR_OXY_NIBP_LOOP_DEL_NOT_TRIGGER:
		j = 0;
		t = m_AirOxyAlm.size();
		if (t)
		{
			for (i = m_AirOxyAlm.begin(); (i != m_AirOxyAlm.end()); i++, j++)
			{
				if ((i->u8Type == alm_type) && (i->u8Trigger == 0))
				{
					if (i->u8Type == ALM_TYPE_AIROXY)
					{
						//设置为触发状态
						m_u8AirOxyTrigger[i->u8SubType] = 0;
						m_u8AirOxyAlm[i->u8SubType] = 0;
					}
					m_AirOxyAlm.erase(i);
					if ((j + 1) == t)
					{
						break;
					}
					else
						goto AIR_OXY_NIBP_LOOP_DEL_NOT_TRIGGER;
				}
			}
		}
	}

	return 0;

}

int CData::Del_AirOxy_Alm(INT num)
{
	list<struct SHOW_ALM>::iterator i;
	int j = 0;
	if (m_AirOxyAlm.size())
	{
		for (i = m_AirOxyAlm.begin(); (i != m_AirOxyAlm.end()) && (j <= num); i++)
		{
			if (j == num)
			{
				m_AirOxyAlm.erase(i);
				return 0;
			}
			j++;
		}

	}

	return 1;
}

int CData::Del_AirOxy_Alm(INT	u8Type, INT	u8SubType)
{
	list<struct SHOW_ALM>::iterator i;
	INT j = 0;


	if (theApp.m_i32AlmLock)
	{
		//如果为栓锁
		for (i = m_AirOxyAlm.begin(); (i != m_AirOxyAlm.end()); i++, j++)
		{
			if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
			{
				//更新为非触发
				i->u8Trigger = 0;
				if (i->u8Type == ALM_TYPE_AIROXY)
				{
					//设置为触发状态
					m_u8AirOxyTrigger[i->u8SubType] = 0;
					m_u8AirOxyAlm[i->u8SubType] = 0;
				}
				break;
			}
		}
	}
	else
	{
		//非栓锁状态
		//从报警队列中,去除报警项
		if (m_AirOxyAlm.size())
		{
			for (i = m_AirOxyAlm.begin(); (i != m_AirOxyAlm.end()); i++, j++)
			{
				if ((i->u8Type == u8Type) && (i->u8SubType == u8SubType))
				{
					if (i->u8Type == ALM_TYPE_AIROXY)
					{
						//设置为触发状态
						m_u8AirOxyTrigger[i->u8SubType] = 0;
						m_u8AirOxyAlm[i->u8SubType] = 0;
					}
					m_AirOxyAlm.erase(i);
					break;
				}
			}
			//更新报警轮显示的读取 位置
			if (j <= m_i32AirOxyAlmShowIndex)
			{
				--m_i32AirOxyAlmShowIndex;
			}
		}
	}


	return 0;
}



INT CData::Get_Alm_Type(struct SHOW_ALM *alm)
{
	if (alm->u8Type == ALM_TYPE_ECG)
	{
		if (alm->u8SubType == ALM_ECG_HR_L)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_HR_H)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_LL_LEAD_OFF)
		{
			return 1;
		}
		else if (alm->u8SubType == ALM_ECG_LA_LEAD_OFF)
		{
			return 1;
		}
		else if (alm->u8SubType == ALM_ECG_RA_LEAD_OFF)
		{
			return 1;
		}
		else if (alm->u8SubType == ALM_ECG_V_LEAD_OFF)
		{
			return 1;
		}
	}
	else if (alm->u8Type == ALM_TYPE_ST)
	{
		if (alm->u8SubType == ALM_ECG_ST1_L)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_ST1_H)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_ST2_L)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_ST2_H)
		{
			return 0;
		}
	}

	else if (alm->u8Type == ALM_TYPE_ARRA)
	{
		if (alm->u8SubType == ALM_ECG_BIGEMINY)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_TRIGEMINY)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_SLOW)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_FAST)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_RONT)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_RVONT)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_PAIR)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_ECG_ASYSTOLE)
		{
			return 0;
		}
	}
	else if (alm->u8Type == ALM_TYPE_RESP)
	{
		if (alm->u8SubType == ALM_RESP_RR_L)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_RESP_RR_H)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_RESP_APNEA)
		{
			return 0;
		}
	}
	else if (alm->u8Type == ALM_TYPE_OXY)
	{
		if (alm->u8SubType == ALM_OXY_OXY_L)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_OXY_OXY_H)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_OXY_PR_L)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_OXY_PR_H)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_OXY_FINGER)
		{
			return 1;
		}
		else if (alm->u8SubType == ALM_OXY_PROBE)
		{
			return 1;
		}
	}
	else if (alm->u8Type == ALM_TYPE_TEMP)
	{
		if (alm->u8SubType == ALM_TEMP_L)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_TEMP_H)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_TEMP_PROBE)
		{
			return 1;
		}
	}
	else if (alm->u8Type == ALM_TYPE_NIBP)
	{
		if (alm->u8SubType == ALM_NIBP_SBP_L)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_NIBP_SBP_H)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_NIBP_DBP_L)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_NIBP_DBP_H)
		{
			return 0;
		}
	}
	else if (alm->u8Type == ALM_TYPE_AIROXY)
	{
		if (alm->u8SubType == ALM_AIROXY_OXY_L)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_AIROXY_OXY_H)
		{
			return 0;
		}
		else if (alm->u8SubType == ALM_AIROXY_OXY_PROBE)
		{
			return 1;
		}
	}
	return 0;
}

//获得要保存的数据
INT CData::Get_Alm_Data(struct SAVE_ALM *st)
{
	INT i = 0, j = 0;
	INT a_i32ECGDateR, a_i32RespDateR, a_i32PlethDateR;
	INT16 a_i16HR;
	INT16 a_i16ST1, a_i16ST2, a_i32PVCs;
	INT16 a_i16RR;
	INT16 a_i16PR, a_i16Spo2;
	INT16 a_i16SBP, a_i16DBP;
	INT8 a_i8AirOxy;
	INT16 a_i16Temp;
	CPatient a_CPatient;

	g_CSECGDataSave.Lock();
	a_i32ECGDateR = m_i32ECGDateW;
	a_i16HR = m_i16HR;
	a_i16ST1 = m_i16ST1, a_i16ST2 = m_i16ST2, a_i32PVCs = m_i16ST2;
	g_CSECGDataSave.Unlock();

	g_CSECGDataSave.Lock();
	a_i32RespDateR = m_i32RespDateW;
	a_i16RR = m_i16RR;
	g_CSECGDataSave.Unlock();

	g_CSECGDataSave.Lock();
	a_i32PlethDateR = m_i32PlethDataW;
	a_i16PR = m_i16PR, a_i16Spo2 = m_i16Spo2;
	g_CSECGDataSave.Unlock();

	g_CSTempData.Lock();
	a_i16Temp = m_i16Temp;
	g_CSTempData.Unlock();

	g_CSNIBPData.Lock();
	a_i16SBP = m_i16SBP, a_i16DBP = m_i16DBP;
	g_CSNIBPData.Unlock();

	g_CSAirOxyData.Lock();
	a_i8AirOxy = m_i8AirOxy;
	g_CSAirOxyData.Unlock();

	for (i = 0, a_i32ECGDateR = (a_i32ECGDateR + SHOW_BUFF_LENGTH - 12 * 500 - 1) % SHOW_BUFF_LENGTH;
		i < 12 * 500;
		a_i32ECGDateR = (a_i32ECGDateR + 1) % SHOW_BUFF_LENGTH, i++)
	{
		st->pECGData[0][i] = m_u16ECGSaveData[0][a_i32ECGDateR];
		st->pECGData[1][i] = m_u16ECGSaveData[1][a_i32ECGDateR];
	}

	for (i = 0, a_i32RespDateR = (a_i32RespDateR + SHOW_BUFF_LENGTH - 12 * 125 - 1) % SHOW_BUFF_LENGTH;
		i < 12 * 125;
		a_i32RespDateR = (a_i32RespDateR + 1) % SHOW_BUFF_LENGTH, i++)
	{
		st->pRespData[i] = m_u8RespSaveData[a_i32RespDateR];
	}

	for (i = 0, a_i32PlethDateR = (a_i32PlethDateR + SHOW_BUFF_LENGTH - 12 * 125 - 1) % SHOW_BUFF_LENGTH;
		i < 12 * 125;
		a_i32PlethDateR = (a_i32PlethDateR + 1) % SHOW_BUFF_LENGTH, i++)
	{
		st->pPlethData[i] = m_u8PlethSaveData[a_i32PlethDateR];
	}

	CString cs1;
	COleDateTime tm = COleDateTime::GetCurrentTime();
	cs1.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tm.GetYear(), tm.GetMonth(), tm.GetDay(), tm.GetHour(), tm.GetMinute(), tm.GetSecond());

	theApp.m_Data->Get_Pat(a_CPatient);


	st->stPara.i16HR = a_i16HR;
	st->stPara.i16ST1 = a_i16ST1;
	st->stPara.i16ST2 = a_i16ST2;
	st->stPara.i16PVCs = a_i32PVCs;
	st->stPara.i16RR = a_i16RR;
	st->stPara.i16Spo2 = a_i16Spo2;
	st->stPara.i16PR = a_i16PR;
	st->stPara.i16SBP = a_i16SBP;
	st->stPara.i16DBP = a_i16DBP;
	st->stPara.i16MBP = 0;
	st->stPara.i16Temp = a_i16Temp;
	st->stPara.i8AirOxy = a_i8AirOxy;

	wcscpy_s(st->stPara.cTime, 20, cs1);
	wcscpy_s(st->stPara.cName, 9, a_CPatient.m_cName);

	return 0;
}

void CData::Get_Alm()
{
	COleDateTime tm = COleDateTime::GetCurrentTime();
	CString cs1;
	TCHAR a_cTime[20];
	cs1.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tm.GetYear(), tm.GetMonth(), tm.GetDay(), tm.GetHour(), tm.GetMinute(), tm.GetSecond());
	wcscpy_s(a_cTime, cs1.GetBuffer(cs1.GetLength()));

	//如果打开心电报警
	if (m_i32ParaECGALM_SW == CData::m_i32AlmSWOn)
	{
		//心律过高
		if (m_i16HR > m_i32ParaECGHR_ALM_H)
		{
			Add_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_HR_H, a_cTime, m_i32ParaECGHR_ALM_H, m_i16HR);
		}
		else
		{
			Del_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_HR_H);
		}

		//心律过低
		if (m_i16HR < m_i32ParaECGHR_ALM_L)
		{
			Add_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_HR_L, a_cTime, m_i32ParaECGHR_ALM_L, m_i16HR);
		}
		else
		{
			Del_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_HR_L);
		}

		//导联脱落报警
		if (m_i32LeadOff & 0x01)
		{
			Add_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_LL_LEAD_OFF, a_cTime, 0, 0);
		}
		else
		{
			Del_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_LL_LEAD_OFF);
		}

		if (m_i32LeadOff & 0x02)
		{
			Add_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_LA_LEAD_OFF, a_cTime, 0, 0);
		}
		else
		{
			Del_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_LA_LEAD_OFF);
		}

		if (m_i32LeadOff & 0x04)
		{
			Add_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_RA_LEAD_OFF, a_cTime, 0, 0);
		}
		else
		{
			Del_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_RA_LEAD_OFF);
		}

		if (m_i32LeadOff & 0x08)
		{
			Add_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_V_LEAD_OFF, a_cTime, 0, 0);
		}
		else
		{
			Del_ECG_Alm(ALM_TYPE_ECG, ALM_ECG_V_LEAD_OFF);
		}
	}

	if (m_i32ParaECGST_SW)
	{
		//如果打开ST报警
		if (m_i32ParaECGST_ALM_SW == CData::m_i32AlmSWOn)
		{

			//ST1过高
			if (m_i16ST1 > m_i32ParaECGST_ALM_H)
			{
				Add_ECG_Alm(ALM_TYPE_ST, ALM_ECG_ST1_H, a_cTime, m_i32ParaECGST_ALM_H, m_i16ST1);
			}
			else
			{
				Del_ECG_Alm(ALM_TYPE_ST, ALM_ECG_ST1_H);
			}

			//ST1过低
			if (m_i16ST1 < m_i32ParaECGST_ALM_L)
			{
				Add_ECG_Alm(ALM_TYPE_ST, ALM_ECG_ST1_L, a_cTime, m_i32ParaECGST_ALM_L, m_i16ST1);
			}
			else
			{
				Del_ECG_Alm(ALM_TYPE_ST, ALM_ECG_ST1_L);
			}

			//ST2过高
			if (m_i16ST2 > m_i32ParaECGST_ALM_H)
			{
				Add_ECG_Alm(ALM_TYPE_ST, ALM_ECG_ST2_H, a_cTime, m_i32ParaECGST_ALM_H, m_i16ST2);
			}
			else
			{
				Del_ECG_Alm(ALM_TYPE_ST, ALM_ECG_ST2_H);
			}

			//ST2过低
			if (m_i16ST2 < m_i32ParaECGST_ALM_L)
			{
				Add_ECG_Alm(ALM_TYPE_ST, ALM_ECG_ST2_L, a_cTime, m_i32ParaECGST_ALM_L, m_i16ST2);
			}
			else
			{
				Del_ECG_Alm(ALM_TYPE_ST, ALM_ECG_ST2_L);
			}
		}

	}
	if (m_i32ParaECGARRASW)
	{
		//如果打开心律异常分析报警
		if (m_i32ParaECGARRA_ALM_SW == CData::m_i32AlmSWOn)
		{
			if (m_u8ARRA)
			{
				Add_ECG_Alm(ALM_TYPE_ARRA, m_u8ARRA, a_cTime, 0, 0);
			}
			else
			{
				Del_ECG_Alm_ALL(ALM_TYPE_ARRA, DEL_ALL);
			}
		}
	}



	//如果打开呼吸报警
	if (m_i32ParaRespALM_SW == CData::m_i32AlmSWOn)
	{
		//呼吸率过高
		if (m_i16RR > m_i32ParaRespRR_ALM_H)
		{
			Add_Resp_Temp_Alm(ALM_TYPE_RESP, ALM_RESP_RR_H, a_cTime, m_i32ParaRespRR_ALM_H, m_i16RR);
		}
		else
		{
			Del_Resp_Temp_Alm(ALM_TYPE_RESP, ALM_RESP_RR_H);
		}

		//呼吸率过低
		if (m_i16RR < m_i32ParaRespRR_ALM_L)
		{
			Add_Resp_Temp_Alm(ALM_TYPE_RESP, ALM_RESP_RR_L, a_cTime, m_i32ParaRespRR_ALM_L, m_i16RR);
		}
		else
		{
			Del_Resp_Temp_Alm(ALM_TYPE_RESP, ALM_RESP_RR_L);
		}

		//窒息报警
		if (m_u8APNEA)
		{
			Add_Resp_Temp_Alm(ALM_TYPE_RESP, ALM_RESP_APNEA, a_cTime, 0, m_i16RR);
		}
		else
		{
			Del_Resp_Temp_Alm(ALM_TYPE_RESP, ALM_RESP_APNEA);
		}
	}



	//如果打开体温报警
	if (m_i32ParaTempALM_SW == CData::m_i32AlmSWOn)
	{
		//体温过高
		if (m_i16Temp > m_i32ParaTempTEMP_ALM_H)
		{
			Add_Resp_Temp_Alm(ALM_TYPE_TEMP, ALM_TEMP_H, a_cTime, m_i32ParaTempTEMP_ALM_H, m_i16Temp);
		}
		else
		{
			Del_Resp_Temp_Alm(ALM_TYPE_TEMP, ALM_TEMP_H);
		}

		//体温过低
		if (m_i16Temp < m_i32ParaTempTEMP_ALM_L)
		{
			Add_Resp_Temp_Alm(ALM_TYPE_TEMP, ALM_TEMP_L, a_cTime, m_i32ParaTempTEMP_ALM_L, m_i16Temp);
		}
		else
		{
			Del_Resp_Temp_Alm(ALM_TYPE_TEMP, ALM_TEMP_L);
		}

		//体温探头脱落
		if (m_u8TempProbe)
		{
			Add_Resp_Temp_Alm(ALM_TYPE_TEMP, ALM_TEMP_PROBE, a_cTime, 0, 0);
		}
		else
		{
			Del_Resp_Temp_Alm(ALM_TYPE_TEMP, ALM_TEMP_PROBE);
		}
	}



	//如果打开血氧报警
	if (m_i32ParaOxyALM_SW == CData::m_i32AlmSWOn)
	{
		//血氧饱和度过高
		if (m_i16Spo2 > m_i32ParaOxyOXY_ALM_H)
		{
			Add_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_OXY_H, a_cTime, m_i32ParaOxyOXY_ALM_H, m_i16Spo2);
		}
		else
		{
			Del_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_OXY_H);
		}

		//血氧饱和度过低
		if (m_i16Spo2 < m_i32ParaOxyOXY_ALM_L)
		{
			Add_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_OXY_L, a_cTime, m_i32ParaOxyOXY_ALM_L, m_i16Spo2);
		}
		else
		{
			Del_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_OXY_L);
		}

		//脉率过高
		if (m_i16PR > m_i32ParaOxyOXY_PR_ALM_H)
		{
			Add_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_PR_H, a_cTime, m_i32ParaOxyOXY_PR_ALM_H, m_i16PR);
		}
		else
		{
			Del_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_PR_H);
		}

		//脉率过低
		if (m_i16PR < m_i32ParaOxyOXY_PR_ALM_L)
		{
			Add_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_PR_L, a_cTime, m_i32ParaOxyOXY_PR_ALM_L, m_i16PR);
		}
		else
		{
			Del_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_PR_L);
		}

		//探头脱落报警
		if (u16Probe)
		{
			Add_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_PROBE, a_cTime, 0, 0);
		}
		else
		{
			Del_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_PROBE);
		}
		//手指脱落八戒
		if (u16Finger)
		{
			Add_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_FINGER, a_cTime, 0, 0);
		}
		else
		{
			Del_Oxy_NIBP_Alm(ALM_TYPE_OXY, ALM_OXY_FINGER);
		}
	}


	//如果打开血压报警
	if (m_i32ParaBPALM_SW == CData::m_i32AlmSWOn)
	{
		//收缩压过高
		if (m_i16SBP > m_i32ParaBPSBP_ALM_H)
		{
			Add_Oxy_NIBP_Alm(ALM_TYPE_NIBP, ALM_NIBP_SBP_H, a_cTime, m_i32ParaBPSBP_ALM_H, m_i16SBP);
		}
		else
		{
			Del_Oxy_NIBP_Alm(ALM_TYPE_NIBP, ALM_NIBP_SBP_H);
		}

		//收缩压过低
		if (m_i16SBP < m_i32ParaBPSBP_ALM_L)
		{
			Add_Oxy_NIBP_Alm(ALM_TYPE_NIBP, ALM_NIBP_SBP_L, a_cTime, m_i32ParaBPSBP_ALM_L, m_i16SBP);
		}
		else
		{
			Del_Oxy_NIBP_Alm(ALM_TYPE_NIBP, ALM_NIBP_SBP_L);
		}

		//舒张压过高
		if (m_i16DBP > m_i32ParaBPDBP_ALM_H)
		{
			Add_Oxy_NIBP_Alm(ALM_TYPE_NIBP, ALM_NIBP_DBP_H, a_cTime, m_i32ParaBPDBP_ALM_H, m_i16DBP);
		}
		else
		{
			Del_Oxy_NIBP_Alm(ALM_TYPE_NIBP, ALM_NIBP_DBP_H);
		}

		//舒张压过低
		if (m_i16DBP < m_i32ParaBPDBP_ALM_L)
		{
			Add_Oxy_NIBP_Alm(ALM_TYPE_NIBP, ALM_NIBP_DBP_L, a_cTime, m_i32ParaBPDBP_ALM_L, m_i16DBP);
		}
		else
		{
			Del_Oxy_NIBP_Alm(ALM_TYPE_NIBP, ALM_NIBP_DBP_L);
		}
	}


	//如果打开氧浓度报警
	if (m_i32ParaAirOxyALM_SW == CData::m_i32AlmSWOn)
	{
		//收缩压过高
		if (m_i8AirOxy > m_i32ParaAirOxy_ALM_H)
		{
			Add_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_H, a_cTime, m_i32ParaAirOxy_ALM_H, m_i8AirOxy);
		}
		else
		{
			Del_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_H);
		}

		//收缩压过低
		if (m_i8AirOxy < m_i32ParaAirOxy_ALM_L)
		{
			Add_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_L, a_cTime, m_i32ParaAirOxy_ALM_L, m_i8AirOxy);
		}
		else
		{
			Del_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_L);
		}

		if (m_u8AirOxySTS)
		{
			Add_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_PROBE, a_cTime, 0, 0);
		}
		else
		{
			Del_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_PROBE);
		}
	}



	//如果打开氧浓度报警
	if (m_i32ParaAirOxyALM_SW == CData::m_i32AlmSWOn)
	{
		//氧浓度过高
		if (m_i8AirOxy > m_i32ParaAirOxy_ALM_H)
		{
			Add_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_H, a_cTime, m_i32ParaAirOxy_ALM_H, m_i8AirOxy);
		}
		else
		{
			Del_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_H);
		}

		//氧浓度过低
		if (m_i8AirOxy < m_i32ParaAirOxy_ALM_L)
		{
			Add_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_L, a_cTime, m_i32ParaAirOxy_ALM_L, m_i8AirOxy);
		}
		else
		{
			Del_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_L);
		}

		//氧浓度探头脱落
		if (m_u8AirOxySTS)
		{
			Add_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_PROBE, a_cTime, 0, 0);
		}
		else
		{
			Del_AirOxy_Alm(ALM_TYPE_AIROXY, ALM_AIROXY_OXY_PROBE);
		}

	}
}


//判断是否有新报警发生
INT CData::Get_New_Alm_Trigger()
{
	INT i = 0, j = 0, a_i32Return = 0;

	for (i = 0; i < 16; i++)
	{
		if ((m_u8ECGTrigger[i] != 0)
			|| (m_u8STTrigger[i] != 0)
			|| (m_u8ARRATrigger[i] != 0)
			|| (m_u8RespTrigger[i] != 0)
			|| (m_u8OxyTrigger[i] != 0)
			|| (m_u8TempTrigger[i] != 0)
			|| (m_u8NIBPTrigger[i] != 0)
			|| (m_u8AirOxyTrigger[i] != 0))
		{
			a_i32Return = 1;
			break;
		}

	}
	//复位
	for (i = 0; i < 16; i++)
	{
		m_u8ECGTrigger[i] = 0;
		m_u8STTrigger[i] = 0;
		m_u8ARRATrigger[i] = 0;
		m_u8RespTrigger[i] = 0;
		m_u8OxyTrigger[i] = 0;
		m_u8TempTrigger[i] = 0;
		m_u8NIBPTrigger[i] = 0;
		m_u8AirOxyTrigger[i] = 0;
	}

	return a_i32Return;
}

INT CData::Get_ECG_ALL_Alm_Trigger()
{
	if (Get_ECG_Alm_Trigger())
		return 1;
	else if (Get_ST_Alm_Trigger())
		return 1;
	else if (Get_ARRA_Alm_Trigger())
		return 1;
	else
		return 0;

}

//获得心电 当前是否发生报警
INT CData::Get_ECG_Alm_Trigger()
{
	INT i = 0, a_i32Return = 0;

	for (i = 0; i < 16; i++)
	{
		if ((m_u8ECGAlm[i] != 0) )
		{
			a_i32Return = 1;
			break;
		}

	}
	return a_i32Return;
}

//获得ST 当前是否发生报警
INT CData::Get_ST_Alm_Trigger()
{
	INT i = 0, a_i32Return = 0;

	for (i = 0; i < 16; i++)
	{
		if ((m_u8STAlm[i] != 0))
		{
			a_i32Return = 1;
			break;
		}

	}
	return a_i32Return;
}

//获得ARRA 当前是否发生报警
INT CData::Get_ARRA_Alm_Trigger()
{
	INT i = 0, a_i32Return = 0;

	for (i = 0; i < 16; i++)
	{
		if ((m_u8ARRAAlm[i] != 0))
		{
			a_i32Return = 1;
			break;
		}

	}
	return a_i32Return;
}

INT CData::Get_Resp_Alm_Trigger()
{
	INT i = 0, a_i32Return = 0;

	for (i = 0; i < 16; i++)
	{
		if ((m_u8RespAlm[i] != 0))
		{
			a_i32Return = 1;
			break;
		}

	}
	return a_i32Return;
}



INT CData::Get_Oxy_Alm_Trigger()
{
	INT i = 0, a_i32Return = 0;

	for (i = 0; i < 16; i++)
	{
		if ((m_u8OxyAlm[i] != 0))
		{
			a_i32Return = 1;
			break;
		}

	}
	return a_i32Return;
}



INT CData::Get_Temp_Alm_Trigger()
{
	INT i = 0, a_i32Return = 0;

	for (i = 0; i < 16; i++)
	{
		if ((m_u8TempAlm[i] != 0))
		{
			a_i32Return = 1;
			break;
		}

	}
	return a_i32Return;
}



INT CData::Get_NIBP_Alm_Trigger()
{
	INT i = 0, a_i32Return = 0;

	for (i = 0; i < 16; i++)
	{
		if ((m_u8NIBPAlm[i] != 0))
		{
			a_i32Return = 1;
			break;
		}

	}
	return a_i32Return;
}



INT CData::Get_AirOxy_Alm_Trigger()
{
	INT i = 0, a_i32Return = 0;

	for (i = 0; i < 16; i++)
	{
		if ((m_u8AirOxyAlm[i] != 0))
		{
			a_i32Return = 1;
			break;
		}

	}
	return a_i32Return;
}

//获得当前所有报警的最高级别
INT CData::Get_All_Alm_LevelH()
{
	INT a_i32Level = 0;
	a_i32Level = 0;

	if (Get_ECG_Alm_Trigger())
	{
		if (m_i32ParaECGALM_LEVEL > a_i32Level)
			a_i32Level = m_i32ParaECGALM_LEVEL;
	}

	if (Get_ST_Alm_Trigger())
	{
		if (m_i32ParaECGST_ALM_LEVEL > a_i32Level)
			a_i32Level = m_i32ParaECGST_ALM_LEVEL;
	}

	if (Get_ARRA_Alm_Trigger())
	{
		if (m_i32ParaECGARRA_ALM_LEVEL > a_i32Level)
			a_i32Level = m_i32ParaECGARRA_ALM_LEVEL;
	}

	if (Get_Resp_Alm_Trigger())
	{
		if (m_i32ParaRespALM_LEVEL > a_i32Level)
			a_i32Level = m_i32ParaRespALM_LEVEL;
	}

	if (Get_Temp_Alm_Trigger())
	{
		if (m_i32ParaTempALM_LEVEL > a_i32Level)
			a_i32Level = m_i32ParaTempALM_LEVEL;
	}

	if (Get_Oxy_Alm_Trigger())
	{
		if (m_i32ParaOxyALM_LEVEL > a_i32Level)
			a_i32Level = m_i32ParaOxyALM_LEVEL;
	}
	if (Get_NIBP_Alm_Trigger())
	{
		if (m_i32ParaBPALM_LEVEL > a_i32Level)
			a_i32Level = m_i32ParaBPALM_LEVEL;
	}

	if (Get_AirOxy_Alm_Trigger())
	{
		if (m_i32ParaAirOxyALM_LEVEL > a_i32Level)
			a_i32Level = m_i32ParaAirOxyALM_LEVEL;	
	}
	return a_i32Level;
}

//保存报警记录、
INT CData::Save_Alm()
{
	//心律报警
	//如果打开报警记入
	if (m_i32ParaECGALM_REC == CData::m_i32AlmRecOn)
	{
		if (m_u8ECGTrigger[ALM_ECG_HR_L])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ECG;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_HR_L;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaECGHR_ALM_L;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16HR;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8ECGTrigger[ALM_ECG_HR_H])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ECG;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_HR_H;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaECGHR_ALM_H;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16HR;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
	}

	if (m_i32ParaECGST_ALM_REC == CData::m_i32AlmRecOn)
	{
		//ST报警
		if (m_u8STTrigger[ALM_ECG_ST1_L])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ST;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_ST1_L;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaECGST_ALM_L;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16ST1;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8STTrigger[ALM_ECG_ST1_H])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ST;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_ST1_H;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaECGST_ALM_H;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16ST1;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8STTrigger[ALM_ECG_ST2_L])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ST;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_ST2_L;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaECGST_ALM_L;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16ST2;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8STTrigger[ALM_ECG_ST2_H])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ST;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_ST2_H;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaECGST_ALM_H;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16ST2;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
	}


	if (m_i32ParaECGARRA_ALM_REC == CData::m_i32AlmRecOn)
	{
		if (m_u8ARRATrigger[ALM_ECG_BIGEMINY])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ARRA;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_BIGEMINY;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = 0;
			m_stSAVE_ALM.stInfo.i16Result = 0;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8ARRATrigger[ALM_ECG_TRIGEMINY])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ARRA;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_TRIGEMINY;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = 0;
			m_stSAVE_ALM.stInfo.i16Result = 0;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		//过缓
		if (m_u8ARRATrigger[ALM_ECG_SLOW])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ARRA;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_SLOW;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = 0;
			m_stSAVE_ALM.stInfo.i16Result = 0;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		//过速
		if (m_u8ARRATrigger[ALM_ECG_FAST])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ARRA;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_FAST;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = 0;
			m_stSAVE_ALM.stInfo.i16Result = 0;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		//室早
		if (m_u8ARRATrigger[ALM_ECG_RONT])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ARRA;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_RONT;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = 0;
			m_stSAVE_ALM.stInfo.i16Result = 0;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		//室速
		if (m_u8ARRATrigger[ALM_ECG_RVONT])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ARRA;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_RVONT;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = 0;
			m_stSAVE_ALM.stInfo.i16Result = 0;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		//室早成对
		if (m_u8ARRATrigger[ALM_ECG_PAIR])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ARRA;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_PAIR;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = 0;
			m_stSAVE_ALM.stInfo.i16Result = 0;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		//停搏
		if (m_u8ARRATrigger[ALM_ECG_ASYSTOLE])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_ARRA;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_ECG_ASYSTOLE;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = 0;
			m_stSAVE_ALM.stInfo.i16Result = 0;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
	}



	//如果打开报警记入
	if (m_i32ParaRespALM_REC == CData::m_i32AlmRecOn)
	{
		if (m_u8RespTrigger[ALM_RESP_RR_L])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_RESP;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_RESP_RR_L;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaRespRR_ALM_L;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16RR;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8RespTrigger[ALM_RESP_RR_H])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_RESP;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_RESP_RR_H;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaRespRR_ALM_H;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16RR;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8RespTrigger[ALM_RESP_APNEA])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_RESP;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_RESP_APNEA;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = 0;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16RR;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
	}



	//如果打开报警记入
	if (m_i32ParaOxyALM_REC == CData::m_i32AlmRecOn)
	{
		if (m_u8OxyTrigger[ALM_OXY_OXY_L])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_OXY;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_OXY_OXY_L;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaOxyOXY_ALM_L;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16Spo2;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8OxyTrigger[ALM_OXY_OXY_H])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_OXY;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_OXY_OXY_H;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaOxyOXY_ALM_H;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16Spo2;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8OxyTrigger[ALM_OXY_PR_L])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_OXY;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_OXY_PR_L;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaOxyOXY_PR_ALM_L;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16PR;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8OxyTrigger[ALM_OXY_PR_H])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_OXY;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_OXY_PR_H;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaOxyOXY_PR_ALM_H;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16PR;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
	}



	//如果打开报警记入
	if (m_i32ParaBPALM_REC == CData::m_i32AlmRecOn)
	{
		if (m_u8NIBPTrigger[ALM_NIBP_SBP_L])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_NIBP;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_NIBP_SBP_L;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaBPSBP_ALM_L;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16SBP;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8NIBPTrigger[ALM_NIBP_SBP_H])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_NIBP;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_NIBP_SBP_H;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaBPSBP_ALM_H;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16SBP;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8NIBPTrigger[ALM_NIBP_DBP_L])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_NIBP;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_NIBP_SBP_L;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaBPSBP_ALM_L;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16SBP;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8NIBPTrigger[ALM_NIBP_DBP_H])
		{

		}
	}

	//如果打开报警记入
	if (m_i32ParaTempALM_REC == CData::m_i32AlmRecOn)
	{
		if (m_u8TempTrigger[ALM_TEMP_L])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_TEMP;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_TEMP_L;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaTempTEMP_ALM_L;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16Temp;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8TempTrigger[ALM_TEMP_H])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_TEMP;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_TEMP_H;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaTempTEMP_ALM_H;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i16Temp;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
	}





	//如果打开报警记入
	if (m_i32ParaAirOxyALM_REC == CData::m_i32AlmRecOn)
	{
		if (m_u8AirOxyTrigger[ALM_AIROXY_OXY_L])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_AIROXY;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_AIROXY_OXY_L;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaAirOxy_ALM_L;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i8AirOxy;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
		if (m_u8AirOxyTrigger[ALM_AIROXY_OXY_H])
		{
			Get_Alm_Data(&m_stSAVE_ALM);
			wcscpy_s(m_stSAVE_ALM.stInfo.cTime, 20, m_stSAVE_ALM.stPara.cTime);
			m_stSAVE_ALM.stInfo.u8Flag = 0x00;
			m_stSAVE_ALM.stInfo.u8Type = ALM_TYPE_AIROXY;
			m_stSAVE_ALM.stInfo.u8SubType = ALM_AIROXY_OXY_H;
			m_stSAVE_ALM.stInfo.u16FileW = 0x00;
			m_stSAVE_ALM.stInfo.i16Threshold = m_i32ParaAirOxy_ALM_H;
			m_stSAVE_ALM.stInfo.i16Result = m_stSAVE_ALM.stPara.i8AirOxy;

			((CThreadDataAlmRec *)(theApp.m_pThrdDataSave))->Alm_Save(&m_stSAVE_ALM);
		}
	}


	return 0;
}