Option Explicit On 
Option Strict On

Imports System.Data.SqlClient

Public Class AddRelatedLinks
	Inherits System.Web.UI.UserControl
	Protected WithEvents btnSave As System.Web.UI.WebControls.Button
	Protected WithEvents txtLinkText As System.Web.UI.WebControls.TextBox
	Protected WithEvents txtLinkAddress As System.Web.UI.WebControls.TextBox
	Protected WithEvents daPCL As System.Data.SqlClient.SqlDataAdapter
	Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
	Protected WithEvents SqlInsertCommand1 As System.Data.SqlClient.SqlCommand
	Protected WithEvents lblErrorMsg As System.Web.UI.WebControls.Label
	Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection

#Region " Web Form Designer Generated Code "

	'This call is required by the Web Form Designer.
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.daPCL = New System.Data.SqlClient.SqlDataAdapter()
		Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand()
		Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
		Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand()
		'
		'daPCL
		'
		Me.daPCL.InsertCommand = Me.SqlInsertCommand1
		Me.daPCL.SelectCommand = Me.SqlSelectCommand1
		Me.daPCL.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "cmdCL_Select", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ID", "ID"), New System.Data.Common.DataColumnMapping("Page_ID", "Page_ID"), New System.Data.Common.DataColumnMapping("LinkName", "LinkName"), New System.Data.Common.DataColumnMapping("LinkURL", "LinkURL"), New System.Data.Common.DataColumnMapping("LinkPic", "LinkPic")})})
		'
		'SqlInsertCommand1
		'
		Me.SqlInsertCommand1.CommandText = "[cmdCL_Insert]"
		Me.SqlInsertCommand1.CommandType = System.Data.CommandType.StoredProcedure
		Me.SqlInsertCommand1.Connection = Me.SqlConnection1
		Me.SqlInsertCommand1.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.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Page_ID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0, Byte), "Page_ID", System.Data.DataRowVersion.Current, Nothing))
		Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LinkName", System.Data.SqlDbType.VarChar, 255, "LinkName"))
		Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LinkURL", System.Data.SqlDbType.VarChar, 255, "LinkURL"))
		Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LinkPic", System.Data.SqlDbType.VarChar, 255, "LinkPic"))
		'
		'SqlConnection1
		'
		Me.SqlConnection1.ConnectionString = "data source=localhost;initial catalog=allsaints;persist security info=False;user " & _
		"id=sa;workstation id=GALAXY;packet size=4096"
		'
		'SqlSelectCommand1
		'
		Me.SqlSelectCommand1.CommandText = "[cmdCL_Select]"
		Me.SqlSelectCommand1.CommandType = System.Data.CommandType.StoredProcedure
		Me.SqlSelectCommand1.Connection = Me.SqlConnection1
		Me.SqlSelectCommand1.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.SqlSelectCommand1.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))

	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

	Dim _PageID As Integer
	Public Event LinkAdded()
	Public Property PageID() As Integer
		Get
			Return _PageID
		End Get
		Set(ByVal Value As Integer)
			_PageID = Value
		End Set
	End Property

	Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Dim sConStr As String = ConfigurationSettings.AppSettings("sConnection")
		SqlConnection1.ConnectionString = sConStr
	End Sub

	Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
		If (Trim(txtLinkAddress.Text) = "" Or Trim(txtLinkText.Text) = "") Then
			lblErrorMsg.Text = "New link text and address location cannot be left empty !"
			lblErrorMsg.Visible = True
			Dim s As String = "<script type=""text/javascript"" language=""javascript"">"
			s &= "document.getElementById(""" & Me.ID.ToString & "_btnSave"").focus();"
			s &= "</script>"
			Me.Page.RegisterStartupScript("FocusManager", s)
		Else
			With daPCL.InsertCommand
				.Parameters("@Page_ID").Value = _PageID
				.Parameters("@LinkName").Value = Trim(txtLinkText.Text)
				.Parameters("@LinkURL").Value = Trim(txtLinkAddress.Text)
				.Parameters("@LinkPic").Value = ""
				If .Connection.State = ConnectionState.Closed Then .Connection.Open()
				.ExecuteNonQuery()
			End With
			txtLinkAddress.Text = ""
			txtLinkText.Text = ""
			RaiseEvent LinkAdded()
		End If
	End Sub

End Class
