Option Explicit On 
Option Strict On

Imports System.Data
Imports System.Data.SqlClient

Public Class show_errors
	Inherits System.Web.UI.Page
	Protected WithEvents btnClearErrors As System.Web.UI.WebControls.Button
	Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

#Region " Web Form Designer Generated Code "

	'This call is required by the Web Form Designer.
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

	End Sub

	Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
		'CODEGEN: This method call is required by the Web Form Designer
		'Do not modify it using the code editor.
		InitializeComponent()
	End Sub

#End Region

	Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		If Not Page.IsPostBack Then
			Dim con As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("sConnection"))
			If con.State = ConnectionState.Closed Then con.Open()
			Dim da As New SqlDataAdapter()
			da.SelectCommand = New SqlCommand()
			With da.SelectCommand
				.CommandText = "Select Top 20 * from as_Errors order by DateTime Desc"
				.CommandType = CommandType.Text
				.Connection = con
			End With
			Dim ds As New DataSet()
			da.Fill(ds)
			DataGrid1.DataSource = ds
			DataGrid1.DataBind()
		End If
	End Sub

	Private Sub btnClearErrors_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearErrors.Click
		Dim con As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("sConnection"))
		If con.State = ConnectionState.Closed Then con.Open()
		Dim cmd As New SqlCommand()
		With cmd
			.CommandType = CommandType.Text
			.CommandText = "Delete from as_Errors"
			Try
				.Connection = con
				.ExecuteNonQuery()
				DataGrid1.DataSource = Nothing
				DataGrid1.DataBind()
			Catch ex As Exception
				'do nothing
			End Try
		End With
	End Sub
End Class
