Kodingnya adalah :
Double klik Tombol Update lalu ketikkan listing koding berikut :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| procedure TForm2.Button6Click(Sender: TObject);var jumlah : integer;stock:integer;beginadoquery5.SQL.Clear;adoquery5.SQL.Add('Select * from djual WHERE no_faktur = "'+ edit1.Text +'" and kode_barang ="'+ DBLookupComboBox2.KeyValue+'" ');adoquery5.Open;if not adoquery5.Eof thenbeginadoquery1.SQL.Clear;adoquery1.SQL.Add('select * from barang where kode_barang="'+DBLookupComboBox2.KeyValue+'"');adoquery1.open;jumlah := adoquery5.Fields[3].AsInteger + adoquery1.Fields[3].AsInteger;stock := jumlah - strtoint(edit2.Text);adoquery1.SQL.Clear;adoquery1.SQL.Add('update barang set stock="'+inttostr(stock)+'" where kode_barang="'+DBLookupComboBox2.KeyValue+'"');adoquery1.ExecSQL;adoquery5.SQL.Clear;adoquery5.SQL.Add('update penjualan set tgl_faktur="'+datetostr(DateTimePicker1.Date)+'", id_pembeli="'+ DBLookupComboBox1.KeyValue +'" where no_Faktur="'+edit1.Text+'"');adoquery5.ExecSQL;adoquery4.sql.Clear;adoquery4.SQL.add('update djual set jumlah="'+ edit2.Text +'", harga ="'+ edit3.Text +'" where no_Faktur="'+ edit1.Text +'" and kode_barang="'+ DBLookupComboBox2.KeyValue +'"');adoquery4.ExecSQL;adoquery1.SQL.Clear;adoquery1.SQL.Add('select * from barang');adoquery1.open;endelsebeginadoquery4.SQL.Clear;adoquery4.SQL.Add('insert into Djual(no_faktur,kode_barang,jumlah,harga)values("'+edit1.text+'","'+DBLookupComboBox2.KeyValue+'","'+ edit2.Text +'","'+edit3.Text+'")');adoquery4.ExecSQL;tampildb();end;tampildb();kosongbarang();end; |
2. Buatlah Procedure TAmpildb dan kosongbarang;
<strong>a. Procedure Tampil Database</strong>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| procedure TForm2.tampildb();beginadoquery4.Close;adoquery4.SQL.Clear;adoquery4.SQL.Add('select no_Faktur,kode_barang,harga,jumlah, (harga*jumlah) as total from djual where no_Faktur = "'+ edit1.text +'"');adoquery4.Open;datasource4.DataSet := adoquery4;dbgrid1.DataSource := datasource4;adoquery5.Close;adoquery5.SQL.clear;adoquery5.SQL.add('select sum(harga*jumlah) from djual where no_Faktur = "'+ edit1.text +'"');adoquery5.Open;edit4.Text := adoquery5.Fields[0].AsString;end; |
a. Procedure Kosong
1
2
3
4
5
6
7
8
| procedure TForm2.kosongbarang();beginDBLookupComboBox2.KeyValue:='';dbedit3.Text:='';dbedit4.Text:='';edit2.Text:='';edit3.Text:='';End; |
3. Double Klik Pada Edit2 (Jumlah), lalu rubah pada event di properties menjadi On KeyPress, selanjutnya ketik listing berikut :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| procedure TForm2.Edit2KeyPress(Sender: TObject; var Key: Char);VAR SISA:INTEGER;beginIF KEY=#13 THENBEGIN IF (ADOQUERY1.Fields[3].AsInteger < sTRTOINT(eDIT2.Text)) then BEGIN Application.MessageBox('DATA TIDAK CUKUP','cONTROL',MB_ICONSTOP); END; EDIT3.Text := INTTOSTR(STRTOINT(DBEDIT4.Text) * STRTOINT(EDIT2.TEXT)); SISA:= ADOQUERY1.Fields[3].AsInteger - STRTOINT(EDIT2.Text); ADOQUERY6.Close; ADOQUERY6.SQL.CLEAR; ADOQUERY6.SQL.Add('UPDATE BARANG SET STOCK = "'+ inttostr(SISA) +'" WHERE KODE_BARANG = "'+ ADOQUERY1.Fields[0].ASSTRING +'"'); ADOQUERY6.ExecSQL;END; |
4. Double klik Tombol Save, lalu ketikkan listing berikut :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| procedure TForm2.Button3Click(Sender: TObject);var i : integer;beginadoquery3.SQL.Clear;adoquery3.SQL.add('insert into Penjualan(no_faktur,id_pembeli,tgl_faktur)values("'+ edit1.Text +'","'+DBLookupCombobox1.Text+'","'+DateToStr(DateTimePicker1.Date)+'")');adoquery3.ExecSQL;for i := 1 to SG.RowCount-1 dobeginadoquery4.SQL.Clear;adoquery4.SQL.Add('insert into Djual(no_faktur,kode_barang,jumlah,harga)values("'+edit1.text+'","'+ sg.Cells[1,i] +'","'+ edit2.Text +'","'+edit3.Text+'")');adoquery4.ExecSQL;end;end; |
Source : https://ahmadrizal.wordpress.com/2011/01/20/pemrograman-delphi-6-aplikasi-pengolahan-transaksi-pembelian-barang-form-transaksi-pembelian-barang/

No comments:
Post a Comment