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_SelectMVTest : FormEngineUserControl { #region "Variables" private int mNodeID = 0; private bool mPostbackOnChange = false; private bool dataLoaded = false; #endregion #region "Properties" /// /// Returns or sets MVTestID 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; } } /// /// Enables/disables control /// public override bool Enabled { get { return base.Enabled; } set { ucUniSelector.Enabled = value; base.Enabled = value; } } /// /// 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; } } /// /// 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; } } /// /// Gets Uniselector object /// public UniSelector UniSelector { get { return ucUniSelector; } } #endregion #region "Methods" /// /// Handles the Load event of the Page control. /// protected void Page_Load(object sender, EventArgs e) { ReloadData(false); 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 MVTest 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("MVTestSiteID = " + CMSContext.CurrentSiteID + " AND MVTestPage = '" + SqlHelperClass.GetSafeQueryString(node.NodeAliasPath, false) + "'", String.Empty, 1, "MVTestID", null); if (!DataHelper.DataSourceIsEmpty(ds)) { int abTestID = ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["MVTestID"], 0); if (abTestID != 0) { ucUniSelector.Value = abTestID; } } } } } } /// /// Reloads the 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, "MVTestSiteID =" + CMSContext.CurrentSiteID); ucUniSelector.Reload(forceReload); dataLoaded = true; } } /// /// 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(); } /// /// 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); } #endregion }