//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::CalculateTotalTime()
{
//TODO: Add your source code here
double monday, tuesday, wednesday, thursday,
friday, saturday, sunday, totalHours;
monday = this->edtMonday->Text.ToDouble();
tuesday = this->edtTuesday->Text.ToDouble();
wednesday = this->edtWednesday->Text.ToDouble();
thursday = this->edtThursday->Text.ToDouble();
friday = this->edtFriday->Text.ToDouble();
saturday = this->edtSaturday->Text.ToDouble();
sunday = this->edtSunday->Text.ToDouble();
totalHours = monday + tuesday + wednesday + thursday +
friday + saturday + sunday;
this->edtTotalTime->Text = FloatToStrF(totalHours, ffFixed, 6, 2);
}
//---------------------------------------------------------------------------
double __fastcall TfrmMain::CalculateDailyTime(TDateTime Start, TDateTime End)
{
//TODO: Add your source code here
// Calculate the time difference between both arguments
TDateTime tmeDiff = End - Start;
// Retrieve the time span values of the difference
unsigned short hour, minute, second, ms;
tmeDiff.DecodeTime(&hour, &minute, &second, &ms);
int nbrHours;
double nbrMinutes;
AnsiString strTotalTime;
// Calculate the number of minutes in the elapsed time
int minutes = minute + (hour * 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
strTotalTime = IntToStr(nbrHours) + "." + FloatToStr(nbrMinutes);
double dblTotalTime = strTotalTime.ToDouble();
// Return the result
return dblTotalTime;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpMondayInChange(TObject *Sender)
{
// Make sure the time in doesn't occur after the time out
if( this->dtpMondayIn->Time > this->dtpMondayOut->Time )
this->dtpMondayIn->Time = this->dtpMondayOut->Time;
// Retrieve the time values of the start and end of the shift
// Then pass it to the method that can calculate the difference
double tmeElapsed =
this->CalculateDailyTime(this->dtpMondayOut->Time,
this->dtpMondayIn->Time);
// Display the result in the corresponding text mox
this->edtMonday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpMondayOutChange(TObject *Sender)
{
if( this->dtpMondayOut->Time < this->dtpMondayIn->Time )
this->dtpMondayOut->Time = this->dtpMondayIn->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpMondayOut->Time,
this->dtpMondayIn->Time);
// Display the result in the corresponding text mox
this->edtMonday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpTuesdayInChange(TObject *Sender)
{
if( this->dtpTuesdayIn->Time > this->dtpTuesdayOut->Time )
this->dtpTuesdayIn->Time = this->dtpTuesdayOut->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpTuesdayOut->Time,
this->dtpTuesdayIn->Time);
// Display the result in the corresponding text mox
this->edtTuesday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpTuesdayOutChange(TObject *Sender)
{
if( this->dtpTuesdayOut->Time < this->dtpTuesdayIn->Time )
this->dtpTuesdayOut->Time = this->dtpTuesdayIn->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpTuesdayOut->Time,
this->dtpTuesdayIn->Time);
// Display the result in the corresponding edit control
this->edtTuesday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpWednesdayInChange(TObject *Sender)
{
if( this->dtpWednesdayIn->Time > this->dtpWednesdayOut->Time )
this->dtpWednesdayIn->Time = this->dtpWednesdayOut->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpWednesdayOut->Time,
this->dtpWednesdayIn->Time);
// Display the result in the corresponding text mox
this->edtWednesday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpWednesdayOutChange(TObject *Sender)
{
if( this->dtpWednesdayOut->Time < this->dtpWednesdayIn->Time )
this->dtpWednesdayOut->Time = this->dtpWednesdayIn->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpWednesdayOut->Time,
this->dtpWednesdayIn->Time);
this->edtWednesday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpThursdayInChange(TObject *Sender)
{
if( this->dtpThursdayIn->Time > this->dtpThursdayOut->Time )
this->dtpThursdayIn->Time = this->dtpThursdayOut->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpThursdayOut->Time,
this->dtpThursdayIn->Time);
// Display the result in the corresponding text mox
this->edtThursday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpThursdayOutChange(TObject *Sender)
{
if( this->dtpThursdayOut->Time < this->dtpThursdayIn->Time )
this->dtpThursdayOut->Time = this->dtpThursdayIn->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpThursdayOut->Time,
this->dtpThursdayIn->Time);
// Display the result in the corresponding edit control
this->edtThursday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpFridayInChange(TObject *Sender)
{
if( this->dtpFridayIn->Time > this->dtpFridayOut->Time )
this->dtpFridayIn->Time = this->dtpFridayOut->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpFridayOut->Time,
this->dtpFridayIn->Time);
// Display the result in the corresponding text mox
this->edtFriday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpFridayOutChange(TObject *Sender)
{
if( this->dtpFridayOut->Time < this->dtpFridayIn->Time )
this->dtpFridayOut->Time = this->dtpFridayIn->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpFridayOut->Time,
this->dtpFridayIn->Time);
// Display the result in the corresponding edit control
this->edtFriday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpSaturdayInChange(TObject *Sender)
{
if( this->dtpSaturdayIn->Time > this->dtpSaturdayOut->Time )
this->dtpSaturdayIn->Time = this->dtpSaturdayOut->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpSaturdayOut->Time,
this->dtpSaturdayIn->Time);
// Display the result in the corresponding edit control
this->edtSaturday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpSaturdayOutChange(TObject *Sender)
{
if( this->dtpSaturdayOut->Time < this->dtpSaturdayIn->Time )
this->dtpSaturdayOut->Time = this->dtpSaturdayIn->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpSaturdayOut->Time,
this->dtpSaturdayIn->Time);
// Display the result in the corresponding edit control
this->edtSaturday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpSundayInChange(TObject *Sender)
{
if( this->dtpSundayIn->Time > this->dtpSundayOut->Time )
this->dtpSundayIn->Time = this->dtpSundayOut->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpSundayOut->Time,
this->dtpSundayIn->Time);
// Display the result in the corresponding edit control
this->edtSunday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::dtpSundayOutChange(TObject *Sender)
{
if( this->dtpSundayOut->Time < this->dtpSundayIn->Time )
this->dtpSundayOut->Time = this->dtpSundayIn->Time;
double tmeElapsed =
this->CalculateDailyTime(this->dtpSundayOut->Time,
this->dtpSundayIn->Time);
// Display the result in the corresponding edit control
this->edtSunday->Text = FloatToStrF(tmeElapsed, ffFixed, 6, 2);
this->CalculateTotalTime();
}
//---------------------------------------------------------------------------
|