using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Text;
namespace Estore
{
public class SelectorCustomization : WebBlocksControl
{
public int SelectorID
{
get { return (ViewState["SelectorID"] == null ? 0 : (int)ViewState["SelectorID"]); }
set { ViewState["SelectorID"] = value; }
}
public string GetCustomizationText()
{
StringBuilder sb = new StringBuilder();
foreach (Estore.CustomizationControls.CustomizationControlBase ctl in Controls)
{
sb.Append(ctl.Label);
sb.Append(": ");
sb.Append(ctl.Text);
sb.Append("
");
}
return sb.ToString();
}
public decimal GetCustomizationCost()
{
// we have to do a database lookup to determine what the "value" of the chosen
// customization is, if any. This only occurs when the control type is not a textbox.
decimal TotalCost = 0;
foreach (Estore.CustomizationControls.CustomizationControlBase ctl in Controls)
{
TotalCost += ctl.SelectedCustomizationCost;
}
return TotalCost;
}
public void BindData()
{
Controls.Clear();
DataTable dtCustomizations = Database.Customizations_GetBySelectorID(SelectorID);
DataView dvCustomizationOptions = Database.CustomizationOptions_GetBySelectorID(SelectorID).DefaultView;
foreach (DataRow dr in dtCustomizations.Rows)
{
CustomizationControls.CustomizationControlBase ctl;
//CustomizationEntry custEntry = new CustomizationEntry((CustomizationControlTypes)dr["ControlType"], (int)dr["CustomizationID"], (string)dr["Name"]);
switch ((DatabaseClass.Enumerations.CustomizationControlTypes)dr["ControlType"])
{
case DatabaseClass.Enumerations.CustomizationControlTypes.DropDownList:
ctl = new Estore.CustomizationControls.DropDownList();
break;
case DatabaseClass.Enumerations.CustomizationControlTypes.CheckBoxList:
ctl = new Estore.CustomizationControls.CheckBoxList();
break;
case DatabaseClass.Enumerations.CustomizationControlTypes.TextBox:
ctl = new Estore.CustomizationControls.TextBox();
break;
case DatabaseClass.Enumerations.CustomizationControlTypes.LargeTextBox:
ctl = new Estore.CustomizationControls.LargeTextBox();
break;
case DatabaseClass.Enumerations.CustomizationControlTypes.FileUpload:
ctl = new Estore.CustomizationControls.FileUpload();
break;
default:
ctl = new Estore.CustomizationControls.TextBox();
break;
}
// add the compulsory stuff, and add the control
ctl.Label = (string)dr["Prompt"];
ctl.Name = (string)dr["Name"];
Controls.Add(ctl);
// bind the options
dvCustomizationOptions.RowFilter = "CustomizationID=" + dr["CustomizationID"].ToString();
ctl.BindOptions(dvCustomizationOptions.ToTable());
}
}
protected override void Render(HtmlTextWriter writer)
{
if (Controls.Count > 0)
{
writer.Write("