Вы находитесь на странице: 1из 10

Transaksi One To One Buat Database di Acces 2003/2007 Tabel Jualbuku berikut ini :

Nama Field Type Data Size Keterangan Notrans Tgltrans Kodebuku Namabuku Harga Stok Jmlbeli Bayar Text Text Text Text Number Number Number Number 7 15 6 30 Primary Key

Setting Idtrans dari propertis inspector maxlength = 7 Buat ADOBUKU dan ADOJUAL dan buat 2 datasource juga yang saling koneksi ke tabel Buku dan tabel Jualbuku sesuaikan nama obyeknya juga

private { Private declarations } public procedure aktif; procedure pasif; procedure bersih; procedure tampil; procedure no_otomatis;

{ Public declarations } end;

var Form2: TForm2; isi:boolean; implementation {$R *.dfm} procedure tform2.aktif; begin e_trans.enabled:= true; e_tgl.enabled:= true; c_buku.enabled:= true; e_nama.Enabled:=true; e_harga.Enabled:=true; e_stok.Enabled:=true; e_jml.enabled:= true; e_byr.enabled:= true; e_ubay.enabled:= true; e_ukem.enabled:= true; end;

procedure tform2.pasif ; begin e_trans.enabled:= false; e_tgl.enabled:= false; c_buku.enabled:= false; e_nama.Enabled:=false; e_harga.Enabled:=false; e_stok.Enabled:=false; e_jml.enabled:= false; e_byr.enabled:= false; e_ubay.enabled:= false; e_ukem.enabled:= false; end;

procedure tform2.bersih; begin e_trans.Text:=''; e_tgl.Text:=datetostr(date()); c_buku.Text:=''; e_nama.Text:=''; e_harga.Text:='0'; e_stok.Text :='0'; e_jml.Text :='0';

e_byr.Text :='0'; e_ubay.Text :='0'; e_ukem.Text :='0'; end;

procedure tform2.no_otomatis; var nomor:integer; tgl,bln :string; begin tgl:=copy(e_tgl.Text,1,2); bln:=copy(e_tgl.Text,4,2); adojual.Refresh; If adojual.RecordCount = 0 Then begin e_trans.Text := 'T' +tgl+bln+'-'+'01' ; end else begin adojual.Last; nomor := strtoint(copy(adojual['notrans'],7,2)); //mengambil dr karakter 7 sebanyak 2 buah huruf inc(nomor);

if nomor<10 then e_trans.Text:='T' + tgl + bln +'-'+ '0' + inttostr(nomor) else e_trans.Text:='T' + tgl + bln +'-' + inttostr(nomor); e_trans.Enabled:=false; end; end;

procedure TForm2.FormActivate(Sender: TObject); begin pasif; bersih; e_tgl.Text:=datetostr(date()); b_add.Enabled := TRUE; b_save.Enabled := FALSE; end;

procedure TForm2.FormCreate(Sender: TObject); begin adobuku.First; while not adobuku.eof do begin

c_buku.Items.add(adobuku['kodebuku']); adobuku.Next; end; end;

procedure TForm2.b_addClick(Sender: TObject); begin if b_add.Caption='ADD' then begin b_add.Caption:='CANCEL'; b_save.Enabled := true; aktif ; bersih ; e_tgl.Text:=datetostr(date()); no_otomatis; end else begin b_add.caption:='ADD'; pasif ; bersih; end; end;

procedure TForm2.C_BUKUClick(Sender: TObject); begin if adobuku.locate('kodebuku',c_buku.Text,[]) then begin e_nama.Text:=adobuku['nmbuku']; e_harga.Text:=adobuku['harga']; e_stok.Text:=adobuku['stok']; e_jml.SetFocus; end; end;

procedure TForm2.E_JMLKeyPress(Sender: TObject; var Key: Char); begin if key=#13 then if strtoint(e_jml.Text)> strtofloat(e_stok.Text) then begin showmessage('Stok Abis'); e_jml.Text:=''; exit; end else begin

showmessage('OK'); e_byr.Text:=inttostr(strtoint(e_jml.Text)* strtoint(e_harga.Text)); e_ubay.SetFocus end end;

procedure TForm2.E_UBAYKeyPress(Sender: TObject; var Key: Char); begin if key=#13 then if strtoint(e_ubay.Text)< strtoint(e_byr.Text) then begin showmessage('KURANG'); e_ubay.Text :=''; exit; end else begin showmessage('OK'); e_ukem.Text:=inttostr(strtoint(e_ubay.Text)- strtoint(e_byr.Text)); e_ubay.Enabled:=false; e_ukem.Enabled:=false; end end;

procedure TForm2.b_saveClick(Sender: TObject); begin adojual.Append; adojual['notrans']:=e_trans.Text; adojual['tgltrans']:=e_tgl.Text; adojual['kodebuku']:=c_buku.Text; adojual['nmbuku']:=e_nama.Text; adojual['harga']:=e_harga.Text; adojual['stok']:=e_stok.Text; adojual['jmlbeli']:=e_jml.Text; adojual['bayar']:=e_byr.Text; adojual.Post ; b_add.Caption:='ADD'; pasif; end;

procedure TForm2.b_exitClick(Sender: TObject); begin if (application.MessageBox('EXIT?','ASK',MB_Yesno)=idyes)then close; end; end.