using System; using System.Windows.Forms; using DevExpress.XtraEditors; using UAS_PLCDataReader.DataOperate; using UAS_PLCDataReader.Entity; using System.Data; namespace UAS_PLCDataReader.CustomerControl.PagingControl { public partial class PageControl : UserControl { DataHelper dh = SystemInf.dh; private AutoDataGridControl.AutoDataGridControl gridcontrol; public AutoDataGridControl.AutoDataGridControl Gridcontrol { get { return gridcontrol; } set { gridcontrol = value; } } public PageControl() { InitializeComponent(); } private void PageControl_Load(object sender, EventArgs e) { if (gridcontrol != null) gridcontrol.VisibleChanged += Gridcontrol_VisibleChanged; } private void Gridcontrol_VisibleChanged(object sender, EventArgs e) { PageCount.Text = (gridcontrol.RowCount / int.Parse(PageSize.Text) + 1).ToString(); } private void GoPage_Click(object sender, EventArgs e) { SimpleButton button = sender as SimpleButton; string SQL = gridcontrol.GetDataSQL; int pagesize = int.Parse(PageSize.Text); int currentpage = int.Parse(CurrentPage.Text); int rowcount = gridcontrol.RowCount; switch (button.Name) { case "GoFirstPage": CurrentPage.Text = "1"; currentpage = 1; break; case "GoFormerPage": if (currentpage == 1) { XtraMessageBox.Show("当前已经是第一页", "提示"); return; } CurrentPage.Text = (currentpage - 1).ToString(); currentpage = currentpage - 1; break; case "GoNextPage": if (currentpage.ToString() == PageCount.Text) { XtraMessageBox.Show("当前已经是最后一页", "提示"); return; } CurrentPage.Text = (currentpage + 1).ToString(); currentpage = currentpage + 1; break; case "GoLastPage": CurrentPage.Text = ((rowcount / pagesize) + 1).ToString(); currentpage = int.Parse(PageCount.Text); break; default: break; } gridcontrol.DataSource = dh.ExecuteSql("select * from (select RowNum RN, A.* from(" + SQL + ")A) where RN<=" + pagesize * currentpage + "and RN >" + pagesize * (currentpage - 1), "select"); } private void PageSize_SelectedIndexChanged(object sender, EventArgs e) { DataTable dt = (DataTable)dh.ExecuteSql(gridcontrol.GetDataSQL,"select"); PageCount.Text = (dt.Rows.Count / int.Parse(PageSize.Text)).ToString(); } } }