using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CMS.FormControls; using CMS.GlobalHelper; using CMS.Notifications; using CMS.UIControls; public partial class CMSModules_Notifications_FormControls_NotificationGatewaySelector : FormEngineUserControl { #region "Variables" private bool mUseGatewayNameForSelection = true; private bool mAddNoneRecord = false; private bool mUseAutoPostBack = false; #endregion #region "Public properties" /// /// 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; } } } /// /// Returns ClientID of the dropdown with gateways. /// public override string ValueElementID { get { return uniSelector.DropDownSingleSelect.ClientID; } } /// /// Gets or sets the field value. /// public override object Value { get { if (mUseGatewayNameForSelection) { return GatewayName; } else { return GatewayID; } } set { if (mUseGatewayNameForSelection) { GatewayName = ValidationHelper.GetString(value, ""); } else { GatewayID = ValidationHelper.GetInteger(value, 0); } } } /// /// Gets or sets the Gateway ID. /// public int GatewayID { get { if (mUseGatewayNameForSelection) { // Convert name to ID string name = ValidationHelper.GetString(uniSelector.Value, ""); NotificationGatewayInfo ngi = NotificationGatewayInfoProvider.GetNotificationGatewayInfo(name); if (ngi != null) { return ngi.GatewayID; } return 0; } else { return ValidationHelper.GetInteger(uniSelector.Value, 0); } } set { if (uniSelector == null) { pnlUpdate.LoadContainer(); } if (mUseGatewayNameForSelection) { // Convert ID to name NotificationGatewayInfo ngi = NotificationGatewayInfoProvider.GetNotificationGatewayInfo(value); if (ngi != null) { uniSelector.Value = ngi.GatewayName; } } else { uniSelector.Value = value; } } } /// /// Gets or sets the Gateway code name. /// public string GatewayName { get { if (mUseGatewayNameForSelection) { return ValidationHelper.GetString(uniSelector.Value, ""); } else { // Convert ID to name int id = ValidationHelper.GetInteger(uniSelector.Value, 0); NotificationGatewayInfo ngi = NotificationGatewayInfoProvider.GetNotificationGatewayInfo(id); if (ngi != null) { return ngi.GatewayName; } return ""; } } set { if (uniSelector == null) { pnlUpdate.LoadContainer(); } if (mUseGatewayNameForSelection) { uniSelector.Value = value; } else { // Convert name to ID NotificationGatewayInfo ngi = NotificationGatewayInfoProvider.GetNotificationGatewayInfo(value); if (ngi != null) { uniSelector.Value = ngi.GatewayID; } } } } /// /// If true, selected value is GatewayName, if false, selected value is GatewayID. /// public bool UseGatewayNameForSelection { get { return mUseGatewayNameForSelection; } set { mUseGatewayNameForSelection = value; if (uniSelector != null) { uniSelector.ReturnColumnName = (value ? "GatewayName" : "GatewayID"); } } } /// /// Gets or sets the value which determines, whether to add none item record to the dropdownlist. /// public bool AddNoneRecord { get { return mAddNoneRecord; } set { mAddNoneRecord = value; if (uniSelector != null) { uniSelector.AllowEmpty = value; } } } /// /// Gets or sets the value which determines, whether the dropdown should use AutoPostBack. /// public bool UseAutoPostBack { get { return mUseAutoPostBack; } set { mUseAutoPostBack = value; if (uniSelector != null) { uniSelector.DropDownSingleSelect.AutoPostBack = value; } } } #endregion protected void Page_Load(object sender, EventArgs e) { if (StopProcessing) { uniSelector.StopProcessing = true; } else { ReloadData(); } } /// /// Reloads the data in the selector. /// public void ReloadData() { uniSelector.IsLiveSite = IsLiveSite; uniSelector.SelectionMode = SelectionModeEnum.SingleDropDownList; uniSelector.ReturnColumnName = (UseGatewayNameForSelection ? "GatewayName" : "GatewayID"); uniSelector.DropDownSingleSelect.AutoPostBack = UseAutoPostBack; uniSelector.AllowEmpty = AddNoneRecord; } }