Sabtu, 21 Mei 2011

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

Tidak ada komentar:

Posting Komentar