Aplikasi Perpustakaan - Edisi 4 (Form Data Buku)

Program Perpustakaan.


Tampilan Menu Utama
1. Membuat Form Data Buku.

Buatlah sebuah Form baru untuk form Data Buku. Apabila kalian sudah menambahkan form coba kalian masukan koding di bawah ini.

source code:
1: unit Unit7;
2:
3: interface
4:
5: uses
6: Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7: Dialogs, StdCtrls, DB, ADODB, XPMan;
8:
9: type
10: TForm_DataBuku = class(TForm)
11: XPManifest1: TXPManifest;
12: GroupBox1: TGroupBox;
13: ListBox1: TListBox;
14: Label1: TLabel;
15: Edit1: TEdit;
16: Label2: TLabel;
17: Edit2: TEdit;
18: Label3: TLabel;
19: Edit3: TEdit;
20: Label4: TLabel;
21: Edit4: TEdit;
22: Label5: TLabel;
23: Edit5: TEdit;
24: Edit6: TEdit;
25: Label6: TLabel;
26: Label7: TLabel;
27: Edit7: TEdit;
28: Label8: TLabel;
29: Edit8: TEdit;
30: Label9: TLabel;
31: Edit9: TEdit;
32: GroupBox2: TGroupBox;
33: Button1: TButton;
34: Button2: TButton;
35: Button3: TButton;
36: Button4: TButton;
37: Button6: TButton;
38: Label10: TLabel;
39: Edit10: TEdit;
40: Query: TADOQuery;
41: procedure FormActivate(Sender: TObject);
42: procedure ListBox1Click(Sender: TObject);
43: procedure Button1Click(Sender: TObject);
44: procedure Button2Click(Sender: TObject);
45: procedure FormClose(Sender: TObject; var Action: TCloseAction);
46: procedure Button6Click(Sender: TObject);
47: procedure Button3Click(Sender: TObject);
48: procedure Button4Click(Sender: TObject);
49: private
50: { Private declarations }
51: public
52: procedure bersih;
53: procedure aktif;
54: procedure nonaktif;
55: procedure otomatis;
56: procedure tombol(const bTambah,bSimpan,bEdit,bHapus: Boolean);
57: { Public declarations }
58: end;
59:
60: var
61: Form_DataBuku: TForm_DataBuku;
62: bTambahRecord: Boolean;
63:
64: implementation
65:
66: uses unit2;
67:
68: {$R *.dfm}
69:
70: procedure TForm_DataBuku.bersih;
71: begin
72: listbox1.Clear;
73: edit1.Clear;
74: edit2.Clear;
75: edit3.Clear;
76: edit4.Clear;
77: edit5.Clear;
78: edit6.Clear;
79: edit7.Clear;
80: edit8.Clear;
81: edit9.Clear;
82: edit10.Clear;
83: end;
84:
85: procedure TForm_DataBuku.nonaktif;
86: begin
87: edit1.ReadOnly := true;
88: edit2.ReadOnly := true;
89: edit3.ReadOnly := true;
90: edit4.ReadOnly := true;
91: edit5.ReadOnly := true;
92: edit6.ReadOnly := true;
93: edit7.ReadOnly := true;
94: edit8.ReadOnly := true;
95: edit9.ReadOnly := true;
96: edit10.ReadOnly := true;
97: listbox1.Enabled := true;
98: end;
99:
100: procedure TForm_DataBuku.aktif;
101: begin
102: edit1.ReadOnly := false;
103: edit2.ReadOnly := false;
104: edit3.ReadOnly := false;
105: edit4.ReadOnly := false;
106: edit5.ReadOnly := false;
107: edit6.ReadOnly := false;
108: edit7.ReadOnly := false;
109: edit8.ReadOnly := false;
110: edit9.ReadOnly := false;
111: edit10.ReadOnly := false;
112: listbox1.Enabled := false;
113: end;
114:
115: procedure TForm_DataBuku.tombol(const bTambah,bSimpan,bEdit,bHapus: Boolean);
116: begin
117: button1.Enabled := bTambah;
118: button2.Enabled := bSimpan;
119: button3.Enabled := bEdit;
120: button4.Enabled := bHapus;
121: end;
122:
123: procedure TForm_DataBuku.otomatis;
124: begin
125: bersih;
126: Query.SQL.Add('select kd_buku from tabel_buku;');
127: Query.Active := true;
128:
129: if Query.RecordCount = 0 then
130: begin
131: Tombol(true,false,false,false);
132: MessageDlg('Kosong!',mtInformation,[mbOk],0);
133: end
134: else
135: begin
136: Tombol(true,false,true,true);
137:
138: while not Query.Eof do
139: begin
140: listbox1.Items.Add(Query['kd_buku']);
141: Query.Next;
142: end;
143:
144: end;
145: Query.Active := false;
146: Query.SQL.Clear;
147: nonaktif;
148: end;
149:
150: procedure TForm_DataBuku.FormActivate(Sender: TObject);
151: begin
152: Query.Connection := Form_Utama.Koneksi;
153: otomatis;
154: end;
155:
156: procedure TForm_DataBuku.ListBox1Click(Sender: TObject);
157: var
158: i: integer;
159: begin
160: i := listbox1.ItemIndex;
161: if i < 0 then
162: exit;
163: Query.SQL.Add('select * from tabel_buku where kd_buku="' + listbox1.Items[i] + '";');
164: Query.Active := true;
165:
166: edit1.Text := Query['kd_buku'];
167: edit2.Text := Query['judul'];
168: edit3.Text := Query['penulis'];
169: edit4.Text := Query['penerbit'];
170: edit5.Text := Query['tahun'];
171: edit6.Text := Query['isbn'];
172: edit7.Text := Query['kategori'];
173: edit8.Text := Query['bahasa'];
174: edit9.Text := Query['denda_telat'];
175: edit10.Text := Query['denda_hilang'];
176:
177: Query.Active := false;
178: Query.SQL.Clear;
179: end;
180:
181: procedure TForm_DataBuku.Button1Click(Sender: TObject);
182: var
183: jumlah: integer;
184: begin
185: aktif;
186: bersih;
187: Tombol(false,true,false,false);
188: bTambahRecord := true;
189:
190: edit1.Text := 'B' + FormatDateTime('ddmmyyyy',date);
191:
192: Query.SQL.Add('select count(*) as jumlah from tabel_buku where kd_buku like "' +
edit1.Text + '___";');
193: Query.Active := true;
194:
195: jumlah := Query['jumlah'] + 1;
196:
197: Query.Active := false;
198: Query.SQL.Clear;
199:
200: if (jumlah = 0) then
201: begin
202: edit1.Text := edit1.Text + '001';
203: end
204: else
205: begin
206: if (jumlah > 0) and (jumlah < 10) then
207: edit1.Text := edit1.Text + '00' + inttostr(jumlah)
208: else if (jumlah >= 10) and (jumlah < 100) then
209: edit1.Text := edit1.Text + '0' + inttostr(jumlah)
210: else
211: edit1.Text := edit1.Text + inttostr(jumlah);
212: end;
213: edit2.SetFocus;
214: end;
215:
216: procedure TForm_DataBuku.Button2Click(Sender: TObject);
217: var
218: jumlah: integer;
219: begin
220: 􀀁 􀀁
221: begin
222: MessageDlg('Cek kembali form isian!',mtError,[mbOk],0);
223: end
224: else
225: begin
226: if (bTambahRecord = true) then
227: begin
228: Query.SQL.Add('select count(*) as jumlah from tabel_buku where kd_buku like "' +
edit1.Text + '";');
229: Query.Active := true;
230:
231: jumlah := Query['jumlah'];
232:
233: Query.Active := false;
234: Query.SQL.Clear;
235:
236: if jumlah > 0 then
237: begin
238: MessageDlg('Kode buku sudah terpakai!',mtError,[mbOk],0);
239: end
240: else
241: begin
242: Query.SQL.Add('select * from tabel_buku;');
243: Query.Active := true;
244: Query.Insert;
245:
246: Query['kd_buku'] := edit1.Text;
247: Query['judul'] := edit2.Text;
248: Query['penulis'] := edit3.Text;
249: Query['penerbit'] := edit4.Text;
250: Query['tahun'] := strtoint(edit5.Text);
251: Query['isbn'] := edit6.Text;
252: Query['kategori'] := edit7.Text;
253: Query['bahasa'] := edit8.Text;
254: Query['denda_telat'] := strtofloat(edit9.Text);
255: Query['denda_hilang'] := strtofloat(edit10.Text);
256:
257: Query.Post;
258: Query.Active := false;
259: Query.SQL.Clear;
260: MessageDlg('Sukses!',mtInformation,[mbOk],0);
261: otomatis;
262: end;
263: end
264: else
265: begin
266: Query.SQL.Add('select * from tabel_buku where kd_buku="' + edit1.Text + '";');
267: Query.Active := true;
268: Query.Edit;
269:
270: Query['judul'] := edit2.Text;
271: Query['penulis'] := edit3.Text;
272: Query['penerbit'] := edit4.Text;
273: Query['tahun'] := strtoint(edit5.Text);
274: Query['isbn'] := edit6.Text;
275: Query['kategori'] := edit7.Text;
276: Query['bahasa'] := edit8.Text;
277: Query['denda_telat'] := strtofloat(edit9.Text);
278: Query['denda_hilang'] := strtofloat(edit10.Text);
279:
280: Query.Post;
281: Query.Active := false;
282: Query.SQL.Clear;
283: MessageDlg('Sukses!',mtInformation,[mbOk],0);
284: otomatis;
285: end;
286: end;
287: end;
288:
289: procedure TForm_DataBuku.FormClose(Sender: TObject;
290: var Action: TCloseAction);
291: begin
292: Form_Utama.Panel1.Show;
293: end;
294:
295: procedure TForm_DataBuku.Button6Click(Sender: TObject);
296: begin
297: close;
298: end;
299:
300: procedure TForm_DataBuku.Button3Click(Sender: TObject);
301: begin
302: aktif;
303: bTambahRecord := false;
304: Tombol(false,true,false,false);
305: edit1.ReadOnly := true;
306: edit2.SetFocus;
307: end;
308:
309: procedure TForm_DataBuku.Button4Click(Sender: TObject);
310: begin
311: if Listbox1.ItemIndex < 0 then
312: begin
313: MessageDlg('Pilih dulu!',mtError,[mbOk],0);
314: end
315: else
316: begin
317: if MessageDlg('Yakin ingin menghapus "' + edit2.Text + '"
?',mtConfirmation,[mbYes,mbNo],0) = mrYes then
318: begin
319: Query.SQL.Add('select * from tabel_buku where kd_buku="' + edit1.Text + '";');
320: Query.Active := true;
321:
322: Query.Delete;
323: Query.Refresh;
324:
325: Query.Active := false;
326: Query.SQL.Clear;
327: MessageDlg('Sukses!',mtInformation,[mbOk],0);
328: otomatis;
329: end;
330: end;
331: end;
332:
333: end.

Comments

  1. The Ultimate Guide to Slots & casino games - DrmCD
    Casino and 밀양 출장샵 games can be enjoyed in other forms such as 시흥 출장마사지 slots, table 안동 출장안마 games, video 안동 출장마사지 poker, video poker, and blackjack. We discuss some 서울특별 출장마사지 strategies for

    BalasHapus