Imports System.Data
Imports System.Data.SqlClient
Public Class frmInicio
Private veces As Integer = 0
Private Const numeroIntentos As Integer = 3
Private cadenaCnn As String = "Data Source = KELINONESQLEXPRESS; Initial Catalog = Usuarios; Integrated Security=True"
Private Sub btnACEPTAR_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnACEPTAR.Click
If comprobarUsuario(Me.txtNICK.Text, Me.txtCLAVE.Text) Then
'If txtCLAVE.Text = "123" Then
Me.DialogResult = Windows.Forms.DialogResult.OK
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 SqlConnection = Nothing
Try
cnn = New SqlClient.SqlConnection(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 SqlClient.SqlCommand(sel.ToString, cnn)
cmd.Parameters.Add("@IDUsuario", SqlDbType.NVarChar, 50)
cmd.Parameters.Add("@IDContraseña", SqlDbType.NVarChar, 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
Private Sub frmInicio_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class