Windows 폼 페이지 구체 적 실현

이 사용자 정의 컨트롤 이 페이지 에서 pager 라 는 이름 을 지 었 습 니 다.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Common;
using System.Collections;

namespace Common
{
    public partial class WinFormPager : UserControl
    {
        public event EventHandler PageChanged; // : 。 
        private int pageSize;
        private int curPage;
        private int pageCount;
        public WinFormPager()
        {
            InitializeComponent(); 
        }

        private void WinFormPager_Load(object sender, EventArgs e)
        {
        }
        /// <summary> 
        /// [ ] 。 
        /// </summary>
        public int PageSize
        {
            get
            {
                if (pageSize <= 0)
                {
                    pageSize = 10;
                }
                return pageSize;
            }
            set
            {
                pageSize = value;
            }
        }

        /// <summary> 
        ///  
        /// </summary> 
        public int CurPage
        {
            get
            {
                if (curPage <= 0)
                {
                    curPage = 1;
                }
                return curPage;
            }
            set
            {
                curPage = value;
                if (PageChanged != null)
                {
                    SafeRaise.Raise(PageChanged,null);// 。 
                }
            }
        }
        /// <summary> 
        /// [ ] 。 
        /// </summary> 
        public int PageCount
        {
            get
            {
                if (RecordCount > 0)
                {
                    int pageCount = RecordCount / PageSize;
                    if (RecordCount % PageSize == 0)
                    {
                      pageCount = RecordCount / PageSize;
                    }

                    else
                    {
                        pageCount = RecordCount / PageSize + 1;
                    }
                    return pageCount;
                }
                else
                {
                    return 0;
                }
            }
            set
            {
                pageCount = value;
            }
        }

        /// <summary> 
        /// [ ] 。 
        /// </summary> 
        public int RecordCount
        {
            get;
            set;
        }

        /// <summary> 
        /// [ ]  
        /// </summary> 
        public int PrevPage
        {
            get
            {
                if (CurPage > 1)
                {
                    return CurPage - 1;
                }
                return 1;
            }
        }

        /// <summary> 
        /// [ ]  
        /// </summary> 
        public int NextPage
        {
            get
            {
                if (CurPage < PageCount)
                {
                    return CurPage + 1;
                }
                return PageCount;
            }
        }

        private void btnFirstPage_Click(object sender, EventArgs e)
        {
            this.CurPage = 1;
        }

        private void btnLastPage_Click(object sender, EventArgs e)
        {
            this.CurPage = this.PrevPage;
        }

        private void btnNextPage_Click(object sender, EventArgs e)
        {
            this.CurPage = this.NextPage;
        }

        private void btnEndPage_Click(object sender, EventArgs e)
        {
            this.CurPage = this.PageCount;
        }

        private void txtPageNumber_TextChanged(object sender, EventArgs e)
        {
            if (!Validator.IsNumeric(this.txtPageNumber.Text.Trim()))
            {
                MessageBox.Show(" !");
            }
        }

        private void btnJump_Click(object sender, EventArgs e)
        {

            if (!Validator.IsNumeric(this.txtPageNumber.Text.Trim()))//
            {
                MessageBox.Show(" !");
            }
            else
            {
                if (int.Parse(this.txtPageNumber.Text.Trim()) > 0)
                {
                    if (int.Parse(this.txtPageNumber.Text.Trim()) < this.PageCount)
                    {
                        this.CurPage = int.Parse(this.txtPageNumber.Text.Trim());
                    }
                    else
                    {
                        this.CurPage = this.PageCount;
                    }
                }
                else
                {
                    this.CurPage = 1;
                }
            }
        } 
    }
}

컨트롤

좋은 웹페이지 즐겨찾기