Option Explicit On 
Option Strict On

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

Public MustInherit Class CensusView
	Inherits System.Web.UI.UserControl
	Protected WithEvents lblError As System.Web.UI.WebControls.Label
	Protected WithEvents pnlViewCensus As System.Web.UI.WebControls.Panel
	Protected WithEvents lblLName As System.Web.UI.WebControls.Label
	Protected WithEvents lblFName1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblAddress1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblPhone1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblEmployment1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblJobTitle1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblEmail1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblGraduate1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblYrGraduate1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblMarital1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblTalent1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblFName2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblMaidenName As System.Web.UI.WebControls.Label
	Protected WithEvents lblAddress2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblPhone2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblEmployment2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblJobTitle2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblEmail2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblGraduate2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblYrGraduate2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblMarital2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblTalent2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblChild1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblAge1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblSchool1 As System.Web.UI.WebControls.Label
	Protected WithEvents lblChild2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblAge2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblSchool2 As System.Web.UI.WebControls.Label
	Protected WithEvents lblChild3 As System.Web.UI.WebControls.Label
	Protected WithEvents lblAge3 As System.Web.UI.WebControls.Label
	Protected WithEvents lblSchool3 As System.Web.UI.WebControls.Label
	Protected WithEvents lblChild4 As System.Web.UI.WebControls.Label
	Protected WithEvents lblAge4 As System.Web.UI.WebControls.Label
	Protected WithEvents lblSchool4 As System.Web.UI.WebControls.Label
	Protected WithEvents lblChild5 As System.Web.UI.WebControls.Label
	Protected WithEvents lblAge5 As System.Web.UI.WebControls.Label
	Protected WithEvents lblSchool5 As System.Web.UI.WebControls.Label
	Protected WithEvents lblLeftTitle As System.Web.UI.WebControls.Label
	Protected WithEvents lblReason As System.Web.UI.WebControls.Label
	Dim _CensusID As Integer

#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

	Public Property CensusID() As Integer
		Get
			Return _CensusID
		End Get
		Set(ByVal Value As Integer)
			_CensusID = Value
		End Set
	End Property


	Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		On Error Resume Next
		If _CensusID <> 0 Then
			Dim cmd As New SqlCommand()
			Dim dr As SqlDataReader
			Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("sConnection"))
			With cmd
				.CommandText = "Select * from as_Census where ID=" & _CensusID
				.Connection = conn
				.CommandType = CommandType.Text
				If conn.State = ConnectionState.Closed Then conn.Open()
				'Response.Write(.CommandText & vbCrLf)
				dr = .ExecuteReader()

				If Not dr.Read Then
					lblError.Text = "<BR><p align=center><span class=maintitle2><b>No census data found !</b></span></p><BR>"
					lblError.Visible = True
					pnlViewCensus.Visible = False
					Exit Sub
				Else
					lblLName.Text = CStr(dr.Item("LName"))
					lblFName1.Text = CStr(dr.Item("FName1"))
					lblFName2.Text = CStr(dr.Item("FName2"))

					lblAddress1.Text = CStr(dr.Item("Address1"))
					lblAddress2.Text = CStr(dr.Item("Address2"))

					lblPhone1.Text = CStr(dr.Item("Phone1"))
					lblPhone2.Text = CStr(dr.Item("Phone2"))

					lblEmail1.Text = CStr(dr.Item("Email1"))
					lblEmail2.Text = CStr(dr.Item("Email2"))

					lblEmployment1.Text = CStr(dr.Item("PlaceofEmployment1"))
					lblEmployment2.Text = CStr(dr.Item("PlaceofEmployment2"))

					lblJobTitle1.Text = CStr(dr.Item("PlacementTitle1"))
					lblJobTitle2.Text = CStr(dr.Item("PlacementTitle2"))

					lblTalent1.Text = CStr(dr.Item("Talents1"))
					lblTalent2.Text = CStr(dr.Item("Talents2"))

					If CBool(dr.Item("AllSaintsGraduate1")) Then
						lblGraduate1.Text = "Yes"
						lblYrGraduate1.Text = CStr(dr.Item("GraduateDate1"))
					End If
					If CBool(dr.Item("AllSaintsGraduate2")) Then
						lblGraduate2.Text = "Yes"
						lblYrGraduate2.Text = CStr(dr.Item("GraduateDate2"))
					End If

					lblMarital1.Text = CStr(dr.Item("MaritalStatus1"))
					lblMarital2.Text = CStr(dr.Item("MaritalStatus2"))
					lblMaidenName.Text = CStr(dr.Item("MaidenName"))

					lblReason.Text = CStr(dr.Item("ReasonToLeave"))
					If lblReason.Text.Trim.Length > 0 Then
						lblLeftTitle.Text = "We have left All Saints Parish. We left the parish because:"
					End If

					With cmd
						.CommandText = "SELECT * FROM as_Children WHERE CensusID=" & CStr(dr.Item("ID"))
						dr.Close()
						.CommandType = CommandType.Text
						.Connection = conn
						If conn.State = ConnectionState.Closed Then conn.Open()
						dr = .ExecuteReader
					End With

					If dr.Read() Then
						lblChild1.Text = CStr(dr.Item("ChildName"))
						lblAge1.Text = CStr(dr.Item("Age"))
						lblSchool1.Text = CStr(dr.Item("School"))
					End If

					If dr.Read() Then
						lblChild2.Text = CStr(dr.Item("ChildName"))
						lblAge2.Text = CStr(dr.Item("Age"))
						lblSchool2.Text = CStr(dr.Item("School"))
					End If

					If dr.Read() Then
						lblChild3.Text = CStr(dr.Item("ChildName"))
						lblAge3.Text = CStr(dr.Item("Age"))
						lblSchool3.Text = CStr(dr.Item("School"))
					End If

					If dr.Read() Then
						lblChild4.Text = CStr(dr.Item("ChildName"))
						lblAge4.Text = CStr(dr.Item("Age"))
						lblSchool4.Text = CStr(dr.Item("School"))
					End If

					If dr.Read() Then
						lblChild5.Text = CStr(dr.Item("ChildName"))
						lblAge5.Text = CStr(dr.Item("Age"))
						lblSchool5.Text = CStr(dr.Item("School"))
					End If
				End If
			End With
		End If
	End Sub
End Class
