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

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


// CDialogPatInfo 对话框

IMPLEMENT_DYNAMIC(CDialogPatInfo, CDialogEx)

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

}

CDialogPatInfo::~CDialogPatInfo()
{
}

void CDialogPatInfo::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_PAT_INFO_NO, m_CEdit_No);
	DDX_Control(pDX, IDC_EDIT_PAT_INFO_NAME, m_CEditName);
	DDX_Control(pDX, IDC_EDIT__PAT_INFO_HEIGHT, m_CEditHeight);
	DDX_Control(pDX, IDC_EDIT__PAT_INFO_WEIGHT, m_CEditWeight);
	DDX_Control(pDX, IDC_COMBO_PAT_INFO_BLOOD_TYPE, m_CCombBloodType);
	DDX_Control(pDX, IDC_COMBO__PAT_INFO_TYPE, m_CCombType);
	DDX_Control(pDX, IDC_DATETIMEPICKER__PAT_INFO_BIRTH, m_CDateBirth);
	DDX_Control(pDX, IDC_DATETIMEPICKER_PAT_INFO_DATE, m_CDateIn);
	DDX_Control(pDX, IDC_BUTTON_PAT_INFO_UPDATE, m_CRadioMale);
}

BOOL CDialogPatInfo::OnInitDialog()
{
	int i = 0;
	CDialogEx::OnInitDialog();

	CPatient a_CPatient;

	theApp.m_Data->Get_Pat(a_CPatient);

	m_CPat.set_pat(a_CPatient);

	COleVariant vtime1(m_CPat.m_cBirth);
	COleVariant vtime2(m_CPat.m_cDateIn);

	//血型
	m_CCombBloodType.AddString(CString(_T("O")));
	m_CCombBloodType.AddString(CString(_T("A")));
	m_CCombBloodType.AddString(CString(_T("B")));
	m_CCombBloodType.AddString(CString(_T("AB")));
	
	m_CCombBloodType.SetCurSel(m_CPat.m_i32BloodType);

	m_CCombType.AddString(CString(_T("新生儿")));
	m_CCombType.SetCurSel(0);

	//出生日期
	m_CDateBirth.SetFormat(_T("yyyy-MM-dd"));
	m_CDateBirth.SetTime(vtime1);

	//入院日期
	m_CDateIn.SetFormat(_T("yyyy'- 'MM'- 'dd"));
	m_CDateIn.SetTime(vtime2);
	
	//性别单选
	if (m_CPat.m_i32Sex==0)
	{
		((CButton *)GetDlgItem(IDC_RADIO_PAT_INFO_MALE))->SetCheck(TRUE);
	}
	else
	{
		((CButton *)GetDlgItem(IDC_RADIO_PAT_INFO_FEMALE))->SetCheck(TRUE);
	}

	((CButton *)GetDlgItem(IDC_RADIO_PAT_INFO_UPDATE_NO))->SetCheck(TRUE);


	m_CEdit_No.SetWindowTextW(m_CPat.m_cID);
	m_CEditName.SetWindowTextW(m_CPat.m_cName);
	m_CEditHeight.SetWindowTextW(m_CPat.m_cHeight);
	m_CEditWeight.SetWindowTextW(m_CPat.m_cWeight);

	
	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}
BEGIN_MESSAGE_MAP(CDialogPatInfo, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_PAT_INFO_UPDATE, &CDialogPatInfo::OnBnClickedButtonPatInfoUpdate)
	ON_CBN_SELCHANGE(IDC_COMBO_PAT_INFO_BLOOD_TYPE, &CDialogPatInfo::OnCbnSelchangeComboPatInfoBloodType)
	ON_CBN_SELCHANGE(IDC_COMBO__PAT_INFO_TYPE, &CDialogPatInfo::OnCbnSelchangeCombo)
	ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER__PAT_INFO_BIRTH, &CDialogPatInfo::OnDtnDatetimechangeDatetimepicker)
	ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_PAT_INFO_DATE, &CDialogPatInfo::OnDtnDatetimechangeDatetimepickerPatInfoDate)
	ON_WM_DESTROY()
	ON_WM_CREATE()
	ON_BN_CLICKED(IDOK, &CDialogPatInfo::OnBnClickedOk)
END_MESSAGE_MAP()


// CDialogPatInfo 消息处理程序


void CDialogPatInfo::OnBnClickedButtonPatInfoUpdate()
{
	// TODO:  在此添加控件通知处理程序代码
	CString a_cs;
	INT i = 0;
	m_CEdit_No.GetWindowTextW(a_cs);
	a_cs = a_cs.Left(32);
	wcscpy_s(m_CPat.m_cID, 32, a_cs);
	
	//病人姓名 最多 8个字符
	m_CEditName.GetWindowTextW(a_cs);
	a_cs = a_cs.Left(8);
	wcscpy_s(m_CPat.m_cName, 9, a_cs);
	

	m_CEditHeight.GetWindowTextW(a_cs);
	a_cs = a_cs.Left(8);
	wcscpy_s(m_CPat.m_cHeight, 8, a_cs);


	m_CEditWeight.GetWindowTextW(a_cs);
	a_cs = a_cs.Left(8);
	wcscpy_s(m_CPat.m_cWeight, 8, a_cs);


	if (((CButton *)GetDlgItem(IDC_RADIO_PAT_INFO_MALE))->GetCheck())
	{
		m_CPat.m_i32Sex = 0;
	}
	else
	{
		m_CPat.m_i32Sex = 1;
	}

	if (((CButton *)GetDlgItem(IDC_RADIO_PAT_INFO_UPDATAE_YES))->GetCheck())
	{
		if (IDYES == MessageBox( _T("是否更新回顾数据"),_T("确认更新"), MB_YESNO))
		{
			//更新回顾数据
		}
	}
	CTime timeTime;

	m_CDateBirth.GetTime(timeTime);
	a_cs.Format(_T("%d-%02d-%02d"), timeTime.GetYear(), timeTime.GetMonth(), timeTime.GetDay());
	wcscpy_s(m_CPat.m_cBirth, 32, a_cs);

	m_CDateIn.GetTime(timeTime);
	a_cs.Format(_T("%d-%02d-%02d"), timeTime.GetYear(), timeTime.GetMonth(), timeTime.GetDay());
	wcscpy_s(m_CPat.m_cDateIn, 32, a_cs);



	theApp.m_Data->Set_Pat(m_CPat);

	//theApp.m_Data->m_CPat.set_pat(m_CPat);
}


void CDialogPatInfo::OnCbnSelchangeComboPatInfoBloodType()
{
	// TODO:  在此添加控件通知处理程序代码
	m_CPat.m_i32BloodType = m_CCombBloodType.GetCurSel();
}


void CDialogPatInfo::OnCbnSelchangeCombo()
{
	// TODO:  在此添加控件通知处理程序代码
	m_CPat.m_i32Type = m_CCombType.GetCurSel();
}


void CDialogPatInfo::OnDtnDatetimechangeDatetimepicker(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
	// TODO:  在此添加控件通知处理程序代码
	*pResult = 0;
}


void CDialogPatInfo::OnDtnDatetimechangeDatetimepickerPatInfoDate(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
	// TODO:  在此添加控件通知处理程序代码
	*pResult = 0;
}


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

	// TODO:  在此处添加消息处理程序代码
}


int CDialogPatInfo::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialogEx::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此添加您专用的创建代码

	return 0;
}


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