Aplikasi Perpustakaan - Edisi 2 (Form Daftar Anggota Baru)

Program Perpusatakaan.


Tampilan Menu Utama
1. Membuat Form Daftar Anggota Baru.

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

source code:
1: unit Unit4;
2:
3: interface
4:
5: uses
6: Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7: Dialogs, StdCtrls, XPMan, DB, ADODB;
8:
9: type
10: TForm_AnggotaBaru = class(TForm)
11: GroupBox1: TGroupBox;
12: Label1: TLabel;
13: Label2: TLabel;
14: Label3: TLabel;
15: Label4: TLabel;
16: Label5: TLabel;
17: Label6: TLabel;
18: Label7: TLabel;
19: Label8: TLabel;
20: Label9: TLabel;
21: Label10: TLabel;
22: Edit1: TEdit;
23: Edit2: TEdit;
24: Edit3: TEdit;
25: Edit5: TEdit;
26: Memo1: TMemo;
27: Edit6: TEdit;
28: Edit7: TEdit;
29: Edit8: TEdit;
30: Edit4: TEdit;
31: ComboBox1: TComboBox;
32: Button1: TButton;
33: Button2: TButton;
34: XPManifest1: TXPManifest;
35: Query: TADOQuery;
36: procedure FormActivate(Sender: TObject);
37: procedure Button2Click(Sender: TObject);
38: procedure Edit1Change(Sender: TObject);
39: procedure Edit2Change(Sender: TObject);
40: procedure Edit3Change(Sender: TObject);
41: procedure ComboBox1Click(Sender: TObject);
42: procedure Edit4Change(Sender: TObject);
43: procedure Memo1Change(Sender: TObject);
44: procedure Edit5Change(Sender: TObject);
45: procedure Edit6Change(Sender: TObject);
46: procedure Edit7Change(Sender: TObject);
47: procedure Edit8Change(Sender: TObject);
48: procedure Button1Click(Sender: TObject);
49: procedure FormClose(Sender: TObject; var Action: TCloseAction);
50: private
51: { Private declarations }
52: public
53: procedure CekForm;
54: { Public declarations }
55: end;
56:
57: var
58: Form_AnggotaBaru: TForm_AnggotaBaru;
59:
60: implementation
61:
62: uses unit2;
63:
64: {$R *.dfm}
65:
66: procedure TForm_AnggotaBaru.CekForm;
67: begin
68: 􀀁 􀀁
69: button1.Enabled := true
70: else
71: button1.Enabled := false;
72: end;
73:
74: procedure TForm_AnggotaBaru.FormActivate(Sender: TObject);
75: var
76: sSementara: string;
77: fJumlah: real;
78: begin
79: Combobox1.Items.Add('Laki-Laki');
80: Combobox1.Items.Add('Perempuan');
81: edit1.Clear;
82: edit2.Clear;
83: edit3.Clear;
84: edit4.Clear;
85: edit5.Clear;
86: edit6.Clear;
87: edit7.Clear;
88: edit8.Clear;
89: memo1.Clear;
90: sSementara := 'A' + FormatDateTime('ddmmyy',date);
91: Query.Connection := Form_Utama.Koneksi;
92: Query.SQL.Add('select count(*) as jumlah from tabel_anggota where id_anggota like "' +
sSementara + '___";');
93: Query.Active := true;
94: fJumlah := Query['jumlah'] + 1;
95: if fJumlah = 0 then
96: begin
97: edit1.Text := sSementara + '001';
98: end
99: else
100: begin
101: if (fJumlah > 0) and (fJumlah < 10) then
102: edit1.Text := sSementara + '00' + floattostr(fJumlah)
103: else if (fJumlah >= 10) and (fJumlah < 100) then
104: edit1.Text := sSementara + '0' + floattostr(fJumlah)
105: else
106: edit1.Text := sSementara + floattostr(fJumlah);
107: end;
108: Query.Active := false;
109: Query.SQL.Clear;
110: combobox1.ItemIndex := 0;
111: end;
112:
113: procedure TForm_AnggotaBaru.Button2Click(Sender: TObject);
114: begin
115: close;
116: end;
117:
118: procedure TForm_AnggotaBaru.Edit1Change(Sender: TObject);
119: begin
120: CekForm;
121: end;
122:
123: procedure TForm_AnggotaBaru.Edit2Change(Sender: TObject);
124: begin
125: CekForm;
126: end;
127:
128: procedure TForm_AnggotaBaru.Edit3Change(Sender: TObject);
129: begin
130: CekForm;
131: end;
132:
133: procedure TForm_AnggotaBaru.ComboBox1Click(Sender: TObject);
134: begin
135: CekForm;
136: end;
137:
138: procedure TForm_AnggotaBaru.Edit4Change(Sender: TObject);
139: begin
140: CekForm;
141: end;
142:
143: procedure TForm_AnggotaBaru.Memo1Change(Sender: TObject);
144: begin
145: CekForm;
146: end;
147:
148: procedure TForm_AnggotaBaru.Edit5Change(Sender: TObject);
149: begin
150: CekForm;
151: end;
152:
153: procedure TForm_AnggotaBaru.Edit6Change(Sender: TObject);
154: begin
155: CekForm;
156: end;
157:
158: procedure TForm_AnggotaBaru.Edit7Change(Sender: TObject);
159: begin
160: CekForm;
161: end;
162:
163: procedure TForm_AnggotaBaru.Edit8Change(Sender: TObject);
164: begin
165: CekForm;
166: end;
167:
168: procedure TForm_AnggotaBaru.Button1Click(Sender: TObject);
169: begin
170: Query.Connection := Form_Utama.Koneksi;
171: Query.SQL.Add('select * from tabel_anggota;');
172: Query.Active := true;
173: memo1.Lines.Delimiter := #13;
174: Query.InsertRecord([edit1.Text, edit2.Text, edit3.Text, combobox1.Text, edit4.Text,
memo1.Lines.DelimitedText, edit5.Text, edit6.Text, edit7.Text, edit8.Text]);
175: Query.Refresh;
176: messagedlg('ID ' + edit1.Text + ' berhasil didaftarkan!',mtInformation,[mbOk],0);
177: Query.Active := false;
178: Query.SQL.Clear;
179: self.Close;
180: end;
181:
182: procedure TForm_AnggotaBaru.FormClose(Sender: TObject;
183: var Action: TCloseAction);
184: begin
185: Form_Utama.Panel1.Show;
186: end;
187:

188: end.

Comments