Imports MySql.Data.MySqlClient
Module user
    Public con As MySqlConnection = mysqldb()
    Public Sub visibleMenu(result As String, user As String)
        With Form1
            If user = "admin" Then
                .SupplierToolStripMenuItem.Visible = result
                .ManageUsersToolStripMenuItem.Visible = result
                .ListOfItemsToolStripMenuItem.Visible = result
                .AssignmentsToolStripMenuItem.Visible = result
                .TransactionToolStripMenuItem.Visible = result
                .UtilitiesToolStripMenuItem.Visible = result
                .ReportsToolStripMenuItem.Visible = result
            Else
                .ListOfItemsToolStripMenuItem.Visible = result
                .AssignmentsToolStripMenuItem.Visible = result
                .TransactionToolStripMenuItem.Visible = result
                .ReportsToolStripMenuItem.Visible = result

            End If
        End With

    End Sub
    Public Sub login(ByVal username As Object, ByVal pass As Object)
        Try

            con.Open()
            reloadtxt("SELECT * FROM `tbluseraccounts` WHERE Username= '" & username & "' and Pass = sha1('" & pass & "')")


            If dt.Rows.Count > 0 Then

                If dt.Rows(0).Item("Role") = "Administrator" Then
                    MsgBox("Welcome " & dt.Rows(0).Item("Role"))
                    Form1.Text = "User :" & dt.Rows(0).Item("Fullname")
                    Form1.LogoutToolStripMenuItem.Text = "Logout"
                    visibleMenu("true", "admin")
                    LoginForm1.Close()
                Else
                    visibleMenu("true", "not admin")
                    Form1.LogoutToolStripMenuItem.Text = "Logout"
                    LoginForm1.Close()
                End If

            Else
                MsgBox("Acount doest not exits!", MsgBoxStyle.Information)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        con.Close()
        da.Dispose()
    End Sub
    Public Sub append(ByVal sql As String, ByVal field As String, ByVal txt As Object)
        reloadtxt(sql)
        Try
            Dim r As DataRow
            txt.AutoCompleteCustomSource.Clear()
            For Each r In dt.Rows
                txt.AutoCompleteCustomSource.Add(r.Item(field).ToString)
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
       

    End Sub
End Module
