Form Trans Aks I
Form Trans Aks I
Recordset Public rsdetail As New ADODB.Recordset Public rstrans As New ADODB.Recordset Public rssem As New ADODB.Recordset Public Sub koneksi() dbpenj.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=penjualan_ynt" dbpenj.Open End Sub FORM BARANG
Dim isibrg As Boolean Sub refresh_tabel() strbrg = "select * from barang order by kdbrg" Set rsbrg = dbpenj.Execute(strbrg, , adCmdText) Set grid1.DataSource = rsbrg grid1.Refresh End Sub Function tombol(tambah, simpan, hapus, batal, ubah, keluar As Boolean) CMDADD.Enabled = tambah CMDSAVE.Enabled = simpan CMDDELETE.Enabled = hapus CMDCANCEL.Enabled = batal CMDEDIT.Enabled = ubah CMDEXIT.Enabled = keluar End Function Sub tampil() TXTNMBRG.Text = rsbrg.Fields("nmbrg") TXTHARGA.Text = rsbrg.Fields("harga") TXTSTOK.Text = rsbrg.Fields("stok") End Sub Sub bersih() For Each X In Me If TypeName(X) = "TextBox" Then X.Text = "" Next End Sub
Created by YNT
VisualBasicLanjutan Sub tdkaktif() For Each X In Me If TypeName(X) = "TextBox" Then X.Enabled = False Next End Sub Sub aktif() For Each X In Me If TypeName(X) = "TextBox" Then X.Enabled = True Next End Sub Sub warna_aktif() For Each X In Me If TypeName(X) = "TextBox" Then X.BackColor = &H80000009 Next End Sub Sub warna_tdkaktif() For Each X In Me If TypeName(X) = "TextBox" Then X.BackColor = &H8000000B Next End Sub Private Sub cmdAdd_Click() tombol False, True, False, True, False, False aktif bersih warna_aktif TXTKDBRG.SetFocus End Sub Private Sub CMDCANCEL_Click() tdkaktif bersih warna_tdkaktif tombol True, False, False, False, False, True End Sub Private Sub cmdDelete_Click() Dim cari As String Dim hapus As String cari = "select * from barang where kdbrg='" & TXTKDBRG & "'" hapus = "delete from barang where kdbrg='" & TXTKDBRG & "'" Set rsbrg = dbpenj.Execute(cari, , adCmdText) With rsbrg If .BOF And .EOF Then MsgBox "kode barang tidak ada" Else n = MsgBox("Yakin ingin hapus data?", vbQuestion + vbYesNo, "Perhatian") If n = vbYes Then Set rsbrg = dbpenj.Execute(hapus, , adCmdText) refresh_tabel End If End If Created by YNT
VisualBasicLanjutan End With bersih tdkaktif warna_tdkaktif tombol True, False, False, False, False, True End Sub Private Sub CMDEDIT_Click() isibrg = False aktif tombol False, True, False, True, False, False TXTNMBRG.SetFocus TXTKDBRG.Enabled = False End Sub Private Sub CMDEXIT_Click() r = MsgBox("Ingin keluar?", vbQuestion + vbYesNo, "Info") If r = vbYes Then Unload Me End If End Sub Private Sub cmdsave_Click() Dim simpan As String Dim ubah As String If TXTKDBRG = "" Or TXTNMBRG = "" Or TXTHARGA = "" Or TXTSTOK = "" Then MsgBox ("Data Belum Lengkap") Else If isibrg = True Then simpan = "insert into barang values('" & TXTKDBRG & "','" & TXTNMBRG & "','" & TXTHARGA & "', '" & TXTSTOK & "')" Set rsbrg = dbpenj.Execute(simpan, , adCmdText) MsgBox "data sudah tersimpan" Else ubah = "update barang set nmbrg ='" & TXTNMBRG & "',harga='" & TXTHARGA & "', stok='" & TXTSTOK & "' where kdbrg ='" & TXTKDBRG & "'" Set rsbrg = dbpenj.Execute(ubah, , adCmdText) MsgBox "data sudah terupdate" End If End If refresh_tabel tombol True, False, False, False, False, True bersih tdkaktif warna_tdkaktif End Sub Private Sub Form_Activate() isibrg = True End Sub Private Sub Form_Load() tombol True, False, False, False, False, True tdkaktif warna_tdkaktif Created by YNT
VisualBasicLanjutan Call koneksi refresh_tabel End Sub Private Sub TXTKDBRG_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Dim cari As String cari = "select * from barang where kdbrg='" & TXTKDBRG & "'" Set rsbrg = dbpenj.Execute(cari, , adCmdText) With rsbrg If .BOF And .EOF Then t = MsgBox("Kode " & TXTKDBRG & " belum ada, mo tambah data lagi?", vbYesNo + vbQuestion, "Konfirmasi") If t = vbYes Then isibrg = True TXTNMBRG.SetFocus grid1.Refresh tombol False, True, False, True, False, False Else refresh_tabel End If Else MsgBox ("Kode Barang sudah ada") tampil tombol True, False, True, False, True, False TXTKDBRG.Enabled = False tdkaktif End If End With End If End Sub FORM CUSTOMER
Dim isicust As Boolean Sub tampil() TXTKDCUST.Text = rscust.Fields("kdcust") TXTNMCUST.Text = rscust.Fields("nmcust") TXTALAMAT.Text = rscust.Fields("alamat") TXTTELP.Text = rscust.Fields("telp") End Sub Sub refresh_tabel() strcust = "select * from customer order by kdcust"
Created by YNT
VisualBasicLanjutan Set rscust = dbpenj.Execute(strcust, , adCmdText) Set grid1.DataSource = rscust grid1.Refresh End Sub Function tombol(tambah, simpan, batal, ubah, cari, hapus, keluar As Boolean) CMDADD.Enabled = tambah CMDSAVE.Enabled = simpan CMDCANCEL.Enabled = batal CMDEDIT.Enabled = ubah CMDFIND.Enabled = cari CMDDELETE.Enabled = hapus CMDEXIT.Enabled = keluar End Function Sub bersih() For Each X In Me If TypeName(X) = "TextBox" Then X.Text = "" Next End Sub Sub aktif() For Each X In Me If TypeName(X) = "TextBox" Then X.Enabled = True Next End Sub Sub tdkaktif() For Each X In Me If TypeName(X) = "TextBox" Then X.Enabled = False Next End Sub Sub nomat() Dim sqlcust As String sqlcust = "SELECT *FROM customer ORDER BY kdcust desc" Set rscust = dbpenj.Execute(sqlcust, , adCmdText) If rscust.BOF And rscust.EOF Then TXTKDCUST = "C001" Else rscust.MoveFirst TXTKDCUST.Text = "C00" & LTrim(Right(Str(Val(Right(rscust!kdcust, 3)) + 1), 3)) End If End Sub Private Sub cmdAdd_Click() nomat aktif TXTNMCUST.SetFocus tombol False, True, True, False, False, False, False End Sub Private Sub CMDCANCEL_Click() tdkaktif tombol True, False, False, False, False, False, True bersih Created by YNT
VisualBasicLanjutan End Sub Private Sub cmdDelete_Click() Dim hapus As String hapus = "delete from customer where kdcust='" & TXTKDCUST & "'" Set rscust = dbpenj.Execute(hapus, , adCmdText) n = MsgBox("Yakin ingin hapus data?", vbQuestion + vbYesNo, "Perhatian") If n = vbYes Then Set rscust = dbpenj.Execute(hapus, , adCmdText) refresh_tabel End If bersih tdkaktif tombol True, False, False, False, True, False, True End Sub Private Sub CMDEDIT_Click() isicust = False TXTKDCUST.Enabled = False tombol False, True, True, False, False, False, False End Sub Private Sub CMDEXIT_Click() n = MsgBox("Keluar?", vbQuestion + vbYesNo, "Info") If n = vbYes Then Unload Me End If End Sub Private Sub CMDFIND_Click() Dim cari As String n = InputBox("Kode Customer", "Kode Customer", 0) cari = "select * from customer where kdcust='" & n & "'" Set rscust = dbpenj.Execute(cari, , adCmdText) With rscust If .BOF And .EOF Then MsgBox ("Kode Customer Tidak ditemukan") Else tampil tombol False, False, False, True, fale, True, False aktif TXTKDCUST.Enabled = False End If End With End Sub Private Sub cmdsave_Click() Dim simpan As String Dim ubah As String If TXTNMCUST = "" Or TXTALAMAT = "" Or TXTTELP = "" Then MsgBox ("Data Belum Lengkap") Else If isicust = True Then simpan = "insert into customer values('" & TXTKDCUST & "','" & TXTNMCUST & "','" & TXTALAMAT & "', '" & TXTTELP & "')" Set rscust = dbpenj.Execute(simpan, , adCmdText) Created by YNT
VisualBasicLanjutan MsgBox "data sudah tersimpan" Else ubah = "update customer set nmcust ='" & TXTNMCUST & "',alamat ='" & TXTALAMAT & "', telp='" & TXTTELP & "' where kdcust ='" & TXTKDCUST & "'" Set rscust = dbpenj.Execute(ubah, , adCmdText) MsgBox "data sudah terupdate" End If End If refresh_tabel tombol True, False, False, False, True, False, True bersih tdkaktif End Sub Private Sub Form_Activate() isicust = True End Sub Private Sub Form_Load() Call koneksi refresh_tabel tombol True, False, False, False, True, False, True tdkaktif End Sub FORM TRANSAKSI
Sub refresh_semtrans() sqlsem = "select * from semtransaksi" Set rssem = dbpenj.Execute(sqlsem, , adCmdText) Set grid1.DataSource = rssem End Sub Sub nomat() Dim sqltrans As String sqltrans = "SELECT *FROM transaksi ORDER BY NoTransaksi desc" Set rstrans = dbpenj.Execute(sqltrans, , adCmdText) If rstrans.BOF And rstrans.EOF Then txtnotrans.Text = Format("F") & "0001" Else
Created by YNT
VisualBasicLanjutan rstrans.MoveFirst txtnotrans.Text = Format("F") & Format(Val(Right(rstrans!NoTransaksi, 4)) + 1, "000") End If End Sub Function tombol(tambah, simpan, batal, keluar As Boolean) cmdadd.Enabled = tambah cmdsave.Enabled = simpan cmdcancel.Enabled = batal cmdexit.Enabled = keluar End Function Sub aktif() cmbpel.Enabled = True cmbbrg.Enabled = True txtqty.Enabled = True txtubay.Enabled = True End Sub Sub tdkaktif() For Each X In Me If TypeName(X) = "TextBox" Or TypeName(X) = "ComboBox" Then X.Enabled = False Next End Sub Sub bersih() For Each X In Me If TypeName(X) = "TextBox" Or TypeName(X) = "ComboBox" Then X.Text = "" Next End Sub Private Sub cmbbrg_Click() Dim caribrg As String caribrg = "select * from barang where kdbrg='" & cmbbrg.Text & "'" Set rsbrg = dbpenj.Execute(caribrg, , adCmdText) If Not rsbrg.EOF Then txtnmbrg.Text = rsbrg.Fields("nmbrg") txthrgbrg.Text = rsbrg.Fields("harga") txtstok.Text = rsbrg.Fields("stok") End If txtqty.SetFocus End Sub Private Sub cmbpel_Click() Dim caricust As String caricust = "select * from customer where kdcust='" & cmbpel.Text & "'" Set rscust = dbpenj.Execute(caricust, , adCmdText) If Not rscust.EOF Then txtnmpel.Text = rscust.Fields("nmcust") End If End Sub Private Sub cmdAdd_Click() aktif tombol False, True, True, False Created by YNT
VisualBasicLanjutan nomat End Sub Private Sub cmdcancel_Click() bersih tdkaktif tombol True, False, False, True hapus = "delete from semtransaksi" Set rssem = dbpenj.Execute(hapus, , adCmdText) refresh_semtrans End Sub Private Sub cmdexit_Click() Unload Me End Sub Private Sub CMDSAVE_Click() On Error Resume Next Dim simpan As String If txtnotrans.Text = "" Or cmbpel.Text = "" Or txttobay.Text = "" Then MsgBox "data belum lengkap" End If Call koneksi simpan = "insert into transaksi values('" & txtnotrans.Text & "','" & Label2.Caption & "','" & cmbpel.Text & "', '" & txttobay.Text & "')" Set rstrans = dbpenj.Execute(simpan, , adCmdText) MsgBox "data sudah tersimpan" sqlsem = "select * from semtransaksi" Set rssem = dbpenj.Execute(sqlsem, , adCmdText) Do While Not rssem.EOF If rssem!kdbrg <> vbNullString Then Dim simpandetail As String simpandetail = "insert into detailtransaksi values('" & txtnotrans.Text & "','" & rssem!kdbrg & "','" & rssem!qty & "','" & rssem!subtotal & "')" dbpenj.Execute simpandetail hapus = "delete from semtransaksi" dbpenj.Execute hapus End If rssem.MoveNext Loop refresh_semtrans End Sub Private Sub Form_Activate() Call koneksi Dim caribrg, caricust As String caribrg = "select * from barang" Set rsbrg = dbpenj.Execute(caribrg, , adCmdText) Do Until rsbrg.EOF cmbbrg.AddItem rsbrg!kdbrg rsbrg.MoveNext Loop caricust = "select * from customer" Set rscust = dbpenj.Execute(caricust, , adCmdText) Created by YNT
VisualBasicLanjutan Do Until rscust.EOF cmbpel.AddItem rscust!kdcust rscust.MoveNext Loop refresh_semtrans tombol True, False, False, True bersih tdkaktif End Sub Private Sub Form_Load() tombol True, False, False, True bersih tdkaktif End Sub Private Sub Timer1_Timer() Label2.Caption = Format(Date, "yyyy-mm-dd") End Sub Private Sub txtqty_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Dim sqlbrg, sqlsem, upbrg, savesem As String sqlbrg = "select * from barang" Set rsbrg = dbpenj.Execute(sqlbrg, , adCmdText) txtst.Text = Val(txthrgbrg.Text) * Val(txtqty.Text) If Val(txtstok.Text) < Val(txtqty.Text) Then MsgBox "Stok Kurang" Else a = Val(txtstok.Text) - Val(txtqty.Text) upbrg = "update barang set stok='" & a & "' where kdbrg='" & cmbbrg.Text & "'" Set rsbrg = dbpenj.Execute(upbrg, , adCmdText) sqlsem = "select * from semtransaksi" Set rssem = dbpenj.Execute(sqlsem, , adCmdText) savesem = "insert into semtransaksi values('" & cmbbrg.Text & "', '" & txtnmbrg.Text & "','" & txthrgbrg.Text & "', '" & txtst.Text & "','" & txtqty.Text & "')" Set rssem = dbpenj.Execute(savesem, , adCmdText) n = MsgBox("Input data lagi?", vbQuestion + vbYesNo) refresh_semtrans rssem.MoveFirst txttobay.Text = Val(txtst.Text) + Val(txttobay.Text) If n = vbYes Then cmbbrg.Text = "" txtnmbrg.Text = "" txtqty.Text = "" txthrgbrg.Text = "" txtst.Text = "" End If End If End If End Sub
Created by YNT