Option Explicit On 
Option Strict On

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

Public Class ViewCalender
	Inherits System.Web.UI.Page
	Protected WithEvents daViewPage As System.Data.SqlClient.SqlDataAdapter
	Protected WithEvents txtPageName As System.Web.UI.WebControls.TextBox
	Protected WithEvents lblID As System.Web.UI.WebControls.Label
	Protected WithEvents rfvPageName As System.Web.UI.WebControls.RequiredFieldValidator
	Protected WithEvents dlChildPages As System.Web.UI.WebControls.DataList
	Protected WithEvents btnUpdate As System.Web.UI.WebControls.Button
	Protected WithEvents daChildPageLinks As System.Data.SqlClient.SqlDataAdapter
	Protected WithEvents DsChildPageLinks1 As AllSaints.dsChildPageLinks
	Protected WithEvents DsViewPage1 As AllSaints.dsViewPage
	Protected WithEvents imgTop As System.Web.UI.WebControls.Image
	Protected WithEvents lnkTopPicRemove As System.Web.UI.WebControls.LinkButton
	Protected WithEvents btnTopPicUpdate As System.Web.UI.WebControls.Button
	Protected WithEvents TopPicture As System.Web.UI.HtmlControls.HtmlInputFile
	Protected WithEvents ECalender As System.Web.UI.WebControls.Calendar
	Protected WithEvents EventList As System.Web.UI.WebControls.DataList
	Protected WithEvents daEvents As System.Data.SqlClient.SqlDataAdapter
	Protected WithEvents cmdGetEvent As System.Data.SqlClient.SqlCommand
	Protected WithEvents cmdInsEvent As System.Data.SqlClient.SqlCommand
	Protected WithEvents cmdSetEvents As System.Data.SqlClient.SqlCommand
	Protected WithEvents cmdDelEvent As System.Data.SqlClient.SqlCommand
	Protected WithEvents DsEvents1 As AllSaints.dsEvents
	Protected WithEvents daAllEvents As System.Data.SqlClient.SqlDataAdapter
	Protected WithEvents cmdAllEvents As System.Data.SqlClient.SqlCommand
	Protected WithEvents DsAllEvents1 As AllSaints.dsAllEvents
	Protected WithEvents SqlConn As System.Data.SqlClient.SqlConnection
	Protected WithEvents cmdGetViewPage As System.Data.SqlClient.SqlCommand
	Protected WithEvents cmdGetChildPages As System.Data.SqlClient.SqlCommand
	Protected WithEvents AddEvent1 As AllSaints.AddEvent

#Region " Web Form Designer Generated Code "

	'This call is required by the Web Form Designer.
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.daViewPage = New System.Data.SqlClient.SqlDataAdapter()
		Me.cmdGetViewPage = New System.Data.SqlClient.SqlCommand()
		Me.SqlConn = New System.Data.SqlClient.SqlConnection()
		Me.daChildPageLinks = New System.Data.SqlClient.SqlDataAdapter()
		Me.cmdGetChildPages = New System.Data.SqlClient.SqlCommand()
		Me.DsChildPageLinks1 = New AllSaints.dsChildPageLinks()
		Me.DsViewPage1 = New AllSaints.dsViewPage()
		Me.daEvents = New System.Data.SqlClient.SqlDataAdapter()
		Me.cmdDelEvent = New System.Data.SqlClient.SqlCommand()
		Me.cmdInsEvent = New System.Data.SqlClient.SqlCommand()
		Me.cmdGetEvent = New System.Data.SqlClient.SqlCommand()
		Me.cmdSetEvents = New System.Data.SqlClient.SqlCommand()
		Me.DsEvents1 = New AllSaints.dsEvents()
		Me.daAllEvents = New System.Data.SqlClient.SqlDataAdapter()
		Me.cmdAllEvents = New System.Data.SqlClient.SqlCommand()
		Me.DsAllEvents1 = New AllSaints.dsAllEvents()
		CType(Me.DsChildPageLinks1, System.ComponentModel.ISupportInitialize).BeginInit()
		CType(Me.DsViewPage1, System.ComponentModel.ISupportInitialize).BeginInit()
		CType(Me.DsEvents1, System.ComponentModel.ISupportInitialize).BeginInit()
		CType(Me.DsAllEvents1, System.ComponentModel.ISupportInitialize).BeginInit()
		'
		'daViewPage
		'
		Me.daViewPage.SelectCommand = Me.cmdGetViewPage
		Me.daViewPage.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "GetPageInfo", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ID", "ID"), New System.Data.Common.DataColumnMapping("PageName", "PageName"), New System.Data.Common.DataColumnMapping("Body", "Body"), New System.Data.Common.DataColumnMapping("BodyHeading", "BodyHeading"), New System.Data.Common.DataColumnMapping("TopPicture", "TopPicture"), New System.Data.Common.DataColumnMapping("RightPicture", "RightPicture"), New System.Data.Common.DataColumnMapping("ParentID", "ParentID"), New System.Data.Common.DataColumnMapping("RightPicDesc", "RightPicDesc")})})
		'
		'cmdGetViewPage
		'
		Me.cmdGetViewPage.CommandText = "[GetPageInfo]"
		Me.cmdGetViewPage.CommandType = System.Data.CommandType.StoredProcedure
		Me.cmdGetViewPage.Connection = Me.SqlConn
		Me.cmdGetViewPage.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
		Me.cmdGetViewPage.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PageID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
		'
		'SqlConn
		'
		Me.SqlConn.ConnectionString = "data source=localhost;initial catalog=Online_allsaints;persist security info=Fals" & _
		"e;user id=sa;workstation id=GALAXY;packet size=4096"
		'
		'daChildPageLinks
		'
		Me.daChildPageLinks.SelectCommand = Me.cmdGetChildPages
		Me.daChildPageLinks.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "GetChildPages", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ID", "ID"), New System.Data.Common.DataColumnMapping("PageName", "PageName"), New System.Data.Common.DataColumnMapping("Body", "Body"), New System.Data.Common.DataColumnMapping("BodyHeading", "BodyHeading"), New System.Data.Common.DataColumnMapping("TopPicture", "TopPicture"), New System.Data.Common.DataColumnMapping("RightPicture", "RightPicture"), New System.Data.Common.DataColumnMapping("ParentID", "ParentID"), New System.Data.Common.DataColumnMapping("RightPicDesc", "RightPicDesc")})})
		'
		'cmdGetChildPages
		'
		Me.cmdGetChildPages.CommandText = "[GetChildPages]"
		Me.cmdGetChildPages.CommandType = System.Data.CommandType.StoredProcedure
		Me.cmdGetChildPages.Connection = Me.SqlConn
		Me.cmdGetChildPages.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
		Me.cmdGetChildPages.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PageID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
		'
		'DsChildPageLinks1
		'
		Me.DsChildPageLinks1.DataSetName = "dsChildPageLinks"
		Me.DsChildPageLinks1.Locale = New System.Globalization.CultureInfo("en-US")
		Me.DsChildPageLinks1.Namespace = "http://www.tempuri.org/dsChildPageLinks.xsd"
		'
		'DsViewPage1
		'
		Me.DsViewPage1.DataSetName = "dsViewPage"
		Me.DsViewPage1.Locale = New System.Globalization.CultureInfo("en-US")
		Me.DsViewPage1.Namespace = "http://www.tempuri.org/dsViewPage.xsd"
		'
		'daEvents
		'
		Me.daEvents.DeleteCommand = Me.cmdDelEvent
		Me.daEvents.InsertCommand = Me.cmdInsEvent
		Me.daEvents.SelectCommand = Me.cmdGetEvent
		Me.daEvents.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "GetEvents", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("EventID", "EventID"), New System.Data.Common.DataColumnMapping("PageID", "PageID"), New System.Data.Common.DataColumnMapping("EventDate", "EventDate"), New System.Data.Common.DataColumnMapping("Details", "Details")})})
		Me.daEvents.UpdateCommand = Me.cmdSetEvents
		'
		'cmdDelEvent
		'
		Me.cmdDelEvent.CommandText = "[DelEvents]"
		Me.cmdDelEvent.CommandType = System.Data.CommandType.StoredProcedure
		Me.cmdDelEvent.Connection = Me.SqlConn
		Me.cmdDelEvent.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
		Me.cmdDelEvent.Parameters.Add(New System.Data.SqlClient.SqlParameter("@EventID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0, Byte), "EventID", System.Data.DataRowVersion.Original, Nothing))
		'
		'cmdInsEvent
		'
		Me.cmdInsEvent.CommandText = "[InsEvents]"
		Me.cmdInsEvent.CommandType = System.Data.CommandType.StoredProcedure
		Me.cmdInsEvent.Connection = Me.SqlConn
		Me.cmdInsEvent.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
		Me.cmdInsEvent.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PageID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0, Byte), "PageID", System.Data.DataRowVersion.Current, Nothing))
		Me.cmdInsEvent.Parameters.Add(New System.Data.SqlClient.SqlParameter("@EventDate", System.Data.SqlDbType.DateTime, 8, "EventDate"))
		Me.cmdInsEvent.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Details", System.Data.SqlDbType.VarChar, 7168, "Details"))
		'
		'cmdGetEvent
		'
		Me.cmdGetEvent.CommandText = "[GetEvents]"
		Me.cmdGetEvent.CommandType = System.Data.CommandType.StoredProcedure
		Me.cmdGetEvent.Connection = Me.SqlConn
		Me.cmdGetEvent.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
		Me.cmdGetEvent.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PageID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
		Me.cmdGetEvent.Parameters.Add(New System.Data.SqlClient.SqlParameter("@EventDate", System.Data.SqlDbType.DateTime, 8))
		'
		'cmdSetEvents
		'
		Me.cmdSetEvents.CommandText = "[SetEvents]"
		Me.cmdSetEvents.CommandType = System.Data.CommandType.StoredProcedure
		Me.cmdSetEvents.Connection = Me.SqlConn
		Me.cmdSetEvents.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
		Me.cmdSetEvents.Parameters.Add(New System.Data.SqlClient.SqlParameter("@EventID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0, Byte), "EventID", System.Data.DataRowVersion.Current, Nothing))
		Me.cmdSetEvents.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Details", System.Data.SqlDbType.VarChar, 7168, "Details"))
		'
		'DsEvents1
		'
		Me.DsEvents1.DataSetName = "dsEvents"
		Me.DsEvents1.Locale = New System.Globalization.CultureInfo("en-US")
		Me.DsEvents1.Namespace = "http://www.tempuri.org/dsEvents.xsd"
		'
		'daAllEvents
		'
		Me.daAllEvents.SelectCommand = Me.cmdAllEvents
		Me.daAllEvents.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "as_Events", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("EventID", "EventID"), New System.Data.Common.DataColumnMapping("PageID", "PageID"), New System.Data.Common.DataColumnMapping("EventDate", "EventDate"), New System.Data.Common.DataColumnMapping("Details", "Details")})})
		'
		'cmdAllEvents
		'
		Me.cmdAllEvents.CommandText = "SELECT EventID, PageID, EventDate, Details FROM as_Events where PageID=@PageID OR" & _
		"DER BY EventDate"
		Me.cmdAllEvents.Connection = Me.SqlConn
		Me.cmdAllEvents.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PageID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0, Byte), "PageID", System.Data.DataRowVersion.Current, Nothing))
		'
		'DsAllEvents1
		'
		Me.DsAllEvents1.DataSetName = "dsAllEvents"
		Me.DsAllEvents1.Locale = New System.Globalization.CultureInfo("en-US")
		Me.DsAllEvents1.Namespace = "http://www.tempuri.org/dsAllEvents.xsd"
		CType(Me.DsChildPageLinks1, System.ComponentModel.ISupportInitialize).EndInit()
		CType(Me.DsViewPage1, System.ComponentModel.ISupportInitialize).EndInit()
		CType(Me.DsEvents1, System.ComponentModel.ISupportInitialize).EndInit()
		CType(Me.DsAllEvents1, System.ComponentModel.ISupportInitialize).EndInit()

	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 GetData()
		If (CType(Request("Level"), Integer) = 1) Then
			'get the second level parent id of this child page
			Dim cmd As New SqlCommand("Select ParentID from as_Pages where ID=" & CType(Request("ID"), Integer), SqlConn)
			If SqlConn.State = ConnectionState.Closed Then SqlConn.Open()
			Dim intParentID As Integer = CType(cmd.ExecuteScalar(), Integer)

			'get to an other up level if view calender is requested
			If Not (Request("view") Is Nothing) AndAlso Request("view").ToString.Trim = "Calendar" Then
				cmd.CommandText = "Select ParentID from as_Pages where ID=" & intParentID
				If SqlConn.State = ConnectionState.Closed Then SqlConn.Open()
				intParentID = CType(cmd.ExecuteScalar(), Integer)
			End If

			'get the first level parent id of this child page
			cmd.CommandText = "Select ParentID from as_Pages where ID=" & intParentID
			If SqlConn.State = ConnectionState.Closed Then SqlConn.Open()
			intParentID = CType(cmd.ExecuteScalar(), Integer)

			'get the details about this page's parent's sublings
			daChildPageLinks.SelectCommand.Parameters("@PageID").Value = intParentID
			daChildPageLinks.Fill(DsChildPageLinks1)

			'get the details about this page
			daViewPage.SelectCommand.Parameters("@PageID").Value = CType(Request("ID"), Integer)
			daViewPage.Fill(DsViewPage1)

			daEvents.SelectCommand.Parameters("@PageID").Value = CType(lblID.Text, Integer)
			daEvents.SelectCommand.Parameters("@EventDate").Value = ECalender.SelectedDate.Year & "-" & ECalender.SelectedDate.Month & "-" & ECalender.SelectedDate.Day
			daEvents.Fill(DsEvents1)
			If (DsEvents1.Tables(0).Rows.Count <= 0) Then
				Dim arValues(3) As Object
				arValues(0) = "-1"
				arValues(1) = "-1"
				arValues(2) = System.DateTime.Today.Date
				arValues(3) = ""
				DsEvents1.Tables(0).Rows.Add(arValues)
			End If

			With daAllEvents
				.SelectCommand.Parameters("@PageID").Value = CType(lblID.Text, Integer)
				.Fill(DsAllEvents1)
			End With
		End If

	End Sub

	Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		If SqlConn.State = ConnectionState.Closed Then
			SqlConn.ConnectionString = ConfigurationSettings.AppSettings("sConnection")
		End If

		If Not Page.IsPostBack Then
			lblID.Text = Request("ID")
			ECalender.VisibleDate = Now
			ECalender.SelectedDate = Now
			Call GetData()
			Page.DataBind()
		End If

		lnkTopPicRemove.Attributes.Add("onclick", "return confirm('Are you sure ?')")
		AddEvent1.PageID = CType(lblID.Text, Integer)
		AddEvent1.EventDate = ECalender.SelectedDate

	End Sub

	'****************************************************************************
	'update the page info it will update the title of the calender page only
	'****************************************************************************
	Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
		Dim cmd As New SqlCommand()
		With cmd
			If Not (Request("view") Is Nothing) AndAlso Request("view").ToString.Trim = "Calendar" Then
				.CommandText = "Update as_Pages set BodyHeading=@PageName where(ID=@PageID)"
			Else
				.CommandText = "Update as_Pages set PageName=@PageName,BodyHeading=@PageName where(ID=@PageID)"
			End If

			.Parameters.Add("@PageName", Trim(txtPageName.Text))
			.Parameters.Add("@PageID", CType(lblID.Text, Integer))
			.CommandType = CommandType.Text
			.Connection = SqlConn
			If SqlConn.State = ConnectionState.Closed Then SqlConn.Open()
			.ExecuteScalar()
			Call GetData()
			Page.DataBind()
		End With
	End Sub

	'****************************************************************************
	'****************************************************************************
	Private Sub EventList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EventList.SelectedIndexChanged

	End Sub

	Private Sub ECalender_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ECalender.SelectionChanged
		Call GetData()
		Page.DataBind()
	End Sub

	Private Sub ECalender_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles ECalender.VisibleMonthChanged
		ECalender.SelectedDate = ECalender.SelectedDate.AddMonths(e.NewDate.Month - e.PreviousDate.Month)
		Call GetData()
		Page.DataBind()
	End Sub

	Private Sub ECalender_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles ECalender.DayRender
		If Not (DsAllEvents1.Tables.Count > 0 AndAlso DsAllEvents1.Tables(0).Rows.Count > 0) Then
			Call GetData()
			Page.DataBind()
		End If

		If DsAllEvents1.Tables.Count > 0 AndAlso DsAllEvents1.Tables(0).Rows.Count > 0 Then
			Dim dr As DataRow
			Dim i As Integer = 0
			Dim lnkStr As String = "", s As String = ""
			For Each dr In DsAllEvents1.Tables(0).Rows
				If e.Day.Date.Equals(CType(dr.Item("EventDate"), Date)) Then
					If dr.Item("Details").ToString.Length > 0 Then
						s = CType(dr.Item("Details"), String)
						'get only 20 words and add the beggining dot
						If s.Length > 20 Then
							s = s.Substring(0, 20)
						End If

						'if it is the scond link then display ... more >
						If i = 1 Then
							Dim hlnk As New HyperLink()
							With hlnk
								If Trim(s) <> "" Then
									.Text = s & "<BR>...&nbsp;More &gt<BR>"
									.NavigateUrl = "javascript:__doPostBack('ECalender','" & e.Day.Date.Subtract(CDate("1/1/2000")).Days & "')"
									.CssClass = "navCalender"
								End If
							End With
							e.Cell.Controls.Add(New LiteralControl("<BR>&nbsp;<b>·</b>"))
							e.Cell.Controls.Add(hlnk)

							'the first link is here
						Else
							Dim hlnk As New HyperLink()
							With hlnk
								If Trim(s) <> "" Then
									.Text = s
									.NavigateUrl = "javascript:__doPostBack('ECalender','" & e.Day.Date.Subtract(CDate("1/1/2000")).Days & "')"
									.CssClass = "navCalender"
								End If
							End With
							e.Cell.Controls.Add(New LiteralControl("<BR>&nbsp;<b>·</b>"))
							e.Cell.Controls.Add(hlnk)
						End If
						i += 1						  'show only two events in each box
						If i >= 2 Then
							Exit For
						End If
					End If
				End If
			Next
			e.Cell.Attributes.Add("onclick", "javascript:__doPostBack('ECalender','" & e.Day.Date.Subtract(CDate("1/1/2000")).Days & "')")
		End If
		'Static a As Integer
		'a += 1
		'e.Cell.ID = CType(a, String)
		'Dim scriptStr As String = "<script language=JavaScript> function DoClick() {"
		'scriptStr += "alert(''Welcome to .NET'}</script>"
		'
		'Page.RegisterClientScriptBlock("E" & CType(a, String), scriptStr)
		'If e.Day.Date.Equals("1/Apr/1998") Then
		'Dim dayText As LiteralControl = CType(e.Cell.Controls(0), LiteralControl)
		'e.Cell.Attributes("onclick") = Page.GetPostBackClientHyperlink(ECalender, "-637")
		'End If
		'Response.Write(e.Cell.Controls(0).GetType.ToString)
		'Dim hpl As HyperLink = CType(e.Cell.Controls(0), HyperLink)
		'Response.Write(hpl.Text)
	End Sub

	Private Sub EventList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles EventList.ItemCommand
		If e.CommandName = "DeleteSelected" Then
			Dim dl As DataListItem
			Dim chk As CheckBox
			For Each dl In EventList.Items
				chk = CType(dl.Controls(1), CheckBox)
				If chk.Checked Then
					daEvents.DeleteCommand.Parameters("@EventID").Value = CType(chk.ToolTip, Integer)
					If SqlConn.State = ConnectionState.Closed Then SqlConn.Open()
					daEvents.DeleteCommand.ExecuteNonQuery()
				End If
			Next
			Call GetData()
			Page.DataBind()
		End If
	End Sub


	Private Sub EventList_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles EventList.DataBinding
		If DsEvents1.Tables.Count <= 0 AndAlso DsEvents1.Tables(0).Rows.Count <= 0 Then
			EventList.Visible = False
		Else
			If CType(DsEvents1.Tables(0).Rows(0).Item(0), Integer) > 0 Then
				EventList.Visible = True
			Else
				EventList.Visible = False
			End If
		End If
	End Sub

	'****************************************************************************
	'	This will add the alert in the Delete button
	'****************************************************************************
	Private Sub EventList_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles EventList.ItemCreated
		If e.Item.ItemType = ListItemType.Footer Then
			Dim btn As LinkButton = CType(e.Item.FindControl("lnkDeleteSelected"), LinkButton)
			btn.Attributes.Add("onclick", "return confirm('Are you sure ?')")
		End If
	End Sub

	'****************************************************************************
	'	This will Remove Top Body Picture { right of Top Links }
	'****************************************************************************
	Private Sub lnkTopPicRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkTopPicRemove.Click
		Dim cmd As New SqlCommand()
		With cmd
			.CommandText = "Select TopPicture from as_Pages where ID=" & CType(Trim(lblID.Text), Integer)
			.CommandType = CommandType.Text
			.Connection = SqlConn
			If SqlConn.State = ConnectionState.Closed Then SqlConn.Open()
			Dim sFilename As String = CType(.ExecuteScalar, String)

			If sFilename.Length > 0 Then
				Try
					sFilename = sFilename.Substring(1)
					'System.IO.File.Delete(Server.MapPath("..") & sFilename)
				Catch ex As Exception
					'do nothing
				End Try
				.CommandText = "Update as_Pages Set TopPicture='' where ID=" & CType(Trim(lblID.Text), Integer)
				.CommandType = CommandType.Text
				.Connection = SqlConn
				If SqlConn.State = ConnectionState.Closed Then SqlConn.Open()
				.ExecuteNonQuery()

			End If

		End With

		'referesh the page data
		Call GetData()
		Page.DataBind()

	End Sub

	'****************************************************************************
	'	This will update the Top picture of the page
	'****************************************************************************
	Private Sub btnTopPicUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTopPicUpdate.Click
		Dim cmd As New SqlCommand()

		With TopPicture.PostedFile
			If .FileName <> "" Then
				Select Case Trim(.ContentType.ToLower)

					Case "image/gif", "image/pjpg", "image/jpeg", "image/pjpeg", "image/jpg"
						Try
							Dim sFilename As String = System.IO.Path.GetExtension(.FileName)
							sFilename = "\contents\images\" & Trim(lblID.Text) & "top" & sFilename
							.SaveAs(Server.MapPath("..") & sFilename)

							With cmd
								.CommandText = "Update as_Pages Set TopPicture='." & sFilename & "' where ID=" & CType(Trim(lblID.Text), Integer)
								.CommandType = CommandType.Text
								.Connection = SqlConn
								If SqlConn.State = ConnectionState.Closed Then SqlConn.Open()
								.ExecuteNonQuery()
							End With

						Catch ex As Exception
							Response.Write(ex.ToString)

						End Try

					Case Else
						'nothing
				End Select
			End If
		End With
		'referesh the page data
		Call GetData()
		Page.DataBind()
	End Sub

	'******************************************************************************
	'	This is to just display the "no_img" instead of empty box of image
	'******************************************************************************
	Private Sub imgTop_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles imgTop.PreRender
		Dim img As System.Web.UI.WebControls.Image = CType(sender, System.Web.UI.WebControls.Image)
		If img.ImageUrl.Length > 0 Then
			img.ImageUrl = img.ImageUrl.Substring(2)
			img.ImageUrl = "..\" & img.ImageUrl
		Else
			img.ImageUrl = "..\contents\images\noimage.jpg"
		End If
	End Sub

	Private Sub AddEvent1_EventAdded() Handles AddEvent1.EventAdded
		Call GetData()
		Page.DataBind()
	End Sub

	'*******************************************************************************
	'*******************************************************************************
	Private Sub dlChildPages_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dlChildPages.SelectedIndexChanged

	End Sub

	Private Sub dlChildPages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlChildPages.ItemCommand
		Response.Redirect("MgrContent.aspx?ID=" & e.CommandArgument.ToString, True)
		''Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
		''If Not drv Is Nothing Then
		'Select Case e.CommandName
		'	Case "Calendar"
		'		'Case 249, 250, 261, 318 -- Church,School, Facilities, Special Calenders
		'		Response.Redirect("ViewCalender.aspx?Level=1&ID=" & e.CommandArgument.ToString, True)
		'	Case Else
		'		Response.Redirect("MgrContent.aspx?ID=" & e.CommandArgument.ToString, True)
		'End Select
		''End If
	End Sub

	'Private Sub dlChildPages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlChildPages.ItemDataBound
	'	Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
	'	If Not drv Is Nothing Then
	'		Dim lnk As LinkButton = CType(e.Item.FindControl("LinkButton1"), LinkButton)
	'		'set the commandname that comes from db
	'		lnk.CommandName = drv.Item("PageType").ToString
	'	End If
	'End Sub
End Class
