⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datagrid.cs

📁 不错的人事管理系统
💻 CS
📖 第 1 页 / 共 3 页
字号:
/*
 * 
	DataGrid是一个很复杂的类
 * 
 */ 

using System;
using System.Collections;
using System.ComponentModel;

namespace System.Web.UI.WebControls
{
	/// <summary>
	/// Summary description for DataGrid.
	/// </summary>
	public class DataGrid : BaseDataList
	{
		public const string SortCommandName = "Sort";
		public const string SelectCommandName = "Select";
		public const string EditCommandName = "Edit";
		public const string DeleteCommandName = "Delete";
		public const string UpdateCommandName = "Update";
		public const string CancelCommandName = "Cancel";
		public const string PageCommandName = "Page";
		public const string NextPageCommandArgument = "Next";
		public const string PrevPageCommandArgument = "Prev";
		internal const string DataSourceItemCountViewStateKey = "_!DataSourceItemCount";
		private static object EventCancelCommand;
		private static object EventDeleteCommand;
		private static object EventEditCommand;
		private static object EventItemCommand;
		private static object EventItemCreated;
		private static object EventItemDataBound;
		private static object EventPageIndexChanged;
		private static object EventSortCommand;
		private static object EventUpdateCommand;
		private System.Collections.IEnumerator storedData;
		private object firstDataItem;
		private bool storedDataValid;
		private System.Web.UI.WebControls.PagedDataSource pagedDataSource;
		private System.Collections.ArrayList columns;
		private System.Web.UI.WebControls.DataGridColumnCollection columnCollection;
		private System.Web.UI.WebControls.TableItemStyle headerStyle;
		private System.Web.UI.WebControls.TableItemStyle footerStyle;
		private System.Web.UI.WebControls.TableItemStyle itemStyle;
		private System.Web.UI.WebControls.TableItemStyle alternatingItemStyle;
		private System.Web.UI.WebControls.TableItemStyle selectedItemStyle;
		private System.Web.UI.WebControls.TableItemStyle editItemStyle;
		private System.Web.UI.WebControls.DataGridPagerStyle pagerStyle;
		private System.Collections.ArrayList itemsArray;
		private System.Web.UI.WebControls.DataGridItemCollection itemsCollection;
		private System.Collections.ArrayList autoGenColumnsArray;

		static DataGrid() 
		{
			EventCancelCommand = new object();
			EventDeleteCommand = new object();
			EventEditCommand = new object();
			EventItemCommand = new object();
			EventItemCreated = new object();
			EventItemDataBound = new object();
			EventPageIndexChanged = new object();
			EventSortCommand = new object();
			EventUpdateCommand = new object();
		}

		public DataGrid() : base()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		private System.Collections.ArrayList CreateAutoGeneratedColumns(PagedDataSource dataSource) 
		{
			System.Collections.ArrayList local0;
			System.ComponentModel.PropertyDescriptorCollection local1;
			bool local2;
			Type local3;
			object local4;
			System.Collections.IEnumerable local5;
			Type local6;
			System.Reflection.PropertyInfo local7;
			System.Collections.IEnumerator local8;
			System.Web.UI.WebControls.BoundColumn local9;
			System.ComponentModel.PropertyDescriptor local10;
			Type local11;
			System.Web.UI.WebControls.BoundColumn local12;
			System.Type[] local13;
			System.Collections.IEnumerator local14;
			IDisposable local15;

			if (dataSource == null)
				return null;
			local0 = new System.Collections.ArrayList();
			local1 = null;
			local2 = true;
			local1 = dataSource.GetItemProperties(new System.ComponentModel.PropertyDescriptor[0]);
			if (local1 == null) 
			{
				local3 = null;
				local4 = null;
				local5 = dataSource.DataSource;
				local6 = local5.GetType();
				local13 = new Type[1];
				local13[0] = typeof(Int32);
				local7 = local6.GetProperty("Item", (System.Reflection.BindingFlags)28, null, null, local13, null);
				if (local7 != null)
					local3 = local7.PropertyType;
				if (local3 == null || local3 == typeof(Object)) 
				{
					local8 = dataSource.GetEnumerator();
					if (local8.MoveNext())
						local4 = local8.Current;
					else
						local2 = false;
					if (local4 != null)
						local3 = local4.GetType();
					this.StoreEnumerator(local8, local4);
				}
				if (local4 != null && local4 as System.ComponentModel.ICustomTypeDescriptor != null)
					local1 = System.ComponentModel.TypeDescriptor.GetProperties(local4);
				else 		if (local3 != null) 
				{
					if (System.Web.UI.WebControls.BaseDataList.IsBindableType(local3)) 
					{
						local9 = new BoundColumn();
						((System.Web.UI.IStateManager)local9).TrackViewState();
						local9.HeaderText = "Item";
						local9.DataField = System.Web.UI.WebControls.BoundColumn.thisExpr;
						local9.SortExpression = "Item";
						local9.SetOwner(this);
						local0.Add(local9);
					}
					else
						local1 = System.ComponentModel.TypeDescriptor.GetProperties(local3);
				}
			}
			
			if (local1 != null && local1.Count != 0) 
			{
				local14 = local1.GetEnumerator();
				try 
				{
					while (local14.MoveNext()) 
					{
						local10 = (System.ComponentModel.PropertyDescriptor) local14.Current;
						local11 = local10.PropertyType;
						if (!(System.Web.UI.WebControls.BaseDataList.IsBindableType(local11)))
							continue;
						local12 = new BoundColumn();
						((System.Web.UI.IStateManager)local12).TrackViewState();
						local12.HeaderText = local10.Name;
						local12.DataField = local10.Name;
						local12.SortExpression = local10.Name;
						local12.ReadOnly = local10.IsReadOnly;
						local12.SetOwner(this);
						local0.Add(local12);
					}
				}
				finally 
				{
					local15 = local14 as IDisposable;
					if (local15 != null)
					{
						local15.Dispose();
					}
				}
			}
			if (local0.Count == 0 && local2)
			{
				throw new System.Web.HttpException(
					HttpRuntime.FormatResourceString("DataGrid_NoAutoGenColumns", this.ID)
					);
			}
			return local0;
		}

		protected virtual ArrayList CreateColumnSet(PagedDataSource dataSource, bool useDataSource) 
		{
			ArrayList local0;
			System.Web.UI.WebControls.DataGridColumn[] local1;
			int local2;
			ArrayList local3;
			int local4;

			local0 = new ArrayList();
			local1 = new DataGridColumn[checked((uint) this.Columns.Count)];
			this.Columns.CopyTo(local1, 0);
			local2 = 0;
			while (local2 < (int) local1.Length) 
			{
				local0.Add(local1[local2]);
				local2++;
			}
			if (this.AutoGenerateColumns) 
			{
				local3 = null;
				if (useDataSource) 
				{
					local3 = this.CreateAutoGeneratedColumns(dataSource);
					this.autoGenColumnsArray = local3;
				}
				else
					local3 = this.autoGenColumnsArray;
				if (local3 != null) 
				{
					local4 = local3.Count;
					local2 = 0;
					while (local2 < local4) 
					{
						local0.Add(local3[local2]);
						local2++;
					}
				}
			}
			return local0;
		}

		public virtual DataGridColumnCollection Columns
		{
			get
			{
				if (this.columnCollection == null) 
				{
					this.columns = new ArrayList();
					this.columnCollection = new DataGridColumnCollection(this, this.columns);
					if (this.IsTrackingViewState)
						((System.Web.UI.IStateManager)this.columnCollection).TrackViewState();
				}
				return this.columnCollection;
			}
		}


		protected override void CreateControlHierarchy(bool useDataSource) 
		{
			IEnumerator local0;
			int local1;
			int local2;
			ArrayList local3;
			ArrayList local4;
			IEnumerable local5;
			ICollection local6;
			int local7;
			int local8;
			DataGridColumn[] local9;
			int local10;
			Table local11;
			TableRowCollection local12;
			DataGridItem local13;
			ListItemType local14;
			int local15;
			int local16;
			string local17;
			bool local18;
			bool local19;
			int local20;
			int local21;
			object local22;
			object local23;
			object local24;

			this.pagedDataSource = this.CreatePagedDataSource();
			local0 = null;
			local1 = -1;
			local2 = -1;
			local3 = this.DataKeysArray;
			local4 = null;
			if (this.itemsArray != null)
				this.itemsArray.Clear();
			else
				this.itemsArray = new ArrayList();
			if (!(useDataSource)) 
			{
				local1 = (Int32) this.ViewState["_!ItemCount"];
				local2 = (Int32) this.ViewState["_!DataSourceItemCount"];
				if (local1 == -1)
					goto i0;
				if (this.pagedDataSource.IsCustomPagingEnabled)
					this.pagedDataSource.DataSource = new DummyDataSource(local1);
				else
					this.pagedDataSource.DataSource = new DummyDataSource(local2);
				local0 = this.pagedDataSource.GetEnumerator();
				local4 = this.CreateColumnSet(null, false);
				this.itemsArray.Capacity = local1;
			}
			else 
			{
				local3.Clear();
				local5 = DataSourceHelper.GetResolvedDataSource(this.DataSource, this.DataMember);
				if (local5 != null) 
				{
					local6 = local5 as ICollection;
					if (local6 == null && this.pagedDataSource.IsPagingEnabled && !(this.pagedDataSource.IsCustomPagingEnabled))
						throw new System.Web.HttpException(System.Web.HttpRuntime.FormatResourceString("DataGrid_Missing_VirtualItemCount", this.ID));
					this.pagedDataSource.DataSource = local5;
					if (this.pagedDataSource.IsPagingEnabled && this.pagedDataSource.CurrentPageIndex < 0 || this.pagedDataSource.CurrentPageIndex >= this.pagedDataSource.PageCount)
						throw new System.Web.HttpException(System.Web.SR.GetString("Invalid_CurrentPageIndex"));
					local4 = this.CreateColumnSet(this.pagedDataSource, useDataSource);
					if (this.storedDataValid)
						local0 = this.storedData;
					else
						local0 = this.pagedDataSource.GetEnumerator();
					if (local6 != null) 
					{
						local7 = this.pagedDataSource.Count;
						local3.Capacity = local7;
						this.itemsArray.Capacity = local7;
					}
				}
			}
			i0: local8 = 0;
			if (local4 != null)
				local8 = local4.Count;
			if (local8 > 0) 
			{
				local9 = new DataGridColumn[checked((uint) local8)];
				local4.CopyTo(local9, 0);
				local10 = 0;
				while (local10 < (int) local9.Length) 
				{
					local9[local10].Initialize();
					local10++;
				}
				local11 = new DataGridTable();
				this.Controls.Add(local11);
				local12 = local11.Rows;
				local15 = 0;
				local16 = 0;
				local17 = this.DataKeyField;

				//Modify:
				local18 = (useDataSource)? (local17.Length != 0) : false;

				//line 0257
				local19 = this.pagedDataSource.IsPagingEnabled;
				local20 = this.EditItemIndex;
				local21 = this.SelectedIndex;
				if (this.pagedDataSource.IsPagingEnabled)
					local16 = this.pagedDataSource.FirstIndexInPage;
				local1 = 0;
				if (local19)
					this.CreateItem(-1, -1, ListItemType.Pager, false, null, local9, local12, this.pagedDataSource);
				this.CreateItem(-1, -1, 0, useDataSource, null, local9, local12, null);

				//storedDataValid == false goto 03c1
				//this.firstDataItem == null goto 03c1
				if ((this.storedDataValid)
					&& (this.firstDataItem != null)
					)
				{
					if (local18) 
					{
						local22 = System.Web.UI.DataBinder.GetPropertyValue(this.firstDataItem, local17);
						local3.Add(local22);
					}
					local14 = ListItemType.Item;
					if (local15 == local20)
						local14 = ListItemType.EditItem;
					else 		if (local15 == local21)
					{
						//line 0301
						local14 = ListItemType.SelectedItem;
					}
					local13 = this.CreateItem(0, local16, local14, useDataSource, this.firstDataItem, local9, local12, null);
					this.itemsArray.Add(local13);
					local1++;
					local15++;
					local16++;

					this.storedDataValid = false;
					this.firstDataItem = null;

				}

				while (local0.MoveNext()) 
				{
					local23 = local0.Current;
					if (local18) 
					{
						local24 = System.Web.UI.DataBinder.GetPropertyValue(local23, local17);
						local3.Add(local24);
					}
					local14 = ListItemType.Item;
					if (local15 == local20)
						local14 = ListItemType.EditItem;
					else 
					{
						if (local15 == local21)
							//line 037f
							local14 = ListItemType.SelectedItem;
						else 				if (local15 % 2 != 0)
							local14 = ListItemType.AlternatingItem;
					}
					local13 = this.CreateItem(local15, local16, local14, useDataSource, local23, local9, local12, null);
					this.itemsArray.Add(local13);
					local1++;
					local16++;
					local15++;
				}

				//line 03c9
				this.CreateItem(-1, -1, ListItemType.Footer, useDataSource, null, local9, local12, null);

				//line 03da
				if (local19)
					this.CreateItem(-1, -1, ListItemType.Pager, false, null, local9, local12, this.pagedDataSource);
			}

			//line 03f4
			if (useDataSource) 
			{
				if (local0 != null) 
				{
					//line 0406
					this.ViewState["_!ItemCount"] = local1;
					if (this.pagedDataSource.IsPagingEnabled) 
					{
						this.ViewState["PageCount"] = this.pagedDataSource.PageCount;
						this.ViewState["_!DataSourceItemCount"] = this.pagedDataSource.DataSourceCount;
						goto i1;
					}
					this.ViewState["PageCount"] =  1;
					this.ViewState["_!DataSourceItemCount"] = local1;
				}
				else 
				{
					this.ViewState["_!ItemCount"] = -1;
					this.ViewState["_!DataSourceItemCount"] = -1;
					this.ViewState["PageCount"] = 0;
				}
			}
			i1: this.pagedDataSource = null;

		}

		
		protected override Style CreateControlStyle() 
		{
			TableStyle local0;

			local0 = new TableStyle(this.ViewState);
			local0.GridLines = System.Web.UI.WebControls.GridLines.Both;
			local0.CellSpacing = 0;
			return local0;
		}

		
		protected virtual void InitializeItem(DataGridItem item, System.Web.UI.WebControls.DataGridColumn[] columns) 
		{
//			TableCellCollection local0;
//			int local1;
//			TableCell local2;
//
//			local0 = item.Cells;
//			local1 = 0;
//			while (local1 < (int) columns.Length) 
//			{
//				local2 = new TableCell();
//				columns[local1].InitializeCell(local2, local1, item.ItemType);
//				local0.Add(local2);
//				local1++;
//			}
		}

		
		protected virtual void InitializePager(DataGridItem item, int columnSpan, PagedDataSource pagedDataSource) 
		{
//			TableCell local0;
//			DataGridPagerStyle local1;
//			LinkButton local2;
//			Label local3;
//			LinkButton local4;
//			Label local5;
//			int local6;
//			int local7;
//			int local8;
//			int local9;
//			int local10;
//			int local11;
//			int local12;
//			LinkButton local13;
//			int local14;
//			string local15;
//			Label local16;
//			int local17;
//
//			local0 = new TableCell();
//			local0.ColumnSpan = columnSpan;
//			local1 = this.PagerStyle;
//			if (local1.Mode == 0) 
//			{
//				if (!(pagedDataSource.IsFirstPage)) 
//				{
//					local2 = new DataGridLinkButton();
//					local2.Text = local1.PrevPageText;
//					local2.CommandName = "Page";
//					local2.CommandArgument = "Prev";
//					local2.CausesValidation = false;
//					local0.Controls.Add(local2);
//				}
//				else 
//				{
//					local3 = new Label();
//					local3.Text = local1.PrevPageText;
//					local0.Controls.Add(local3);
//				}
//				local0.Controls.Add(new LiteralControl("&nbsp;"));
//				if (!(pagedDataSource.IsLastPage)) 
//				{
//					local4 = new DataGridLinkButton();
//					local4.Text = local1.NextPageText;
//					local4.CommandName = "Page";
//					local4.CommandArgument = "Next";
//					local4.CausesValidation = false;
//					local0.Controls.Add(local4);
//					goto i4;
//				}
//				local5 = new Label();
//				local5.Text = local1.NextPageText;
//				local0.Controls.Add(local5);
//			}
//			else 
//			{
//				local6 = pagedDataSource.PageCount;
//				local7 = pagedDataSource.CurrentPageIndex + 1;
//				local8 = local1.PageButtonCount;
//				local9 = local8;
//				if (local6 < local9)
//					local9 = local6;
//				local10 = 1;
//				local11 = local9;
//				if (local7 > local11) 
//				{
//					local12 = pagedDataSource.CurrentPageIndex / local8;
//					local10 = local12 * local8 + 1;
//					local11 = local10 + local8 - 1;
//					if (local11 > local6)
//						local11 = local6;
//					if (local11 - local10 + 1 < local8)
//						local10 = System.Math.Max(1, local11 - local8 + 1);
//				}
//				if (local10 != 1) 
//				{
//					local13 = new DataGridLinkButton();
//					local13.Text = "...";
//					local13.CommandName = "Page";
//					local17 = local10 - 1;
//					local13.CommandArgument = local17.ToString(NumberFormatInfo.InvariantInfo);
//					local13.CausesValidation = false;
//					local0.Controls.Add(local13);
//					local0.Controls.Add(new LiteralControl("&nbsp;"));
//				}
//				local14 = local10;
//				while (local14 <= local11) 
//				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -