Aplikasi Perpustakaan - Edisi 7 (Form Pengembalian)

Program Perpustakaan.


Tampilan Menu Utama
1. Membuat Form Transaksi Pengembalian Buku.

Selanjutnya kita membuat Form Pengembalian Buku, untuk source kode kalian bisa lihat di bawah sini:

source code:
1: unit Unit6;
2:
3: interface
4:
5: uses
6: Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7: Dialogs, StdCtrls, DB, ADODB, XPMan, Buttons;
8:
9: type
10: TForm_Pengembalian = class(TForm)
11: GroupBox1: TGroupBox;
12: Label1: TLabel;
13: Label2: TLabel;
14: ComboBox1: TComboBox;
15: Edit1: TEdit;
16: GroupBox2: TGroupBox;
17: Label3: TLabel;
18: Label4: TLabel;
19: ComboBox2: TComboBox;
20: Edit2: TEdit;
21: ListBox1: TListBox;
22: Button1: TButton;
23: GroupBox3: TGroupBox;
24: Label7: TLabel;
25: Edit3: TEdit;
26: BitBtn2: TBitBtn;
27: BitBtn1: TBitBtn;
28: XPManifest1: TXPManifest;
29: Query: TADOQuery;
30: rB1: TRadioButton;
31: rB2: TRadioButton;
32: Label6: TLabel;
33: Edit4: TEdit;
34: ListBox2: TListBox;
35: ListBox3: TListBox;
36: procedure FormActivate(Sender: TObject);
37: procedure ComboBox1Click(Sender: TObject);
38: procedure ComboBox2Click(Sender: TObject);
39: procedure Button1Click(Sender: TObject);
40: procedure BitBtn1Click(Sender: TObject);
41: procedure BitBtn2Click(Sender: TObject);
42: procedure FormClose(Sender: TObject; var Action: TCloseAction);
43: procedure ComboBox1Exit(Sender: TObject);
44: private
45: { Private declarations }
46: public
47: { Public declarations }
48: end;
49:
50: var
51: Form_Pengembalian: TForm_Pengembalian;
52:
53: implementation
54:
55: uses unit2;
56:
57: {$R *.dfm}
58:
59: procedure TForm_Pengembalian.FormActivate(Sender: TObject);
60: begin
61: combobox1.Enabled := true;
62: combobox2.Enabled := false;
63: bitbtn1.Enabled := false;
64: combobox1.Clear;
65: combobox2.Clear;
66: edit1.Clear;
67: edit2.Clear;
68: edit3.Text := '0';
69: edit4.Text := '0';
70: rB1.Checked := true;
71: listbox1.Clear;
72: listbox2.Clear;
73: listbox3.Clear;
74: Query.Connection := Form_Utama.Koneksi;
75: Query.SQL.Add('select id_anggota from tabel_peminjaman where status=1 group by
id_anggota;');
76: Query.Active := true;
77:
78: if Query.RecordCount = 0 then
79: begin
80: Query.SQL.Clear;
81: Query.Active := false;
82: MessageDlg('Belum ada yang pinjam!',mtInformation,[mbOk],0);
83: end
84: else
85: begin
86: while not Query.Eof do
87: begin
88: combobox1.Items.Add(Query['id_anggota']);
89: Query.Next;
90: end;
91:
92: Query.SQL.Clear;
93: Query.Active := false;
94: end;
95: end;
96:
97: procedure TForm_Pengembalian.ComboBox1Click(Sender: TObject);
98: begin
99: Query.SQL.Add('select nm_anggota from tabel_anggota where id_anggota="' +
combobox1.Text + '";');
100: Query.Active := true;
101: edit1.Text := Query['nm_anggota'];
102: Query.SQL.Clear;
103: Query.Active := false;
104:
105: Query.SQL.Add('select kd_buku from tabel_peminjaman where id_anggota="' +
combobox1.Text + '" and status=1 order by kd_buku asc;');
106: Query.Active := true;
107: combobox2.Clear;
108: combobox2.Enabled := true;
109:
110: while not Query.Eof do
111: begin
112: combobox2.Items.Add(Query['kd_buku']);
113: Query.Next;
114: end;
115:
116: Query.SQL.Clear;
117: Query.Active := false;
118: end;
119:
120: procedure TForm_Pengembalian.ComboBox2Click(Sender: TObject);
121: begin
122: Query.SQL.Add('select judul from tabel_buku where kd_buku="' + combobox2.Text + '";');
123: Query.Active := true;
124: edit2.Text := Query['judul'];
125: Query.SQL.Clear;
126: Query.Active := false;
127: button1.Enabled := true;
128: rB1.Enabled := true;
129: rB2.Enabled := true;
130: end;
131:
132: procedure TForm_Pengembalian.Button1Click(Sender: TObject);
133: var
134: d1,d2: real;
135: begin
136: listbox1.Items.Add(combobox2.Text);
137: Query.SQL.Add('select denda_telat,denda_hilang from tabel_buku where kd_buku="' +
combobox2.Text + '";');
138: Query.Active := true;
139: d1 := Query['denda_telat'];
140: d2 := Query['denda_hilang'];
141: Query.SQL.Clear;
142: Query.Active := false;
143: Query.SQL.Add('select tgl_kembali from tabel_peminjaman where id_anggota="' +
combobox1.Text + '" and kd_buku="' + combobox2.Text + '";');
144: Query.Active := true;
145: d1 := d1 * (Date - Query['tgl_kembali']);
146: Query.SQL.Clear;
147: Query.Active := false;
148:
149: edit3.Text := inttostr(listbox1.Items.Count);
150:
151: if (d1 > 0) then
152: edit4.Text := floattostr(strtofloat(edit4.Text) + d1);
153: if (rB2.Checked = true) then
154: begin
155: edit4.Text := floattostr(strtofloat(edit4.Text) + d2);
156: if (d1 < 0) then
157: listbox2.Items.Add(floattostr(d2))
158: else
159: listbox2.Items.Add(floattostr(d1 + d2));
160: listbox3.items.Add('1');
161: end
162: else
163: begin
164: if (d1 < 0) then
165: listbox2.Items.Add('0')
166: else
167: listbox2.Items.Add(floattostr(d1));
168: listbox3.Items.Add('0');
169: end;
170: Query.SQL.Clear;
171: Query.Active := false;
172: bitbtn1.Enabled := true;
173: button1.Enabled := false;
174: rB1.Enabled := false;
175: rB2.Enabled := false;
176: combobox2.DeleteSelected;
177: edit2.Clear;
178: end;
179:
180: procedure TForm_Pengembalian.BitBtn1Click(Sender: TObject);
181: var
182: i,j: integer;
183: begin
184: i := 0;
185: j := listbox1.Items.Count; //asyeeeem kelalen bae mesti kie nggon listbox, debug ngasi
ping satus.. kucluk..
186:
187: while (i < j) do
188: begin
189: Query.SQL.Add('select * from tabel_peminjaman where id_anggota="' + combobox1.Text +
'" and kd_buku="' + listbox1.Items[i] + '";');
190: Query.Active := true;
191: Query.Edit;
192: if listbox3.Items[i] = '0' then
193: Query['status'] := 0
194: else
195: Query['status'] := 2;
196: Query['denda'] := strtofloat(listbox2.Items[i]);
197: Query.Post;
198: Query.SQL.Clear;
199: Query.Active := false;
200: i := i + 1;
201: end;
202:
203: MessageDlg('Sukses!',mtInformation,[mbOk],0);
204: close;
205: end;
206:
207: procedure TForm_Pengembalian.BitBtn2Click(Sender: TObject);
208: begin
209: close;
210: end;
211:
212: procedure TForm_Pengembalian.FormClose(Sender: TObject;
213: var Action: TCloseAction);
214: begin
215: Form_Utama.Panel1.Show;
216: end;
217:
218: procedure TForm_Pengembalian.ComboBox1Exit(Sender: TObject);
219: begin
220: if combobox1.Text = '' then
221: combobox1.Enabled := true
222: else
223: combobox1.Enabled := false;
224: end;
225:
226: end.

Comments