Uploaded by User72165

UTS Ina Cahyaningtyas TI 19 B pemrog2

advertisement
UTS_Ina Cahyaningtyas
Pemrograman 2
Ina Cahyaningtyas
11/10/20
2019310001
Imports System.Data.SqlClient
Imports System.Math
Public Class ina_cahyaningtyas_TI19B
Sub kosongkan()
ComboBox2.Text = ""
Label10.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
Label11.Text = ""
ComboBox2.Focus()
End Sub
Sub ketemu()
On Error Resume Next
ComboBox2.Text = dr(2)
TextBox3.Text = dr(3)
TextBox4.Text = dr(4)
TextBox5.Text = dr(5)
Label11.Text = dr(6)
End Sub
Sub tampilgrid()
Call koneksi()
da = New SqlDataAdapter("select * from pinjaman", conn)
ds = New DataSet
da.Fill(ds)
DGV.DataSource = ds.Tables(0)
DGV.ReadOnly = True
End Sub
Sub cariid()
Call koneksi()
cmd = New SqlCommand("select * from pinjaman where id_pinjaman='" & Label9.Text & "'", conn)
dr = cmd.ExecuteReader
dr.Read()
End Sub
Sub nomorotomatis()
Call koneksi()
cmd = New SqlCommand("select id_pinjaman from pinjaman order by id_pinjaman desc", conn)
dr = cmd.ExecuteReader
dr.Read()
If Not dr.HasRows Then
Label9.Text = "P" + "000001"
Else
Label9.Text = Val(Microsoft.VisualBasic.Mid(dr(0).ToString, 6, 3)) + 1
If Len(Label9.Text) = 1 Then
Label9.Text = "P00000" & Label9.Text & ""
ElseIf Len(Label9.Text) = 2 Then
Label9.Text = "P0000" & Label9.Text & ""
ElseIf Len(Label9.Text) = 3 Then
Label9.Text = "P000" & Label9.Text & ""
ElseIf Len(Label9.Text) = 4 Then
Label9.Text = "P00" & Label9.Text & ""
ElseIf Len(Label9.Text) = 5 Then
Label9.Text = "P0" & Label9.Text & ""
End If
End If
End Sub
Sub tampilnasabah()
Call koneksi()
cmd = New SqlCommand("select id_nasabah from nasabah", conn)
dr = cmd.ExecuteReader
Do While dr.Read
ComboBox2.Items.Add(dr(0))
Loop
End Sub
Private Sub Peminjaman_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Call tampilgrid()
Call tampilnasabah()
Call nomorotomatis()
Call koneksi()
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Call koneksi()
cmd = New SqlCommand("select * from nasabah where id_nasabah='" & ComboBox2.Text & "'",
conn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
Label10.Text = dr(1)
Else
MsgBox("id nasabah tidak valid")
End If
Call koneksi()
cmd = New SqlCommand("select * from pinjaman where id_nasabah='" & ComboBox2.Text & "' and
status_pinjaman='BELUM LUNAS '", conn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
Call ketemu()
MsgBox("nasabah pernah pinjam dan belum lunas")
Call kosongkan()
End If
Call koneksi()
cmd = New SqlCommand("select * from nasabah where id_nasabah='" & ComboBox2.Text & "' and
status_kawin='BELUM KAWIN '", conn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
MsgBox("Hanya Nasabah Dengan Status Kawin Yang Boleh Meminjam")
Call kosongkan()
End If
End Sub
Private Sub TextBox5_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox5.KeyDown
If e.KeyCode = Keys.Enter Then
Label11.Text = Round(Pmt(TextBox3.Text / 12 / 100, TextBox4.Text, TextBox5.Text), 0) * -1
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
If ComboBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
MsgBox("transaksi belum lengkap")
Exit Sub
End If
Call koneksi()
Dim simpan As String = "insert into pinjaman values('" & Label9.Text & "','" &
Format(DateValue(DTP.Text), "MM/dd/yyyy") & "','" &
ComboBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" &
Label11.Text & "','" & TextBox5.Text & "','BELUM LUNAS')"
cmd = New SqlCommand(simpan, conn)
cmd.ExecuteNonQuery()
Call kosongkan()
Call nomorotomatis()
Call tampilgrid()
End Sub
Private Sub TextBox3_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyDown
If e.KeyCode = Keys.Enter Then
TextBox4.Focus()
End If
End Sub
Private Sub TextBox4_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyDown
If e.KeyCode = Keys.Enter Then
TextBox5.Focus()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
Call kosongkan()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
Me.Close()
End Sub
Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Label10.Click
End Sub
End Class
DATABASE
Struktur table database Nasabah
Struktur table database Pinjaman
Isi Database Nasabah
Hasil Output
Contoh jika nasabah status belum kawin
Contoh berhasil simpan
Contoh jika nasabah masih ada pinjaman belum lunas
Download