Imports System.Data.OleDb
Imports System.Data
Public Class deleteControle
    Dim Pass2Connection As OleDbConnection
    Dim Pass2Command As OleDbCommand
    Dim Pass2Table As New DataTable
    Dim Pass2Adapter As OleDbDataAdapter
    Dim Pass2Manager As CurrencyManager

    Dim TarifeConnection As OleDbConnection
    Dim TarifeCommand As OleDbCommand
    Dim TarifeAdapter As OleDbDataAdapter
    Dim TarifeTable As New DataTable
    Dim TarifeManager As CurrencyManager

    Dim NumTries As String ' This variable contains Number that the user will enter password
    Public Sub Delete()
        If MessageBox.Show("Are you sure you want to delete this record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
            TarifeManager.RemoveAt(TarifeManager.Position)
        End If

    End Sub

    Private Sub Password1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Pass2Connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Pass2.mdb")
        Pass2Connection.Open()
        Pass2Command = New OleDbCommand("SELECT * FROM Pass2 ORDER BY Passe", Pass2Connection)
        Pass2Adapter = New OleDbDataAdapter()
        Pass2Adapter.SelectCommand = Pass2Command
        Pass2Table = New DataTable()
        Pass2Adapter.Fill(Pass2Table)

        TarifeConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Tarife.mdb")
        TarifeConnection.Open()
        'establish Tarife command object
        TarifeCommand = New OleDbCommand("SELECT * FROM Tarif ORDER BY TxtNom", TarifeConnection)
        'establish Books data adapter/data table
        TarifeAdapter = New OleDbDataAdapter()
        TarifeAdapter.SelectCommand = TarifeCommand
        TarifeTable = New DataTable()
        TarifeAdapter.Fill(TarifeTable)

        'establish currency manager
        TarifeManager = DirectCast(Me.BindingContext(TarifeTable), CurrencyManager)

    End Sub

    Private Sub BtnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnter.Click
        NumTries += 1

        Pass2Table.DefaultView.Sort = "Passe"
        Dim FoundRow As Integer = Pass2Table.DefaultView.Find(Password.Text)

        Pass2Table.DefaultView.Sort = "UserName"
        Dim FindRow As Integer = Pass2Table.DefaultView.Find(UserName.Text)

        If FoundRow <> -1 And FindRow <> -1 Then
            Call Delete()
            Me.Hide()



        ElseIf NumTries < 3 Then
            MsgBox("Mot de Passe invalide!S'il vous palit Essayer de nouveau" & vbCr & "Or the Field Is Empty.", MsgBoxStyle.Critical, )
            UserName.Text = ""
            Password.Text = ""
        ElseIf NumTries >= 3 Then
            Beep()
            MsgBox("Vous n'êtes pas Autorisé à utiliser ce programme!", MsgBoxStyle.Exclamation)
            UserName.Enabled = False
            Password.Enabled = False
            UserName.Text = ""
            Password.Text = ""
            BtnEnter.Enabled = False
            Me.Hide()
            ATarification.Show()

        End If

    End Sub

    Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
        Me.Hide()

    End Sub

    Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
        If MessageBox.Show("Are you sure you want to delete this record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
            TarifeManager.RemoveAt(TarifeManager.Position)
        End If

    End Sub
End Class