// wiz4Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "wiz4.h"
#include "wiz4Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWiz4Dlg dialog

CWiz4Dlg::CWiz4Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWiz4Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWiz4Dlg)
	m_nValoare = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWiz4Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWiz4Dlg)
	DDX_Control(pDX, IDC_CALENDAR, m_Calendar);
	DDX_Control(pDX, IDC_TIMP, m_Timp);
	DDX_Control(pDX, IDC_DATA, m_Data);
	DDX_Control(pDX, IDC_SLIDER_VALOARE, m_slValoare);
	DDX_Control(pDX, IDC_PROGRESS_VALOARE, m_prValoare);
	DDX_Text(pDX, IDC_VALOARE, m_nValoare);
	DDV_MinMaxInt(pDX, m_nValoare, 0, 50);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CWiz4Dlg, CDialog)
	//{{AFX_MSG_MAP(CWiz4Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_CHANGE(IDC_VALOARE, OnChangeValoare)
	ON_WM_HSCROLL()
	ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATA, OnDatetimechangeData)
	ON_NOTIFY(DTN_DATETIMECHANGE, IDC_TIMP, OnDatetimechangeData)
	ON_NOTIFY(MCN_SELCHANGE, IDC_CALENDAR, OnSelchangeCalendar)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWiz4Dlg message handlers

BOOL CWiz4Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	CEdit* pValoare=(CEdit*)GetDlgItem(IDC_VALOARE);
	CSpinButtonCtrl* pSpin=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_VALOARE);
	pSpin->SetBuddy(pValoare);
    pSpin->SetRange(0,50);
	pSpin->SetPos(25);
	m_prValoare.SetRange(0,50);
	m_prValoare.SetStep(1);
	m_prValoare.SetPos(25);
	m_slValoare.SetRange(0,50);
	m_slValoare.SetTicFreq(1);
	m_slValoare.SetPos(25);
	m_Calendar.SetColor(MCSC_TITLEBK, RGB(0,255,0));
    m_Calendar.SetMaxSelCount(14);
    m_Calendar.SetSelRange(COleDateTime (2003,1,1,0,0,0), COleDateTime (2003,12,31,23,59,59));

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CWiz4Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CWiz4Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CWiz4Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CWiz4Dlg::OnChangeValoare() 
{
	// 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.
	
	// TODO: Add your control notification handler code here
	COleDateTime dtData;
	UpdateData();
	m_prValoare.SetPos(m_nValoare);
	m_slValoare.SetPos(m_nValoare);
	m_Timp.GetTime(dtData);
	dtData.SetTime(dtData.GetHour(),dtData.GetMinute(),m_nValoare);
	m_Timp.SetTime(dtData);
}

void CWiz4Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	m_nValoare=m_slValoare.GetPos();;
	m_prValoare.SetPos(m_nValoare);
	UpdateData(FALSE);
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CWiz4Dlg::OnOK() 
{
	// TODO: Add extra validation here
	COleDateTime dtDataCurenta;
	CString strDataCurenta, strTemp;

	m_Data.GetTime(dtDataCurenta);
	strTemp.Format("%d ",dtDataCurenta.GetDay());

	switch (dtDataCurenta.GetDayOfWeek()) {
	   case 1: strDataCurenta += "Duminica, "; break;
		 case 2: strDataCurenta += "Luni, "; break;
		 case 3: strDataCurenta += "Marti, "; break;
		 case 4: strDataCurenta += "Miercuri, "; break;
		 case 5: strDataCurenta += "Joi, "; break;
		 case 6: strDataCurenta += "Vineri, "; break;
		 case 7: strDataCurenta += "Sambata, "; break;
	 }
	
	 strDataCurenta += strTemp;

	switch (dtDataCurenta.GetMonth()) {
		case 1: strTemp = "Ianuarie, "; break;
		case 2: strTemp = "Februarie, "; break;
		case 3: strTemp = "Martie, "; break;
		case 4: strTemp = "Aprilie, "; break;
		case 5: strTemp = "Mai, "; break;
		case 6: strTemp = "Iunie, "; break;
		case 7: strTemp = "Iulie, "; break;
		case 8: strTemp = "August, "; break;
		case 9: strTemp = "Septembrie, "; break;
		case 10: strTemp = "Octombrie, "; break;
		case 11: strTemp = "Noiembrie, "; break;
		case 12: strTemp = "Decembrie, "; break;
	}

	strDataCurenta += strTemp;
	strTemp.Format("%d",dtDataCurenta.GetYear());
//	strDataCurenta += strTemp;
//	MessageBox(strDataCurenta,"Data de azi",MB_ICONEXCLAMATION);

    COleDateTime dtMin, dtMax;	
    m_Calendar.GetSelRange(dtMin, dtMax);
    COleDateTimeSpan dtSpan = dtMax-dtMin;
    strDataCurenta += dtSpan.Format("\n Ati selectat %D zile,");
	AfxMessageBox(strDataCurenta);

	CDialog::OnOK();
}

void CWiz4Dlg::OnDatetimechangeData(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	COleDateTime dtSelectata;

    switch(pNMHDR->idFrom) 
	{
			case IDC_DATA:
			m_Data.GetTime(dtSelectata);
			m_Calendar.SetToday(dtSelectata);
			SetWindowText(" Data: "+dtSelectata.Format("%#x"));
			break;
		case IDC_TIMP:
			m_Timp.GetTime(dtSelectata);
			SetWindowText(" Timp: "+ dtSelectata.Format("%H:%M:%S"));
			break;
	}

	*pResult = 0;
}

void CWiz4Dlg::OnSelchangeCalendar(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	COleDateTime dtMin, dtMax;	
    m_Calendar.GetSelRange(dtMin, dtMax);
	m_Data.SetTime(dtMin);
	COleDateTimeSpan dtSpan = dtMax-dtMin;
	SetWindowText(dtSpan.Format(" Ati selectat %D zile,")); 
	*pResult = 0;
}
