Kita akan membuat form login,sebelumnya kita buat data base di sql server terlebih dahulu,dengan mengisi kolom nama_user dan password,sebelum ini pastikan kita juga sudah membuat module untuk koneksi ke sql server seperti pada episode sebelumnya…..
lalu agar password yang kita ketik menjadi bintang(*)atau titik (.)pada properties textbox2 ada di ubah use system password menjadi “true”
Public Class log_in
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call Koneksi()
Try
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from form_login where nama_user='" & TextBox1.Text & "'and password_='" & TextBox2.Text & "'"
Tampilkan = Tampil.ExecuteReader
If Tampilkan.HasRows = True Then
form_menu.Show()
Me.Visible = False
Else
MsgBox("Nama dan Password yang Anda Masukkan Salah, Silahkan Ulangi Lagi")
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub log_in_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
TextBox1.Focus()
TextBox2.Focus()
Button1.Focus()
End Sub
Private Sub log_in_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
*)buat db dengan kolom nama_user dan password terlebih dulu
Public Class jadwal_dokter
Sub Kosong()
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
End Sub
Sub netral()
Button1.Text = "input"
Button2.Text = "edit"
Button3.Text = "delete"
Button4.Text = "exit"
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
TextBox1.Enabled = True
End Sub
Sub cekrecord()
Call Koneksi()
tampil.Connection = Database
tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from form_jadwal where id_dokter='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil.ExecuteReader
If tampilkan.HasRows = True Then
hasilcek = True
Else
hasilcek = False
End If
End Sub
Sub Hapuskelompok()
If Button3.Text = "delete" Then
TextBox1.Text = ""
Button3.Text = "Ok"
Button1.Enabled = False
Button2.Enabled = False
Button4.Text = "batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
If TextBox5.Text = "" Then Exit Sub
If TextBox6.Text = "" Then Exit Sub
If TextBox7.Text = "" Then Exit Sub
Try
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "Delete from form_jadwal where id_dokter='" & Trim(TextBox1.Text) & "'"
Tampil.ExecuteNonQuery()
Call Kosong()
TextBox1.Focus()
MsgBox("delete berhasil")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Sub simpankelompok()
If Button1.Text = "input" Then
TextBox1.Text = ""
Button1.Text = "simpan"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
If TextBox5.Text = "" Then Exit Sub
If TextBox6.Text = "" Then Exit Sub
If TextBox7.Text = "" Then Exit Sub
Call cekrecord()
Try
If hasilcek = "False" Then
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "insert into form_jadwal (id_dokter,nm_dokter,alamat,no_tlp,no_hp,hari,jam)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "')"
Tampil.ExecuteNonQuery()
Call Kosong()
TextBox1.Focus()
Else
MsgBox("Data sudah ada, silahkan cek data yang di input", MsgBoxStyle.Critical, "Input data")
TextBox1.Focus()
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Sub ubahkelompok()
If Button2.Text = "edit" Then
TextBox1.Text = ""
Button2.Text = "simpan"
Button1.Enabled = False
Button3.Enabled = False
Button4.Text = "batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
If TextBox5.Text = "" Then Exit Sub
If TextBox6.Text = "" Then Exit Sub
If TextBox7.Text = "" Then Exit Sub
Try
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "update form_jadwal set nm_dokter ='" & Trim(TextBox2.Text) & "',hari ='" & Trim(TextBox6.Text) & "',jam ='" & Trim(TextBox7.Text) & "' where id_dokter ='" & Trim(TextBox1.Text) & "'"
Tampil.ExecuteNonQuery()
Call Kosong()
TextBox1.Focus()
MsgBox("update jadwal berhasil")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call simpankelompok()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "exit" Then
Me.Close()
Else
Call Kosong()
Call netral()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call ubahkelompok()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call Hapuskelompok()
End Sub
End Class
0 komentar:
Posting Komentar