Imports System.Collections.Generic
Imports CharterDotCom.CommonEntities.Library
Imports CharterDotCom.CommonEntities.Library.Enumerations
Imports CharterDotCom.CommonEntities.Library.EntityMemberServices
'Imports CharterDotCom.CommonEntities.Library.EntityEBSServices
Imports CharterDotCom.CommonEntities.Library.EntitySupport
Imports CharterDotCom.CommonEntities.Library.EntitySearch
Imports CharterDotCom.CommonEntities.Library.EntityWebConfig
'Imports CharterDotCom.CommonEntities.Library.EntityG2BServices
Imports CharterDotCom.CommonEntities.Library.Common
Imports CharterDotCom.WebSite.Library

Partial Class Controls_Updates
	Inherits System.Web.UI.UserControl

	Public Event SignedIn()

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Dim _catalogManager As CatalogManager
		Dim _catalog As ICatalog
		Dim _features As Dictionary(Of String, ISubCartItem)
		Dim _feature As KeyValuePair(Of String, ISubCartItem)
		Dim sb(3) As StringBuilder
		Dim i As Integer

		_catalogManager = CatalogManager.Instance
		_catalog = _catalogManager.GetCatalog()

		_features = _catalogManager.GetFeatures()

		For i = 0 To 2
			sb(i) = New StringBuilder()
		Next i

		For Each _feature In _features
			Select Case _feature.Value.Category
				Case Category.Cable
					RenderFeature(sb(0), _feature.Value)
				Case Category.HSD
					RenderFeature(sb(1), _feature.Value)
				Case Category.Telephoney
					RenderFeature(sb(2), _feature.Value)
			End Select
		Next

		For i = 0 To 2
			If sb(i).Length > 0 Then
				sb(i).Insert(0, "<table>")
				sb(i).Append("</table>")
			End If
		Next i

		ltrCableTV.Text = sb(0).ToString()
		ltrInternet.Text = sb(1).ToString()
		ltrTelephone.Text = sb(2).ToString()
		If Not IsPostBack Then
			'Dim _membership As New Membership()
			'Dim services As Dictionary(Of Integer, String)
			'txtEmail.Text = _membership.GetEmailAddress(MemberID)
			If txtEmail.Text Is String.Empty Then
				checkAcceptTerms.Checked = False
				btnSignUp.Visible = False
			Else
				checkAcceptTerms.Checked = True
				checkAcceptTerms.Enabled = False
				btnSignUp.Visible = True
			End If
			'services = _membership.GetSubscription(MemberID)
			checkCableTV.Checked = False
			checkCableTV.Checked = False
			checkTelephone.Checked = False
			'For Each i In services.Keys
			'	Select Case i
			'		Case 1
			'			checkCableTV.Checked = True
			'		Case 2
			'			checkHSI.Checked = True
			'		Case 3
			'			checkTelephone.Checked = True
			'	End Select
			'Next
		End If
	End Sub

	Private Sub RenderFeature(ByVal sb As StringBuilder, ByVal feature As ISubCartItem)
		sb.Append("<tr>")
		sb.Append("<td style='width:20px'/>")
		sb.AppendFormat("<td style='width:100px' >{0}</td>", feature.Name)
		sb.AppendFormat("<td style='width:100px' ><a href='{0}'>Learn More</a></td>", feature.ID)
		sb.AppendFormat("</tr>")
	End Sub

	Protected Sub btnSignUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSignUp.Click
		'Dim _membership As New Membership()
		'Dim services As New Dictionary(Of Integer, String)
		'If checkCableTV.Checked Then
		'	services.Add(1, "Cable TV")
		'End If
		'If checkHSI.Checked Then
		'	services.Add(2, "High Speed Internet")
		'End If
		'If checkTelephone.Checked Then
		'	services.Add(3, "Telephone")
		'End If
		'_membership.UpdateSubscription(MemberID, txtEmail.Text, services)
		RaiseEvent SignedIn()
	End Sub

	Protected Sub checkAcceptTerms_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles checkAcceptTerms.CheckedChanged
		btnSignUp.Visible = checkAcceptTerms.Checked
	End Sub
End Class
