Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Net
Imports System.Net.Mail
Public Class Functions
    Inherits System.Web.UI.Page

    Public Overridable ReadOnly Property GetPageName() As String
        Get
            Dim pgName As String
            pgName = Path.GetFileName(System.Web.HttpContext.Current.Request.Url.AbsolutePath)
            If pgName = "" Then
                Return "Default.aspx"
            Else
                Return pgName
            End If
        End Get
    End Property
    Protected Sub LogStats()
        If Session("stats") <> True Then
            Dim cmd, cmd2 As New SqlCommand
            Dim intCount As Integer
            Dim DBConn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

            Try
                cmd.CommandText = ("SELECT Count(*) FROM stats WHERE year=@Year")
                cmd.Parameters.Add(New SqlParameter("@Year", SqlDbType.VarChar)).Value = Year(Today)
                cmd.Connection = DBConn
                DBConn.Open()
                intCount = cmd.ExecuteScalar()
            Catch ex As Exception

            Finally
                DBConn.Close()
            End Try

            Try
                If intCount = 0 Then
                    cmd2.CommandText = ("INSERT INTO stats (year,[fld1],[fld2],[fld3],[fld4],[fld5],[fld6],[fld7],[fld8],[fld9],[fld10],[fld11],[fld12]) VALUES (@Year,0,0,0,0,0,0,0,0,0,0,0,0)")
                Else
                    cmd2.CommandText = ("UPDATE stats SET fld" & Month(Today) & " = fld" & Month(Today) & " + 1 WHERE year=@Year")
                End If
                cmd2.Parameters.Add(New SqlParameter("@Year", SqlDbType.VarChar)).Value = CStr(Year(Today))
                cmd2.Connection = DBConn
                DBConn.Open()
                cmd2.ExecuteNonQuery()
            Catch ex As Exception

            Finally
                DBConn.Close()
            End Try
            Session("stats") = True
        End If
    End Sub
    Public Sub Authenticate()
        If Session("user") <> True Then
            Response.Redirect("/Default.aspx")
        End If
    End Sub

End Class
