Imports System.IO
Imports G2BServicesProvider

Partial Class Configurations_Default
    Inherits AdminPage

    Private CheckFaled As Boolean = False
    Private Path As String = "d:\CharterRedesignLogs\"


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        On Error Resume Next

        If Not IsPostBack Then
            AddToHitCount()
            GetHitCount()
        End If



    End Sub

    Sub GetHitCount()
        Dim SR As System.IO.StreamReader
        '###################################
        'READ THE COUNT FROM THE FILE.
        '###################################
        SR = System.IO.File.OpenText(Path & "MainPageHitCount.txt")
        Dim lCount As String = SR.ReadLine.ToString()

        SR.Close()


        Response.Write("<br><br><b>Hit Count: " & lCount & "</b><br><br>")
    End Sub

    Protected Sub btnResetHitCount_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnResetHitCount.Click
        On Error Resume Next

        Dim SR As System.IO.StreamReader
        Dim TW As System.IO.TextWriter

        '###################################
        'MAKE SURE THE FOLDER EXISTS FIRST
        '###################################
        If Not Directory.Exists(Path) Then
            Directory.CreateDirectory(Path)
        End If

        '###################################
        'RESET COUNT AND WRITE UPDATED COUNT TO FILE.
        '###################################

        TW = System.IO.File.CreateText(Path & "MainPageHitCount.txt")
        TW.WriteLine("0")
        TW.Flush()
        TW.Close()


        GetHitCount()
    End Sub


    Sub AddToHitCount()
        Dim SR As System.IO.StreamReader
        Dim TW As System.IO.TextWriter

        '###################################
        'MAKE SURE THE FOLDER EXISTS FIRST
        '###################################
        If Not Directory.Exists(Path) Then
            Directory.CreateDirectory(Path)
        End If

        '###################################
        'SEE IF FILE ALREADY EXISTS
        '###################################
        If Not (File.Exists(Path & "MainPageHitCount.txt")) Then
            TW = System.IO.File.CreateText(Path & "MainPageHitCount.txt")
            TW.WriteLine("0")
            TW.Flush()
            TW.Close()
        End If

        '###################################
        'READ THE COUNT FROM THE FILE.
        '###################################
        SR = System.IO.File.OpenText(Path & "MainPageHitCount.txt")
        Dim lCount As String = SR.ReadLine.ToString()
        Dim lCnt As Integer = 0
        If lCount <> "" Then
            lCnt = CType(lCount, Integer) + 1
        End If
        SR.Close()

        '###################################
        'WRITE UPDATED COUNT TO FILE.
        '###################################
        If lCnt > 0 Then
            TW = System.IO.File.CreateText(Path & "MainPageHitCount.txt")
            TW.WriteLine(lCnt.ToString())
            TW.Flush()
            TW.Close()

        End If

    End Sub


End Class
