Nama: Rahmat Darmawan NIM: 5140411186 Jurusan: Teknik Informatika C / Pcs X
Nama: Rahmat Darmawan NIM: 5140411186 Jurusan: Teknik Informatika C / Pcs X
: RAHMAT DARMAWAN
NIM
: 5140411186
JURUSAN
1. Tampilan form
2. Run program
3. Input data
5. Tampilkan data
6. Clear DBgrid
Syntax :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Grids, DBGrids;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit4: TEdit;
ComboBox1: TComboBox;
Button1: TButton;
dbgrd1: TDBGrid;
edt1: TEdit;
Edit3: TEdit;
Edit5: TEdit;
btn1: TButton;
Button2: TButton;
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
ds1: TDataSource;
Button3: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure edt1KeyPress(Sender: TObject; var Key: Char);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
procedure simpan;
procedure ubah;
procedure cari;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.simpan;
begin
with ADOQuery1 do
begin
Active:=False;
Close;
SQL.Clear;
SQL.Text:='insert into mhs values('+QuotedStr(Edit1.Text)+','+
QuotedStr(Edit2.Text)+','+
QuotedStr(ComboBox1.Text)+','+
QuotedStr(Edit3.Text)+','+
QuotedStr(Edit4.Text)+','+
QuotedStr(Edit5.Text)+')';
ExecSQL;
end;
end;
procedure TForm1.ubah;
begin
with ADOQuery1 do
begin
Active:=False;
Close;
SQL.Clear;
SQL.Text:='update mhs set nama='+QuotedStr(Edit2.Text)+
', jurusan='+QuotedStr(ComboBox1.Text)+
', buku_pinjam='+QuotedStr(Edit3.Text)+
', tgl_pinjam='+QuotedStr(Edit4.Text)+
', tgl_kembali='+QuotedStr(Edit5.Text)+
'where nim='+QuotedStr(Edit1.Text);
ExecSQL;
end;
end;
procedure TForm1.cari;
begin
with ADOQuery1 do
begin
Active:=False;
Close;
SQL.Clear;
SQL.Text:='select * from mhs where nim='+QuotedStr(Edit1.Text)+'';
Active:=True;
end;
end;
ShowMessage('Gagal Simpan');
Edit1.SetFocus;
end;
end
else
begin
try ADOConnection1.BeginTrans;
ubah;
ADOConnection1.CommitTrans;
ShowMessage('Berhasil ubah');
except ADOConnection1.RollbackTrans;
ShowMessage('Gagal ubah');
Edit1.SetFocus;
end;
end;
end;
btn1.Click;
end;
procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then
begin
cari;
if ADOQuery1.IsEmpty then
begin
Button1.Caption:='SIMPAN';
Edit2.SetFocus
end
else
begin
Button1.Caption:='UBAH';
Edit2.Text:=ADOQuery1['nama'];
ComboBox1.Text:=ADOQuery1['jurusan'];
Edit3.Text:=ADOQuery1['buku_pinjam'];
Edit4.Text:=ADOQuery1['tgl_pinjam'];
Edit5.Text:=ADOQuery1['tgl_kembali'];
end;
end;
end;
end;
end;
end;
end;
end.