System::Void btnPresseIt_Click(System::Object * sender, System::EventArgs * e)
{
double monday1 = 0.00, tuesday1 = 0.00, wednesday1 = 0.00, thursday1 = 0.00,
friday1 = 0.00, saturday1 = 0.00, sunday1 = 0.00,
monday2 = 0.00, tuesday2 = 0.00, wednesday2 = 0.00, thursday2 = 0.00,
friday2 = 0.00, saturday2 = 0.00, sunday2 = 0.00;
double totalHoursWeek1, totalHoursWeek2;
double regHours1 = 0.00, regHours2 = 0.00, ovtHours1 = 0.00, ovtHours2 = 0.00;
double regAmount1 = 0.00, regAmount2 = 0.00, ovtAmount1 = 0.00, ovtAmount2 = 0.00;
double regularHours, overtimeHours;
double regularAmount, overtimeAmount, totalEarnings;
double hourlySalary = 0.00;
// Retrieve the hourly salary
try
{
hourlySalary = this->txtHourlySalary->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you typed for the salary is invalid \n"
S"Please try again");
this->txtHourlySalary->Focus();
}
// Retrieve the value of each day worked
try
{
monday1 = this->txtMonday1->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtMonday1->Focus();
}
try
{
tuesday1 = this->txtTuesday1->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtTuesday1->Focus();
}
try
{
wednesday1 = this->txtWednesday1->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtWednesday1->Focus();
}
try
{
thursday1 = this->txtThursday1->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtThursday1->Focus();
}
try
{
friday1 = this->txtFriday1->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtFriday1->Focus();
}
try
{
saturday1 = this->txtSaturday1->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtSaturday1->Focus();
}
try
{
sunday1 = this->txtSunday1->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtSunday1->Focus();
}
try
{
monday2 = this->txtMonday2->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtMonday2->Focus();
}
try
{
tuesday2 = this->txtTuesday2->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtTuesday2->Focus();
}
try
{
wednesday2 = this->txtWednesday2->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtWednesday2->Focus();
}
try
{
thursday2 = this->txtThursday2->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtThursday2->Focus();
}
try
{
friday2 = this->txtFriday2->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtFriday2->Focus();
}
try
{
saturday2 = this->txtSaturday2->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtSaturday2->Focus();
}
try
{
sunday2 = this->txtSunday2->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"You typed an invalid value\n"
S"Please try again");
this->txtSunday2->Focus();
}
// Calculate the total number of hours for each week
totalHoursWeek1 = monday1 + tuesday1 + wednesday1 + thursday1 +
friday1 + saturday1 + sunday1;
totalHoursWeek2 = monday2 + tuesday2 + wednesday2 + thursday2 +
friday2 + saturday2 + sunday2;
// The overtime is paid time and half
double ovtSalary = hourlySalary * 1.5;
// If the employee worked under 40 hours, there is no overtime
if( totalHoursWeek1 < 40 )
{
regHours1 = totalHoursWeek1;
regAmount1 = hourlySalary * regHours1;
ovtHours1 = 0.00;
ovtAmount1 = 0.00;
} // If the employee worked over 40 hours, calculate the overtime
else if( totalHoursWeek1 >= 40 )
{
regHours1 = 40;
regAmount1 = hourlySalary * 40;
ovtHours1 = totalHoursWeek1 - 40;
ovtAmount1 = ovtHours1 * ovtSalary;
}
if( totalHoursWeek2 < 40 )
{
regHours2 = totalHoursWeek2;
regAmount2 = hourlySalary * regHours2;
ovtHours2 = 0.00;
ovtAmount2 = 0.00;
}
else if( totalHoursWeek2 >= 40 )
{
regHours2 = 40;
regAmount2 = hourlySalary * 40;
ovtHours2 = totalHoursWeek2 - 40;
ovtAmount2 = ovtHours2 * ovtSalary;
}
regularHours = regHours1 + regHours2;
overtimeHours = ovtHours1 + ovtHours2;
regularAmount = regAmount1 + regAmount2;
overtimeAmount = ovtAmount1 + ovtAmount2;
totalEarnings = regularAmount + overtimeAmount;
this->txtRegularHours->Text = regularHours.ToString(S"F");
this->txtOvertimeHours->Text = overtimeHours.ToString(S"F");
this->txtRegularAmount->Text = regularAmount.ToString(S"F");
this->txtOvertimeAmount->Text = overtimeAmount.ToString(S"F");
this->txtTotalEarnings->Text = totalEarnings.ToString(S"F");
}
|