//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Exercise.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::updAmount1Click(TObject *Sender, TUDBtnType Button)
{
double AmountPledged,
RateAmount1, RateAmount2, RateAmount3,
Amount1, Amount2, Amount3,
Rest;
AmountPledged = this->edtAmountPledged->Text.ToDouble();
RateAmount2 = static_cast<double>(this->updAmount2->Position);
RateAmount3 = static_cast<double>(this->updAmount3->Position);
this->updAmount1->Max = 100 - RateAmount2 - RateAmount3;
RateAmount1 = static_cast<double>(this->updAmount1->Position);
Amount1 = AmountPledged * RateAmount1 / 100;
Amount2 = AmountPledged * RateAmount2 / 100;
Amount3 = AmountPledged * RateAmount3 / 100;
Rest = AmountPledged - Amount1 - Amount2 - Amount3;
this->edtAmount1->Text = FloatToStrF(Amount1, ffCurrency, 8, 2);
this->edtAmount2->Text = FloatToStrF(Amount2, ffCurrency, 8, 2);
this->edtAmount3->Text = FloatToStrF(Amount3, ffCurrency, 8, 2);
if( Rest > 0 )
this->lblMessage->Caption =
FloatToStrF(Rest, ffCurrency, 8, 2) + " still to be used";
else
this->lblMessage->Caption = "";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::updAmount2Click(TObject *Sender, TUDBtnType Button)
{
double AmountPledged,
RateAmount1, RateAmount2, RateAmount3,
Amount1, Amount2, Amount3,
Rest;
AmountPledged = this->edtAmountPledged->Text.ToDouble();
RateAmount1 = static_cast<double>(this->updAmount1->Position);
RateAmount3 = static_cast<double>(this->updAmount3->Position);
this->updAmount2->Max = 100 - RateAmount1 - RateAmount3;
RateAmount2 = static_cast<double>(this->updAmount2->Position);
Amount1 = AmountPledged * RateAmount1 / 100;
Amount2 = AmountPledged * RateAmount2 / 100;
Amount3 = AmountPledged * RateAmount3 / 100;
Rest = AmountPledged - Amount1 - Amount2 - Amount3;
this->edtAmount1->Text = FloatToStrF(Amount1, ffCurrency, 8, 2);
this->edtAmount2->Text = FloatToStrF(Amount2, ffCurrency, 8, 2);
this->edtAmount3->Text = FloatToStrF(Amount3, ffCurrency, 8, 2);
if( Rest > 0 )
this->lblMessage->Caption =
FloatToStrF(Rest, ffCurrency, 8, 2) + " still to be used";
else
this->lblMessage->Caption = "";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::updAmount3Click(TObject *Sender, TUDBtnType Button)
{
double AmountPledged,
RateAmount1, RateAmount2, RateAmount3,
Amount1, Amount2, Amount3,
Rest;
AmountPledged = this->edtAmountPledged->Text.ToDouble();
RateAmount1 = static_cast<double>(this->updAmount1->Position);
RateAmount2 = static_cast<double>(this->updAmount2->Position);
this->updAmount3->Max = 100 - RateAmount1 - RateAmount2;
RateAmount3 = static_cast<double>(this->updAmount3->Position);
Amount1 = AmountPledged * RateAmount1 / 100;
Amount2 = AmountPledged * RateAmount2 / 100;
Amount3 = AmountPledged * RateAmount3 / 100;
Rest = AmountPledged - Amount1 - Amount2 - Amount3;
this->edtAmount1->Text = FloatToStrF(Amount1, ffCurrency, 8, 2);
this->edtAmount2->Text = FloatToStrF(Amount2, ffCurrency, 8, 2);
this->edtAmount3->Text = FloatToStrF(Amount3, ffCurrency, 8, 2);
if( Rest > 0 )
this->lblMessage->Caption =
FloatToStrF(Rest, ffCurrency, 8, 2), " still to be used";
else
this->lblMessage->Caption = "";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::edtAmountPledgedChange(TObject *Sender)
{
if( this->edtAmountPledged->Text == "" )
{
this->updAmount1->Enabled = false;
this->updAmount2->Enabled = false;
this->updAmount3->Enabled = false;
}
else
{
this->updAmount1->Enabled = true;
this->updAmount2->Enabled = true;
this->updAmount3->Enabled = true;
}
}
//---------------------------------------------------------------------------
|