| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- 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 Infragistics.Win.UltraWinGrid;
- using System.Reflection;
- using Infragistics.Shared;
- namespace Core.Mes.Client.Comm.Control
- {
- [ComplexBindingProperties("DataSource", "DataMember")]
- [DefaultEvent("InitializeLayout")]
- [DefaultProperty("DisplayLayout")]
- [Designer("Infragistics.Win.UltraWinGrid.Design.UltraGridDesigner, Infragistics2.Win.v9.2.Design, Version=9.2.20092.1003, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb")]
- [LicenseProvider(typeof(UltraLicenseProvider))]
- [ToolboxBitmap(typeof(UltraGridBase), "ToolboxBitmaps.CLR2.UltraGrid.bmp")]
- public partial class EntityGrid : UltraGrid
- {
- public EntityGrid()
- {
- InitializeComponent();
- }
- private int initCount = 0;
- private bool IsDesignMode()
- {
- if (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime)
- {
- return true;
- }
- else if (System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToUpper().Equals("DEVENV"))
- {
- return true;
- }
- return false;
- }
- protected override void OnInitializeLayout(InitializeLayoutEventArgs e)
- {
- base.OnInitializeLayout(e);
- if (IsDesignMode())
- {
- if (initCount == 0)
- {
- initCount++;
- SetEntityGridCaption();
- }
- }
- else
- {
- this.DisplayLayout.Override.AllowRowLayoutCellSizing = RowLayoutSizing.None;
- this.DisplayLayout.Override.SelectedRowAppearance.BackColor = Color.Empty;
- this.DisplayLayout.Override.ActiveRowAppearance.BackColor = Color.Empty;
- this.DisplayLayout.Override.ActiveRowAppearance.ForeColor = Color.Empty;
- }
- }
- private void SetEntityGridCaption()
- {
- if (this.DataSource != null && this.DataSource is BindingSource)
- {
- try
- {
- BindingSource bindSouce = (BindingSource)this.DataSource;
- Type type = (Type)bindSouce.DataSource;
- SetCaption(this.DisplayLayout.Bands[0], type);
- if (this.DisplayLayout.Bands.Count > 1)
- {
- System.Reflection.PropertyInfo[] pis = type.GetProperties();
- foreach (System.Reflection.PropertyInfo pi in pis)
- {
- if (pi.PropertyType.IsGenericType)
- {
- Type genericType = pi.PropertyType.GetGenericArguments()[0];
- SetCaption(this.DisplayLayout.Bands[1], genericType);
- }
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- }
- private void SetCaption(UltraGridBand gridBand, Type type)
- {
- //this.BeginUpdate();
- try
- {
- PropertyInfo[] propertyInfos = type.GetProperties();
- foreach (PropertyInfo propertyInfo in propertyInfos)
- {
- if (gridBand.Columns.Exists(propertyInfo.Name))
- {
- //设置单元格为空时的值。
- if (propertyInfo.PropertyType == typeof(string)
- && gridBand.Columns[propertyInfo.Name].Nullable != Infragistics.Win.UltraWinGrid.Nullable.EmptyString)
- {
- gridBand.Columns[propertyInfo.Name].Nullable = Infragistics.Win.UltraWinGrid.Nullable.EmptyString;
- }
- object[] desAttributes = propertyInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
- if (desAttributes.Length > 0)
- {
- if (gridBand.Columns[propertyInfo.Name].Header.Caption != ((DescriptionAttribute)desAttributes[0]).Description)
- {
- gridBand.Columns[propertyInfo.Name].Header.Caption = ((DescriptionAttribute)desAttributes[0]).Description;
- }
- }
- }
- }
- }
- finally
- {
- //this.EndUpdate();
- }
- }
- private UltraGrid grid = new UltraGrid();
- public UltraGrid StyleGrid
- {
- get { return grid; }
- set { grid = value; }
- }
- }
- }
|