using System; using System.Data; using System.Web; using System.Web.UI; using CMS.CMSHelper; using CMS.Community; using CMS.Controls; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.SettingsProvider; public partial class CMSWebParts_Community_MessageBoards_GroupMessageBoardViewer : CMSAbstractWebPart { #region "Public properties" /// /// Gets or sets the cache item name. /// public override string CacheItemName { get { return base.CacheItemName; } set { base.CacheItemName = value; boardDataSource.CacheItemName = value; } } /// /// Cache dependencies, each cache dependency on a new line. /// public override string CacheDependencies { get { return ValidationHelper.GetString(base.CacheDependencies, boardDataSource.CacheDependencies); } set { base.CacheDependencies = value; boardDataSource.CacheDependencies = value; } } /// /// Gets or sets the cache minutes. /// public override int CacheMinutes { get { return base.CacheMinutes; } set { base.CacheMinutes = value; boardDataSource.CacheMinutes = value; } } /// /// Gets or sets group name. /// public string GroupName { get { string groupName = ValidationHelper.GetString(GetValue("GroupName"), ""); if ((string.IsNullOrEmpty(groupName) || groupName == GroupInfoProvider.CURRENT_GROUP) && (CommunityContext.CurrentGroup != null)) { return CommunityContext.CurrentGroup.GroupName; } return groupName; } set { SetValue("GroupName", value); } } /// /// Gets or sets Select only approved property. /// public bool DisplayOnlyApproved { get { return ValidationHelper.GetBoolean(GetValue("DisplayOnlyApproved"), true); } set { SetValue("DisplayOnlyApproved", value); boardDataSource.SelectOnlyApproved = value; } } /// /// Gets or sets WHERE condition. /// public string WhereCondition { get { return ValidationHelper.GetString(GetValue("WhereCondition"), ""); } set { SetValue("WhereCondition", value); boardDataSource.WhereCondition = value; } } /// /// Gets or sets ORDER BY condition. /// public string OrderBy { get { return ValidationHelper.GetString(GetValue("OrderBy"), ""); } set { SetValue("OrderBy", value); boardDataSource.OrderBy = value; } } /// /// Gets or sets TopN. /// public int SelectTopN { get { return ValidationHelper.GetInteger(GetValue("SelectTopN"), -1); } set { SetValue("SelectTopN", value); boardDataSource.TopN = value; } } /// /// Gets or sets the source filter name. /// public string FilterName { get { return ValidationHelper.GetString(GetValue("FilterName"), ""); } set { SetValue("FilterName", value); boardDataSource.SourceFilterName = value; } } /// /// Gest or sets selected columns. /// public string Columns { get { return ValidationHelper.GetString(GetValue("Columns"), ""); } set { SetValue("Columns", value); boardDataSource.SelectedColumns = value; } } #endregion #region "Basic repeater properties" /// /// Gets or sets AlternatingItemTemplate property. /// public string AlternatingItemTransformationName { get { return ValidationHelper.GetString(GetValue("AlternatingItemTransformationName"), ""); } set { SetValue("AlternatingItemTransformationName", value); } } /// /// Gets or sets FooterTemplate property. /// public string FooterTransformationName { get { return ValidationHelper.GetString(GetValue("FooterTransformationName"), ""); } set { SetValue("FooterTransformationName", value); } } /// /// Gets or sets HeaderTemplate property. /// public string HeaderTransformationName { get { return ValidationHelper.GetString(GetValue("HeaderTransformationName"), ""); } set { SetValue("HeaderTransformationName", value); } } /// /// Gets or sets ItemTemplate property. /// public string TransformationName { get { return ValidationHelper.GetString(GetValue("TransformationName"), ""); } set { SetValue("TransformationName", value); } } /// /// Gets or sets SeparatorTemplate property. /// public string SeparatorTransformationName { get { return ValidationHelper.GetString(GetValue("SeparatorTransformationName"), ""); } set { SetValue("SeparatorTransformationName", value); } } /// /// Gets or sets HideControlForZeroRows property. /// public bool HideControlForZeroRows { get { return ValidationHelper.GetBoolean(GetValue("HideControlForZeroRows"), true); } set { SetValue("HideControlForZeroRows", value); repMessages.HideControlForZeroRows = value; } } /// /// Gets or sets ZeroRowsText property. /// public string ZeroRowsText { get { return ValidationHelper.GetString(GetValue("ZeroRowsText"), ""); } set { SetValue("ZeroRowsText", value); repMessages.ZeroRowsText = value; } } #endregion #region "UniPager properties" /// /// Gets or sets the value that indicates whether pager should be hidden for single page. /// public bool HidePagerForSinglePage { get { return ValidationHelper.GetBoolean(GetValue("HidePagerForSinglePage"), pagerElem.HidePagerForSinglePage); } set { SetValue("HidePagerForSinglePage", value); pagerElem.HidePagerForSinglePage = value; } } /// /// Gets or sets the number of records to display on a page. /// public int PageSize { get { return ValidationHelper.GetInteger(GetValue("PageSize"), pagerElem.PageSize); } set { SetValue("PageSize", value); pagerElem.PageSize = value; } } /// /// Gets or sets the number of pages displayed for current page range. /// public int GroupSize { get { return ValidationHelper.GetInteger(GetValue("GroupSize"), pagerElem.GroupSize); } set { SetValue("GroupSize", value); pagerElem.GroupSize = value; } } /// /// Gets or sets the pager mode ('querystring' or 'postback'). /// public string PagingMode { get { return ValidationHelper.GetString(GetValue("PagingMode"), "querystring"); } set { if (value != null) { SetValue("PagingMode", value); switch (value.ToLowerCSafe()) { case "postback": pagerElem.PagerMode = UniPagerMode.PostBack; break; default: pagerElem.PagerMode = UniPagerMode.Querystring; break; } } } } /// /// Gets or sets the querysting parameter. /// public string QueryStringKey { get { return ValidationHelper.GetString(GetValue("QueryStringKey"), pagerElem.QueryStringKey); } set { SetValue("QueryStringKey", value); pagerElem.QueryStringKey = value; } } /// /// Gets or sets the value that indicates whether first and last item template are displayed dynamically based on current view. /// public bool DisplayFirstLastAutomatically { get { return ValidationHelper.GetBoolean(GetValue("DisplayFirstLastAutomatically"), pagerElem.DisplayFirstLastAutomatically); } set { SetValue("DisplayFirstLastAutomatically", value); pagerElem.DisplayFirstLastAutomatically = value; } } /// /// Gets or sets the value that indicates whether first and last item template are displayed dynamically based on current view. /// public bool DisplayPreviousNextAutomatically { get { return ValidationHelper.GetBoolean(GetValue("DisplayPreviousNextAutomatically"), pagerElem.DisplayPreviousNextAutomatically); } set { SetValue("DisplayPreviousNextAutomatically", value); pagerElem.DisplayPreviousNextAutomatically = value; } } #endregion #region "UniPager Template properties" /// /// Gets or sets the pages template. /// public string PagesTemplate { get { return ValidationHelper.GetString(GetValue("Pages"), ""); } set { SetValue("Pages", value); } } /// /// Gets or sets the current page template. /// public string CurrentPageTemplate { get { return ValidationHelper.GetString(GetValue("CurrentPage"), ""); } set { SetValue("CurrentPage", value); } } /// /// Gets or sets the separator template. /// public string SeparatorTemplate { get { return ValidationHelper.GetString(GetValue("PageSeparator"), ""); } set { SetValue("PageSeparator", value); } } /// /// Gets or sets the first page template. /// public string FirstPageTemplate { get { return ValidationHelper.GetString(GetValue("FirstPage"), ""); } set { SetValue("FirstPage", value); } } /// /// Gets or sets the last page template. /// public string LastPageTemplate { get { return ValidationHelper.GetString(GetValue("LastPage"), ""); } set { SetValue("LastPage", value); } } /// /// Gets or sets the previous page template. /// public string PreviousPageTemplate { get { return ValidationHelper.GetString(GetValue("PreviousPage"), ""); } set { SetValue("PreviousPage", value); } } /// /// Gets or sets the next page template. /// public string NextPageTemplate { get { return ValidationHelper.GetString(GetValue("NextPage"), ""); } set { SetValue("NextPage", value); } } /// /// Gets or sets the previous group template. /// public string PreviousGroupTemplate { get { return ValidationHelper.GetString(GetValue("PreviousGroup"), ""); } set { SetValue("PreviousGroup", value); } } /// /// Gets or sets the next group template. /// public string NextGroupTemplate { get { return ValidationHelper.GetString(GetValue("NextGroup"), ""); } set { SetValue("NextGroup", value); } } /// /// Gets or sets the layout template. /// public string LayoutTemplate { get { return ValidationHelper.GetString(GetValue("PagerLayout"), ""); } set { SetValue("PagerLayout", value); } } /// /// Gets or sets the direct page template. /// public string DirectPageTemplate { get { return ValidationHelper.GetString(GetValue("DirectPage"), ""); } set { SetValue("DirectPage", value); } } #endregion /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); repMessages.DataBindByDefault = false; pagerElem.PageControl = repMessages.ID; SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { // Do nothing } else { if (!String.IsNullOrEmpty(TransformationName)) { // Basic control properties repMessages.HideControlForZeroRows = HideControlForZeroRows; repMessages.ZeroRowsText = ZeroRowsText; // Data source properties boardDataSource.ShowGroupMessages = true; boardDataSource.TopN = SelectTopN; boardDataSource.OrderBy = OrderBy; boardDataSource.CacheItemName = CacheItemName; boardDataSource.CacheDependencies = CacheDependencies; boardDataSource.CacheMinutes = CacheMinutes; boardDataSource.FilterName = ValidationHelper.GetString(GetValue("WebPartControlID"), ClientID); boardDataSource.SourceFilterName = FilterName; boardDataSource.SelectOnlyApproved = DisplayOnlyApproved; boardDataSource.SiteName = CMSContext.CurrentSiteName; boardDataSource.SelectedColumns = Columns; #region "Repeater template properties" // Apply transformations if they exist repMessages.ItemTemplate = CMSDataProperties.LoadTransformation(this, TransformationName, false); if (!String.IsNullOrEmpty(AlternatingItemTransformationName)) { repMessages.AlternatingItemTemplate = CMSDataProperties.LoadTransformation(this, AlternatingItemTransformationName, false); } if (!String.IsNullOrEmpty(FooterTransformationName)) { repMessages.FooterTemplate = CMSDataProperties.LoadTransformation(this, FooterTransformationName, false); } if (!String.IsNullOrEmpty(HeaderTransformationName)) { repMessages.HeaderTemplate = CMSDataProperties.LoadTransformation(this, HeaderTransformationName, false); } if (!String.IsNullOrEmpty(SeparatorTransformationName)) { repMessages.SeparatorTemplate = CMSDataProperties.LoadTransformation(this, SeparatorTransformationName, false); } #endregion // UniPager properties pagerElem.PageSize = PageSize; pagerElem.GroupSize = GroupSize; pagerElem.QueryStringKey = QueryStringKey; pagerElem.DisplayFirstLastAutomatically = DisplayFirstLastAutomatically; pagerElem.DisplayPreviousNextAutomatically = DisplayPreviousNextAutomatically; pagerElem.HidePagerForSinglePage = HidePagerForSinglePage; switch (PagingMode.ToLowerCSafe()) { case "postback": pagerElem.PagerMode = UniPagerMode.PostBack; break; default: pagerElem.PagerMode = UniPagerMode.Querystring; break; } #region "UniPager template properties" // UniPager template properties if (!String.IsNullOrEmpty(PagesTemplate)) { pagerElem.PageNumbersTemplate = CMSDataProperties.LoadTransformation(pagerElem, PagesTemplate, false); } if (!String.IsNullOrEmpty(CurrentPageTemplate)) { pagerElem.CurrentPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, CurrentPageTemplate, false); } if (!String.IsNullOrEmpty(SeparatorTemplate)) { pagerElem.PageNumbersSeparatorTemplate = CMSDataProperties.LoadTransformation(pagerElem, SeparatorTemplate, false); } if (!String.IsNullOrEmpty(FirstPageTemplate)) { pagerElem.FirstPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, FirstPageTemplate, false); } if (!String.IsNullOrEmpty(LastPageTemplate)) { pagerElem.LastPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, LastPageTemplate, false); } if (!String.IsNullOrEmpty(PreviousPageTemplate)) { pagerElem.PreviousPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, PreviousPageTemplate, false); } if (!String.IsNullOrEmpty(NextPageTemplate)) { pagerElem.NextPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, NextPageTemplate, false); } if (!String.IsNullOrEmpty(PreviousGroupTemplate)) { pagerElem.PreviousGroupTemplate = CMSDataProperties.LoadTransformation(pagerElem, PreviousGroupTemplate, false); } if (!String.IsNullOrEmpty(NextGroupTemplate)) { pagerElem.NextGroupTemplate = CMSDataProperties.LoadTransformation(pagerElem, NextGroupTemplate, false); } if (!String.IsNullOrEmpty(DirectPageTemplate)) { pagerElem.DirectPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, DirectPageTemplate, false); } if (!String.IsNullOrEmpty(LayoutTemplate)) { pagerElem.LayoutTemplate = CMSDataProperties.LoadTransformation(pagerElem, LayoutTemplate, false); } #endregion string where = "(GroupName = N'" + SqlHelperClass.GetSafeQueryString(GroupName, false) + "')"; if (!string.IsNullOrEmpty(WhereCondition)) { where = "(" + WhereCondition + ") AND (" + where + ")"; } boardDataSource.WhereCondition = where; repMessages.DataSource = boardDataSource.DataSource; if (!DataHelper.DataSourceIsEmpty(repMessages.DataSource)) { repMessages.DataBind(); } } } } /// /// OnPreRender override. /// protected override void OnPreRender(EventArgs e) { Visible = repMessages.HasData() || !HideControlForZeroRows; base.OnPreRender(e); } /// /// Clears cache. /// public override void ClearCache() { boardDataSource.ClearCache(); } /// /// Reload data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); repMessages.ReloadData(true); } }