using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CMS.CMSHelper;
using CMS.FormControls;
using CMS.GlobalHelper;
using CMS.OnlineMarketing;
using CMS.SettingsProvider;
using CMS.DocumentEngine;
using CMS.UIControls;
using TreeNode = CMS.DocumentEngine.TreeNode;
public partial class CMSModules_OnlineMarketing_FormControls_SelectABTest : FormEngineUserControl
{
#region "Variables"
private int mNodeID = 0;
private bool mPostbackOnChange = false;
private bool dataLoaded = false;
#endregion
#region "Properties"
///
/// Returns or sets ABTestID value.
///
public override object Value
{
get
{
EnsureChildControls();
return ucUniSelector.Value;
}
set
{
EnsureChildControls();
ucUniSelector.Value = value;
}
}
///
/// If true, full postback is raised when item changed.
///
public bool PostbackOnChange
{
get
{
return mPostbackOnChange;
}
set
{
mPostbackOnChange = value;
}
}
///
/// Uni selector control.
///
public UniSelector UniSelector
{
get
{
return ucUniSelector;
}
}
///
/// Node ID.
///
public int NodeID
{
get
{
return mNodeID;
}
set
{
mNodeID = value;
}
}
///
/// If true (all) option is enabled.
///
public bool AllowAll
{
get
{
return ucUniSelector.AllowAll;
}
set
{
ucUniSelector.AllowAll = value;
}
}
///
/// If true empty record is enabled.
///
public bool AllowEmpty
{
get
{
return ucUniSelector.AllowEmpty;
}
set
{
ucUniSelector.AllowEmpty = value;
}
}
///
/// Enables/disables control
///
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
ucUniSelector.Enabled = value;
base.Enabled = value;
}
}
///
/// Returns column name of uniselector.
///
public string ReturnColumnName
{
get
{
return ucUniSelector.ReturnColumnName;
}
set
{
ucUniSelector.ReturnColumnName = value;
}
}
///
/// Gets or sets all record value for uni selector.
///
public string AllRecordValue
{
get
{
return ucUniSelector.AllRecordValue;
}
set
{
ucUniSelector.AllRecordValue = value;
}
}
#endregion
#region "Methods"
protected void Page_Load(object sender, EventArgs e)
{
if (PostbackOnChange)
{
ucUniSelector.DropDownSingleSelect.AutoPostBack = true;
ScriptManager scr = ScriptManager.GetCurrent(Page);
scr.RegisterPostBackControl(ucUniSelector.DropDownSingleSelect);
}
if (!URLHelper.IsPostback())
{
// If some test belongs to node give by NodeID - preselect it in ABTest selector
if (NodeID != 0)
{
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
TreeNode node = tree.SelectSingleNode(NodeID, CMSContext.PreferredCultureCode, tree.CombineWithDefaultCulture);
if (node != null)
{
DataSet ds = ABTestInfoProvider.GetABTests("ABTestSiteID = " + CMSContext.CurrentSiteID + " AND ABTestOriginalPage = '" + SqlHelperClass.GetSafeQueryString(node.NodeAliasPath, false) + "'", "ABTestName", -1, null, null);
if (!DataHelper.DataSourceIsEmpty(ds))
{
// Preselect running test
bool runningTestFound = false;
foreach (DataRow row in ds.Tables[0].Rows)
{
ABTestInfo abTestObj = new ABTestInfo(row);
if (ABTestInfoProvider.ABTestIsRunning(abTestObj))
{
runningTestFound = true;
ucUniSelector.Value = abTestObj.ABTestID;
}
}
// If no running test found for the page, preselect the first test (alphabetically)
if (!runningTestFound)
{
int abTestID = ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["ABTestID"], 0);
if (abTestID != 0)
{
ucUniSelector.Value = abTestID;
}
}
}
}
}
}
ReloadData(false);
}
///
/// Reload data.
///
/// If true, data are loaded in all cases
public void ReloadData(bool forceReload)
{
if (forceReload || !dataLoaded)
{
ucUniSelector.IsLiveSite = IsLiveSite;
ucUniSelector.WhereCondition = SqlHelperClass.AddWhereCondition(ucUniSelector.WhereCondition, "ABTestSiteID =" + CMSContext.CurrentSiteID);
ucUniSelector.Reload(forceReload);
dataLoaded = true;
}
}
///
/// Returns the value of the given property.
///
/// Property name
public override object GetValue(string propertyName)
{
switch (propertyName.ToLowerCSafe())
{
case "allrecordvalue":
return AllRecordValue;
}
return base.GetValue(propertyName);
}
///
/// Sets the property value of the control, setting the value affects only local property value.
///
/// Property name to set
/// New property value
public override void SetValue(string propertyName, object value)
{
switch (propertyName.ToLowerCSafe())
{
case "specialfields":
UniSelector.SpecialFields = (string[,])value;
break;
case "allowempty":
AllowEmpty = ValidationHelper.GetBoolean(value, false);
break;
case "returncolumnname":
ReturnColumnName = ValidationHelper.GetString(value, String.Empty);
break;
}
base.SetValue(propertyName, value);
}
///
/// Creates child controls and loads update panle container if it is required.
///
protected override void CreateChildControls()
{
// If selector is not defined load updat panel container
if (ucUniSelector == null)
{
pnlUpdate.LoadContainer();
}
// Call base method
base.CreateChildControls();
}
#endregion
}