Imports System.Data.Odbc
Module Module1
    Public Conn As OdbcConnection
    Public da As OdbcDataAdapter
    Public ds As DataSet
    Public rd As OdbcDataReader
    Public rd2 As OdbcDataReader
    Public rd3 As OdbcDataReader
    Public cmd As OdbcCommand
    Public str, strSS, strDB, strUID, strPWD, strPort, sqlCari, sda, cKodeBtn, cNamaBtn, cLevelUser, cUserId, cId_Bulan, mPath As String
    Public nData As Integer
    Public cBulan() As String

    Public Sub Koneksi()
        mPath = Application.StartupPath & "\"
        cBulan = {"Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"}
        strSS = GetSetting("Prediksi_Usaha_Kecil", "Database", "Nama Server", "A") 'ambil nilai dr registry, jika blm ada isi dgn karakter kosong ""
        strDB = GetSetting("Prediksi_Usaha_Kecil", "Database", "Nama Database", "")
        strUID = GetSetting("Prediksi_Usaha_Kecil", "Database", "User", "")
        strPWD = GetSetting("Prediksi_Usaha_Kecil", "Database", "Password", "")
        strPort = GetSetting("Prediksi_Usaha_Kecil", "Database", "Port", "")
        str = "" _
            & "DRIVER={MYSQL ODBC 5.1 Driver};" _
            & "SERVER=" & strSS & ";" _
            & "DATABASE=" & strDB & ";" _
            & "UID=" & strUID & ";" _
            & "PWD=" & strPWD & ";" _
            & "OPTION="
        Conn = New OdbcConnection(str)
        On Error Resume Next
        If Conn.State = ConnectionState.Closed Then
            Conn.Open()
        End If

        If Err.Number <> 0 Then
            MessageBox.Show("GAGAL KONEKSI SERVER, SILAHKAN PERBAIKI DATA SETTING ANDA", "Kesalahan", MessageBoxButtons.OK)
            frmSettingDB.Show()
        End If
    End Sub
   
    Public Function StripNonAlphaNum(ByRef sText As String) As String
        Dim strRegex As String = "[^a-zA-Z0-9 -]"
        Dim rgx As New System.Text.RegularExpressions.Regex(strRegex)
        Return rgx.Replace(sText, "")
    End Function
    Public Function NamaBulan(ByVal cNilaiBulan As Byte) As String
        NamaBulan = cBulan(cNilaiBulan)
        Return NamaBulan
    End Function
    Public Function NilaiBulan(ByVal cNamaBulan As String) As Byte
        Dim nBulan As Byte
        Select Case Trim(cNamaBulan)
            Case "Januari"
                nBulan = 1
            Case "Februari", "Pebruari"
                nBulan = 2
            Case "Maret"
                nBulan = 3
            Case "April"
                nBulan = 4
            Case "Mei"
                nBulan = 5
            Case "Juni"
                nBulan = 6
            Case "Juli"
                nBulan = 7
            Case "Agustus"
                nBulan = 8
            Case "September"
                nBulan = 9
            Case "Oktober"
                nBulan = 10
            Case "November", "Nopember"
                nBulan = 11
            Case "Desember"
                nBulan = 12
            Case Else
                nBulan = 0
        End Select
        NilaiBulan = nBulan
        Return NilaiBulan
    End Function
End Module



