AspNetPager paging control

PagerDesigner.cs

    1 /* AspNetPager version 7.3.2
    2 Copyright (C) 2003-2010  Webdiyer(http://en.webdiyer.com)
    3 
    4 This file is part of AspNetPager.
    5 
    6 AspNetPager is free software: you can redistribute it and/or modify
    7 it under the terms of the GNU Lesser General Public License as published by
    8 the Free Software Foundation, either version 3 of the License, or
    9 (at your option) any later version.
   10 
   11 AspNetPager is distributed in the hope that it will be useful,
   12 but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 GNU Lesser General Public License for more details.
   15 
   16 You should have received a copy of the GNU Lesser General Public License
   17 along with AspNetPager.  If not, see <http://www.gnu.org/licenses/>.
   18 */
   19 
   20 using System;
   21 using System.ComponentModel;
   22 using System.ComponentModel.Design;
   23 using System.Web.UI;
   24 using System.IO;
   25 
   26 namespace Wuqi.Webdiyer
   27 {
   28 
   29     #region AspNetPager Control Designer
   30     /// <include file='AspNetPagerDocs.xml' path='AspNetPagerDoc/Class[@name="PagerDesigner"]/*'/>
   31     public class PagerDesigner : System.Web.UI.Design.ControlDesigner
   32     {
   33 
   34         private AspNetPager wb;
   35 
   36         /// <include file='AspNetPagerDocs.xml' path='AspNetPagerDoc/Method[@name="GetEditableDesignerRegionContent"]/*'/>
   37         public override string GetEditableDesignerRegionContent(System.Web.UI.Design.EditableDesignerRegion region)
   38         {
   39             region.Selectable = false;
   40             return null;
   41         }
   42 
   43         /// <include file='AspNetPagerDocs.xml' path='AspNetPagerDoc/Method[@name="GetErrorDesignTimeHtml"]/*'/>
   44         protected override string GetErrorDesignTimeHtml(Exception e)
   45         {
   46             string errorstr = "Error creating control:" + e.Message;
   47             return CreatePlaceHolderDesignTimeHtml(errorstr);
   48         }
   49 
   50         public override DesignerActionListCollection ActionLists
   51         {
   52             get
   53             {
   54                 DesignerActionListCollection actionLists = new DesignerActionListCollection();
   55                 actionLists.Add(new AspNetPagerActionList(this.Component));
   56                 return actionLists;
   57             }
   58         }
   59 
   60         /// <include file='AspNetPagerDocs.xml' path='AspNetPagerDoc/Method[@name="GetDesignTimeHtml"]/*'/>
   61         public override string GetDesignTimeHtml()
   62         {
   63 
   64             wb = (AspNetPager)Component;
   65             wb.RecordCount = 225;
   66             StringWriter sw = new StringWriter();
   67             HtmlTextWriter writer = new HtmlTextWriter(sw);
   68             wb.RenderControl(writer);
   69             return sw.ToString();
   70         }
   71 
   72     }
   73 
   74     /// <summary>
   75     /// Designer Action List
   76     /// </summary>
   77     public class AspNetPagerActionList : DesignerActionList
   78     {
   79         private AspNetPager pager;
   80         private DesignerActionUIService svc = null;
   81         /// <summary>
   82         /// Constructor
   83         /// </summary>
   84         /// <param name="component"></param>
   85         public AspNetPagerActionList(IComponent component)
   86             : base(component)
   87         {
   88             pager = component as AspNetPager;
   89             svc = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
   90         }
   91 
   92         public override DesignerActionItemCollection GetSortedActionItems()
   93         {
   94             DesignerActionItemCollection actionItems = new DesignerActionItemCollection();
   95             actionItems.Add(new DesignerActionHeaderItem("Paging mode"));
   96             actionItems.Add(new DesignerActionPropertyItem("UrlPaging", "enable url paging", "Paging"));
   97 
   98             actionItems.Add(new DesignerActionHeaderItem("Appearance"));
   99             actionItems.Add(new DesignerActionPropertyItem("ShowFirstLast", "Show first and last page buttons", "Appearance"));
  100             actionItems.Add(new DesignerActionPropertyItem("ShowPrevNext", "Show previous and next page buttons", "Appearance"));
  101             actionItems.Add(new DesignerActionPropertyItem("CurrentPageButtonPosition", "Position of urrent paging button", "Appearance"));
  102             actionItems.Add(new DesignerActionMethodItem(this, "ShowAboutForm", "About AspNetPager...", "Help", true));
  103 
  104             return actionItems;
  105         }
  106 
  107         public bool UrlPaging
  108         {
  109             get
  110             {
  111                 return pager.UrlPaging;
  112             }
  113             set
  114             {
  115                 SetProperty("UrlPaging", value);
  116                 if (!value)
  117                     SetProperty("EnableUrlRewriting", false);
  118             }
  119         }
  120 
  121         public bool ShowFirstLast
  122         {
  123             get
  124             {
  125                 return pager.ShowFirstLast;
  126             }
  127             set
  128             {
  129                 SetProperty("ShowFirstLast", value);
  130             }
  131         }
  132 
  133         public bool ShowPrevNext
  134         {
  135             get
  136             {
  137                 return pager.ShowPrevNext;
  138             }
  139             set
  140             {
  141                 SetProperty("ShowPrevNext", value);
  142             }
  143         }
  144 
  145         public PagingButtonPosition CurrentPageButtonPosition
  146         {
  147             get
  148             {
  149                 return pager.CurrentPageButtonPosition;
  150             }
  151             set
  152             {
  153                 SetProperty("CurrentPageButtonPosition", value);
  154             }
  155         }
  156 
  157         public void ShowAboutForm()
  158         {
  159             AboutForm f = new AboutForm();
  160             f.ShowDialog();
  161         }
  162 
  163         // Helper method to safely set a component’s property
  164         private void SetProperty(string propertyName, object value)
  165         {
  166             // Get property
  167             PropertyDescriptor property = TypeDescriptor.GetProperties(pager)[propertyName];
  168             // Set property value
  169             property.SetValue(pager, value);
  170         }
  171     }
  172     #endregion
  173 
  174 }