Imports System
Imports System.Data
Imports System.Data.SqlClient

Partial Public Class Login
    Inherits System.Web.UI.Page
    Dim Conn As SqlConnection = New SqlConnection
    Dim errmsg As String


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        txtUserName.Focus()
    End Sub

    Protected Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Dim strPwd As String = ""
        If (txtUserName.Text.Trim().Length = 0) And (txtPassword.Text.Trim().Length = 0) Then
            lbl_alert_message.Text = "* User ID and Password Cannot be Blank!"
            txtUserName.Focus()
            Exit Sub
        ElseIf (txtUserName.Text.Trim().Length = 0) Then
            lbl_alert_message.Text = "* User ID Cannot be Blank!"
            txtUserName.Focus()
            Exit Sub
        ElseIf (txtPassword.Text.Trim().Length = 0) Then
            lbl_alert_message.Text = "* Password Cannot be Blank!"
            txtPassword.Focus()
            Exit Sub
        End If
        Conn.ConnectionString = ConfigurationManager.ConnectionStrings("CalendarConnStr").ConnectionString
        Conn.Open()
        Dim UserPassSql As String = "SELECT id,Userid,upassword,user_type From user_master Where Userid='" & txtUserName.Text.Trim() & "'  and upassword='" & txtPassword.Text.Trim() & "'"
        Dim UserPassAdapter As New SqlDataAdapter(UserPassSql, Conn)
        Dim UserPassDataSet As New DataSet()
        UserPassAdapter.Fill(UserPassDataSet, "User")
        If UserPassDataSet.Tables(0).Rows.Count = 0 Then 'If no registred user exists
            lbl_alert_message.Text = "* No Such User Exist."
        Else
            Session("user_id") = UserPassDataSet.Tables(0).Rows(0)("id").ToString()
            Session("user_type") = UserPassDataSet.Tables(0).Rows(0)("user_type").ToString()
            Conn.Close()
            Response.Redirect("Event.aspx")
        End If
        Conn.Close()
    End Sub
End Class