using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CMS.FormControls;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
using CMS.UIControls;
public partial class CMSModules_OnlineMarketing_FormControls_SelectMVTCombination : FormEngineUserControl
{
#region "Variables"
private int mPageTemplateID = 0;
private int mDocumentID = 0;
private bool dataLoaded = false;
private bool mUseQueryStringOnChange = false;
private string mQueryStringKey = string.Empty;
private bool mPostbackOnChange = false;
private bool mApplyDefaultCondition = true;
#endregion
#region "Properties"
///
/// Gets or sets the combination id.
///
///
public override object Value
{
get
{
EnsureChildControls();
return ucUniSelector.Value;
}
set
{
EnsureChildControls();
ucUniSelector.Value = value;
}
}
///
/// Return column name for uni-selector
///
public string ReturnColumnName
{
get
{
EnsureChildControls();
return ucUniSelector.ReturnColumnName;
}
set
{
EnsureChildControls();
ucUniSelector.ReturnColumnName = value;
}
}
///
/// All record value for uni-selector
///
public string AllRecordValue
{
get
{
EnsureChildControls();
return ucUniSelector.AllRecordValue;
}
set
{
EnsureChildControls();
ucUniSelector.AllRecordValue = value;
}
}
///
/// Where condition for uniselector
///
public string WhereCondition
{
get
{
EnsureChildControls();
return ucUniSelector.WhereCondition;
}
set
{
EnsureChildControls();
ucUniSelector.WhereCondition = value;
}
}
///
/// Gets or sets the page template ID.
///
public int PageTemplateID
{
get
{
EnsureChildControls();
return mPageTemplateID;
}
set
{
EnsureChildControls();
mPageTemplateID = value;
}
}
///
/// Gets or sets the document ID.
///
public int DocumentID
{
get
{
EnsureChildControls();
return mDocumentID;
}
set
{
EnsureChildControls();
mDocumentID = value;
}
}
///
/// Gets the uni selector control.
///
public UniSelector UniSelector
{
get
{
EnsureChildControls();
return ucUniSelector;
}
}
///
/// Gets the drop down select control.
///
public DropDownList DropDownSelect
{
get
{
EnsureChildControls();
return ucUniSelector.DropDownSingleSelect;
}
}
///
/// Gets a value indicating whether this instance has data.
///
public bool HasData
{
get
{
EnsureChildControls();
return ucUniSelector.HasData;
}
}
///
/// Gets or sets a value indicating whether to use query string and redirect when OnChange event is fired or if use a postback.
///
public bool UseQueryStringOnChange
{
get
{
return mUseQueryStringOnChange;
}
set
{
mUseQueryStringOnChange = value;
}
}
///
/// Enables/disables all (all) value
///
public bool AllowAll
{
get
{
EnsureChildControls();
return ucUniSelector.AllowAll;
}
set
{
EnsureChildControls();
ucUniSelector.AllowAll = value;
}
}
///
/// Enables/disables emtpy (none) value
///
public bool AllowEmpty
{
get
{
EnsureChildControls();
return ucUniSelector.AllowEmpty;
}
set
{
EnsureChildControls();
ucUniSelector.AllowEmpty = value;
}
}
///
/// If true, full postback is raised when item changed.
///
public bool PostbackOnChange
{
get
{
return mPostbackOnChange;
}
set
{
mPostbackOnChange = value;
}
}
///
/// Gets or sets the query string key when the UseQueryStringOnChangeis set to true.
///
public string QueryStringKey
{
get
{
return mQueryStringKey;
}
set
{
mQueryStringKey = value;
}
}
///
/// If true, default condition (NodeID, TemplateID) is applied for selector
///
public bool ApplyDefaultCondition
{
get
{
return mApplyDefaultCondition;
}
set
{
mApplyDefaultCondition = value;
}
}
#endregion
#region "Methods"
///
/// Handles the PreRender event of the Page control.
///
protected void Page_PreRender(object sender, EventArgs e)
{
if (PostbackOnChange)
{
ucUniSelector.DropDownSingleSelect.AutoPostBack = true;
ScriptManager scr = ScriptManager.GetCurrent(Page);
scr.RegisterPostBackControl(ucUniSelector.DropDownSingleSelect);
}
if (!mUseQueryStringOnChange)
{
ucUniSelector.DropDownSingleSelect.AutoPostBack = true;
}
else if (!string.IsNullOrEmpty(mQueryStringKey))
{
string script = @"
function ChangeCombination() {
var ddlEl = document.getElementById('" + ucUniSelector.DropDownSingleSelect.ClientID + @"');
if (ddlEl != null) {
var value = ddlEl.options[ddlEl.selectedIndex].value;
var url = '" + URLHelper.RemoveUrlParameter(URLHelper.RemoveUrlParameter(URLHelper.CurrentURL, "mvtitemupdated"), "mvtiszoneupdated") + @"';
url = AddUrlParameter(url, 'combinationid', value, true);
document.location.replace(url);
}
}";
ScriptHelper.RegisterStartupScript(this, typeof(string), "mvtSelectCombination", ScriptHelper.GetScript(script));
// Use query string instead of postback
ucUniSelector.DropDownSingleSelect.Attributes.Add("onchange", "ChangeCombination()");
}
}
///
/// Reload data.
///
/// If true, data are loaded in all cases
public void ReloadData(bool forceReload)
{
if (forceReload || !dataLoaded)
{
if (ApplyDefaultCondition)
{
string where = SqlHelperClass.AddWhereCondition(ucUniSelector.WhereCondition, "MVTCombinationPageTemplateID =" + PageTemplateID);
where = SqlHelperClass.AddWhereCondition(where, "(MVTCombinationDocumentID = " + DocumentID + ") OR (MVTCombinationDocumentID IS NULL)");
ucUniSelector.WhereCondition = where;
}
ucUniSelector.IsLiveSite = IsLiveSite;
ucUniSelector.Reload(forceReload);
dataLoaded = true;
}
}
///
/// Creates child controls and loads update panel container if it is required.
///
protected override void CreateChildControls()
{
// Call base method
base.CreateChildControls();
// If selector is not defined, load update panel container
if (ucUniSelector == null)
{
pnlUpdate.LoadContainer();
}
}
#endregion
}