PageControl.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Windows.Forms;
  3. using DevExpress.XtraEditors;
  4. using UAS_DeviceMonitor.DataOperate;
  5. using UAS_DeviceMonitor.Entity;
  6. namespace UAS_DeviceMonitor.CustomerControl.PagingControl
  7. {
  8. public partial class PageControl : UserControl
  9. {
  10. DataHelper dh = SystemInf.dh;
  11. private AutoDataGridControl.AutoDataGridControl gridcontrol;
  12. public AutoDataGridControl.AutoDataGridControl Gridcontrol
  13. {
  14. get
  15. {
  16. return gridcontrol;
  17. }
  18. set
  19. {
  20. gridcontrol = value;
  21. }
  22. }
  23. public PageControl()
  24. {
  25. InitializeComponent();
  26. }
  27. private void PageControl_Load(object sender, EventArgs e)
  28. {
  29. if (gridcontrol != null)
  30. gridcontrol.VisibleChanged += Gridcontrol_VisibleChanged;
  31. }
  32. private void Gridcontrol_VisibleChanged(object sender, EventArgs e)
  33. {
  34. PageCount.Text = (gridcontrol.RowCount / int.Parse(PageSize.Text) + 1).ToString();
  35. }
  36. private void GoPage_Click(object sender, EventArgs e)
  37. {
  38. SimpleButton button = sender as SimpleButton;
  39. string SQL = gridcontrol.GetDataSQL;
  40. int pagesize = int.Parse(PageSize.Text);
  41. int currentpage = int.Parse(CurrentPage.Text);
  42. int rowcount = gridcontrol.RowCount;
  43. switch (button.Name)
  44. {
  45. case "GoFirstPage":
  46. CurrentPage.Text = "1";
  47. currentpage = 1;
  48. break;
  49. case "GoFormerPage":
  50. if (currentpage == 1)
  51. {
  52. MessageBox.Show("当前已经是第一页");
  53. return;
  54. }
  55. CurrentPage.Text = (currentpage - 1).ToString();
  56. currentpage = currentpage - 1;
  57. break;
  58. case "GoNextPage":
  59. if (currentpage.ToString() == PageCount.Text)
  60. {
  61. MessageBox.Show("当前已经是最后一页");
  62. return;
  63. }
  64. CurrentPage.Text = (currentpage + 1).ToString();
  65. currentpage = currentpage + 1;
  66. break;
  67. case "GoLastPage":
  68. CurrentPage.Text = ((rowcount / pagesize) + 1).ToString();
  69. currentpage = int.Parse(PageCount.Text);
  70. break;
  71. default:
  72. break;
  73. }
  74. gridcontrol.DataSource = dh.ExecuteSql("select * from (select RowNum RN, A.* from(" + SQL + ")A) where RN<=" + pagesize * currentpage + "and RN >" + pagesize * (currentpage - 1), "select");
  75. }
  76. }
  77. }