Aplikasi Surat Masuk-Keluar

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Aplikasi Pengolahan Surat Masuk dan Keluar

Koneksi dengan MySql ODBC dalam Modul

Imports System.Data.Odbc.OdbcConnection
Module Module1
Public ad As Odbc.OdbcConnection
Public Sub kon()
Dim KONEKSI As String = "driver={MySQL ODBC 5.1 Driver};" & _
"SERVER=localhost;" & _
"DATABASE=SURAT;" & _
"UID=root;" & _
"PASSWORD= ;" & _
"OPTION=3;"

ad = New Odbc.OdbcConnection(KONEKSI)
ad.Open()
End Sub
End Module

Login User

Source Code
Imports System.Data.Odbc
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
'=================================================
' PEMERIKSAAN USERNAME DAN PASSWORD
'=================================================
kon()
Dim cek = "select * from user where username='" & TextBox1.Text & "' AND
PASSWORD='" & TextBox2.Text & "'"
Dim AK As New OdbcCommand
AK.Connection = ad
AK.CommandText = cek
Dim AKP As OdbcDataReader
AKP = AK.ExecuteReader
'=================================================
' MEMBERIKAN BATASAN USER SESUAI DENGAN AKSESNYA
'=================================================
If AKP.HasRows = True Then
If AKP.Item("AKSES") = "1" Then
Form5.Button1.Enabled = True
Form5.Button2.Enabled = True
Form5.Button3.Enabled = True
Form5.Button4.Enabled = True
Form9.Button1.Enabled = True
Form9.Button3.Enabled = True
Form5.UbahPasswordToolStripMenuItem.Enabled = True
showdata()
Else
Form5.Button1.Enabled = False
Form5.Button2.Enabled = False
Form5.Button3.Enabled = True
Form5.Button4.Enabled = True
Form9.Button1.Enabled = False
Form9.Button3.Enabled = False
Form5.UbahPasswordToolStripMenuItem.Enabled = True
datauser()
End If
Form5.Show()
Me.Hide()
Else
MsgBox(" Username atau Password Salah !!", MsgBoxStyle.Information)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End If
Form2.TextBox2.Text = TextBox1.Text
Form9.Label1.Text = TextBox1.Text
Form2.TextBox2.Enabled = False

End Sub
'=====================================================
' PENGATURAN USER DAN PASSWORD FORM 9
' MENAMPILKAN DATA DALAM D.GRID SESUAI AKSES
'=====================================================
Dim a As OdbcDataAdapter
Dim d As DataSet
Dim x As New BindingSource
Public Sub datauser()
kon()
a = New OdbcDataAdapter("select * from user where USERNAME='" & TextBox1.Text
& "'", ad)
d = New DataSet
a.Fill(d)
x.DataSource = d
x.DataMember = d.Tables(0).ToString
Form9.DataGridView1.DataSource = x
Form9.TextBox3.Enabled = False
End Sub

Public Sub showdata()


kon()
a = New OdbcDataAdapter("select * from user", ad)
d = New DataSet
a.Fill(d)
x.DataSource = d
x.DataMember = d.Tables(0).ToString
Form9.DataGridView1.DataSource = x
End Sub
End Class

Menu utama User

Source Code:
Public Class Form5

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Form2.Show()
Me.Hide()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
'SURAT KLUAR
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
Form4.Show()
Me.Hide()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Me.Hide()
Form6.Show()
End Sub
Private Sub UbahPasswordToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles UbahPasswordToolStripMenuItem.Click
Form9.Show()
End Sub

Private Sub LogoutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles LogoutToolStripMenuItem.Click
Me.Hide()
Form1.TextBox1.Text = ""
Form1.TextBox2.Text = ""
Form1.Show()
End Sub

Private Sub Form5_FormClosed(ByVal sender As Object, ByVal e As


System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
End
End Sub
End Class

Form Cari
Source code :
Imports System.Data.Odbc
Public Class Form4
Sub showt()
Dim tb As OdbcDataAdapter
Dim rd As DataSet
Dim sc As New BindingSource
tb = New OdbcDataAdapter("select * from suratmasuk where " + ComboBox1.Text +
" LIKE '%" + TextBox1.Text + "%'", ad)
rd = New DataSet
tb.Fill(rd)
sc.DataSource = rd
sc.DataMember = rd.Tables(0).ToString
DataGridView1.DataSource = sc
ad.Close()
End Sub
Sub showK()
Dim tb As OdbcDataAdapter
Dim rd As DataSet
Dim sc As New BindingSource
tb = New OdbcDataAdapter("select * from KELUAR where " + ComboBox1.Text + "
LIKE '%" + TextBox1.Text + "%'", ad)
rd = New DataSet
tb.Fill(rd)
sc.DataSource = rd
sc.DataMember = rd.Tables(0).ToString
DataGridView1.DataSource = sc
ad.Close()
End Sub
Sub showB()
Dim tb As OdbcDataAdapter
Dim rd As DataSet
Dim sc As New BindingSource
tb = New OdbcDataAdapter("select * from suratmasuk where " & ComboBox1.Text &
" between '" & DateTimePicker1.Value & "' and '" & DateTimePicker2.Value & "'", ad)
rd = New DataSet
tb.Fill(rd)
sc.DataSource = rd
sc.DataMember = rd.Tables(0).ToString
DataGridView1.DataSource = sc
ad.Close()
End Sub
Sub showBk()
Dim tb As OdbcDataAdapter
Dim rd As DataSet
Dim sc As New BindingSource
tb = New OdbcDataAdapter("select * from kluar where " + ComboBox1.Text + "
between ('" & DateTimePicker1.Value & "' and '" & DateTimePicker2.Value & "')", ad)
rd = New DataSet
tb.Fill(rd)
sc.DataSource = rd
sc.DataMember = rd.Tables(0).ToString
DataGridView1.DataSource = sc
ad.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
kon()
If ComboBox1.Text = "TGL" Then
showB()
TextBox1.Visible = False
DateTimePicker1.Visible = True
DateTimePicker2.Visible = True
ElseIf ComboBox1.Text = "TGL_K" Then
showBk()
TextBox1.Visible = False
DateTimePicker1.Visible = True
DateTimePicker2.Visible = True
ElseIf ComboBox2.Text = "MASUK" Then
showt()
TextBox1.Visible = False
DateTimePicker1.Visible = False
DateTimePicker2.Visible = False
Else
showK()
TextBox1.Visible = False
DateTimePicker1.Visible = False
DateTimePicker2.Visible = False
End If
End Sub

Sub showgb()
Dim I As Integer
I = Me.DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(I)
Form3.PictureBox1.Image = System.Drawing.Bitmap.FromFile(.Cells(6).Value)
End With
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
showgb()
Form3.Show()
End Sub

Private Sub Form4_FormClosed(ByVal sender As Object, ByVal e As


System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Form5.Show()
End Sub

Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
ComboBox2.Items.Add("MASUK")
ComboBox2.Items.Add("KELUAR")
End Sub

Private Sub ComboBox2_DropDownClosed(ByVal sender As Object, ByVal e As


System.EventArgs) Handles ComboBox2.DropDownClosed
ComboBox1.Items.Clear()
End Sub

Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As


System.EventArgs) Handles ComboBox1.DropDown
If ComboBox2.Text = "KELUAR" Then
ComboBox1.Items.Add("NO_K")
ComboBox1.Items.Add("USERNAME")
ComboBox1.Items.Add("NOKLUAR")
ComboBox1.Items.Add("TGL_KLUAR")
ComboBox1.Items.Add("TUJUAN")
ComboBox1.Items.Add("PERIHAL_K")
End If
If ComboBox2.Text = "MASUK" Then
ComboBox1.Items.Add("NO")
ComboBox1.Items.Add("USERNAME")
ComboBox1.Items.Add("NOMERSURAT")
ComboBox1.Items.Add("TGL")
ComboBox1.Items.Add("DARI")
ComboBox1.Items.Add("PERIHAL")
End If
End Sub
End Class

Laporan
Source Code :
Imports System.Data.Odbc
Public Class Form6
'========================================================================
' PROSEDUR SHOWT UNTUK MENAMPILKAN DATA SURAT MASUK KE DALAM DATAGRIDVIEW
'========================================================================
Dim tb As OdbcDataAdapter
Sub showt()
Dim rd As DataSet
Dim sc As New BindingSource
If ComboBox2.Text = "=" Then
tb = New OdbcDataAdapter("select no,nomersurat,tgl,dari,perihal from
suratmasuk where " + ComboBox1.Text + " " + ComboBox2.Text + " '" + TextBox1.Text +
"'", ad)
ElseIf ComboBox2.Text = "like" Then
tb = New OdbcDataAdapter("select no,nomersurat,tgl,dari,perihal from
suratmasuk where " + ComboBox1.Text + " " + ComboBox2.Text + " '%" + TextBox1.Text +
"%'", ad)
Else
tb = New OdbcDataAdapter("select no,nomersurat,tgl,dari,perihal from
suratmasuk where " + ComboBox1.Text + " " + ComboBox2.Text + " '" + TextBox1.Text + "'
and '" + TextBox2.Text + "'", ad)
End If

rd = New DataSet
tb.Fill(rd)
sc.DataSource = rd
sc.DataMember = rd.Tables(0).ToString
DataGridView1.DataSource = sc
ad.Close()
End Sub

'========================================================================
' PROSEDUR SHOWT UNTUK MENAMPILKAN DATA SURAT KLUAR KE DALAM DATAGRIDVIEW
'========================================================================
Sub showK()
Dim rd As DataSet
Dim sc As New BindingSource
If ComboBox2.Text = "=" Then
tb = New OdbcDataAdapter("select no_K,noKLUAR,tgl_KLUAR,TUJUAN,perihal_K
from KELUAR where " + ComboBox1.Text + " " + ComboBox2.Text + " '" + TextBox1.Text +
"'", ad)
ElseIf ComboBox2.Text = "like" Then
tb = New OdbcDataAdapter("select no_K,noKLUAR,tgl_KLUAR,TUJUAN,perihal_K
from KELUAR " + ComboBox1.Text + " " + ComboBox2.Text + " '%" + TextBox1.Text + "%'",
ad)
Else
tb = New OdbcDataAdapter("select no_K,noKLUAR,tgl_KLUAR,TUJUAN,perihal_K
from KELUAR " + ComboBox1.Text + " " + ComboBox2.Text + " '" + TextBox1.Text + "' and
'" + TextBox2.Text + "'", ad)
End If

rd = New DataSet
tb.Fill(rd)
sc.DataSource = rd
sc.DataMember = rd.Tables(0).ToString
DataGridView1.DataSource = sc
ad.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If RadioButton1.Checked Then
showt()
'======================================
' CETAK REPORT SURAT MASUK KE DLM FORM7
'======================================
Dim dtr As New DataTable
With dtr
.Columns.Add("no")
.Columns.Add("nomersurat")
.Columns.Add("TGL")
.Columns.Add("DARI")
.Columns.Add("perihal")
End With
For Each Row As DataGridViewRow In DataGridView1.Rows
dtr.Rows.Add(Row.Cells(0).Value, Row.Cells(1).Value,
Row.Cells(2).FormattedValue, Row.Cells(3).Value, Row.Cells(4).Value)
Next
Form7.ReportViewer1.LocalReport.DataSources.Item(0).Value = dtr
Form7.Show()
Else
showK()
'=======================================
' CETAK REPORT SURAT KELUAR KE DLM FORM7
'=======================================
Dim dtr As New DataTable
With dtr
.Columns.Add("no_K")
.Columns.Add("noKLUAR")
.Columns.Add("tgl_KLUAR")
.Columns.Add("TUJUAN")
.Columns.Add("perihal_K")
End With
For Each Row As DataGridViewRow In DataGridView1.Rows
dtr.Rows.Add(Row.Cells(0).Value, Row.Cells(1).Value,
Row.Cells(2).FormattedValue, Row.Cells(3).Value, Row.Cells(4).Value)
Next
Form8.ReportViewer1.LocalReport.DataSources.Item(0).Value = dtr
Form8.Show()
End If
End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton1.CheckedChanged
ComboBox1.Items.Clear()
ComboBox1.Items.Add("NO")
ComboBox1.Items.Add("USERNAME")
ComboBox1.Items.Add("NOMERSURAT")
ComboBox1.Items.Add("TGL")
ComboBox1.Items.Add("DARI")
ComboBox1.Items.Add("PERIHAL")
End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton2.CheckedChanged
ComboBox1.Items.Clear()
ComboBox1.Items.Add("NO_K")
ComboBox1.Items.Add("USERNAME")
ComboBox1.Items.Add("NOKLUAR")
ComboBox1.Items.Add("TGL_KLUAR")
ComboBox1.Items.Add("TUJUAN")
ComboBox1.Items.Add("PERIHAL_K")
End Sub

Private Sub Form6_FormClosed(ByVal sender As Object, ByVal e As


System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Form5.Show()
End Sub

Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
kon()
ComboBox2.Items.Add("=")
ComboBox2.Items.Add("like")
ComboBox2.Items.Add("between")
End Sub

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)


Handles TextBox1.GotFocus
If ComboBox2.Text = "=" Or ComboBox2.Text = "like" Then
TextBox2.Visible = False
Else
TextBox2.Visible = True
End If
End Sub
End Class

Ganti password

Login Admin

Menu Utama Admin


Input Data Surat
Source code :
Imports System.Data.Odbc

Public Class Form2


Sub showt()
Dim tb As OdbcDataAdapter
Dim rd As DataSet
Dim sc As New BindingSource
tb = New OdbcDataAdapter("select * from suratmasuk", ad)
rd = New DataSet
tb.Fill(rd)
sc.DataSource = rd
sc.DataMember = rd.Tables(0).ToString
DataGridView1.DataSource = sc
End Sub

'=============================================================
' MEMBUAT PENOMORAN OTOMATIS BERDASARKAN JUMLAH BARIS TERAKHIR
'=============================================================
Sub autonum()
kon()
Dim da As OdbcCommand
da = New OdbcCommand("SELECT count(no) FROM `suratmasuk` WHERE 1 ", ad)
Dim bc = da.ExecuteReader
bc.Read()
If bc.HasRows Then
TextBox1.Text = "SM." & bc.Item(0) + 1
Else
TextBox1.Text = "SM." & 1
End If
End Sub

Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As


System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Form5.Show()
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
autonum()
showt()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim pathf As String = Nothing
OpenFileDialog1.Filter = "*.JPG|*.JPG|*.JPEG|*.JPEG"
OpenFileDialog1.FileName = ""
OpenFileDialog1.ShowDialog()
pathf = OpenFileDialog1.FileName
TextBox7.Text = OpenFileDialog1.FileName

Me.PictureBox1.Image =
System.Drawing.Bitmap.FromFile(OpenFileDialog1.FileName)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim tbin As OdbcCommand
Dim sql As String
sql = "INSERT INTO SURATMASUK VALUES(?,?,?,?,?,?,?)"
tbin = New OdbcCommand(sql, Module1.ad)
With tbin.Parameters
.Add("?", OdbcType.VarChar, 10).Value = TextBox1.Text.Trim
.Add("?", OdbcType.VarChar, 10).Value = TextBox2.Text.Trim
.Add("?", OdbcType.VarChar, 30).Value = TextBox3.Text.Trim
.Add("?", OdbcType.Date, 10).Value = DateTimePicker1.Text.Trim
.Add("?", OdbcType.VarChar, 25).Value = TextBox5.Text.Trim
.Add("?", OdbcType.VarChar, 20).Value = TextBox6.Text.Trim
.Add("?", OdbcType.VarChar, 100).Value = TextBox7.Text.Trim
End With
tbin.ExecuteNonQuery()
MsgBox("SELESAI")
showt()
ad.Close()
autonum()
End Sub

'=====================================================================================
=
' KEBUTUHAN UPDATE, MENAMPILKAN DATA DARI GRID KE DLM TEXTBOX DAN OBJEK INPUTAN YG
LAIN

'=====================================================================================
=
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim I As Integer
I = Me.DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(I)
TextBox1.Text = .Cells(0).Value
TextBox2.Text = .Cells(1).Value
TextBox3.Text = .Cells(2).Value
TextBox4.Text = .Cells(3).Value
DateTimePicker1.Value = .Cells(3).Value
TextBox5.Text = .Cells(4).Value
TextBox6.Text = .Cells(5).Value
TextBox7.Text = .Cells(6).Value
Me.PictureBox1.Image = System.Drawing.Bitmap.FromFile(TextBox7.Text)
End With
ad.Close()
End Sub

End Class

Ubah Password dan Tambah Admin

Souece Code:

Imports System.Data.Odbc
Public Class Form9

Sub kosong()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
kon()
Dim tbin As OdbcCommand
Dim sql As String
sql = "INSERT INTO user VALUES(?,?,?)"
tbin = New OdbcCommand(sql, Module1.ad)
With tbin.Parameters
.Add("?", OdbcType.VarChar, 10).Value = TextBox1.Text.Trim
.Add("?", OdbcType.VarChar, 10).Value = TextBox2.Text.Trim
.Add("?", OdbcType.VarChar, 30).Value = TextBox3.Text.Trim
End With
tbin.ExecuteNonQuery()
MsgBox("SELESAI")
Form1.showdata()
kosong()
ad.Close()
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim I As Integer
I = Me.DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(I)
TextBox1.Text = .Cells(0).Value
TextBox2.Text = .Cells(1).Value
TextBox3.Text = .Cells(2).Value
TextBox1.Enabled = False
End With
ad.Close()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
kon()
If Button3.Enabled = False Then
Dim tbin As OdbcCommand
Dim sql As String
sql = "update user set password='" & TextBox2.Text & "', akses='" &
TextBox3.Text & "'where username='" & TextBox1.Text & "'"
tbin = New OdbcCommand(sql, Module1.ad)
tbin.ExecuteNonQuery()
MsgBox("SELESAI")
Form1.datauser()
Form5.UbahPasswordToolStripMenuItem.Enabled = False
Else
Dim tbin As OdbcCommand
Dim sql As String
sql = "update user set password='" & TextBox2.Text & "', akses='" &
TextBox3.Text & "'where username='" & TextBox1.Text & "'"
tbin = New OdbcCommand(sql, Module1.ad)
tbin.ExecuteNonQuery()
MsgBox("SELESAI")
Form1.showdata()
kosong()
TextBox1.Enabled = True
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
kon()
Dim tbin As OdbcCommand
Dim sql As String
sql = "delete from user where username='" & TextBox1.Text & "'"
tbin = New OdbcCommand(sql, Module1.ad)
tbin.ExecuteNonQuery()
MsgBox("SELESAI")
Form1.showdata()
kosong()
ad.Close()
End Sub

Private Sub Form9_FormClosed(ByVal sender As Object, ByVal e As


System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
If Button1.Enabled = False Then
Form5.UbahPasswordToolStripMenuItem.Enabled = False
End If
End Sub
Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
DataGridView1.Columns.Item("password").Visible = False

End Sub

End Class

Data Set :

PDM
user suratmasuk
username varchar(12) <pk> no int <pk>
password varchar(12) username varchar(12) <fk>
akses int nomersurat varchar(20)
... tgl date
dari varchar(20)
perihal varchar(20)
lampran longblob
...

keluar
no_k int <pk>
username varchar(12) <fk>
nokluar varchar(20)
tgl_kluar date
tujuan varchar(20)
perihal_k varchar(20)
lam_k longblob
...

You might also like