Imports System.Data.SqlClient
Public Class Login
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Abre_BDs()
Try
cnSQL = New SqlConnection("Data Source=SBSLAM\SQLEXPRESS;Initial Catalog=Inventario;Persist Security Info=True;User ID=Elo;Password=elo2007")
cnSQL.Open()
Catch
End Try
End Sub
Private Sub txtUtilizador_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
txtUtilizador.SelectAll()
End Sub
Private Sub txtPassword_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
txtPassword.SelectAll()
End Sub
Private Sub OK_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Try
daSql = New SqlDataAdapter("select count(*) from Username_inv where Utilizador='" & txtUtilizador.Text & "' and password='" & txtPassword.Text & "'", cnSQL)
Dim dsSQL As DataSet = New DataSet()
'Chamar a tabela
daSql.Fill(dsSQL, "Username_inv")
If dsSQL.Tables.Item(0).Rows(0).Item(0) = 1 Then
Module1.Utilizador = txtUtilizador.Text
Me.Hide()
Principal.Show()
Else
MsgBox("Utilizador ou password incorrectas.", MsgBoxStyle.Critical)
txtUtilizador.Text = ""
txtPassword.Text = ""
txtUtilizador.Focus()
End If
daSql = Nothing
dsSQL = Nothing
Catch
End Try
End Sub
Private Sub Cancel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
End
End Sub
Private Sub txtPassword_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyDown
Try
If e.KeyCode = Keys.Enter Then
OK_Click_1(Nothing, Nothing)
End If
Catch
End Try
End Sub