using System;
using System.Collections.Generic;
using System.Data;
using System.Web.UI.WebControls;
using System.Web.UI;
using CMS.FormControls;
using CMS.FormEngine;
using CMS.GlobalHelper;
using CMS.SiteProvider;
using CMS.Controls;
public partial class CMSFormControls_System_UserControlTypeSelector : CMSAbstractBaseFilterControl
{
#region "Variables"
private string mSelectedValue = String.Empty;
private bool mIncludeAllItem = true;
private string mDataType = null;
private FieldEditorControlsEnum mFieldEditorControls = FieldEditorControlsEnum.All;
private bool mIsPrimary = false;
#endregion
#region "Properties"
///
/// Where condition.
///
public override string WhereCondition
{
get
{
// Retrieve WHERE condition according to filter
string where = null;
if (ValidationHelper.GetInteger(Value, -1) >= 0)
{
where = "UserControlType = " + ((int)ControlType).ToString();
}
base.WhereCondition = where;
return base.WhereCondition;
}
set
{
base.WhereCondition = value;
}
}
///
/// Gets the collection of arbitrary attributes (for rendering only) that do
/// not correspond to properties on the control.
///
public new AttributeCollection Attributes
{
get
{
return drpType.Attributes;
}
}
///
/// Gets or sets the field value.
///
public override object Value
{
get
{
return drpType.SelectedValue;
}
set
{
mSelectedValue = (string)value;
if (drpType.Items.FindByValue(mSelectedValue) != null)
{
drpType.SelectedValue = mSelectedValue;
}
}
}
///
/// Gets or sets the field value.
///
public FormUserControlTypeEnum ControlType
{
get
{
return FormUserControlInfoProvider.GetTypeEnum(ValidationHelper.GetInteger(Value, 0));
}
set
{
Value = Convert.ToString((int)value);
}
}
///
/// Gets or sets whether "all" item is present in the list.
///
public bool IncludeAllItem
{
get
{
return mIncludeAllItem;
}
set
{
mIncludeAllItem = value;
}
}
///
/// Gets or sets value indicating if drop-down is set to cause AutoPostBack.
///
public bool AutoPostBack
{
get
{
return drpType.AutoPostBack;
}
set
{
drpType.AutoPostBack = value;
}
}
///
/// Column data type to limit form control types.
///
public string DataType
{
get
{
return mDataType;
}
set
{
mDataType = value;
}
}
///
/// FieldEditorControlsEnum to limit form control types.
///
public FieldEditorControlsEnum FieldEditorControls
{
get
{
return mFieldEditorControls;
}
set
{
mFieldEditorControls = value;
}
}
///
/// Primary field to limit form control types.
///
public bool IsPrimary
{
get
{
return mIsPrimary;
}
set
{
mIsPrimary = value;
}
}
///
/// Indicates if field is External.
///
public bool External
{
get;
set;
}
#endregion
#region "Page events"
protected void Page_Load(object sender, EventArgs e)
{
// Initialize filter dropdownlist
if (drpType.Items.Count <= 0)
{
ReLoadUserControl();
}
if (drpType.Items.FindByValue(mSelectedValue) != null)
{
drpType.SelectedValue = mSelectedValue;
}
drpType.SelectedIndexChanged += new EventHandler(drpType_SelectedIndexChanged);
}
protected void drpType_SelectedIndexChanged(object sender, EventArgs e)
{
FilterChanged = true;
RaiseOnFilterChanged();
}
#endregion
#region "Methods"
///
/// Clears selection of drop-down list.
///
public void ClearSelection()
{
drpType.ClearSelection();
}
///
/// Loads control with items.
///
public void ReLoadUserControl()
{
drpType.Items.Clear();
drpType.SelectedValue = null;
drpType.ClearSelection();
// Load control dynamicaly with limited set of available types
if (!String.IsNullOrEmpty(DataType))
{
drpType.DataTextField = "text";
drpType.DataValueField = "value";
DataSet ds = FormHelper.GetAvailableControlTypes(DataType, FieldEditorControls, (IsPrimary && !External));
if (!DataHelper.DataSourceIsEmpty(ds))
{
// Sort result by 'text' column
ds.Tables[0].DefaultView.Sort = "text";
drpType.DataSource = ds.Tables[0].DefaultView;
drpType.DataBind();
}
}
// Load control with all types
else
{
foreach (FormUserControlTypeEnum en in new FormUserControlTypeEnum[]
{
FormUserControlTypeEnum.Captcha, FormUserControlTypeEnum.Filter, FormUserControlTypeEnum.Input, FormUserControlTypeEnum.Multifield,
FormUserControlTypeEnum.Selector, FormUserControlTypeEnum.Uploader, FormUserControlTypeEnum.Viewer, FormUserControlTypeEnum.Visibility
})
{
drpType.Items.Add(new ListItem(GetString("formcontrolstype." + en.ToString()), Convert.ToInt32(en).ToString()));
}
}
// Include 'all' item in first position
if (IncludeAllItem)
{
drpType.Items.Insert(0, new ListItem(GetString("general.selectall"), Convert.ToInt32(FormUserControlTypeEnum.Unspecified).ToString()));
}
}
///
/// Loads control with items.
///
/// Specified control types
public void ReLoadUserControl(List controlTypes)
{
drpType.Items.Clear();
foreach (FormUserControlTypeEnum controlType in controlTypes)
{
drpType.Items.Add(new ListItem(GetString("formcontrolstype." + controlType.ToString()), Convert.ToInt32(controlType).ToString()));
}
// Include 'all' item in first position
if (IncludeAllItem)
{
drpType.Items.Insert(0, new ListItem(GetString("general.selectall"), Convert.ToInt32(FormUserControlTypeEnum.Unspecified).ToString()));
}
}
#endregion
#region "State management"
///
/// Resets filter to the default state.
///
public override void ResetFilter()
{
ClearSelection();
}
///
/// Restores filter state from the specified object.
///
/// The object that holds the filter state.
public override void RestoreFilterState(FilterState state)
{
base.RestoreFilterState(state);
Value = state.GetString("Value");
}
///
/// Stores filter state to the specified object.
///
/// The object that holds the filter state.
public override void StoreFilterState(FilterState state)
{
state.AddValue("Value", Value);
base.StoreFilterState(state);
}
#endregion
}