unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, Mask, DBCtrls, StdCtrls, ComCtrls;
type
TForm6 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
DateTimePicker1: TDateTimePicker;
produk: TGroupBox;
Label3: TLabel;
Label4: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Button1: TButton;
DBLookupComboBox1: TDBLookupComboBox;
DBEdit1: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
Edit2: TEdit;
StringGrid1: TStringGrid;
Label9: TLabel;
Edit3: TEdit;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Label5: TLabel;
Edit4: TEdit;
batal: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure DBLookupComboBox1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure batalClick(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
private
procedure hitung;
{ Private declarations }
public
{ Public declarations }
end;
var
Form6: TForm6;
implementation
uses Unit3, Unit2;
{$R *.dfm}
procedure TForm6.hitung;
var i,t,D:Integer;
begin
t:=0;
D:=0;
for i := 1 to StringGrid1.RowCount - 1 do begin
StringGrid1.Cells[0,i]:=IntToStr(i);
t:=t + StrToInt(StringGrid1.Cells[5,i]);
D:=D + StrToInt(StringGrid1.Cells[4,i]);
end;
Edit3.Text:=IntToStr(t);
Edit4.Text:=IntToStr(D);
end;
procedure TForm6.batalClick(Sender: TObject);
var bs,i,t:integer;
begin
bs:=StringGrid1.Row;
for i := bs+1 to StringGrid1.RowCount- 1 do begin
StringGrid1.Rows[i-1]:=StringGrid1.Rows[i];
end;
StringGrid1.RowCount:=StringGrid1.RowCount-1;
for i := 1 to StringGrid1.RowCount - 1 do
begin
StringGrid1.Cells[0,i]:=inttostr(i);
end;
t:=0;
for i := 1 to StringGrid1.RowCount - 1 do begin
StringGrid1.Cells[0,i]:=IntToStr(i);
t:=t + StrToInt(StringGrid1.Cells[5,i]);
Edit3.Text:=IntToStr(t);
end;
end;
procedure TForm6.Button1Click(Sender: TObject);
var
i:Integer;
a,b,c:real;
begin
a:=strtofloat(DBEdit4.Text);
b:=strtofloat(Edit2.Text);
if (a<b) then
begin
(Application.MessageBox('stok saat ini kurang untuk permintaan sekarang ini. . . !!!','peringatan'));
exit;
end;
for i:= 1 to StringGrid1.RowCount - 1 do
begin
if DBLookupComboBox1.Text=StringGrid1.cells[1,i] then
begin
ShowMessage('data udah ada') ;
if StrToInt (StringGrid1.Cells[6,i])<StrToInt (edit2.Text) then
begin
ShowMessage('stok tidak cukup') ;
edit2.SetFocus;
exit;
end;
StringGrid1.Cells[4,StringGrid1.RowCount-1]:=IntToStr(strtoint(StringGrid1.Cells[4,i])+ (strtoint(Edit2.Text)));
StringGrid1.Cells[5,StringGrid1.RowCount-1]:=IntToStr(strtoint(StringGrid1.cells[3,i])* (strtoint(StringGrid1.cells[4,i])));
StringGrid1.Cells[6,StringGrid1.RowCount-1]:=IntToStr(strtoint(StringGrid1.cells[6,i])- (strtoint(Edit2.Text)));
hitung;
exit;
end;
end;
StringGrid1.RowCount:=StringGrid1.RowCount+1;
StringGrid1.Cells[1,StringGrid1.RowCount-1]:=DBLookupComboBox1.Text;
StringGrid1.Cells[2,StringGrid1.RowCount-1]:=DBEdit1.Text;
StringGrid1.Cells[3,StringGrid1.RowCount-1]:=DBEdit3.Text;
StringGrid1.Cells[4,StringGrid1.RowCount-1]:=edit2.Text;
StringGrid1.Cells[5,StringGrid1.RowCount-1]:=DBEdit4.Text;
StringGrid1.Cells[5,StringGrid1.RowCount-1]:=IntToStr(strtoint(DBEdit3.Text)* (strtoint(Edit2.Text)));
StringGrid1.Cells[6,StringGrid1.RowCount-1]:=IntToStr(strtoint(DBEdit4.Text)- (strtoint(Edit2.Text)));
hitung;
for i:= 1 to StringGrid1.RowCount - 1 do
DataModule2.ADOQuery2.SQL.Clear;
DataModule2.ADOQuery2.SQL.Add('update product set stok="'+StringGrid1.Cells[6,i]+'"');
DataModule2.ADOQuery2.SQL.Add('where product_id='''+StringGrid1.Cells[1,i]+'''');
DataModule2.ADOQuery2.ExecSQL;
datamodule2.ADOQuery2.SQL.Clear;
datamodule2.ADOQuery2.SQL.Add('select* from product');
datamodule2.ADOQuery2.Open;
end;
procedure TForm6.Button2Click(Sender: TObject);
var
i: Integer;
begin
if messagedlg(' Yakin Simpan Data?',mtinformation,[mbyes,mbno],0)=mryes then
begin
for i:= 1 to StringGrid1.RowCount - 1 do
//menyimpan k
datamodule2.ADOQuery3.SQL.Clear;
datamodule2.ADOQuery3.SQL.Add('insert into detail_transaksi(no_transaksi,product_id,jumlah,harga_satuan,user_login_id,we)');
datamodule2.ADOQuery3.SQL.Add('values("'+Edit1.Text+'","'+StringGrid1.Cells[1,i]+'","'+StringGrid1.Cells[4,i]+'","'+StringGrid1.Cells[3,i]+'","kasir","'+formatdatetime('yyyy-mm-dd hh:mm:ss',now)+'")');
datamodule2.ADOQuery3.ExecSQL;
//refresh data dengan adoquery1
datamodule2.ADOQuery3.SQL.Clear;
datamodule2.ADOQuery3.SQL.Add('select* from detail_transaksi');
datamodule2.ADOQuery3.Open;
DataModule2.ADOQuery3.SQL.Clear;
DataModule2.ADOQuery3.SQL.Add('insert into transaksi(no_transaksi,tgl_transaksi,total_barang,total_harga,user_login_id,we)');
DataModule2.ADOQuery3.sql.Add('values ("'+Edit1.Text+'","'+formatdatetime('yyyy-mm-dd ',DateTimePicker1.Date)+'","'+edit4.Text+'","'+edit3.Text+'","kasir","'+formatdatetime('yyyy-mm-dd hh:mm:ss',now)+'")');
DataModule2.ADOQuery3.ExecSQL;
datamodule2.ADOQuery3.SQL.Clear;
datamodule2.ADOQuery3.SQL.Add('select * from transaksi');
datamodule2.ADOQuery3.Open;
end;
end;
procedure TForm6.Button3Click(Sender: TObject);
begin
StringGrid1.RowCount:=0;
end;
procedure TForm6.DBLookupComboBox1Click(Sender: TObject);
begin
edit2.SetFocus;
end;
procedure TForm6.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in['0'..'9',#8]) then key:=#0;
end;
procedure TForm6.FormCreate(Sender: TObject);
begin
StringGrid1.RowCount:=1;
StringGrid1.ColCount:=7;
StringGrid1.Cells[0,0]:='No';
StringGrid1.Cells[1,0]:='kode';
StringGrid1.Cells[2,0]:='nama produk';
StringGrid1.Cells[3,0]:='harga';
StringGrid1.Cells[4,0]:='jumlah';
StringGrid1.Cells[5,0]:='total';
StringGrid1.Cells[6,0]:='stok';
StringGrid1.ColWidths[0]:=50;
StringGrid1.ColWidths[1]:=100;
StringGrid1.ColWidths[2]:=100;
StringGrid1.ColWidths[3]:=100;
StringGrid1.ColWidths[4]:=100;
end;
end.
0 Comments