Imports System.Windows.Forms
Imports System.Drawing
Imports System.Data
Imports System.Data.OleDb
Public Class frmInicio
Private veces As Integer = 0
Private Const NumeroIntentos As Integer = 3
Private cadenaCnn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=transporte.mdb"
Private Sub btnACEPTAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnACEPTAR.Click
'If TxtClave.Text = "911" Then
If ComprobarUsuario(txtNICK.Text, txtCLAVE.Text) Then
'Dim claveSHA As String = Me.generarClaveSHA1(Me.TxtClave.Text)
'If ComprobarUsuario(Me.TxtUsuario.Text, claveSHA) Then
Me.DialogResult = Windows.Forms.DialogResult.OK
'Form1.Show()
Else
veces = veces + 1
If veces < NumeroIntentos Then
Label3.Text = "Quedan " & (NumeroIntentos - veces) & " intentos"
Exit Sub
End If
Me.DialogResult = Windows.Forms.DialogResult.No
End If
Hide()
End Sub
Private Sub btnSALIR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSALIR.Click
Me.DialogResult = Windows.Forms.DialogResult.Cancel
Hide()
End Sub
Private Function ComprobarUsuario( _
ByVal IDUsuario As String, _
ByVal IDContraseña As String) As Boolean
Dim cnn As OleDbConnection = Nothing
'
Try
cnn = New OleDbConnection(cadenaCnn)
cnn.Open()
Dim sel As New System.Text.StringBuilder
sel.Append("SELECT COUNT (*) FROM Usuarios ")
sel.Append("WHERE IDUsuario = @IDUsuario AND IDContraseña = @IDContraseña")
Dim cmd As New OleDbCommand(sel.ToString, cnn)
cmd.Parameters.Add("@IDUsuario", OleDbType.VarChar, 50)
cmd.Parameters.Add("@IDContraseña", OleDbType.VarChar, 40)
cmd.Parameters("@IDUsuario").Value = IDUsuario
cmd.Parameters("@IDContraseña").Value = IDContraseña
Dim t As Integer = CInt(cmd.ExecuteScalar())
cnn.Close()
If t = 0 Then
Return False
End If
Catch ex As Exception
MessageBox.Show("ERROR al conectar a la base de datos: " & vbCrLf & _
ex.Message, "Comprobar usuario", MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
Return False
Finally
If Not cnn Is Nothing Then
cnn.Dispose()
End If
End Try
Return True
End Function
end class