Option Strict Off
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 cmd As OdbcCommand
    Public str, strSS, strDB, strUID, strPWD, strPort, sqlCari, cKodeCari, cNamaCari, cTabelCari, cKodeBtn, cNamaBtn, sda As String

    Public Sub Koneksi()

        strSS = GetSetting("SPKBarangImportir", "Database", "Nama Server", "A") 'ambil nilai dr registry, jika blm ada isi dgn karakter kosong ""
        strDB = GetSetting("SPKBarangImportir", "Database", "Nama Database", "")
        strUID = GetSetting("SPKBarangImportir", "Database", "User", "")
        strPWD = GetSetting("SPKBarangImportir", "Database", "Password", "")
        strPort = GetSetting("SPKBarangImportir", "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
    Function NilaiIndeksRandom(ByVal jlhMatriks As Integer) As Double
        Select Case jlhMatriks
            Case 1
                Return 0
            Case 2
                Return 0
            Case 3
                Return 0.58
            Case 4
                Return 0.9
            Case 5
                Return 1.12
            Case 6
                Return 1.24
            Case 7
                Return 1.32
            Case 8
                Return 1.41
            Case 9
                Return 1.45
            Case 10
                Return 1.49
            Case 11
                Return 1.51
            Case 12
                Return 1.48
            Case 13
                Return 1.56
            Case 14
                Return 1.57
            Case 15
                Return 1.59
            Case Else
                Return 0
        End Select
    End Function
    Function GetList(ByVal table As String, ByVal field As String, ByVal orderBy As String) As String()
        Dim query As String = "select `" & field & "` from `" & table & "` order by `" & orderBy & "` asc"
        Dim lst As New List(Of String)
        'If Conn() Then
        Dim cmd As New OdbcCommand(query, Conn)
        Dim rd As OdbcDataReader = cmd.ExecuteReader
        While rd.Read
            lst.Add(rd(0))
        End While
        rd.Close()
        Return lst.ToArray
        cmd = Nothing
        rd = Nothing
        ' Else
        ' Return Nothing
        ' MsgBox("Database Belum TerConnectsi!")
        'End If
        query = Nothing
        lst = Nothing
    End Function
    Function GetMax(ByVal number() As Double) As Double
        Dim buff As Double = 0

        For i As Integer = 0 To number.Length - 2
            For j As Integer = i + 1 To number.Length - 1
                If number(i) < number(j) Then
                    buff = number(i)
                    number(i) = number(j)
                    number(j) = buff
                End If
            Next
        Next
        Return number(0)
    End Function
End Module

