//---------------------------------------------------------------------------
void __fastcall TfrmWorkOrders::CalculateOrder()
{
//TODO: Add your source code here
double part1UnitPrice, part1SubTotal, part2UnitPrice, part2SubTotal,
part3UnitPrice, part3SubTotal, part4UnitPrice, part4SubTotal,
part5UnitPrice, part5SubTotal, totalParts;
int part1Quantity = 0, part2Quantity = 0, part3Quantity = 0,
part4Quantity = 0, part5Quantity = 0;
double job1Price = 0.00, job2Price = 0.00, job3Price = 0.00,
job4Price = 0.00, job5Price = 0.00;
double totalLabor;
double taxRate, taxAmount, totalOrder;
// Don't charge a part unless it is clearly identified
if( this->edtUnitPrice1->Text == "" )
{
this->edtUnitPrice1->Text = "0.00";
this->edtQuantity1->Text = "0";
this->edtSubTotal1->Text = "0.00";
part1UnitPrice = 0.00;
}
else
{
try {
part1UnitPrice = this->edtUnitPrice1->Text.ToDouble();
}
catch(EConvertError *)
{
ShowMessage("Invalid unit price");
this->edtUnitPrice1->Text = "0.00";
this->edtUnitPrice1->SetFocus();
}
try {
part1Quantity = this->edtQuantity1->Text.ToInt();
}
catch(EConvertError *)
{
ShowMessage("Invalid Quantity");
this->edtQuantity1->Text = "0";
this->edtQuantity1->SetFocus();
}
}
if( this->edtPartName2->Text == "" )
{
this->edtUnitPrice2->Text = "0.00";
this->edtQuantity2->Text = "0";
this->edtSubTotal2->Text = "0.00";
part2UnitPrice = 0.00;
}
else
{
try {
part2UnitPrice = this->edtUnitPrice2->Text.ToDouble();
}
catch(EConvertError *)
{
ShowMessage("Invalid Unit Price");
this->edtUnitPrice2->Text = "0.00";
this->edtUnitPrice2->SetFocus();
}
try {
part2Quantity = this->edtQuantity2->Text.ToInt();
}
catch(EConvertError *)
{
ShowMessage("Invalid Quantity");
this->edtQuantity2->Text = "0";
this->edtQuantity2->SetFocus();
}
}
if( this->edtPartName3->Text == "" )
{
this->edtUnitPrice3->Text = "0.00";
this->edtQuantity3->Text = "0";
this->edtSubTotal3->Text = "0.00";
part3UnitPrice = 0.00;
}
else
{
try {
part3UnitPrice = this->edtUnitPrice3->Text.ToDouble();
}
catch(EConvertError *)
{
ShowMessage("Invalid Unit Price");
this->edtUnitPrice3->Text = "0.00";
this->edtUnitPrice3->SetFocus();
}
try {
part3Quantity = this->edtQuantity3->Text.ToInt();
}
catch(EConvertError *)
{
ShowMessage("Invalid Quantity");
this->edtQuantity3->Text = "0";
this->edtQuantity3->SetFocus();
}
}
if( this->edtPartName4->Text == "" )
{
this->edtUnitPrice4->Text = "0.00";
this->edtQuantity4->Text = "0";
this->edtSubTotal4->Text = "0.00";
part4UnitPrice = 0.00;
}
else
{
try {
part4UnitPrice = this->edtUnitPrice4->Text.ToDouble();
}
catch(EConvertError *)
{
ShowMessage("Invalid Unit Price");
this->edtUnitPrice4->Text = "0.00";
this->edtUnitPrice4->SetFocus();
}
try {
part4Quantity = this->edtQuantity4->Text.ToInt();
}
catch(EConvertError *)
{
ShowMessage("Invalid Quantity");
this->edtQuantity4->Text = "0";
this->edtQuantity4->SetFocus();
}
}
if( this->edtPartName5->Text == "" )
{
this->edtUnitPrice5->Text = "0.00";
this->edtQuantity5->Text = "0";
this->edtSubTotal5->Text = "0.00";
part5UnitPrice = 0.00;
}
else
{
try {
part5UnitPrice = this->edtUnitPrice5->Text.ToDouble();
}
catch(EConvertError *)
{
ShowMessage("Invalid Unit Price");
this->edtUnitPrice5->Text = "0.00";
this->edtUnitPrice5->SetFocus();
}
try {
part5Quantity = this->edtQuantity5->Text.ToInt();
}
catch(EConvertError *)
{
ShowMessage("Invalid Quantity");
this->edtQuantity5->Text = "0";
this->edtQuantity5->SetFocus();
}
}
// Don't bill the customer for a job that is not specified
if( this->edtJobPerformed1->Text == "" )
{
this->edtJobPrice1->Text = "0.00";
job1Price = 0.00;
}
else
{
try {
job1Price = this->edtJobPrice1->Text.ToDouble();
}
catch(EConvertError *)
{
ShowMessage("Invalid Job Price");
this->edtJobPrice1->Text = "0.00";
this->edtJobPrice1->SetFocus();
}
}
if( this->edtJobPerformed2->Text == "" )
{
this->edtJobPrice2->Text = "0.00";
job2Price = 0.00;
}
else
{
try {
job2Price = this->edtJobPrice2->Text.ToDouble();
}
catch(EConvertError *)
{
ShowMessage("Invalid Job Price");
this->edtJobPrice2->Text = "0.00";
this->edtJobPrice2->SetFocus();
}
}
if( this->edtJobPerformed3->Text == "" )
{
this->edtJobPrice3->Text = "0.00";
job3Price = 0.00;
}
else
{
try {
job3Price = this->edtJobPrice3->Text.ToDouble();
}
catch(EConvertError *)
{
ShowMessage("Invalid Job Price");
this->edtJobPrice3->Text = "0.00";
this->edtJobPrice3->SetFocus();
}
}
if( this->edtJobPerformed4->Text == "" )
{
this->edtJobPrice4->Text = "0.00";
job4Price = 0.00;
}
else
{
try {
job4Price = this->edtJobPrice4->Text.ToDouble();
}
catch(EConvertError *)
{
ShowMessage("Invalid Job Price");
this->edtJobPrice4->Text = "0.00";
this->edtJobPrice4->SetFocus();
}
}
part1SubTotal = part1UnitPrice * part1Quantity;
part2SubTotal = part2UnitPrice * part2Quantity;
part3SubTotal = part3UnitPrice * part3Quantity;
part4SubTotal = part4UnitPrice * part4Quantity;
part5SubTotal = part5UnitPrice * part5Quantity;
this->edtSubTotal1->Text = FloatToStrF(part1SubTotal, ffFixed, 8, 2);
this->edtSubTotal2->Text = FloatToStrF(part2SubTotal, ffFixed, 8, 2);
this->edtSubTotal3->Text = FloatToStrF(part3SubTotal, ffFixed, 8, 2);
this->edtSubTotal4->Text = FloatToStrF(part4SubTotal, ffFixed, 8, 2);
this->edtSubTotal5->Text = FloatToStrF(part5SubTotal, ffFixed, 8, 2);
totalParts = part1SubTotal + part2SubTotal + part3SubTotal +
part4SubTotal + part5SubTotal;
totalLabor = job1Price + job2Price + job3Price +
job4Price + job5Price;
try {
taxRate = this->edtTaxRate->Text.ToDouble();
}
catch(EConvertError *)
{
ShowMessage("Invalid Tax Rate");
this->edtTaxRate->Text = "7.75";
this->edtTaxRate->SetFocus();
}
double totalPartsAndLabor = totalParts + totalLabor;
taxAmount = totalPartsAndLabor * taxRate / 100;
totalOrder = totalPartsAndLabor + taxAmount;
this->edtTotalParts->Text = FloatToStrF(totalParts, ffFixed, 8, 2);
this->edtTotalLabor->Text = FloatToStrF(totalLabor, ffFixed, 8, 2);
this->edtTaxAmount->Text = FloatToStrF(taxAmount, ffFixed, 8, 2);
this->edtOrderTotal->Text = FloatToStrF(totalOrder, ffFixed, 8, 2);
}
//---------------------------------------------------------------------------
|