using System; using System.Data; using CMS.SettingsProvider; using CMS.UIControls; using CMS.Controls; using CMS.GlobalHelper; public partial class CMSModules_ContactManagement_Controls_UI_IP_Filter : CMSAbstractBaseFilterControl { #region "Public properties" /// /// Gets the where condition created using filtered parameters. /// public override string WhereCondition { get { return GenerateWhereCondition(); } } /// /// If true, site selector is visible. /// public bool ShowSiteFilter { get; set; } /// /// If true, contact filter (for contact name) is visible /// public bool ShowContactNameFilter { get; set; } #endregion #region "Methods" protected override void OnLoad(EventArgs e) { base.OnLoad(e); plcSite.Visible = ShowSiteFilter; plcCon.Visible = ShowContactNameFilter; btnReset.Text = GetString("general.reset"); btnReset.Click += btnReset_Click; btnSearch.Click += btnSearch_Click; } /// /// Resets the associated UniGrid control. /// protected void btnReset_Click(object sender, EventArgs e) { UniGrid grid = FilteredControl as UniGrid; if (grid != null) { grid.Reset(); } } /// /// Applies filter on associated UniGrid control. /// protected void btnSearch_Click(object sender, EventArgs e) { UniGrid grid = FilteredControl as UniGrid; if (grid != null) { grid.ApplyFilter(sender, e); } } /// /// Generates complete filter where condition. /// private string GenerateWhereCondition() { string where = null; if (ShowContactNameFilter) { where = SqlHelperClass.AddWhereCondition(where, fltContact.GetCondition()); } if (ShowSiteFilter) { if (siteSelector.SiteID > 0) { where = SqlHelperClass.AddWhereCondition(where, "ContactSiteID = " + siteSelector.SiteID); } } where = SqlHelperClass.AddWhereCondition(where, fltIP.GetCondition()); where = SqlHelperClass.AddWhereCondition(where, dtFromTo.GetCondition()); return where; } #endregion #region "State management" /// /// Resets filter to the default state. /// public override void ResetFilter() { siteSelector.Value = null; fltContact.ResetFilter(); fltIP.ResetFilter(); dtFromTo.Clear(); } /// /// Stores filter state to the specified object. /// /// The object that holds the filter state. public override void StoreFilterState(FilterState state) { state.AddValue("ToTime", dtFromTo.ValueToTime); state.AddValue("FromTime", dtFromTo.ValueFromTime); base.StoreFilterState(state); } /// /// Restores filter state from the specified object. /// /// The object that holds the filter state. public override void RestoreFilterState(FilterState state) { base.RestoreFilterState(state); dtFromTo.ValueFromTime = state.GetDateTime("FromTime"); dtFromTo.ValueToTime = state.GetDateTime("ToTime"); } #endregion }