82 lines
2.7 KiB
C#
82 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
using UI.Framework.Entitys;
|
|
using DevExpress.XtraGrid.Columns;
|
|
|
|
namespace UI.Framework.Controls
|
|
{
|
|
public partial class GridPageControl : DevExpress.XtraEditors.XtraUserControl
|
|
{
|
|
public GridPageControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void Bind<T>(PageControl.SerchEvents serchDataMethod, int pageSize = 30)
|
|
{
|
|
try
|
|
{
|
|
var type = typeof(T);
|
|
var properties = type.GetProperties();
|
|
int number = 1;
|
|
List<GridColumn> GridColumns = new List<GridColumn>();
|
|
foreach (var item in properties)
|
|
{
|
|
|
|
DataViewAtrribute att = item.GetCustomAttributes(typeof(DataViewAtrribute), true).FirstOrDefault() as DataViewAtrribute;
|
|
|
|
var column = new DevExpress.XtraGrid.Columns.GridColumn();
|
|
column.Caption = att != null ? att.Name : item.Name;
|
|
column.Name = item.Name;
|
|
column.Visible = true;
|
|
column.VisibleIndex = item.Name.ToLower() == "id" ? 0 : number;
|
|
if (item.Name.ToLower() == "id") column.MinWidth = column.Width = column.MaxWidth = 80;
|
|
column.FieldName = item.Name;
|
|
GridColumns.Add(column);
|
|
}
|
|
this.gridView1.Columns.AddRange(GridColumns.ToArray());
|
|
this.DataPage.Bind(serchDataMethod, DataView, pageSize);//给分页组件绑定值,搜索函数,显示控件,每页显示行数
|
|
}
|
|
catch (Exception)
|
|
{ }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定数据源
|
|
/// </summary>
|
|
public void Bind(PageControl.SerchEvents serchDataMethod, int pageSize = 30)
|
|
{
|
|
try
|
|
{
|
|
this.DataPage.Bind(serchDataMethod, DataView, pageSize);//给分页组件绑定值,搜索函数,显示控件,每页显示行数
|
|
}
|
|
catch (Exception)
|
|
{ }
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString();
|
|
}
|
|
catch (Exception)
|
|
{ }
|
|
}
|
|
}
|
|
|
|
|
|
}
|