unit Sewa;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LR_Class, LR_BarC, Forms, Controls, Graphics,
Dialogs, StdCtrls, ExtCtrls, Buttons, Process, db, Printers, Menus, ComCtrls,
ZConnection, ZDataset;
type
{ TFSewaan }
TFSewaan = class(TForm)
Bbayar: TButton;
Bhome: TButton;
Biaya: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
cekkode: TLabel;
DateTimeSewa: TLabel;
frBarCodeObject1: TfrBarCodeObject;
frReport1: TfrReport;
Info: TLabel;
Komfirmasi: TButton;
Label1: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
Shape5: TShape;
Timer1: TTimer;
Timer2: TTimer;
Timer3: TTimer;
ZConnection1: TZConnection;
ZQuery1: TZQuery;
procedure BbayarClick(Sender: TObject);
procedure BhomeClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure KomfirmasiClick(Sender: TObject);
procedure Printsaja;
procedure BacaRFID;
procedure CLoseDialog;
procedure Timer2Timer(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
procedure insertdata(nomorloker:string);
private
sc: Integer;
flagbayar: Boolean;
terpilihloker :Char;
public
data1,data2,data3,data4,data5 :Integer;
caridata:integer;
barkode: string;
flagterbayar: boolean;
procedure findbarkode(bar:string);
procedure tutupstatusloker(kolombarkode:string);
procedure Tombolkomfirmasi(uploadbarkode:string);
procedure cekloker;
end;
const
BUF_SIZE = 2048;
var
FSewaan: TFSewaan;
AProcess: TProcess;
OutputStream: Tstream;
BytesRead : longint;
Buffer : array[1..BUF_SIZE] of byte;
implementation
uses
MainGUI,message,ambil;
{$R *.lfm}
{ TFSewaan }
//pencetakan struk pembayaran
procedure TFSewaan.Timer2Timer(Sender: TObject);
begin
if flagbayar=true then
begin
BacaRFID;
if sc<0 then
begin
ShowMessage('Pembayaran dibatalkan');
flagbayar:=false;
flagterbayar:=false;
sc:=15;
end
else if cekkode.Caption <>'' then
begin
flagbayar:=false;
flagterbayar:=true;
Printsaja; //Cetak Struk pembayaran
insertdata(terpilihloker);
Info.Caption:='Cetak Struk pembayaran';
sleep(1000);
Info.Caption:='Pembayaran selesai';
sleep(1000);
Info.Caption:= 'Silahkan tekan tombol komfirmasi'+LineEnding+'untuk membuka loker anda'+LineEnding+barkode;
komfirmasi.Visible:=True;
sc:=15;
end
else
dec(sc,1);
end;
end;
//atur cek status loker
procedure TFSewaan.Timer3Timer(Sender: TObject);
begin
cekloker;
//perubahan isiloker ke warna GUI
//loker1
if data1=1 then
Shape1.Brush.Color := clRed
else
Shape1.Brush.Color := clGreen;
//loker2
if data2=1 then
Shape2.Brush.Color := clRed
else
Shape2.Brush.Color := clGreen;
//loker3
if data3=1 then
Shape3.Brush.Color := clRed
else
Shape3.Brush.Color := clGreen;
//loker4
if data4=1 then
Shape4.Brush.Color := clRed
else
Shape4.Brush.Color := clGreen;
//loker5
if data5=1 then
Shape5.Brush.Color := clRed
else
Shape5.Brush.Color := clGreen;
end;
procedure TFSewaan.insertdata(nomorloker:string);
begin
zconnection1.Connected:=true;
zquery1.close;
zquery1.SQL.Clear;
zquery1.SQL.add('insert into uji1 (Barcode, Noloker, Status, Isiloker) values (:a, :b, 1, 1)');
zquery1.ParamByName('a').AsString:= barkode;
zquery1.ParamByName('b').AsString:= nomorloker;
zquery1.ExecSQL;
zquery1.close;
zconnection1.Connected:=true;
end;
//Tombol
procedure TFSewaan.BhomeClick(Sender: TObject);
begin
Bbayar.Visible:= False;
Info.Caption:='Silahkan pilih loker yang'+LineEnding+'ingin digunakan' ;
close;
Home.Show;
end;
procedure TFSewaan.CloseDialog;
begin
close;
end;
procedure TFSewaan.Button1Click(Sender: TObject);
begin
if Shape1.Brush.Color = clRed then
begin
Info.Caption:='Loker ini telah terisi';
end
else
begin
try
begin
Info.Caption:='Silahkan lakukan pembayaran';
flagbayar:=true;
mssge.Show;
end;
finally
terpilihloker:='1';
end;
end;
end;
procedure TFSewaan.Button2Click(Sender: TObject);
begin
if Shape2.Brush.Color = clRed
then
Info.Caption:='Loker ini telah terisi'
else
begin
Info.Caption:='Silahkan lakukan pembayaran'+LineEnding+'dengan Tap Kartu';
flagbayar:=true;
end;
end;
procedure TFSewaan.Button3Click(Sender: TObject);
begin
try
begin
if Shape3.Brush.Color = clRed
then
Info.Caption:='Loker ini telah terisi'
else
begin
while flagterbayar=false do
begin
Info.Caption:='Silahkan lakukan pembayaran'+LineEnding+'dengan Tap Kartu';
flagbayar:=true;
if flagterbayar=true then
exit;
end;
end;
end;
finally
insertdata('3');
end;
end;
procedure TFSewaan.Button4Click(Sender: TObject);
begin
if Shape4.Brush.Color = clRed
then
Info.Caption:='Loker ini telah terisi'
else
begin
Info.Caption:='Silahkan lakukan pembayaran'+LineEnding+'dengan Tap Kartu';
flagbayar:=true;
end;
end;
procedure TFSewaan.Button5Click(Sender: TObject);
begin
if Shape5.Brush.Color = clRed
then
Info.Caption:='Loker ini telah terisi'
else
begin
Info.Caption:='Silahkan lakukan pembayaran'+LineEnding+'dengan Tap Kartu';
flagbayar:=true;
end;
end;
procedure TFSewaan.Button6Click(Sender: TObject);
begin
mssge.show;
end;
procedure TFSewaan.FormCreate(Sender: TObject);
begin
sc:=15;
flagbayar:=false;
komfirmasi.Visible:=false;
end;
procedure TFSewaan.KomfirmasiClick(Sender: TObject);
begin
zquery1.close;
zquery1.SQL.Clear;
zquery1.SQL.add('update uji1 set Status = 1 where Barcode = :a order by Tanggal desc limit 1');
zquery1.ParamByName('a').AsString:=barkode;
zquery1.ExecSQL;
zquery1.close;
Komfirmasi.Visible:=false;
end;
procedure TFSewaan.BbayarClick(Sender: TObject);
begin
if Shape1.Brush.Color = clRed
then
Shape1.Brush.Color:=clGreen
else
Shape1.Brush.Color:=clRed;
end;
// Baca RFID
procedure TFSewaan.BacaRFID;
var
datarfid :string;
R :Longint;
begin
begin
// Set up the process; as an example a recursive directory search is used
// because that will usually result in a lot of data.
AProcess := TProcess.Create(nil);
// The commands for Windows and *nix are different hence the $IFDEFs
{$IFDEF Unix}
AProcess.Executable := '/home/pi/MFRC522-python/Read.py';
{$ENDIF Unix}
// Process option poUsePipes has to be used so the output can be captured.
// Process option poWaitOnExit can not be used because that would block
// this program, preventing it from reading the output data of the process.
AProcess.Options := [poUsePipes];
// Start the process (run the dir/ls command)
AProcess.Execute;
// Create a stream object to store the generated output in. This could
// also be a file stream to directly save the output to disk.
OutputStream := TMemoryStream.Create;
// All generated output from AProcess is read in a loop until no more data is available
repeat
// Get the new data from the process to a maximum of the buffer size that was allocated.
// Note that all read(...) calls will block except for the last one, which returns 0 (zero).
BytesRead := AProcess.Output.Read(Buffer, BUF_SIZE);
// Add the bytes that were read to the stream for later usage
OutputStream.Write(Buffer, BytesRead)
until BytesRead = 0; // Stop if no more data is available
// The process has finished so it can be cleaned up
AProcess.Free;
// Or the data can be shown on screen
with TStringList.Create do
begin
OutputStream.Position := 0; // Required to make sure all data is copied from the start
LoadFromStream(OutputStream);
cekkode.Caption:=Text;
Free
end;
datarfid:='176,64,150,90'+LineEnding;
R:=CompareText(cekkode.Caption,datarfid);
// Clean up
OutputStream.Free;
end;
if R=0
then
begin
Info.Caption:= 'Pembayaran Selesai';
end
else
Info.Caption:= 'Saldo anda kurang';
end;
// Print
procedure TFSewaan.Printsaja;
begin
try
frReport1.LoadFromFile('/home/pi/Desktop/Berhasil/LazReportt/test_1.lrf');
frReport1.FindObject('Bar1').Memo.Text := InttoStr(Random(999999));
barkode:= frReport1.FindObject('Bar1').Memo.Text;
if frReport1.PrepareReport then
frReport1.PrintPreparedReport('1',1)
else
ShowMessage('error');
except
on e: exception do
ShowMessage(e.Message);
end;
end;
procedure TFSewaan.cekloker;
begin
//cek isiloker
zconnection1.Connected:=true;
zquery1.close;
zquery1.SQL.Clear;
zquery1.SQL.add('select * from uji1 where Noloker = 1 order by Tanggal desc limit 1');
zquery1.open;
while not zquery1.EOF do begin
data1:=zquery1.FieldByName('Isiloker').AsInteger;
zquery1.Next;
end;
zquery1.close;
zquery1.SQL.Clear;
zquery1.SQL.add('select * from uji1 where Noloker = 2 order by Tanggal desc limit 1');
zquery1.open;
while not zquery1.EOF do begin
data2:=zquery1.FieldByName('Isiloker').AsInteger;
zquery1.Next;
end;
zquery1.close;
zquery1.SQL.Clear;
zquery1.SQL.add('select * from uji1 where Noloker = 3 order by Tanggal desc limit 1');
zquery1.open;
while not zquery1.EOF do begin
data3:=zquery1.FieldByName('Isiloker').AsInteger;
zquery1.Next;
end;
zquery1.close;
zquery1.SQL.Clear;
zquery1.SQL.add('select * from uji1 where Noloker = 4 order by Tanggal desc limit 1');
zquery1.open;
while not zquery1.EOF do begin
data4:=zquery1.FieldByName('Isiloker').AsInteger;
zquery1.Next;
end;
zquery1.close;
zquery1.SQL.Clear;
zquery1.SQL.add('select * from uji1 where Noloker = 5 order by Tanggal desc limit 1');
zquery1.open;
while not zquery1.EOF do begin
data5:=zquery1.FieldByName('Isiloker').AsInteger;
zquery1.Next;
end;
zquery1.close;
zconnection1.Connected:=false;
end;
procedure TFSewaan.findbarkode(bar:string);
begin
zconnection1.Connected:=true;
zquery1.close;
zquery1.SQL.Clear;
zquery1.SQL.add('select * from uji1 where Barcode = :a order by Tanggal desc limit 1');
zquery1.ParamByName('a').AsString:=bar;
zquery1.open;
while not zquery1.EOF do begin
caridata:=zquery1.FieldByName('Isiloker').AsInteger;
zquery1.Next;
end;
zquery1.close;
zconnection1.Connected:=False;
end;
procedure TFSewaan.tutupstatusloker(kolombarkode:string);
begin
zconnection1.Connected:=true;
zquery1.close;
zquery1.SQL.Clear;
zquery1.SQL.add('update uji1 set Isiloker=0 where Barcode = :a order by Tanggal desc limit 1');
zquery1.ParamByName('a').AsString:=kolombarkode;
zquery1.ExecSQL;
zquery1.close;
zconnection1.Connected:=False;
end;
procedure TFSewaan.Tombolkomfirmasi(uploadbarkode:string);
begin
zconnection1.Connected:=true;
zquery1.close;
zquery1.SQL.Clear;
zquery1.SQL.add('update uji1 set Status = 1 where Barcode = :a order by Tanggal desc limit 1');
zquery1.ParamByName('a').AsString:=uploadbarkode;
zquery1.ExecSQL;
Zquery1.close;
zconnection1.Connected:=False;
end;
end.