// TimeSheet1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "TimeSheet1.h"
#include "TimeSheet1Dlg.h"
#include ".\timesheet1dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CTimeSheet1Dlg dialog
CTimeSheet1Dlg::CTimeSheet1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTimeSheet1Dlg::IDD, pParent)
, m_EmployeeName(_T(""))
, m_Monday(_T("0.00"))
, m_Tuesday(_T("0.00"))
, m_Wednesday(_T("0.00"))
, m_Thursday(_T("0.00"))
, m_Friday(_T("0.00"))
, m_Saturday(_T("0.00"))
, m_Sunday(_T("0.00"))
, m_TotalHours(_T("0.00"))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTimeSheet1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EMPLNAME, m_EmployeeName);
DDX_Control(pDX, IDC_MONDAYIN, m_MondayIn);
DDX_Control(pDX, IDC_MONDAYOUT, m_MondayOut);
DDX_Text(pDX, IDC_MONDAY, m_Monday);
DDX_Control(pDX, IDC_TUESDAYIN, m_TuesdayIn);
DDX_Control(pDX, IDC_TUESDAYOUT, m_TuesdayOut);
DDX_Text(pDX, IDC_TUESDAY, m_Tuesday);
DDX_Control(pDX, IDC_WEDNESDAYIN, m_WednesdayIn);
DDX_Control(pDX, IDC_WEDNESDAYOUT, m_WednesdayOut);
DDX_Text(pDX, IDC_WEDNESDAY, m_Wednesday);
DDX_Control(pDX, IDC_THURSDAYIN, m_ThursdayIn);
DDX_Control(pDX, IDC_THURSDAYOUT, m_ThursdayOut);
DDX_Text(pDX, IDC_THURSDAY, m_Thursday);
DDX_Control(pDX, IDC_FRIDAYIN, m_FridayIn);
DDX_Control(pDX, IDC_FRIDAYOUT, m_FridayOut);
DDX_Text(pDX, IDC_FRIDAY, m_Friday);
DDX_Control(pDX, IDC_SATURDAYIN, m_SaturdayIn);
DDX_Control(pDX, IDC_SATURDAYOUT, m_SaturdayOut);
DDX_Text(pDX, IDC_SATURDAY, m_Saturday);
DDX_Control(pDX, IDC_SUNDAYIN, m_SundayIn);
DDX_Control(pDX, IDC_SUNDAYOUT, m_SundayOut);
DDX_Text(pDX, IDC_SUNDAY, m_Sunday);
DDX_Text(pDX, IDC_TOTALHOURS, m_TotalHours);
}
BEGIN_MESSAGE_MAP(CTimeSheet1Dlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_MONDAYIN, OnDtnDatetimechangeMondayin)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_MONDAYOUT, OnDtnDatetimechangeMondayout)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_TUESDAYIN, OnDtnDatetimechangeTuesdayin)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_TUESDAYOUT, OnDtnDatetimechangeTuesdayout)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_WEDNESDAYIN, OnDtnDatetimechangeWednesdayin)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_WEDNESDAYOUT, OnDtnDatetimechangeWednesdayout)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_THURSDAYIN, OnDtnDatetimechangeThursdayin)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_THURSDAYOUT, OnDtnDatetimechangeThursdayout)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_FRIDAYIN, OnDtnDatetimechangeFridayin)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_FRIDAYOUT, OnDtnDatetimechangeFridayout)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_SATURDAYIN, OnDtnDatetimechangeSaturdayin)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_SATURDAYOUT, OnDtnDatetimechangeSaturdayout)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_SUNDAYIN, OnDtnDatetimechangeSundayin)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_SUNDAYOUT, OnDtnDatetimechangeSundayout)
END_MESSAGE_MAP()
// CTimeSheet1Dlg message handlers
BOOL CTimeSheet1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CTime TimeToSet = CTime::GetCurrentTime();
this->m_MondayIn.SetTime(&TimeToSet);
this->m_MondayOut.SetTime(&TimeToSet);
this->m_TuesdayIn.SetTime(&TimeToSet);
this->m_TuesdayOut.SetTime(&TimeToSet);
this->m_WednesdayIn.SetTime(&TimeToSet);
this->m_WednesdayOut.SetTime(&TimeToSet);
this->m_ThursdayIn.SetTime(&TimeToSet);
this->m_ThursdayOut.SetTime(&TimeToSet);
this->m_FridayIn.SetTime(&TimeToSet);
this->m_FridayOut.SetTime(&TimeToSet);
this->m_SaturdayIn.SetTime(&TimeToSet);
this->m_SaturdayOut.SetTime(&TimeToSet);
this->m_SundayIn.SetTime(&TimeToSet);
this->m_SundayOut.SetTime(&TimeToSet);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CTimeSheet1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTimeSheet1Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
// This function gathers the time value of each day and calculates the total time for the week
void CTimeSheet1Dlg::CalculateWeeklyHours(void)
{
double monday, tuesday, wednesday, thursday,
friday, saturday, sunday, totalHours;
monday = atof(this->m_Monday);
tuesday = atof(this->m_Tuesday);
wednesday = atof(this->m_Wednesday);
thursday = atof(this->m_Thursday);
friday = atof(this->m_Friday);
saturday = atof(this->m_Saturday);
sunday = atof(this->m_Sunday);
totalHours = monday + tuesday + wednesday + thursday +
friday + saturday + sunday;
this->m_TotalHours.Format("%.2f", totalHours);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeMondayin(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
UpdateData();
CTime timeIn, timeOut;
this->m_MondayIn.GetTime(timeIn);
this->m_MondayOut.GetTime(timeOut);
// Make sure the time in doesn't occur AFTER the time out
if( timeIn > timeOut )
this->m_MondayIn.SetTime(&timeOut);
// Calculate the time difference between both ends of the shift
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
// Calculate the number of minutes in the elapsed time
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
// Calculate the number of hours in the elapsed time
nbrHours = minutes / 60;
// Convert the time difference to a decimal value
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
// Format the number to display appropriately
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
// Display the result in the corresponding text mox
this->m_Monday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeMondayout(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
CTime timeIn, timeOut;
this->m_MondayIn.GetTime(timeIn);
this->m_MondayOut.GetTime(timeOut);
if( timeOut < timeIn )
this->m_MondayOut.SetTime(&timeIn);
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
nbrHours = minutes / 60;
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
this->m_Monday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeTuesdayin(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
UpdateData();
CTime timeIn, timeOut;
this->m_TuesdayIn.GetTime(timeIn);
this->m_TuesdayOut.GetTime(timeOut);
// Make sure the time in doesn't occur AFTER the time out
if( timeIn > timeOut )
this->m_TuesdayIn.SetTime(&timeOut);
// Calculate the time difference between both ends of the shift
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
// Calculate the number of minutes in the elapsed time
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
// Calculate the number of hours in the elapsed time
nbrHours = minutes / 60;
// Convert the time difference to a decimal value
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
// Format the number to display appropriately
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
// Display the result in the corresponding text mox
this->m_Tuesday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeTuesdayout(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
CTime timeIn, timeOut;
this->m_TuesdayIn.GetTime(timeIn);
this->m_TuesdayOut.GetTime(timeOut);
if( timeOut < timeIn )
this->m_TuesdayOut.SetTime(&timeIn);
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
nbrHours = minutes / 60;
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
this->m_Tuesday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeWednesdayin(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
UpdateData();
CTime timeIn, timeOut;
this->m_WednesdayIn.GetTime(timeIn);
this->m_WednesdayOut.GetTime(timeOut);
// Make sure the time in doesn't occur AFTER the time out
if( timeIn > timeOut )
this->m_WednesdayIn.SetTime(&timeOut);
// Calculate the time difference between both ends of the shift
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
// Calculate the number of minutes in the elapsed time
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
// Calculate the number of hours in the elapsed time
nbrHours = minutes / 60;
// Convert the time difference to a decimal value
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
// Format the number to display appropriately
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
// Display the result in the corresponding text mox
this->m_Wednesday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeWednesdayout(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
CTime timeIn, timeOut;
this->m_WednesdayIn.GetTime(timeIn);
this->m_WednesdayOut.GetTime(timeOut);
if( timeOut < timeIn )
this->m_WednesdayOut.SetTime(&timeIn);
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
nbrHours = minutes / 60;
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
this->m_Wednesday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeThursdayin(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
UpdateData();
CTime timeIn, timeOut;
this->m_ThursdayIn.GetTime(timeIn);
this->m_ThursdayOut.GetTime(timeOut);
// Make sure the time in doesn't occur AFTER the time out
if( timeIn > timeOut )
this->m_ThursdayIn.SetTime(&timeOut);
// Calculate the time difference between both ends of the shift
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
// Calculate the number of minutes in the elapsed time
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
// Calculate the number of hours in the elapsed time
nbrHours = minutes / 60;
// Convert the time difference to a decimal value
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
// Format the number to display appropriately
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
// Display the result in the corresponding text mox
this->m_Thursday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeThursdayout(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
CTime timeIn, timeOut;
this->m_ThursdayIn.GetTime(timeIn);
this->m_ThursdayOut.GetTime(timeOut);
if( timeOut < timeIn )
this->m_ThursdayOut.SetTime(&timeIn);
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
nbrHours = minutes / 60;
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
this->m_Thursday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeFridayin(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
UpdateData();
CTime timeIn, timeOut;
this->m_FridayIn.GetTime(timeIn);
this->m_FridayOut.GetTime(timeOut);
// Make sure the time in doesn't occur AFTER the time out
if( timeIn > timeOut )
this->m_FridayIn.SetTime(&timeOut);
// Calculate the time difference between both ends of the shift
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
// Calculate the number of minutes in the elapsed time
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
// Calculate the number of hours in the elapsed time
nbrHours = minutes / 60;
// Convert the time difference to a decimal value
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
// Format the number to display appropriately
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
// Display the result in the corresponding text mox
this->m_Friday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeFridayout(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
CTime timeIn, timeOut;
this->m_FridayIn.GetTime(timeIn);
this->m_FridayOut.GetTime(timeOut);
if( timeOut < timeIn )
this->m_FridayOut.SetTime(&timeIn);
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
nbrHours = minutes / 60;
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
this->m_Friday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeSaturdayin(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
UpdateData();
CTime timeIn, timeOut;
this->m_SaturdayIn.GetTime(timeIn);
this->m_SaturdayOut.GetTime(timeOut);
// Make sure the time in doesn't occur AFTER the time out
if( timeIn > timeOut )
this->m_SaturdayIn.SetTime(&timeOut);
// Calculate the time difference between both ends of the shift
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
// Calculate the number of minutes in the elapsed time
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
// Calculate the number of hours in the elapsed time
nbrHours = minutes / 60;
// Convert the time difference to a decimal value
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
// Format the number to display appropriately
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
// Display the result in the corresponding text mox
this->m_Saturday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeSaturdayout(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
CTime timeIn, timeOut;
this->m_MondayIn.GetTime(timeIn);
this->m_MondayOut.GetTime(timeOut);
if( timeOut < timeIn )
this->m_MondayOut.SetTime(&timeIn);
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
nbrHours = minutes / 60;
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
this->m_Saturday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeSundayin(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
UpdateData();
CTime timeIn, timeOut;
this->m_SundayIn.GetTime(timeIn);
this->m_SundayOut.GetTime(timeOut);
// Make sure the time in doesn't occur AFTER the time out
if( timeIn > timeOut )
this->m_SundayIn.SetTime(&timeOut);
// Calculate the time difference between both ends of the shift
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
// Calculate the number of minutes in the elapsed time
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
// Calculate the number of hours in the elapsed time
nbrHours = minutes / 60;
// Convert the time difference to a decimal value
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
// Format the number to display appropriately
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
// Display the result in the corresponding text mox
this->m_Sunday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
void CTimeSheet1Dlg::OnDtnDatetimechangeSundayout(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
CTime timeIn, timeOut;
this->m_SundayIn.GetTime(timeIn);
this->m_SundayOut.GetTime(timeOut);
if( timeOut < timeIn )
this->m_SundayOut.SetTime(&timeIn);
CTimeSpan diff = timeOut - timeIn;
int nbrHours;
double nbrMinutes;
CString strTotalTime;
int minutes = diff.GetMinutes() + (diff.GetHours() * 60);
nbrHours = minutes / 60;
nbrMinutes = (minutes - (nbrHours * 60)) * 5 / 3;
char strHours[6];
itoa(nbrHours, strHours, 10);
int dec, sign;
CString strMinutes = fcvt(nbrMinutes, 2, &dec, &sign);
strTotalTime = CString(strHours) + CString(".") + CString(strMinutes);
this->m_Sunday = strTotalTime;
CalculateWeeklyHours();
UpdateData(FALSE);
}
|