unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Grids, Buttons;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
GroupBox1: TGroupBox;
ComboBox1: TComboBox;
Edit1: TEdit;
UpDown1: TUpDown;
Label2: TLabel;
Label3: TLabel;
GroupBox2: TGroupBox;
Label1: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
lb_kupon: TLabel;
lb_total: TLabel;
lb_diskon: TLabel;
lb_jlh_byr: TLabel;
lb_kembali: TLabel;
Edit2: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
procedure Edit2Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
function hitung_kembali(s: string): string;
{ Private declarations }
public
{ Public declarations }
function hitung_total(s,p:string): string;
function hit_bayar:real;
procedure hitung_kupon;
procedure hit_diskon(x:integer; var d:string);
function hit_kembali(x,y:integer):string;
end;
var
Form1: TForm1;
beli :integer;
jumlah_kupon:real;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.ColWidths[0]:=25;
StringGrid1.ColWidths[1]:=130;
StringGrid1.Cells[0,0]:='No';
StringGrid1.Cells[1,0]:='Nama Barang';
StringGrid1.Cells[2,0]:='Harga';
StringGrid1.Cells[3,0]:='jumlah';
StringGrid1.Cells[4,0]:='Total';
beli:=1;
StringGrid1.RowCount := 2;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
case ComboBox1.ItemIndex of
0: label4.Caption := '7500';
1: label4.Caption := '9000';
2: label4.Caption := '14000';
end;
end;
procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
begin
Edit1.Text:= IntToStr(UpDown1.Position);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
// untuk diskon /edit1-->jumlah beli /label4 --> harga
diskon : string;
begin
StringGrid1.RowCount := beli+1;
StringGrid1.Cells[0,beli] := IntToStr(beli);
StringGrid1.Cells[1,beli] := ComboBox1.Text;
StringGrid1.Cells[2,beli] := Label4.Caption;
StringGrid1.Cells[3,beli] := Edit1.Text;
StringGrid1.Cells[4,beli] :=
IntToStr(StrToInt(label4.Caption)*
StrToInt(edit1.Text));
lb_total.Caption :=
hitung_total
(StringGrid1.Cells[4,beli],lb_total.Caption);
hit_diskon(StrToInt(lb_total.Caption),diskon);
lb_diskon.Caption :=diskon;
hitung_kupon;
lb_kupon.Caption := format('%0.0f',[jumlah_kupon]);
lb_jlh_byr.Caption :=FloatToStr(hit_bayar);
inc(beli);
end;
function TForm1.hitung_total(s,p: string): string;
begin
hitung_total:=inttostr(strtoint(p) + StrToInt(s));
end;
procedure TForm1.hitung_kupon;
begin
jumlah_kupon := StrToInt(lb_total.Caption)/100000;
end;
function TForm1.hitung_kembali(s: string): string;
begin
hitung_kembali:=floattostr(strtofloat(Edit2.Text)-StrTofloat(s));
end;
procedure TForm1.Edit2Change(Sender: TObject);
begin
lb_kembali.Caption := hit_kembali(StrToInt(lb_jlh_byr.Caption),StrToInt(Edit2.Text));
end;
function TForm1.hit_kembali(x, y: integer): string;
begin
hit_kembali:=IntToStr(y-x);
end;
procedure TForm1.hit_diskon(x: integer; var d: string);
begin
d := FloatToStr(x*5/100);
end;
function TForm1.hit_bayar: real;
begin
hit_bayar:=StrToInt(lb_total.Caption)-StrToInt(lb_diskon.Caption);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
ComboBox1.Text := '';
Edit1.Text:= '0';
Edit2.Text:= '0';
lb_kupon.Caption := '0';
lb_total.Caption := '0';
lb_diskon.Caption := '0';
lb_jlh_byr.Caption := '0';
lb_kembali.Caption := '0';
end;
end.
ga menjamin
BalasHapus