using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.ExtendedControls; using CMS.GlobalHelper; using CMS.OnlineMarketing; using CMS.SettingsProvider; using CMS.UIControls; public partial class CMSModules_ContactManagement_Controls_UI_Ip_List : CMSAdminListControl { #region "Properties" /// /// Indicates if the control should perform the operations. /// public override bool StopProcessing { get { return base.StopProcessing; } set { base.StopProcessing = value; gridElem.StopProcessing = value; } } /// /// Indicates if the control is used on the live site. /// public override bool IsLiveSite { get { return base.IsLiveSite; } set { base.IsLiveSite = value; gridElem.IsLiveSite = value; } } /// /// True if site name column is visible. /// public bool ShowSiteNameColumn { get; set; } /// /// True if contact name is visible. /// public bool ShowContactNameColumn { get; set; } /// /// True if remove action button is visible. /// public bool ShowRemoveButton { get; set; } /// /// Gets or sets contact ID. /// public int ContactID { get; set; } /// /// Gets or sets value that indicates whether contact is merged. /// public bool IsMergedContact { get; set; } /// /// Gets or sets value that indicates whether contact is global contact. /// public bool IsGlobalContact { get; set; } /// /// Additional WHERE condition. /// public string WhereCondition { get; set; } #endregion #region "Methods" protected override void OnInit(EventArgs e) { gridElem.OnFilterFieldCreated += new OnFilterFieldCreated(gridElem_OnFilterFieldCreated); gridElem.LoadGridDefinition(); base.OnInit(e); } void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition) { var filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_IP_Filter; if (filter != null) { filter.ShowContactNameFilter = ShowContactNameColumn; filter.ShowSiteFilter = ShowSiteNameColumn; filter.IsLiveSite = IsLiveSite; } } protected void Page_Load(object sender, EventArgs e) { QueryDataParameters parameters = new QueryDataParameters(); parameters.Add("@ContactID", ContactID); // Choose correct object type ("query") according to contact type if (IsGlobalContact) { gridElem.ObjectType = OnlineMarketingObjectType.IPGLOBALLIST; } else if (IsMergedContact) { gridElem.ObjectType = OnlineMarketingObjectType.IPMERGEDLIST; } else { gridElem.ObjectType = OnlineMarketingObjectType.IPLIST; } gridElem.QueryParameters = parameters; gridElem.WhereCondition = WhereCondition; gridElem.ZeroRowsText = GetString("om.ip.noips"); gridElem.OnExternalDataBound += new OnExternalDataBoundEventHandler(gridElem_OnExternalDataBound); gridElem.OnAction += new OnActionEventHandler(gridElem_OnAction); } protected void Page_PreRender(object sender, EventArgs e) { gridElem.NamedColumns["ContactSiteID"].Visible = ShowSiteNameColumn; // Display contact full name if some merged contacts point to this contact or if required bool showFullName = ShowContactNameColumn; if (!showFullName) { object dataSrc = gridElem.GridView.DataSource; if (!DataHelper.DataSourceIsEmpty(dataSrc)) { DataRow[] dr = null; if (dataSrc is DataSet) { DataSet ds = (DataSet)dataSrc; dr = ds.Tables[0].Select("ContactMergedWithContactID > 0"); } if (dataSrc is DataView) { DataView dv = ((DataView)dataSrc); dr = dv.Table.Select("ContactMergedWithContactID > 0"); } showFullName = (dr != null) && (dr.Length > 0); } } gridElem.NamedColumns["ContactFullName"].Visible = showFullName; } /// /// UniGrid action handler. /// private void gridElem_OnAction(string actionName, object actionArgument) { if (actionName == "delete") { ContactInfo contact = ContactInfoProvider.GetContactInfo(ContactID); // Check permission if ((contact != null) && ContactHelper.AuthorizedModifyContact(contact.ContactSiteID, true)) { int ipId = ValidationHelper.GetInteger(actionArgument, 0); IPInfoProvider.DeleteIPInfo(ipId); } } } /// /// UniGrid databound handler. /// private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName) { case "delete": if (ShowRemoveButton) { ((CMSImageButton)sender).ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Delete.png"); ((CMSImageButton)sender).Enabled = true; } else { ((CMSImageButton)sender).ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/DeleteDisabled.png"); ((CMSImageButton)sender).Enabled = false; } break; } return null; } #endregion }