Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Decimal
Partial Class Admin_Login_Record
    Inherits System.Web.UI.Page

    Dim sel_val As String
    Dim ret_user As String
    Dim ds As DataSet
    Dim dt As DataTable
    Dim i As Integer

    Protected Sub form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Session("AdminID") Is Nothing Then
                Response.Redirect("AdminLogin.aspx?sesn=expire")
                Exit Sub
            End If

            If Not IsPostBack Then
                If Session("AdminID") = Nothing Then
                    Response.Redirect("AdminLogin.aspx")
                End If
                fillgrid_user()

            End If

        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "strkey")   'Display error Message
        End Try
    End Sub

    Protected Sub fillgrid_user()
        Try

            dt = ReturnDataTable("select AdminUserLog_Kid,AdminUserLog_UserName,AdminUserLog_Status,AdminUserLog_UserType from AdminUserLog where AdminUserLog_Status='0'")
            GridView1.DataSource = dt
            GridView1.DataBind()

            If dt.Rows.Count <> 0 Then
                For i = 0 To dt.Rows.Count - 1
                    If dt.Rows(i).Item("AdminUserLog_Status") = "0" Then
                        GridView1.Rows(i).Cells(2).Text = "LogIn"
                    End If
                Next
            End If

        Catch ex As Exception
        End Try
    End Sub

    Protected Sub lnklogout_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try

            If CType(sender, LinkButton).CommandArgument.ToString = Session("LogKid") Then
                Label2.Text = "You Can not Logout to Yourself."
                Exit Sub
            End If
            Label2.Text = ""
            Dim kid As String = CType(sender, LinkButton).CommandArgument.ToString
            Dim username As String = ReturnValue("SELECT  AdminUserLog_UserName FROM  AdminUserLog WHERE AdminUserLog_Kid = '" & RemoveLiterals(kid) & "'")
            Dim nextlogintime As String = ReturnValue("SELECT  TOP (1) AdminUserLog_LoginDateTime AS NextLogin  FROM AdminUserLog  WHERE  (AdminUserLog_LoginDateTime > (SELECT  AdminUserLog_LoginDateTime   FROM  AdminUserLog AS AdminUserLog_1   WHERE  (AdminUserLog_Status = '0') AND (AdminUserLog_Kid = '" & RemoveLiterals(kid) & "'))) AND AdminUserLog_UserName ='" & username & "' ORDER BY NextLogin")

            If nextlogintime = "" Then
                InsertAdminUserLog(RemoveLiterals(kid), GridView1.Rows(i).Cells(0).Text.ToString, Request.UserHostAddress, 1, GridView1.Rows(i).Cells(1).Text, "AdminLogin", "Update")
            Else
                ExecuteQuery("Update AdminUserLog set AdminUserLog_Status =1,AdminUserLog_LogoutDateTime='" & nextlogintime.Trim & "',AdminUserLog_ClientIP='" & Request.UserHostAddress & "' where AdminUserLog_Kid='" & RemoveLiterals(kid) & "'")
            End If

            fillgrid_user()

        Catch ex As Exception
        End Try

    End Sub

    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
        GridView1.PageIndex = e.NewPageIndex
        fillgrid_user()

    End Sub
End Class
