using System; using CMS.Controls; using CMS.GlobalHelper; using CMS.SiteProvider; using CMS.CMSHelper; using CMS.UIControls; public partial class CMSModules_BadWords_Controls_BadWordsFilter : CMSAbstractBaseFilterControl { #region "Public properties" public override string WhereCondition { get { return BuildWhereCondition(); } set { base.WhereCondition = value; } } #endregion #region "Page events" protected override void OnInit(EventArgs e) { base.OnInit(e); ucBadWordAction.NoSelectionText = GetString("general.allactions"); // Initialize reset link button UniGrid grid = FilteredControl as UniGrid; if (grid != null && grid.RememberState) { btnReset.Text = GetString("general.reset"); btnReset.Click += btnReset_Click; } else { btnReset.Visible = false; } } #endregion #region "Private methods" /// /// Builds complete where condition to filter. /// private string BuildWhereCondition() { string where = null; // Create WHERE condition with 'Expression' string txt = txtExpression.Text.Trim().Replace("'", "''"); if (!string.IsNullOrEmpty(txt)) { where = "(WordExpression LIKE N'%" + txt + "%')"; } // Create WHERE condition with 'Action' int action = ValidationHelper.GetInteger(ucBadWordAction.Value, -1); if (action != -1) { if (!String.IsNullOrEmpty(where)) { where += " AND "; } // Select also bad words that ihnerit action from settings if (action == (int)BadWordsHelper.BadWordsAction(CMSContext.CurrentSiteName)) { where += "(WordAction = " + action + " OR WordAction IS NULL)"; } else { where += "(WordAction = " + action + ")"; } } return where; } #endregion #region "State management" /// /// Resets filter to the default state. /// public override void ResetFilter() { txtExpression.Text = String.Empty; ucBadWordAction.Value = ucBadWordAction.NoSelectionText; } /// /// 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 btnShow_Click(object sender, EventArgs e) { UniGrid grid = FilteredControl as UniGrid; if (grid != null) { grid.ApplyFilter(sender, e); } } #endregion }