// DtDialog.cpp : implementation file
//

#include "stdafx.h"
#include "DtDialog.h"
#include "datataker.h"

//#include "afxdialogex.h"


extern DataTakerApp theApp;

// DtDialog dialog

IMPLEMENT_DYNAMIC(DtDialog, CDialog)

DtDialog::DtDialog(CWnd* pParent /*=NULL*/)
	: CDialog(DtDialog::IDD, pParent)
{
  
}

DtDialog::~DtDialog()
{

  //theApp.DataTakerExit( TRUE);
}

void DtDialog::SetDefaults( void)
{
  
  DTdiag_Init.SetWindowTextA( theApp.GetStartString().GetBuffer());
}

void DtDialog::UpdateContent( DT_SLAVE *Device)
{

  CString strTmp;

  //naam van de pers
  DTdiag_Pers.SetWindowTextA( Device->name);

  //datum tijd stempel van blok
  DTdiag_DatumTijd.SetWindowTextA( (LPCTSTR) Device->date_time);

  //anode teller
  strTmp.Format( "%d", Device->anode);
  DTdiag_Anode.SetWindowTextA( strTmp.GetBuffer());

  //hoogte van het blok
  strTmp.Format( "%d", Device->height);
  DTdiag_Hoogte.SetWindowTextA( strTmp.GetBuffer());

  //gewicht van het blok
  strTmp.Format( "%d", Device->weight);
  DTdiag_Gewicht.SetWindowTextA( strTmp.GetBuffer());

  //temperatuur van het blok
  strTmp.Format( "%d", Device->temperature);
  DTdiag_Temperatuur.SetWindowTextA( strTmp.GetBuffer());
}



void DtDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_PERS, DTdiag_Pers);
	DDX_Control(pDX, IDC_ANODE, DTdiag_Anode);
	DDX_Control(pDX, IDC_DATUM, DTdiag_DatumTijd);
	DDX_Control(pDX, IDC_HOOGTE, DTdiag_Hoogte);
	DDX_Control(pDX, IDC_INIT, DTdiag_Init);
	DDX_Control(pDX, IDC_GEWICHT, DTdiag_Gewicht);
	DDX_Control(pDX, IDC_TEMPERATUUR, DTdiag_Temperatuur);
}


BEGIN_MESSAGE_MAP(DtDialog, CDialog)
  ON_BN_CLICKED(IDC_BUTTON1, &DtDialog::OnBnClickedButton1)
  ON_EN_CHANGE(IDC_INIT, &DtDialog::OnEnChangeInit)
END_MESSAGE_MAP()


// DtDialog message handlers


void DtDialog::OnBnClickedButton1()
{
  // TODO: Add your control notification handler code here
  theApp.InitDevices();
}


void DtDialog::OnEnChangeInit()
{
  // TODO:  If this is a RICHEDIT control, the control will not
  // send this notification unless you override the CDialog::OnInitDialog()
  // function and call CRichEditCtrl().SetEventMask()
  // with the ENM_CHANGE flag ORed into the mask.
	char tmp[1024];
	tmp[0] = '\0';
	DTdiag_Init.GetWindowTextA( tmp, 1024);
	CString strTmp = tmp;
	theApp.SetStartString( strTmp);

//#1015

  // TODO:  Add your control notification handler code here
}



BOOL DtDialog::OnInitDialog()
{
  CDialog::OnInitDialog();

  // TODO:  Add extra initialization here
  HICON hIcon;
  hIcon = (HICON) LoadImage( ::GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON2), IMAGE_ICON,32,32,LR_DEFAULTSIZE); 

  SendMessage( WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
  SendMessage( WM_SETICON, ICON_BIG, (LPARAM)hIcon);


  return TRUE;  // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}


void DtDialog::OnCancel()
{
  // TODO: Add your specialized code here and/or call the base class
  CDialog::DestroyWindow();
  exit(0);
  //theApp.DataTakerExit( TRUE);
  //CDialog::OnCancel();
}


void DtDialog::OnOK()
{
  // TODO: Add your specialized code here and/or call the base class
  theApp.DataTakerExit( TRUE);
  CDialog::OnOK();
}


BOOL DtDialog::DestroyWindow()
{
  // TODO: Add your specialized code here and/or call the base class
  return CDialog::DestroyWindow();
}

