using System;
using CMS.CMSHelper;
using CMS.FormControls;
using CMS.FormEngine;
using CMS.GlobalHelper;
using CMS.UIControls;
public partial class CMSModules_MessageBoards_FormControls_BoardNameSelector : FormEngineUserControl
{
#region "Variables"
private bool mAddAllItemsRecord = true;
private int mGroupId = 0;
private int mSiteId = 0;
#endregion
#region "Public properties"
///
/// ID of the current group.
///
public int GroupID
{
get
{
return mGroupId;
}
set
{
mGroupId = value;
}
}
///
/// ID of the current site.
///
public int SiteID
{
get
{
if (mSiteId == 0)
{
mSiteId = CMSContext.CurrentSiteID;
}
return mSiteId;
}
set
{
mSiteId = value;
}
}
///
/// Gets or sets the enabled state of the control.
///
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
base.Enabled = value;
if (uniSelector != null)
{
uniSelector.Enabled = value;
}
}
}
///
/// Gets or sets the field value.
///
public override object Value
{
get
{
return uniSelector.Value;
}
set
{
if (uniSelector == null)
{
pnlUpdate.LoadContainer();
}
uniSelector.Value = value;
}
}
///
/// Gets or sets the value which determines, whether to add none item record to the dropdownlist.
///
public bool AddAllItemsRecord
{
get
{
return mAddAllItemsRecord;
}
set
{
mAddAllItemsRecord = value;
}
}
///
/// Gets the inner UniSelector control.
///
public UniSelector UniSelector
{
get
{
return uniSelector;
}
}
///
/// Gets or sets value that indicates whether group forums is included in list.
///
private bool ShowGroupBoards
{
get;
set;
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (StopProcessing)
{
uniSelector.StopProcessing = true;
}
else
{
ReloadData(false);
}
}
///
/// Reloads the data in the selector.
///
/// Indicates whether UniSelector Reload data should be called
public void ReloadData(bool forced)
{
// Return forum name or ID according to type of field (if no field specified forum name is returned)
if ((FieldInfo != null) && ((FieldInfo.DataType == FormFieldDataTypeEnum.Integer) || (FieldInfo.DataType == FormFieldDataTypeEnum.LongInteger)))
{
uniSelector.WhereCondition = "BoardSiteID = " + SiteID;
uniSelector.ReturnColumnName = "BoardID";
uniSelector.AllowEmpty = true;
ShowGroupBoards = true;
}
else
{
uniSelector.WhereCondition = "BoardSiteID = " + SiteID + " AND " + (GroupID > 0 ? "BoardGroupID = " + GroupID : "((BoardGroupID = 0) OR (BoardGroupID IS NULL))");
uniSelector.AllowEmpty = false;
}
uniSelector.IsLiveSite = IsLiveSite;
uniSelector.SelectionMode = SelectionModeEnum.SingleDropDownList;
uniSelector.AllowAll = false;
if (AddAllItemsRecord)
{
uniSelector.SpecialFields = new string[,] { { GetString("general.selectall"), "" } };
}
if (forced)
{
uniSelector.Reload(true);
}
}
///
/// Returns WHERE condition for selected form.
///
public override string GetWhereCondition()
{
// Return correct WHERE condition for integer if none value is selected
if ((FieldInfo != null) && ((FieldInfo.DataType == FormFieldDataTypeEnum.Integer) || (FieldInfo.DataType == FormFieldDataTypeEnum.LongInteger)))
{
int id = ValidationHelper.GetInteger(uniSelector.Value, 0);
if (id > 0)
{
return base.GetWhereCondition();
}
}
return null;
}
}