using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CMS.FormControls;
using CMS.GlobalHelper;
using CMS.Synchronization;
public partial class CMSModules_Objects_FormControls_BinObjectTypeSelector : FormEngineUserControl
{
#region "Variables"
private bool mShowAll = true;
private string mObjectType = null;
#endregion
#region "Properties"
///
/// User ID to restrict object types to user recycle bin only.
///
public int UserID
{
get;
set;
}
///
/// Indicates if all item should be displayed.
///
public bool ShowAll
{
get
{
return mShowAll;
}
set
{
mShowAll = value;
}
}
///
/// Ensure creating child controls.
///
protected override void CreateChildControls()
{
base.CreateChildControls();
Reload(false);
}
///
/// Returns ClientID of the DropDownList with order.
///
public override string ValueElementID
{
get
{
return drpObjectTypes.ClientID;
}
}
///
/// Gets or sets the enabled state of the control.
///
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
base.Enabled = value;
drpObjectTypes.Enabled = value;
}
}
///
/// Gets or sets field value.
///
public override object Value
{
get
{
return ValidationHelper.GetString(drpObjectTypes.SelectedValue, "");
}
set
{
mObjectType = ValidationHelper.GetString(value, "");
Reload(false);
}
}
public string SelectedValue
{
get
{
return ValidationHelper.GetString(ViewState["SelectedValue"], null);
}
set
{
ViewState["SelectedValue"] = value;
}
}
///
/// Returns true if user control is valid.
///
public override bool IsValid()
{
return true;
}
///
/// Where condition to filter values.
///
public string WhereCondition
{
get;
set;
}
///
/// Drop-down list control.
///
public DropDownList DropDownListControl
{
get
{
return drpObjectTypes;
}
}
#endregion
#region "Control methods"
///
/// Loads drop down list with data.
///
private void ReloadData()
{
drpObjectTypes.Items.Clear();
// Check if show all item should be displayed
if (ShowAll)
{
drpObjectTypes.Items.Add(new ListItem(GetString("general.selectall"), ""));
}
// Get recycle bin object types
DataSet dsObjectTypes = ObjectVersionHistoryInfoProvider.GetRecycleBin(UserID, WhereCondition, null, -1, "DISTINCT VersionObjectType");
if (!DataHelper.DataSourceIsEmpty(dsObjectTypes))
{
SortedDictionary sdObjectTypes = new SortedDictionary();
foreach (DataRow dr in dsObjectTypes.Tables[0].Rows)
{
string objType = ValidationHelper.GetString(dr["VersionObjectType"], null);
if (!String.IsNullOrEmpty(objType))
{
sdObjectTypes.Add(GetString("ObjectType." + objType.Replace(".", "_")), objType);
}
}
foreach (string key in sdObjectTypes.Keys)
{
drpObjectTypes.Items.Add(new ListItem(key, sdObjectTypes[key]));
}
}
// Preselect value
if (!String.IsNullOrEmpty(SelectedValue))
{
mObjectType = SelectedValue;
}
ListItem selectedItem = drpObjectTypes.Items.FindByValue(mObjectType);
if (selectedItem != null)
{
drpObjectTypes.ClearSelection();
selectedItem.Selected = true;
}
else
{
drpObjectTypes.SelectedIndex = 0;
SelectedValue = null;
}
}
///
/// Reload DDL content.
///
/// Indicates if DDL reload should be forced
public void Reload(bool force)
{
drpObjectTypes.SelectedIndexChanged += new EventHandler(drpObjectTypes_SelectedIndexChanged);
if ((drpObjectTypes.Items.Count == 0) || force)
{
ReloadData();
}
}
///
/// DLL selected index changed event
///
protected void drpObjectTypes_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedValue = drpObjectTypes.SelectedValue;
}
#endregion
}