Sabtu, 21 Mei 2011

Contoh Form Login


Public Class LoginForm1

' TODO: Insert code to perform custom authentication using the provided username and password
' (See http://go.microsoft.com/fwlink/?LinkId=35339).
' The custom principal can then be attached to the current thread's principal as follows:
' My.User.CurrentPrincipal = CustomPrincipal
' where CustomPrincipal is the IPrincipal implementation used to perform authentication.
' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
' such as the username, display name, etc.

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
If UsernameTextBox.Text = "adit" And PasswordTextBox.Text = "keren" Then
MDIParent1.Show()
Me.Visible = False
Else
MsgBox("Login gagal,silahkan ulangi lagi")
End If

End Sub

Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub


End Class

Contoh Program yang Ane Buat


Public Class DATA_CUSTOMER

Sub Kosong()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox1.Focus()
End Sub
Sub netral()
Bttambah.Text = "&Input"
BtUbah.Text = "&Edit"
Bthapus.Text = "&Delete"
btkeluar.Text = "&Exit"
Bttambah.Enabled = True
BtUbah.Enabled = True
Bthapus.Enabled = True
TextBox1.Enabled = True
End Sub

Sub cekrecord()
Call mykoneksi()
Tampil.Connection = DataAdit
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from data_customer where kd_cust='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil.ExecuteReader

If Tampilkan.HasRows = True Then
hasilcek = True
Else
hasilcek = False
End If
End Sub
Private Sub BtnTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bttambah.Click
Call simpankelompok()
'memenggil metod (simpankelompok)
End Sub
Sub simpankelompok()
If Bttambah.Text = "&Input" Then
TextBox1.Text = ""
Bttambah.Text = "Save"
BtUbah.Enabled = False
Bthapus.Enabled = False
btkeluar.Text = "&Cancel"
'TextBox1.Enabled = False
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub


Call cekrecord()
Try
If hasilcek = "False" Then 'jika data true langsung ke else
Call mykoneksi()

Tampil.Connection = DataAdit
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "Insert Into data_customer (kd_cust,Nama_cust,Alamat,Contact)values( '" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
Tampil.ExecuteNonQuery()

Call Kosong()

Else
MsgBox("Data sudah ada bro, 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
Private Sub BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btkeluar.Click
If btkeluar.Text = "&Exit" Then
Me.Close()
Else
Call Kosong()
Call netral()
End If
End Sub
Private Sub BtUbah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtUbah.Click
Call Btnubahkelompok()
End Sub
Sub Btnubahkelompok()
If BtUbah.Text = "&Edit" Then
TextBox1.Text = ""
BtUbah.Text = "Save"
Bttambah.Enabled = False 'enabled= aktif/tidak aktif
Bthapus.Enabled = False
btkeluar.Text = "&Cancel"
TextBox1.Focus()

Else
If TextBox1.Text = "" Then Exit Sub 'untuk mengeck data ada/tidak lalu keluar, dan tidak akan dijalankan
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
Try
Call mykoneksi() 'untuk mengecek data kdjur ada apa tidak

Tampil.Connection = DataAdit
tampil2.Connection = DataAdit
tampil3.Connection = DataAdit
Tampil.CommandType = CommandType.Text
tampil2.CommandType = CommandType.Text
tampil3.CommandType = CommandType.Text
Tampil.CommandText = "Update data_customer Set Nama_cust='" & Trim(TextBox2.Text) & "'where kd_cust ='" & Trim(TextBox1.Text) & "'"
tampil2.CommandText = "Update data_customer Set Alamat='" & Trim(TextBox3.Text) & "'where kd_cust ='" & Trim(TextBox1.Text) & "'"
tampil3.CommandText = "Update data_customer Set Contact='" & Trim(TextBox4.Text) & "'where kd_cust ='" & Trim(TextBox1.Text) & "'"
Tampil.ExecuteNonQuery()
tampil2.ExecuteNonQuery()
tampil3.ExecuteNonQuery()

Call Kosong()
TextBox1.Focus()

Catch ex As Exception
MsgBox(ex.ToString())

End Try

End If
End Sub
Private Sub BtnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bthapus.Click
Call BtnHapuskelompok()
End Sub
Sub BtnHapuskelompok()
If Bthapus.Text = "&Delete" Then
TextBox1.Text = ""
Bthapus.Text = "Ok"
Bttambah.Enabled = False
BtUbah.Enabled = False
btkeluar.Text = "&Cancel"
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
Try
Call mykoneksi()

Tampil.Connection = DataAdit
Tampil.CommandType = CommandType.Text

Tampil.CommandText = "Delete from data_customer where kd_cust='" & Trim(TextBox1.Text) & "'"
Tampil.ExecuteNonQuery()

Call Kosong()
TextBox1.Focus()

Catch ex As Exception
MsgBox(ex.ToString())

End Try

End If
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(Keys.Enter) Then
If Bttambah.Text = "Save" Then
Call cekrecord()
If hasilcek = False Then
TextBox2.Focus()
Else
MsgBox("Kode sudah ada boss, silahkan ganti kode lain boss", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Infromasi")
TextBox1.Focus()
End If
Else
Call mykoneksi()
Tampil.Connection = DataAdit
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from data_customer where kd_cust='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil.ExecuteReader

If Tampilkan.HasRows = True Then
While Tampilkan.Read()
If IsDBNull(Tampilkan("kd_cust")) Then
TextBox1.Focus()
Else
TextBox2.Text = Tampilkan("Nama_cust")
TextBox2.Focus()
TextBox3.Text = Tampilkan("Alamat")
TextBox3.Focus()
TextBox4.Text = Tampilkan("Contact")
TextBox4.Focus()
End If
End While
Else
MsgBox("Data tidak diketemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah Data")
End If
End If
End If
End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class

Contoh Koneksi Yang ane buat

Imports System.Data
Imports System.Data.Sql

Module Module1
Public DataAdit As New OleDb.OleDbConnection
Public Tampil As New OleDb.OleDbCommand
Public tampil2 As New OleDb.OleDbCommand
Public tampil3 As New OleDb.OleDbCommand
Public Tampilkan As OleDb.OleDbDataReader
Public adapter As New OleDb.OleDbDataAdapter
Public ds As New DataSet
Public Tabel, hasilcek As String
Public record As New BindingSource
Public adit As Integer
Public DmlSql As New OleDb.OleDbCommand

Public Sub mykoneksi()
Try
DataAdit.Close()
'server
'DataAdit.ConnectionString = "Provider=SQLOLED.1;Password=;Persist Security Info=True;User ID=sa;Initial Catalog=sim_akuntansi;Data Source=200.200.10.150"

'lokal
DataAdit.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=customer;Data Source=."

DataAdit.Open()

MsgBox("Koneksi Berhasil")
Catch ex As Exception
MsgBox("Koneksi ERROR")

End Try


End Sub

End Module