using System; using System.Data; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.GlobalHelper; using CMS.PortalControls; public partial class CMSWebParts_WebServices_GridForWebService : CMSAbstractWebPart { #region "Public properties" /// /// Gets or sets the value that indicates whether to hide control when no data found. /// public bool HideControlForZeroRows { get { return ValidationHelper.GetBoolean(GetValue("HideControlForZeroRows"), basicDataGrid.HideControlForZeroRows); } set { SetValue("HideControlForZeroRows", value); basicDataGrid.HideControlForZeroRows = value; } } /// /// Gets or sets the text which is displayed when no data found. /// public string ZeroRowsText { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("ZeroRowsText"), basicDataGrid.ZeroRowsText), basicDataGrid.ZeroRowsText); } set { SetValue("ZeroRowsText", value); basicDataGrid.ZeroRowsText = value; } } /// /// Gets or sets the value that indicates whether the sorting is ascending. /// public bool SortAscending { get { return (ValidationHelper.GetBoolean(GetValue("SortAscending"), basicDataGrid.SortAscending)); } set { SetValue("SortAscending", value); basicDataGrid.SortAscending = value; } } /// /// Gets or sets the value that indicates whether the sorting is allowed. /// public bool AllowSorting { get { return ValidationHelper.GetBoolean(GetValue("AllowSorting"), basicDataGrid.AllowSorting); } set { SetValue("AllowSorting", value); basicDataGrid.AllowSorting = value; } } /// /// Gets or sets the value that indicates whether the sorting process is in the code. /// public bool ProcessSorting { get { return ValidationHelper.GetBoolean(GetValue("ProcessSorting"), basicDataGrid.ProcessSorting); } set { SetValue("ProcessSorting", value); basicDataGrid.ProcessSorting = value; } } /// /// Gets or sets the name of the column which should be used for sorting. /// public string SortField { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("SortField"), basicDataGrid.SortField), basicDataGrid.SortField); } set { SetValue("SortField", value); basicDataGrid.SortField = value; } } /// /// Gets or sets the value that indicates whether the the paging should be allowed. /// public bool AllowPaging { get { return ValidationHelper.GetBoolean(GetValue("AllowPaging"), basicDataGrid.AllowPaging); } set { SetValue("AllowPaging", value); basicDataGrid.AllowPaging = value; } } /// /// Gets or sets the value that indicates whether the custom paging should be allowed. /// public bool AllowCustomPaging { get { return ValidationHelper.GetBoolean(GetValue("AllowCustomPaging"), basicDataGrid.AllowCustomPaging); } set { SetValue("AllowCustomPaging", value); basicDataGrid.AllowCustomPaging = value; } } /// /// Gets or sets the size of the page if the paging is allowed. /// public int PageSize { get { return ValidationHelper.GetInteger(GetValue("PageSize"), basicDataGrid.PageSize); } set { SetValue("PageSize", value); basicDataGrid.PageSize = value; } } /// /// Gets or sets the value that indicates whether the databind is automatic. /// public bool DataBindByDefault { get { return ValidationHelper.GetBoolean(GetValue("DataBindByDefault"), basicDataGrid.DataBindByDefault); } set { SetValue("DataBindByDefault", value); basicDataGrid.DataBindByDefault = value; } } /// /// Gets or sets the pager mode. /// public PagerMode PagingMode { get { return basicDataGrid.GetPagerMode(ValidationHelper.GetString(GetValue("Mode"), "")); } set { SetValue("Mode", value); } } /// /// Gets or sets the value that indicates whether the header should be shown. /// public bool ShowHeader { get { return ValidationHelper.GetBoolean(GetValue("ShowHeader"), basicDataGrid.ShowHeader); } set { SetValue("ShowHeader", value); basicDataGrid.ShowHeader = value; } } /// /// Gets or sets the value that indicates whether the footer should be shown. /// public bool ShowFooter { get { return ValidationHelper.GetBoolean(GetValue("ShowFooter"), basicDataGrid.ShowFooter); } set { SetValue("ShowFooter", value); basicDataGrid.ShowFooter = value; } } /// /// Gets or sets the tool tip value. /// public string ToolTip { get { return DataHelper.GetNotEmpty(GetValue("ToolTip"), basicDataGrid.ToolTip); } set { SetValue("ToolTip", value); basicDataGrid.ToolTip = value; } } /// /// Gets or sets the value that indicates whether the columns are generated automatically. /// public bool AutoGenerateColumns { get { return ValidationHelper.GetBoolean(GetValue("AutoGenerateColumns"), basicDataGrid.AutoGenerateColumns); } set { SetValue("AutoGenerateColumns", value); basicDataGrid.AutoGenerateColumns = value; } } #endregion #region "Webservices properties" /// /// Gets or sets the parameters of the web service. /// public string WebServiceParameters { get { return ValidationHelper.GetString(GetValue("WebServiceParameters"), wsDataSource.WebServiceParameters); } set { SetValue("WebServiceParameters", value); wsDataSource.WebServiceParameters = value; } } /// /// Gets or sets the url of the web service. /// public string WebServiceURL { get { return ValidationHelper.GetString(GetValue("WebServiceURL"), wsDataSource.WebServiceUrl); } set { SetValue("WebServiceURL", value); wsDataSource.WebServiceUrl = value; } } #endregion #region "Stop processing" /// /// Returns true if the control processing should be stopped. /// public override bool StopProcessing { get { return base.StopProcessing; } set { base.StopProcessing = value; wsDataSource.StopProcessing = value; } } #endregion /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { basicDataGrid.Visible = false; wsDataSource.StopProcessing = true; } else { // Setup the control // Setup paging basicDataGrid.AllowPaging = AllowPaging; basicDataGrid.PageSize = PageSize; basicDataGrid.AllowCustomPaging = AllowCustomPaging; basicDataGrid.PagerStyle.Mode = PagingMode; basicDataGrid.ShowHeader = ShowHeader; basicDataGrid.ShowFooter = ShowFooter; basicDataGrid.ToolTip = ToolTip; // Set SkinID property if (!StandAlone && (PageCycle < PageCycleEnum.Initialized) && (ValidationHelper.GetString(Page.StyleSheetTheme, "") == "")) { basicDataGrid.SkinID = SkinID; } basicDataGrid.EnableViewState = true; // Setup sorting basicDataGrid.AllowSorting = AllowSorting; basicDataGrid.ProcessSorting = ProcessSorting; basicDataGrid.SortAscending = SortAscending; basicDataGrid.SortField = SortField; basicDataGrid.AutoGenerateColumns = AutoGenerateColumns; basicDataGrid.DataBindByDefault = DataBindByDefault; basicDataGrid.HideControlForZeroRows = HideControlForZeroRows; basicDataGrid.ZeroRowsText = ZeroRowsText; // Get web service URL and parameters wsDataSource.WebServiceUrl = WebServiceURL; wsDataSource.WebServiceParameters = WebServiceParameters; // Connect with data source basicDataGrid.DataSource = wsDataSource.DataSource; Visible = !(DataHelper.DataSourceIsEmpty(basicDataGrid.DataSource) && HideControlForZeroRows); } } /// /// Applies given stylesheet skin. /// public override void ApplyStyleSheetSkin(Page page) { basicDataGrid.SkinID = SkinID; base.ApplyStyleSheetSkin(page); } /// /// Reload control's data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); } }