using System; using System.ComponentModel; using CMS.GlobalHelper; using CMS.UIControls; public partial class CMSAdminControls_UI_UniGrid_Filters_TimeSimpleFilter : CMSUserControl { #region "Private variables" private string mColumn = null; private bool mShowTime = true; #endregion #region "Public properties" /// /// Gets or sets the name of the column that is used to create filtering condition. /// [Browsable(true)] [Category("Data")] [Description("Determines the name of the column that is used to create filtering condition")] public string Column { get { return mColumn; } set { mColumn = value; } } /// /// Enables/disables showing time. /// public bool ShowTime { get { return mShowTime; } set { mShowTime = value; } } /// /// Value of the first textbox - from time. /// public DateTime ValueFromTime { get { return dtmTimeFrom.SelectedDateTime; } set { dtmTimeFrom.SelectedDateTime = value; } } /// /// Value of the second textbox - to time. /// public DateTime ValueToTime { get { return dtmTimeTo.SelectedDateTime; } set { dtmTimeTo.SelectedDateTime = value; } } /// /// Clears both text fields. /// public bool Clear() { dtmTimeTo.SelectedDateTime = DateTimeHelper.ZERO_TIME; dtmTimeFrom.SelectedDateTime = DateTimeHelper.ZERO_TIME; return true; } #endregion protected void Page_Load(object sender, EventArgs e) { dtmTimeFrom.EditTime = ShowTime; dtmTimeTo.EditTime = ShowTime; } #region "Public methods" public string GetCondition() { string resultCondition = null; // Make sure that fromTime precedes toTime DateTime fromTime = dtmTimeFrom.SelectedDateTime; DateTime toTime = dtmTimeTo.SelectedDateTime; if ((fromTime != DataHelper.DATETIME_NOT_SELECTED) && (toTime != DataHelper.DATETIME_NOT_SELECTED)) { if (fromTime > toTime) { DateTime tmp = fromTime; fromTime = toTime; toTime = tmp; } } // Apply fromTime limit if (fromTime != DataHelper.DATETIME_NOT_SELECTED) { resultCondition = mColumn + " >= '" + fromTime.ToString("s") + "'"; } // Apply toTime limit if (toTime != DataHelper.DATETIME_NOT_SELECTED) { if (!String.IsNullOrEmpty(resultCondition)) { resultCondition += " AND "; } resultCondition += mColumn + " <= '" + toTime.ToString("s") + "'"; } return resultCondition; } #endregion }