Kamis, 09 Juni 2011

Next UAS tugazz

PROGRAM APLIKASI JASA SERVICE FUEL INJECTION PUMP & INJECTOR PADA UD.WAHYU DISEL

Pada kali ini kita akan membuat connection to SQL 2000 dengan menggunakan modul. Pertama buat designnya kemudian diisi dengan sourcenya, seperti dibawah ini :
Menampilkan Form1/Form Menu Utama 


Jika dipilih MASTER akan menampilkan,  seperti berikut :

Jika dipilih PROSES akan menampilkan,  seperti berikut :

Jika dipilih CETAK akan menampilkan,  seperti berikut :

Jika dipilih EXIT maka akan keluar,

dan berikut adalah semua syntax yang ada dalam form1 :
Public Class Form1
Untuk menampilkan DATA SERVICE / FORM DATA SERVICE, manggunakan syntax sebagai berikut:
    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        Form2.Show()
    End Sub
Syntax yang digunakaan untuk menampilkan;
•              DATA SPEAR PART (hanya diganti nama Formnya menjadi Form3.Show())
•              DATA KONSUMEN (hanya diganti nama Formnya menjadi Form4.Show())
•              DATA MEKANIK (hanya diganti nama Formnya menjadi Form5.Show())
Untuk syntax EXIT menggunakan syntax sebagai berikut:
    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub
End Class
berikutnya adalah membuat modul seperti berikut :
Imports System.Data
Imports System.Data.Sql
Module koneksidatabase
    Public Database As New OleDb.OleDbConnection
    Public Tampil As New OleDb.OleDbCommand
    Public Tampil2 As New OleDb.OleDbCommand
    Public Tampilkan As OleDb.OleDbDataReader
    Public hasiljur, jur, hasilcek As String
    Public Sub Koneksi()
        Try
            Database.Close()l
            Database.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TI4P;Data Source=."
            Database.Open()
            'Tampil.Connection = Database
            MsgBox(" Koneksi Berhasil ")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Module
  Kemudian buat form2, design serta sourcenya , Dan setiap form diisi sebuah sintax =

Public Class Form2
    Sub kosong()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox1.Focus()
    End Sub
    Sub netral()
        Button2.Text = "TAMBAH"
        Button3.Text = "UBAH"
        Button4.Text = "HAPUS"
        Button5.Text = "KELUAR"
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        Button5.Enabled = True
        TextBox1.Enabled = True
    End Sub
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from Data_Servis where KODE_SERVICE='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader
        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Sub tambah()
        If Button2.Text = "TAMBAH" Then
            TextBox1.Text = ""
            Button2.Text = "SIMPAN"
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            If TextBox3.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()
                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into Data_Servis (Kode_Service,Jenis_Service,Biaya)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call kosong()
                    TextBox1.Focus()
                Else
                    MsgBox("Data sudah ada, silah 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 ubah()
        If Button3.Text = "UBAH" Then
            TextBox1.Text = ""
            Button3.Text = "SIMPAN"
            Button2.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            If TextBox3.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "update Data_Servis set Jenis_Service ='" & Trim(TextBox2.Text) & "', Biaya ='" & TextBox3.Text & "' where Kode_Service='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub hapus()
        If Button4.Text = "HAPUS" Then
            TextBox1.Text = ""
            Button4.Text = "OK"
            Button2.Enabled = False
            Button3.Enabled = False
            Button5.Text = "BATAL"
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            If TextBox3.Text = "" Then Exit Sub

            Call cekrecord()
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Delete from Data_Servis where Kode_service='" & 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
            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandText = "select * from Data_Servis where Kode_Service='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader
            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("Kode_Service")) Then
                        TextBox1.Focus()
                    Else
                        TextBox2.Text = Tampilkan("Jenis_Service")
                        TextBox3.Text = Tampilkan("Biaya")
                    End If
                End While
            Else
                MsgBox("data tidak ditemiukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah data")
            End If
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call tambah()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Call ubah()
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Call hapus()
    End Sub
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If Button5.Text = "KELUAR" Then
            Me.Close()
        Else
            Call kosong()
            Call netral()
        End If
    End Sub   
End Class
Untuk selanjutnya sub kosong,netral dan button (TAMBAH, UBAH, HAPUS, KELUAR) sourcenya tetap dan yang lainnya diganti . . .
Untuk form3

Source yang digunakan :
Public Class Form3
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from Data_Speare_Part where Kode_Speare_Part='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader
        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Sub tambah()
        If Button2.Text = "TAMBAH" Then
            TextBox1.Text = ""
            Button2.Text = "SIMPAN"
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            If TextBox3.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()
                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into Data_Speare_Part (Kode_Speare_Part,Nama_Speare_Part,Harga)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call kosong()
                    TextBox1.Focus()
                Else
                    MsgBox("Data sudah ada, silah 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 ubah()
        If Button3.Text = "UBAH" Then
            TextBox1.Text = ""
            Button3.Text = "SIMPAN"
            Button2.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            If TextBox3.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "update Data_Speare_Part set Nama_Speare_Part ='" & Trim(TextBox2.Text) & "', Harga ='" & TextBox3.Text & "' where Kode_Speare_Part ='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub hapus()
        If Button4.Text = "HAPUS" Then
            TextBox1.Text = ""
            Button4.Text = "OK"
            Button2.Enabled = False
            Button3.Enabled = False
            Button5.Text = "BATAL"
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            If TextBox3.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Delete from Data_Speare_Part where Kode_Speare_Part='" & 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
            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandText = "select * from Data_Speare_Part where Kode_Speare_Part='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader
            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("Kode_Speare_Part")) Then
                        TextBox1.Focus()
                    Else
                        TextBox2.Text = Tampilkan("Nama_Speare_Part")
                        TextBox3.Text = Tampilkan("Harga")
                    End If
                End While
            Else
                MsgBox("data tidak ditemiukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah data")
            End If
        End If
    End Sub
End Class
Untuk  form4

Source yang digunakan :
Public Class Form4
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from Data_Konsumen where Kode_Konsumen ='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader
        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Sub tambah()
        If Button2.Text = "TAMBAH" Then
            TextBox1.Text = ""
            Button2.Text = "SIMPAN"
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            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
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()
                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into Data_Konsumen (Kode_Konsumen,Nama_Konsumen,Alamat,No_Telp,Fax)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call kosong()
                    TextBox1.Focus()
                Else
                    MsgBox("Data sudah ada, silah 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 ubah()
        If Button3.Text = "UBAH" Then
            TextBox1.Text = ""
            Button3.Text = "SIMPAN"
            Button2.Enabled = False
            Button4.Enabled = False
            Button5.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
            Call cekrecord()
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "update Data_Konsumen set Nama_Konsumen ='" & Trim(TextBox2.Text) & "', Alamat ='" & TextBox3.Text & "',No_Telp ='" & TextBox4.Text & "',Fax ='" & TextBox5.Text & "' where Kode_Konsumen ='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub hapus()
        If Button4.Text = "HAPUS" Then
            TextBox1.Text = ""
            Button4.Text = "OK"
            Button2.Enabled = False
            Button3.Enabled = False
            Button5.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
            Call cekrecord()
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Delete from Data_Konsumen where Kode_Konsumen='" & 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
            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandText = "select * from Data_Konsumen where Kode_Konsumen='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader
            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("Kode_Konsumen")) Then
                        TextBox1.Focus()
                    Else
                       TextBox2.Text = Tampilkan("Nama_Konsumen")
                        TextBox3.Text = Tampilkan("Alamat")
                        TextBox4.Text = Tampilkan("No_Telp")
                        TextBox5.Text = Tampilkan("Fax")
                    End If
                End While
            Else
                MsgBox("data tidak ditemiukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah data")
            End If
        End If
    End Sub
End Class
Untuk form5

Source yang digunakan :
Public Class Form5
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from Data_Mekanik where Kode_Mekanik ='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader
        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Sub tambah()
        If Button2.Text = "TAMBAH" Then
            TextBox1.Text = ""
            Button2.Text = "SIMPAN"
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            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 ComboBox1.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()
                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into Data_Mekanik (Kode_Mekanik,Nama_Mekanik,Jabatan,Alamat,Tgl_Lahir,Jenis_kelamin,No_Telp)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & DateTimePicker1.Value & "','" & ComboBox1.Text & "','" & TextBox5.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call kosong()
                    TextBox1.Focus()
                Else
                    MsgBox("Data sudah ada, silah 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 ubah()
        If Button3.Text = "UBAH" Then
            TextBox1.Text = ""
            Button3.Text = "SIMPAN"
            Button2.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            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 ComboBox1.Text = "" Then Exit Sub
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "update Data_Mekanik set Nama_Mekanik ='" & Trim(TextBox2.Text) & "',Jabatan ='" & Trim(TextBox3.Text) & "',Alamat ='" & Trim(TextBox4.Text) & "',Tgl_Lahir ='" & Trim(DateTimePicker1.Value) & "',Jenis_kelamin ='" & Trim(ComboBox1.Text) & "',No_Telp ='" & Trim(TextBox5.Text) & "' where Kode_Mekanik ='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub hapus()
        If Button4.Text = "HAPUS" Then
            TextBox1.Text = ""
            Button4.Text = "OK"
            Button2.Enabled = False
            Button3.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            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 ComboBox1.Text = "" Then Exit Sub
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Delete from Data_Mekanik where Kode_Mekanik='" & 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
            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandText = "select * from Data_Mekanik where Kode_Mekanik='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader
            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("Kode_Mekanik")) Then
                        TextBox1.Focus()
                    Else
                        TextBox2.Text = Tampilkan("Nama_Mekanik")
                        TextBox3.Text = Tampilkan("Jabatan")
                        TextBox4.Text = Tampilkan("Alamat")
                        ComboBox1.Text = Tampilkan("Jenis_Kelamin")
                        TextBox5.Text = Tampilkan("No_Telp")
                    End If
                End While
            Else
                MsgBox("data tidak ditemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah data")
            End If
        End If
    End Sub
End Class
Untuk form6

Source yang digunakan :
Public Class Form6
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from Data_Work_Order where No_Wo ='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader
        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Sub tambah()
        If Button2.Text = "TAMBAH" Then
            TextBox1.Text = ""
            Button2.Text = "SIMPAN"
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            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
            If ComboBox1.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()
                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into Data_Work_Order (No_Wo,Tgl_Wo,Jenis_Service,Nama_Konsumen,No_Polisi,No_Seri_Kendaraan,Type_Kendaraan,Kode_Mekanik,Nama_Mekanik)values ('" & TextBox1.Text & "','" & DateTimePicker1.Value & "','" & ComboBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call kosong()
                    TextBox1.Focus()
                Else
                    MsgBox("Data sudah ada, silah 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 ubah()
        If Button3.Text = "UBAH" Then
            TextBox1.Text = ""
            Button3.Text = "SIMPAN"
            Button2.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            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
            If ComboBox1.Text = "" Then Exit Sub
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "update Data_Work_Order set Tgl_Wo = '" & Trim(DateTimePicker1.Value) & "',Jenis_Service = '" & Trim(ComboBox1.Text) & "', Nama_Konsumen ='" & Trim(TextBox2.Text) & "',No_Polisi ='" & Trim(TextBox3.Text) & "',No_Seri_Kendaraan = '" & Trim(TextBox4.Text) & "',Type_Kendaraan = '" & Trim(TextBox5.Text) & "',Kode_Mekanik = '" & Trim(TextBox6.Text) & "',Nama_Mekanik = '" & Trim(TextBox7.Text) & "' where No_Wo ='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub hapus()
        If Button4.Text = "HAPUS" Then
            TextBox1.Text = ""
            Button4.Text = "OK"
            Button2.Enabled = False
            Button3.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            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 ComboBox1.Text = "" Then Exit Sub
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Delete from Data_Work_Order where No_Wo ='" & 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
            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandText = "select * from Data_Work_Order where No_Wo='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader
            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("No_Wo")) Then
                        TextBox1.Focus()
                    Else
                        ComboBox1.Text = Tampilkan("Jenis_Service")
                        TextBox2.Text = Tampilkan("Nama_Konsumen")
                        TextBox3.Text = Tampilkan("No_Polisi")
                        TextBox4.Text = Tampilkan("No_Seri_Kendaraan")
                        TextBox5.Text = Tampilkan("Type_Kendaraan")
                        TextBox6.Text = Tampilkan("Kode_Mekanik")
                        TextBox7.Text = Tampilkan("Nama_Mekanik")
                    End If
                End While
            Else
                MsgBox("data tidak ditemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah data")
            End If
        End If
    End Sub
End Class
Untuk form7

Source yang digunakan :
Public Class Form7
        End Sub
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from Kwitansi where No_k ='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader
        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Sub tambah()
        If Button2.Text = "TAMBAH" Then
            TextBox1.Text = ""
            Button2.Text = "SIMPAN"
            Button1.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            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
            If TextBox8.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()
                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into Kwitansi (No_k,Tgl,No_Wo,Kode_Speare_Part,QTY,Jumlah,Biaya_Service,Diskon,Total_Bayar)values ('" & TextBox1.Text & "','" & DateTimePicker1.Value & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call kosong()
                    TextBox1.Focus()
                Else
                    MsgBox("Data sudah ada, silah 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 ubah()
        If Button3.Text = "UBAH" Then
            TextBox1.Text = ""
            Button3.Text = "SIMPAN"
            Button1.Enabled = False
            Button2.Enabled = False
            Button4.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            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
            If TextBox8.Text = "" Then Exit Sub
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "update Kwitansi set Tgl = '" & Trim(DateTimePicker1.Value) & "', No_Wo ='" & Trim(TextBox2.Text) & "',Kode_Speare_Part ='" & Trim(TextBox3.Text) & "',QTY = '" & Trim(TextBox4.Text) & "',Jumlah = '" & Trim(TextBox5.Text) & "',Biaya_Service = '" & Trim(TextBox6.Text) & "',Diskon = '" & Trim(TextBox7.Text) & "',Total_Bayar = '" & Trim(TextBox8.Text) & "' where No_k ='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub hapus()
        If Button4.Text = "HAPUS" Then
            TextBox1.Text = ""
            Button4.Text = "OK"
            Button2.Enabled = False
            Button1.Enabled = False
            Button3.Enabled = False
            Button5.Text = "BATAL"
            'TextBox1.Enabled = False
            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
            If TextBox8.Text = "" Then Exit Sub
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Delete from Kwitansi where No_k ='" & 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
            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandText = "select * from Kwitansi where No_k='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader
            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("No_k")) Then
                        TextBox1.Focus()
                    Else
                        TextBox2.Text = Tampilkan("No_Wo")
                        TextBox3.Text = Tampilkan("Kode_Speare_Part")
                        TextBox4.Text = Tampilkan("QTY")
                        TextBox5.Text = Tampilkan("Jumlah")
                        TextBox6.Text = Tampilkan("Biaya_Service")
                        TextBox7.Text = Tampilkan("Diskon")
                        TextBox8.Text = Tampilkan("Total_Bayar")
                    End If
                End While
            Else
                MsgBox("data tidak ditemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah data")
            End If
        End If
    End Sub
End Class


Tidak ada komentar:

Posting Komentar