SHARE
TWEET

UTS_Peminjaman

Nooralfian83 Nov 12th, 2019 (edited) 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Data.SqlClient
  2. Imports System.Math
  3.  
  4. Public Class Form1
  5.     Sub kosongkan()
  6.         lbl_angsur.Text = ""
  7.         lbl_namanasabah.Text = ""
  8.         lbl_penghasilan.Text = ""
  9.         lbl_status.Text = ""
  10.         lbl_limit.Text = ""
  11.         txt_bunga.Clear()
  12.         txt_jmlpinjam.Clear()
  13.         txt_lamacicil.Clear()
  14.         cb_nasabah.Text = ""
  15.         cb_nasabah.Focus()
  16.     End Sub
  17.     Sub ketemu()
  18.         On Error Resume Next
  19.         cb_nasabah.Text = dr(2)
  20.         txt_bunga.Text = dr(3)
  21.         txt_lamacicil.Text = dr(4)
  22.         txt_jmlpinjam.Text = dr(5)
  23.         lbl_angsur.Text = dr(6)
  24.     End Sub
  25.     Sub tampilgrid()
  26.         Call koneksi()
  27.         da = New SqlDataAdapter("SELECT * FROM tbl_pinjaman", conn)
  28.         ds = New DataSet
  29.         da.Fill(ds)
  30.         dgv.DataSource = ds.Tables(0)
  31.         dgv.ReadOnly = True
  32.     End Sub
  33.     Sub notis()
  34.         '    Call koneksi()
  35.         '    cmd = New SqlCommand("SELECT id_pinjaman FROM tbl_pinjaman ORDER BY id_pinjaman desc", conn)
  36.         '    dr = cmd.ExecuteReader
  37.         '    dr.Read()
  38.         '    If Not dr.HasRows Then
  39.         '        lbl_idpinjam.Text = "00001"
  40.         '    Else
  41.         '        lbl_idpinjam.Text = Format(Microsoft.VisualBasic.Right(dr(0), 5) + 1, "00000")
  42.         '    End If
  43.         Call koneksi()
  44.         cmd = New SqlCommand("select Id_pinjaman from tbl_pinjaman order by Id_pinjaman desc", conn)
  45.         dr = cmd.ExecuteReader
  46.         dr.Read()
  47.         If Not dr.HasRows Then
  48.             lbl_idpinjam.Text = "P" + "0001"
  49.         Else
  50.             lbl_idpinjam.Text = "P" + Format(Microsoft.VisualBasic.Right(dr(0), 4) + 1, "0000")
  51.         End If
  52.  
  53.     End Sub
  54.  
  55.     Sub tampilnasabah()
  56.         Call koneksi()
  57.         cmd = New SqlCommand("SELECT * FROM tbl_nasabah", conn)
  58.         dr = cmd.ExecuteReader
  59.         cb_nasabah.Items.Clear()
  60.         Do While dr.Read
  61.             cb_nasabah.Items.Add(dr(0))
  62.         Loop
  63.     End Sub
  64.  
  65.     Sub mulai()
  66.         Call koneksi()
  67.         Call kosongkan()
  68.         Call notis()
  69.         Call tampilgrid()
  70.         Call tampilnasabah()
  71.     End Sub
  72.  
  73.  
  74.  
  75.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  76.         txt_tglpinjam.Text = Format(Now, "dd-MMM-yyyy")
  77.         tampilgrid()
  78.         tampilnasabah()
  79.         notis()
  80.     End Sub
  81.  
  82.     Private Sub cb_nasabah_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_nasabah.SelectedIndexChanged
  83.         Call koneksi()
  84.         cmd = New SqlCommand("select * from tbl_nasabah where id_nasabah = '" & cb_nasabah.Text & "'", conn)
  85.         dr = cmd.ExecuteReader
  86.         dr.Read()
  87.         If dr.HasRows Then
  88.             lbl_namanasabah.Text = dr(1)
  89.             lbl_penghasilan.Text = dr(3)
  90.             lbl_status.Text = dr(2)
  91.         Else
  92.             MsgBox("ID NASABAH TIDAK DITEMUKAN")
  93.         End If
  94.  
  95.         'cari jumlah pinjaman yang bisa dipinjam
  96.  
  97.         If (lbl_status.Text = "Sudah Nikah" And lbl_penghasilan.Text = True) Then
  98.             MsgBox("anda boleh pinjam")
  99.             lbl_limit.Text = lbl_penghasilan.Text * 0.5
  100.         Else
  101.             MsgBox("Anda tidak bisa pinjam")
  102.             lbl_namanasabah.Text = ""
  103.             lbl_penghasilan.Text = ""
  104.             lbl_status.Text = ""
  105.             lbl_limit.Text = ""
  106.         End If
  107.  
  108.  
  109.  
  110.         'cari nasabah yang belum lunas
  111.         Call koneksi()
  112.         cmd = New SqlCommand("select * from tbl_pinjaman where id_nasabah = '" & cb_nasabah.Text & "' and sisa_pinjaman < 1000000", conn)
  113.         dr = cmd.ExecuteReader
  114.         dr.Read()
  115.         If dr.HasRows Then
  116.             MsgBox("Anda Belum Bisa Pinjam karena BELUM LUNAS")
  117.             Call mulai()
  118.         End If
  119.  
  120.     End Sub
  121.  
  122.     Private Sub txt_jmlpinjam_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt_jmlpinjam.KeyDown
  123.         'fungsi kendali Enter
  124.         If e.KeyCode = Keys.Enter Then
  125.             lbl_angsur.Text = Round(Pmt(txt_bunga.Text / 12 / 100, txt_lamacicil.Text, txt_jmlpinjam.Text), 0) * -1
  126.         End If
  127.        
  128.     End Sub
  129.  
  130.     Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
  131.         'cek data yang belum di isi
  132.         If cb_nasabah.Text = "" Or txt_bunga.Text = "" Or txt_jmlpinjam.Text = "" Or txt_lamacicil.Text = "" Then
  133.             MsgBox("Data Belum Lengkap")
  134.             Exit Sub
  135.         End If
  136.         Try
  137.             'simpan disini
  138.             Call koneksi()
  139.             Dim simpan As String = "INSERT INTO tbl_pinjaman values('" & lbl_idpinjam.Text & "', '" & txt_tglpinjam.Text & "','" & cb_nasabah.Text & "','" & txt_bunga.Text & "','" & txt_lamacicil.Text & "', '" & txt_jmlpinjam.Text & "', '" & lbl_angsur.Text & "', '" & txt_jmlpinjam.Text & "', 'BELUM LUNAS')"
  140.             cmd = New SqlCommand(simpan, conn)
  141.             cmd.ExecuteNonQuery()
  142.             kosongkan()
  143.             notis()
  144.             tampilgrid()
  145.             tampilnasabah()
  146.         Catch ex As Exception
  147.             MsgBox(ex.Message)
  148.         End Try
  149.  
  150.     End Sub
  151.  
  152.     Private Sub btntutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntutup.Click
  153.         Me.Close()
  154.     End Sub
  155.  
  156.     Private Sub btnbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
  157.         kosongkan()
  158.     End Sub
  159.  
  160.     Private Sub lbl_angsur_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl_angsur.Click
  161.  
  162.     End Sub
  163. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top