
/* ?————————————————————————————————————————————————————?
   | //版本：1.0                                           |
   | //作者：舒密   shumi@126.com   http://netlm.cnblogs.com |
   | //使用中出现的BUG欢迎发EMAIL给我                              |
   | //                                                 |
   | //引用、转载请保留版权信息   广西师范学院   TCN工 作室                  |
   ?————————————————————————————————————————————————————? */
using System;
using System.CodeDom;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.CodeDom.Compiler;
using Netlm.DataGridGost;
using System.Threading;
namespace Netlm.DataListGost
{
	/// <summary>
	/// UserControl1 的摘要说明。
	/// </summary>
	public class DataListControl : System.Windows.Forms.UserControl
	{
		private System.Windows.Forms.ToolBarButton tbbSelectAll;
		private System.Windows.Forms.ToolBarButton tbbNext;
		private System.Windows.Forms.MenuItem mitSelectAll;
		private System.Windows.Forms.ContextMenu contextMenu1;
		private System.Windows.Forms.MenuItem mitReSelect;
		private System.Windows.Forms.MenuItem mitNotSelect;
		private System.Windows.Forms.MenuItem mit1;
		private System.Windows.Forms.MenuItem mitFirst;
		private System.Windows.Forms.MenuItem mitPrev;
		private System.Windows.Forms.MenuItem mitNext;
		private System.Windows.Forms.MenuItem mitLast;
		private System.Data.DataView mCurrentDataView;
		private System.Windows.Forms.Label labPage;
		private System.Windows.Forms.ToolBarButton tbbReSelect;
		private System.Windows.Forms.ToolBarButton tbbNotSelect;
		private System.Windows.Forms.ToolBarButton tbb2;
		private System.Windows.Forms.ToolBarButton tbbFirst;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.ToolBarButton tbbLast;
		private System.Windows.Forms.ToolBarButton tbb1;
		private System.Windows.Forms.ToolBarButton tbbPrev;
		private System.Windows.Forms.ToolBar toolBar1;
		private System.Windows.Forms.Label labInfo;
		private System.ComponentModel.IContainer components;

		public DataListControl()
		{
			// 该调用是 Windows.Forms 窗体设计器所必需的。
			InitializeComponent();

			// TODO: 在 InitComponent 调用后添加任何初始化

		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if( components != null )
					components.Dispose();
			}
			base.Dispose( disposing );
		}

		
		#region 组件设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器 
		/// 修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DataListControl));
			this.tbbSelectAll = new System.Windows.Forms.ToolBarButton();
			this.tbbNext = new System.Windows.Forms.ToolBarButton();
			this.mitSelectAll = new System.Windows.Forms.MenuItem();
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
			this.mitReSelect = new System.Windows.Forms.MenuItem();
			this.mitNotSelect = new System.Windows.Forms.MenuItem();
			this.mit1 = new System.Windows.Forms.MenuItem();
			this.mitFirst = new System.Windows.Forms.MenuItem();
			this.mitPrev = new System.Windows.Forms.MenuItem();
			this.mitNext = new System.Windows.Forms.MenuItem();
			this.mitLast = new System.Windows.Forms.MenuItem();
			this.mCurrentDataView = new System.Data.DataView();
			this.labPage = new System.Windows.Forms.Label();
			this._CurrentDataGrid = new System.Windows.Forms.DataGrid();
			this.tbbReSelect = new System.Windows.Forms.ToolBarButton();
			this.tbbNotSelect = new System.Windows.Forms.ToolBarButton();
			this.tbb2 = new System.Windows.Forms.ToolBarButton();
			this.tbbFirst = new System.Windows.Forms.ToolBarButton();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.tbbLast = new System.Windows.Forms.ToolBarButton();
			this.tbb1 = new System.Windows.Forms.ToolBarButton();
			this.tbbPrev = new System.Windows.Forms.ToolBarButton();
			this.toolBar1 = new System.Windows.Forms.ToolBar();
			this.labInfo = new System.Windows.Forms.Label();
			((System.ComponentModel.ISupportInitialize)(this.mCurrentDataView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this._CurrentDataGrid)).BeginInit();
			this.SuspendLayout();
			// 
			// tbbSelectAll
			// 
			this.tbbSelectAll.ImageIndex = 0;
			this.tbbSelectAll.ToolTipText = "全选";
			// 
			// tbbNext
			// 
			this.tbbNext.ImageIndex = 5;
			this.tbbNext.ToolTipText = "下一页";
			// 
			// mitSelectAll
			// 
			this.mitSelectAll.Index = 0;
			this.mitSelectAll.Text = "全选";
			this.mitSelectAll.Click += new System.EventHandler(this.mitSelectAll_Click);
			// 
			// contextMenu1
			// 
			this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						 this.mitSelectAll,
																						 this.mitReSelect,
																						 this.mitNotSelect,
																						 this.mit1,
																						 this.mitFirst,
																						 this.mitPrev,
																						 this.mitNext,
																						 this.mitLast});
			// 
			// mitReSelect
			// 
			this.mitReSelect.Index = 1;
			this.mitReSelect.Text = "反选";
			this.mitReSelect.Click += new System.EventHandler(this.mitReSelect_Click);
			// 
			// mitNotSelect
			// 
			this.mitNotSelect.Index = 2;
			this.mitNotSelect.Text = "全否";
			this.mitNotSelect.Click += new System.EventHandler(this.mitNotSelect_Click);
			// 
			// mit1
			// 
			this.mit1.Index = 3;
			this.mit1.Text = "-";
			// 
			// mitFirst
			// 
			this.mitFirst.Index = 4;
			this.mitFirst.Text = "首页";
			this.mitFirst.Click += new System.EventHandler(this.mitFirst_Click);
			// 
			// mitPrev
			// 
			this.mitPrev.Index = 5;
			this.mitPrev.Text = "上一页";
			this.mitPrev.Click += new System.EventHandler(this.mitPrev_Click);
			// 
			// mitNext
			// 
			this.mitNext.Index = 6;
			this.mitNext.Text = "下一页";
			this.mitNext.Click += new System.EventHandler(this.mitNext_Click);
			// 
			// mitLast
			// 
			this.mitLast.Index = 7;
			this.mitLast.Text = "尾页";
			this.mitLast.Click += new System.EventHandler(this.mitLast_Click);
			// 
			// labPage
			// 
			this.labPage.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.labPage.Location = new System.Drawing.Point(344, 8);
			this.labPage.Name = "labPage";
			this.labPage.Size = new System.Drawing.Size(256, 16);
			this.labPage.TabIndex = 6;
			// 
			// _CurrentDataGrid
			// 
			this._CurrentDataGrid.AllowNavigation = false;
			this._CurrentDataGrid.CaptionVisible = false;
			this._CurrentDataGrid.ContextMenu = this.contextMenu1;
			this._CurrentDataGrid.DataMember = "";
			this._CurrentDataGrid.Dock = System.Windows.Forms.DockStyle.Fill;
			this._CurrentDataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this._CurrentDataGrid.Location = new System.Drawing.Point(0, 28);
			this._CurrentDataGrid.Name = "_CurrentDataGrid";
			this._CurrentDataGrid.ReadOnly = true;
			this._CurrentDataGrid.RowHeadersVisible = false;
			this._CurrentDataGrid.RowHeaderWidth = 30;
			this._CurrentDataGrid.Size = new System.Drawing.Size(344, 148);
			this._CurrentDataGrid.TabIndex = 5;
			this._CurrentDataGrid.DoubleClick += new System.EventHandler(this._CurrentDataGrid_DoubleClick);
			this._CurrentDataGrid.MouseUp += new System.Windows.Forms.MouseEventHandler(this._CurrentDataGrid_MouseUp);
			this._CurrentDataGrid.CurrentCellChanged += new System.EventHandler(this._CurrentDataGrid_CurrentCellChanged);
			// 
			// tbbReSelect
			// 
			this.tbbReSelect.ImageIndex = 1;
			this.tbbReSelect.ToolTipText = "反选";
			// 
			// tbbNotSelect
			// 
			this.tbbNotSelect.ImageIndex = 2;
			this.tbbNotSelect.ToolTipText = "全否";
			// 
			// tbb2
			// 
			this.tbb2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// tbbFirst
			// 
			this.tbbFirst.ImageIndex = 3;
			this.tbbFirst.ToolTipText = "首页";
			// 
			// imageList1
			// 
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// tbbLast
			// 
			this.tbbLast.ImageIndex = 6;
			this.tbbLast.ToolTipText = "末页";
			// 
			// tbb1
			// 
			this.tbb1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// tbbPrev
			// 
			this.tbbPrev.ImageIndex = 4;
			this.tbbPrev.ToolTipText = "上一页";
			// 
			// toolBar1
			// 
			this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						this.tbb1,
																						this.tbbSelectAll,
																						this.tbbReSelect,
																						this.tbbNotSelect,
																						this.tbb2,
																						this.tbbFirst,
																						this.tbbPrev,
																						this.tbbNext,
																						this.tbbLast});
			this.toolBar1.DropDownArrows = true;
			this.toolBar1.ImageList = this.imageList1;
			this.toolBar1.Location = new System.Drawing.Point(0, 0);
			this.toolBar1.Name = "toolBar1";
			this.toolBar1.ShowToolTips = true;
			this.toolBar1.Size = new System.Drawing.Size(344, 28);
			this.toolBar1.TabIndex = 4;
			this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
			// 
			// labInfo
			// 
			this.labInfo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.labInfo.Location = new System.Drawing.Point(240, 8);
			this.labInfo.Name = "labInfo";
			this.labInfo.Size = new System.Drawing.Size(100, 16);
			this.labInfo.TabIndex = 7;
			// 
			// DataListControl
			// 
			this.Controls.Add(this.labInfo);
			this.Controls.Add(this._CurrentDataGrid);
			this.Controls.Add(this.labPage);
			this.Controls.Add(this.toolBar1);
			this.Name = "DataListControl";
			this.Size = new System.Drawing.Size(344, 176);
			((System.ComponentModel.ISupportInitialize)(this.mCurrentDataView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this._CurrentDataGrid)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion
		
		#region 私有字段
		private int mSumPage;//总页数
		private bool mIsFirst;//是否是第一页
		private bool mIsLast;//是否是最后一页
		private int _CurrentRowIndex = 0; //记录当前选定行的索引
		private int mPrimaryColumnIndex;
		private ArrayList mSelectKeyIds;
		#endregion
		
		#region 自定义属性
		private DataGrid _CurrentDataGrid;
		[Category("DataGridGost状态和数据")]
		[Description("当前DataGrid")]
		public DataGrid CurrentDataGrid
		{
			get
			{
				return _CurrentDataGrid;
			}
		}
		private string _SelectedKeyID;
		[Browsable(true)]
		[Category("DataGridGost状态和数据")]
		[Description("当前行的主键ID的值")]
		public string SelectedKeyID
		{
			get { return this.GetCurrentRowKeyID(); }
		}
		
		[Category("DataGridGost状态和数据")]
		[DefaultValue("0")]
		[Description("当前行索引")]
		public int CurrentRowIndex
		{
			get
			{
				return _CurrentDataGrid.CurrentRowIndex;
			}
		}
		
		[Category("DataGridGost状态和数据")]
		[Description("当前行视图")]
		public DataRow CurrentDataRow
		{
			get
			{
				return mCurrentDataView[_CurrentRowIndex].Row ;
			}
		}

		#region 分页属性

		private bool _Pagination = false;
		[Browsable(true)]
		[Category("DataGridGost分页")]
		[Description("是否进行分页")]
		public bool Pagination
		{
			set { _Pagination = value; }
			get { return _Pagination; }
		}

		private int _PageSize = 50;
		[Browsable(true)]
		[Category("DataGridGost分页")]
		[Description("分页大小")]
		public int PageSize
		{
			get { return _PageSize; }
			set { _PageSize = value; }
		}

		private int _CurrentPageIndex = 1;
		[Browsable(true)]
		[Category("DataGridGost分页")]
		[Description("当前页")]
		public int CurrentPageIndex
		{
			get { return _CurrentPageIndex; }
			set { _CurrentPageIndex = value; }
		}

		private int _SumCount;
		[Browsable(true)]
		[Category("DataGridGost分页")]
		[Description("记录总数")]
		public int SumCount
		{
			get { return _SumCount; }
			set { _SumCount = value; }
		}

		#endregion

		#region 配置
		private DataGridTableStyle _TableStyle;
		[Browsable(true)]
		[Category("DataGridGost配置")]
		[Description("指定TableStyle类型")]
		public DataGridTableStyle TableStyle
		{
			set { _TableStyle = value; }
			get { return _TableStyle; }
		}
		private ContextMenu _DataGridContextMenu;
		[Browsable(true)]
		[Category("DataGridGost配置")]
		[Description("指定列表中的上下文操作菜单")]
		public ContextMenu DataGridContextMenu
		{
			set { 
				_DataGridContextMenu = value; 
				this.SetContextMenu();
			}
			get { return _DataGridContextMenu; }
		}

		private bool _ShowToolBar = false;
		[Browsable(true)]
		[Category("DataGridGost配置")]
		[Description("是否显示工具栏")]
		public bool ShowToolBar
		{
			set { _ShowToolBar = value; }
			get { return _ShowToolBar; }
		}
		
		private bool _ShowCheckBox = false;
		[Browsable(true)]
		[Category("DataGridGost配置")]
		[Description("指定列表中是否可勾选")]
		public bool ShowCheckBox
		{
			set { _ShowCheckBox = value; }
			get { return _ShowCheckBox; }
		}
		private string _CheckBoxTitle="选择";
		[Browsable(true)]
		[Category("DataGridGost配置")]
		[DefaultValue("选择")]
		[Description("勾选列标题")]
		public string CheckBoxTitle
		{
			get
			{
				return _CheckBoxTitle;
			}
			set
			{
				_CheckBoxTitle = value;
			}
		}
		private int _ChekcBoxWidth=30;
		[Category("DataGridGost配置")]
		[Description("勾选列宽")]
		public int ChekcBoxWidth
		{
			get
			{
				return _ChekcBoxWidth;
			}
			set
			{
				_ChekcBoxWidth = value;
			}
		}
		private string _CheckBoxWhere;
		[Category("DataGridGost配置")]
		[Description("勾选条件")]
		public string CheckBoxWhere
		{
			get
			{
				return _CheckBoxWhere;
			}
			set
			{
				_CheckBoxWhere = value;
			}
		}
		private DataSet _CurrentDataSet = null;
		[Category("DataGridGost配置"),Description("当前的DataSet")]
		public DataSet CurrentDataSet
		{
			get { return _CurrentDataSet; }
			set { _CurrentDataSet = value; }
		}
		
		private string _RowFilterWhere;
		[Browsable(true)]
		[Category("DataGridGost配置")]
		[Description("筛选条件")]
		public string RowFilterWhere
		{
			get
			{
				return _RowFilterWhere;
			}
			set
			{
				_RowFilterWhere = value;
				
				mCurrentDataView.RowFilter = _RowFilterWhere;
				SerNumPaint();
			}
		}
		
		private string _PrimaryKeyName = string.Empty;
		[Browsable(true)]
		[Category("DataGridGost配置")]
		[Description("表的主键")]
		public string PrimaryKeyName
		{
			set
			{
				_PrimaryKeyName = value;
			}
		}
		
		private bool _ShowSerNum;
		[Category("DataGridGost配置")]
		[Description("是否显示序号列")]
		public bool ShowSerNum
		{
			get
			{
				return _ShowSerNum;
			}
			set
			{
				_ShowSerNum = value;
			}
		}
		
		private int _SerNumWidth=30;
		[Category("DataGridGost配置")]
		[Description("序号列宽")]
		public int SerNumWidth
		{
			get
			{
				return _SerNumWidth;
			}
			set
			{
				_SerNumWidth = value;
			}
		}
		
		private string _ColorWhere;
		[Category("DataGridGost配置")]
		[Description("显示自定义颜色的条件")]
		public string ColorWhere
		{
			get
			{
				return _ColorWhere;
			}
			set
			{
				_ColorWhere = value;
			}
		}
		
		private System.Drawing.Color _RowColor;
		[Category("DataGridGost配置")]
		[Description("自定义颜色")]
		public System.Drawing.Color RowColor
		{
			get
			{
				return _RowColor;
			}
			set
			{
				_RowColor = value;
			}
		}
		#endregion
		#endregion
		
		#region 自定义事件

		[Browsable(true)]
		[Category("DataGridGost事件")]
		[Description("行单击事件")]
		public event RowClickEventHandler RowClick;
		public void OnRowClick(string keyid)
		{
			if (RowClick != null)
			{
				//				RowClick(this, e);
				EventTableStyleRowArgs e = new EventTableStyleRowArgs(CurrentDataSet.Tables[0].TableName, keyid);
				RowClick(this, e);
			}
		}

		[Browsable(true)]
		[Category("DataGridGost事件")]
		[Description("行双击事件")]
		public event RowDoubleClickEventHandler RowDoubleClick;
		public void OnRowDoubleClick(string keyid)
		{
			if (RowDoubleClick != null)
			{
				//				RowClick(this, e);
				EventTableStyleRowArgs e = new EventTableStyleRowArgs(CurrentDataSet.Tables[0].TableName, keyid);
				RowDoubleClick(this, e);
			}
		}
		//		public event OperateEventHandler OperatedEvent;
		//
		//		public void OnOperateClick(string keyid, string operateName)
		//		{
		//			if (OperatedEvent != null)
		//			{
		//				//在这里添加事件处理代码				
		//				EventTableStyleOperateArgs e =
		//					new EventTableStyleOperateArgs(CurrentDataSet.Tables[0].TableName, keyid, operateName);
		//				OperatedEvent(this, e);
		//			}
		//		}

		[Browsable(true)]
		[Category("DataGridGost事件")]
		[Description("分页处理事件")]
		public event PaginationEventHandler PaginationEvent;

		public void OnPaginationEvent(int pagesize, int currentpageindex, int sumcount, int sumpage,bool isfirst,bool islast)
		{
			if (PaginationEvent != null)
			{
				//在这里添加事件处理代码				
				EventPaginationArgs e = new EventPaginationArgs(pagesize, currentpageindex, sumcount, sumpage,isfirst,islast);
				PaginationEvent(this, e);
				SerNumPaint();
			}
		}

		#endregion
		
		#region 属性设置完成后,调用此函数

		/// <summary>
		/// 初始化控件(属性设置完成后,调用此函数)
		/// </summary>
		public void Initialize()
		{
			//载入DataGridTableStyle
			LoadDataGridTableStyle();

			if(_ShowCheckBox)
			{
				AddBoolColumnToTableStyle();
				AddCheckBoxColumn();
			}
						
			if(_ShowSerNum)
			{
				AddSerNumColumnToTableStyle();
				
				AddSerNumColumn();
			}
			
			BindGrid();
			SerNumPaint();
			SetPrimaryColumnIndex();
			
			//设置工具条可见性
			SetToolBar();

			InitializePagination();
			RegeionColorEvent();
			
			SetContextMenu();
		}

		#endregion
		
		#region 设置关键字列索引
		private void SetPrimaryColumnIndex()
		{
			if(_ShowSerNum && _ShowCheckBox)
				mPrimaryColumnIndex = 2;
			else 
				if(_ShowSerNum || _ShowCheckBox)
				mPrimaryColumnIndex = 1;
			else 
				mPrimaryColumnIndex = 0;
		}
		#endregion
		
		#region 工具条操作
		#region 设置工具条可见性

		private void SetToolBar()
		{
			if(_CurrentDataSet == null)
			{
				toolBar1.Visible = false;
				SetPaginationVisible(false);
			}
			else
			{
				if(_CurrentDataSet.Tables[0].Rows.Count>0)
				{
					if ((!_ShowCheckBox && ! _Pagination) || !_ShowToolBar)
					{
						toolBar1.Visible = false;
					}
					else
					{
						toolBar1.Visible = true;
					}
				}
				else
				{
					toolBar1.Visible = false;
					SetPaginationVisible(false);
				}
				SetPaginationVisible(_Pagination);
			}
			SetSelecdtVisible(_ShowCheckBox);
		}

		private void SetPaginationVisible(bool bol)
		{
			tbbFirst.Visible = bol;
			tbbPrev.Visible = bol;
			tbbNext.Visible = bol;
			tbbLast.Visible = bol;

			mitFirst.Visible = bol;
			mitPrev.Visible = bol;
			mitNext.Visible = bol;
			mitLast.Visible = bol;
			
			labPage.Visible = bol;
		}

		private void SetSelecdtVisible(bool bol)
		{
			tbb1.Visible = bol;
			tbbSelectAll.Visible = bol;
			tbbReSelect.Visible = bol;
			tbbNotSelect.Visible = bol;

			mit1.Visible = bol;
			mitSelectAll.Visible = bol;
			mitReSelect.Visible = bol;
			mitNotSelect.Visible = bol;
		}

		#endregion
		
		private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
		{
			switch (e.Button.ToolTipText)
			{
				case "全选":
					mitSelectAll_Click(this, e);
					break;

				case "反选":
					mitReSelect_Click(this, e);
					break;

				case "全否":
					mitNotSelect_Click(this, e);
					break;

				case "首页":
					mitFirst_Click(this, e);
					break;

				case "上一页":
					mitPrev_Click(this, e);
					break;

				case "下一页":
					mitNext_Click(this, e);
					break;

				case "末页":
					mitLast_Click(this, e);
					break;

				default:
					break;
			}
		}
		
		#endregion
		
		#region 载入DataGridTableStyle

		private void LoadDataGridTableStyle()
		{
			_CurrentDataGrid.TableStyles.Clear();
			
			if (_TableStyle != null)
				_CurrentDataGrid.TableStyles.AddRange(new DataGridTableStyle[] {_TableStyle});
			else 
				throw new ArgumentNullException("DataGridTableStyle为空!");
		}

		#endregion
		
		#region 全选列处理
		#region 选择操作

		private void ChooseByType(string Type)
		{
			labInfo.Text = "正在选择请梢后.........";
			_CurrentDataGrid.Enabled = false;
			if (_CurrentDataGrid.DataSource == null && _CurrentDataSet != null)
			{
				MessageBox.Show("没有任何可选取的数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
				return;
			}
			switch (Type)
			{
				case "All": //全选
					(new MethodInvoker(CheckBoxSelectAll)).BeginInvoke(new AsyncCallback(CallBack), null);
					break;

				case "Other": //反选
					(new MethodInvoker(CheckBoxSeletcNot)).BeginInvoke(new AsyncCallback(CallBack), null);
					//CheckBoxSeletcNot();
					break;

				case "Not": //全否
					(new MethodInvoker(CheckBoxSelectNone)).BeginInvoke(new AsyncCallback(CallBack), null);
					///CheckBoxSelectNone();
					break;
			}
		}

		private void CallBack(IAsyncResult ar)
		{
			this.Invoke(new MethodInvoker(UpdateUI));
		}
		private void UpdateUI()
		{
			this.labInfo.Text = string.Empty;
			_CurrentDataGrid.Enabled = true;
		}
		private void CheckBoxSelectNone()
		{
			for (int i = 0; i < mCurrentDataView.Count; i++)
			{
				mCurrentDataView[i].Row["NetlmChoose_2006"] = false;
			}
		}

		private void CheckBoxSeletcNot()
		{
			ShowMsg = true;
			int mCount1 = 0;
			for (int i = 0; i < mCurrentDataView.Count; i++)
			{
				if(CheckSavedNum(mCurrentDataView[i].Row))
					mCurrentDataView[i].Row["NetlmChoose_2006"] = !bool.Parse(mCurrentDataView[i]["NetlmChoose_2006"].ToString());
				else 
					mCount1++;
			}
			if(mCount1>0)
				MessageBox.Show(string.Format("一共有{0}条没有不符合选择条件!", mCount1));
		}

		private void CheckBoxSelectAll()
		{
			ShowMsg = true;
			int mCount = 0;
			for (int i = 0; i < mCurrentDataView.Count; i++)
			{
				if(CheckSavedNum(mCurrentDataView[i].Row))
					mCurrentDataView[i].Row["NetlmChoose_2006"] = true;
				else 
					mCount++;
			}
			if(mCount>0)
				MessageBox.Show(string.Format("一共有{0}条没有不符合选择条件!", mCount));
		}

		#endregion
		
		#region 添加选择列

		private void AddCheckBoxColumn()
		{
			if (_CurrentDataSet != null && _ShowCheckBox == true)
			{
				//增加选择列
				DataColumn col = new DataColumn("NetlmChoose_2006", Type.GetType("System.Boolean"));
				col.DefaultValue = false;
				_CurrentDataSet.Tables[0].Columns.Add(col);
			}
		}

		private void AddBoolColumnToTableStyle()
		{
			DataGridColorBoolColumn dgbolChoose_temp;
			dgbolChoose_temp = new DataGridColorBoolColumn();

			//
			//dgbolChoose_temp选择列
			//
			dgbolChoose_temp.HeaderText = _CheckBoxTitle;
			dgbolChoose_temp.MappingName = "NetlmChoose_2006";
			dgbolChoose_temp.FalseValue = false;
			dgbolChoose_temp.NullValue = "";
			dgbolChoose_temp.TrueValue = true;
			dgbolChoose_temp.Width = _ChekcBoxWidth;

			int size = _CurrentDataGrid.TableStyles[0].GridColumnStyles.Count + 1;
			DataGridColumnStyle[] dgcsarry = new DataGridColumnStyle[size];
			dgcsarry[0] = dgbolChoose_temp;
			for (int i = 0; i < size - 1; i++)
			{
				dgcsarry[i + 1] = _CurrentDataGrid.TableStyles[0].GridColumnStyles[i];
			}

			_CurrentDataGrid.TableStyles[0].GridColumnStyles.Clear();
			_CurrentDataGrid.TableStyles[0].GridColumnStyles.AddRange(dgcsarry);
		}

		#endregion
		
		#region 检查钩选状态

		private bool CheckCheckBoxSelect(DataRow dr)
		{
			return bool.Parse(dr["NetlmChoose_2006"].ToString());
		}

		private bool CheckCheckBoxSelect(DataRowView drv)
		{
			return bool.Parse(drv["NetlmChoose_2006"].ToString());
		}

		private bool CheckCheckBoxSelect(string str)
		{
			return bool.Parse(str);
		}

		#endregion
		
		#region 得到选择的值

		/// <summary>
		/// 得到选择的列的主键数组
		/// </summary>
		/// <returns>返回数组</returns>
		public string[] GetSelectedKeyIDs()
		{
			mSelectKeyIds = new ArrayList();
			if(_ShowCheckBox)
			{
				if(_PrimaryKeyName !=string.Empty && _PrimaryKeyName != null)
				{
					for (int i = 0; i < mCurrentDataView.Count; i++)
					{
						if (CheckCheckBoxSelect(mCurrentDataView[i]["NetlmChoose_2006"].ToString()))
						{
							mSelectKeyIds.Add(mCurrentDataView[i][_PrimaryKeyName].ToString());
						}
					}
				}
				else
				{
					for (int i = 0; i < mCurrentDataView.Count; i++)
					{
						if (CheckCheckBoxSelect(mCurrentDataView[i]["NetlmChoose_2006"].ToString()))
						{
							mSelectKeyIds.Add(mCurrentDataView[i][0].ToString());
						}
					}
				}
				
				if (mSelectKeyIds.Count > 0)
					return (string[]) mSelectKeyIds.ToArray(typeof (String));
				else
					return null;
			}
			else 
				throw new SystemException("没有可选择的多列！");
		}

		/// <summary>
		/// 得到所选择的行的列值
		/// </summary>
		/// <param name="columnName">列名</param>
		/// <returns>返回列值的数组</returns>
		public string[] GetSelectedCellsValue(string columnName)
		{
			if (_ShowCheckBox)
			{
				ArrayList temp = new ArrayList();
				foreach (DataRowView drv in mCurrentDataView)
				{
					if (CheckCheckBoxSelect(drv))
						temp.Add(drv[columnName].ToString());
				}

				if (temp.Count > 0)
					return (string[]) temp.ToArray(typeof (String));
				else
					return null;
			}
			else
				throw new Exception();
		}
		/// <summary>
		///  得到所选择的行的列值
		/// </summary>
		/// <param name="columnIndex">列索引</param>
		/// <returns>返回列值的数组</returns>
		public string[] GetSelectedCellsValue(int columnIndex)
		{
			if (_ShowCheckBox)
			{
				ArrayList temp = new ArrayList();
				foreach (DataRowView drv in mCurrentDataView)
				{
					if (CheckCheckBoxSelect(drv))
						temp.Add(drv[columnIndex].ToString());
				}

				if (temp.Count > 0)
					return (string[]) temp.ToArray(typeof (String));
				else
					return null;
			}
			else
				throw new Exception();
		}

		/// <summary>
		/// 得到选择的单元格的值旬列名
		/// </summary>
		/// <param name="columnName">列名</param>
		/// <returns>返回单元格的值</returns>
		public string GetCurrentRowCellValue(string columnName)
		{
			int RowIndex = _CurrentDataGrid.CurrentRowIndex;
			if (RowIndex > -1)
			{
				return mCurrentDataView[_CurrentDataGrid.CurrentRowIndex][columnName].ToString();
			}
			else 
				throw new ArgumentNullException();
		}
		/// <summary>
		/// 得到选择的单元格的值旬列名
		/// </summary>
		/// <param name="columnIndex">列索引</param>
		/// <returns>返回单元格的值</returns>
		public string GetCurrentRowCellValue(int columnIndex)
		{
			int RowIndex = _CurrentDataGrid.CurrentRowIndex;
			if (RowIndex > -1)
			{
				return mCurrentDataView[_CurrentDataGrid.CurrentRowIndex][columnIndex].ToString();
			}
			else 
				throw new ArgumentNullException();
		}

		
		public DataRow[] GetSelectedRows()
		{
			ArrayList rowAry = new ArrayList();
			
			if(_ShowCheckBox)
			{
				if(_PrimaryKeyName !=string.Empty && _PrimaryKeyName != null)
				{
					for (int i = 0; i < mCurrentDataView.Count; i++)
					{
						if (CheckCheckBoxSelect(mCurrentDataView[i]["NetlmChoose_2006"].ToString()))
						{
							rowAry.Add(mCurrentDataView[i].Row);
						}
					}
				}
				else
				{
					for (int i = 0; i < mCurrentDataView.Count; i++)
					{
						if (CheckCheckBoxSelect(mCurrentDataView[i]["NetlmChoose_2006"].ToString()))
						{
							rowAry.Add(mCurrentDataView[i].Row);
						}
					}
				}
				
				if (rowAry.Count > 0)
					return (DataRow[]) rowAry.ToArray(typeof(DataRow));
				else
					return null;
			}
			else 
				throw new SystemException("没有可选择的多列！");
		}
		#endregion
		
		#region 右键菜单

		private void mitSelectAll_Click(object sender, EventArgs e)
		{
			ChooseByType("All");
		}

		private void mitReSelect_Click(object sender, EventArgs e)
		{
			ChooseByType("Other");
		}

		private void mitNotSelect_Click(object sender, EventArgs e)
		{
			ChooseByType("Not");
		}
		#endregion
		#endregion
		
		#region 设置隐藏列
		/// <summary>
		/// 设置隐藏列
		/// </summary>
		/// <param name="columnName">被隐藏列的名称</param>
		public void SetColumnHiden(string columnName)
		{
			_CurrentDataGrid.TableStyles[0].GridColumnStyles[columnName].Width = 0;
			this.Refresh();
		}
		
		/// <summary>
		/// 设置隐藏列
		/// </summary>
		/// <param name="columnIndex">被隐藏列的索引</param>
		public void  SetColumnHiden(int columnIndex)
		{
			_CurrentDataGrid.TableStyles[0].GridColumnStyles[columnIndex].Width = 0;
			this.Refresh();
		}
		
		/// <summary>
		/// 设置隐藏列
		/// </summary>
		/// <param name="columnNames">被隐藏列名数组</param>
		public void SetColumnHiden(string[] columnNames)
		{
			for(int i =0;i<columnNames.Length;i++)
				_CurrentDataGrid.TableStyles[0].GridColumnStyles[columnNames[i]].Width = 0;
			Refresh();
		}
		#endregion
		
		#region 分页处理

		#region 分页信息初始化
		private void InitializePagination()
		{
			if(_Pagination)
			{
				mSumPage = this.GetSumPage();
				
				SetPaginationState();
				SetLabPage();
			}
		}
		#endregion
		
		#region 分页按钮事件处理
		private void mitFirst_Click(object sender, EventArgs e)
		{
			if(CheckPaginationNum())
			{
				_CurrentPageIndex = 1;
				SetPaginationState();
				OnPaginationEvent(_PageSize, _CurrentPageIndex, _SumCount, mSumPage,mIsFirst,mIsLast);
			}
		}

		private void mitPrev_Click(object sender, EventArgs e)
		{
			if(CheckPaginationNum())
			{
				_CurrentPageIndex = _CurrentPageIndex - 1;
				SetPaginationState();
				OnPaginationEvent(_PageSize, _CurrentPageIndex, _SumCount, mSumPage,mIsFirst,mIsLast);
			}
		}

		private void mitNext_Click(object sender, EventArgs e)
		{
			if(CheckPaginationNum())
			{
				_CurrentPageIndex = _CurrentPageIndex + 1;
				SetPaginationState();
				OnPaginationEvent(_PageSize, _CurrentPageIndex, _SumCount, mSumPage,mIsFirst,mIsLast);
			}
		}

		private void mitLast_Click(object sender, EventArgs e)
		{
			if(CheckPaginationNum())
			{
				_CurrentPageIndex = mSumPage;
				SetPaginationState();
				OnPaginationEvent(_PageSize, _CurrentPageIndex, _SumCount, mSumPage,mIsFirst,mIsLast);
			}
		}
		#endregion
		
		private bool CheckPaginationNum()
		{
			if(_CurrentPageIndex > mSumPage || _PageSize<1 || _SumCount<1 || mSumPage<1)
				return false;
			else 
				return true;
		}
		
		#region 设置分页状态
		
		/// <summary>
		/// 设置分页状态
		/// </summary>
		private void SetPaginationState()
		{
			CheckIsFirst();
			CheckIsLast();
			SetPaginationControlVisible();
			SetLabPage();
		}
		private void CheckIsFirst()
		{
			if(_CurrentPageIndex ==1)
				mIsFirst = true;
			else 
				mIsFirst = false;
		}
		
		
		private void CheckIsLast()
		{
			if(_CurrentPageIndex == mSumPage)
				mIsLast = true;
			else 
				mIsLast = false;
		}
		
		#region 设置分页按扭可见性
		private void SetPaginationControlVisible()
		{
			if(mIsFirst && mSumPage ==1)
			{
				//tbbFirst.Enabled = true;
				tbbPrev.Enabled = false;
				tbbNext.Enabled = false;
				tbbLast.Enabled = false;
				 
				mitPrev.Enabled = false;
				mitNext.Enabled = false;
				mitLast.Enabled = false;
			}
			else
			{
				if(mIsFirst)
				{
					tbbFirst.Enabled = true;
					tbbPrev.Enabled = false;
					tbbNext.Enabled = true;
					//tbbLast.Enabled = true;
					
					mitFirst.Enabled = true;
					mitPrev.Enabled = false;
					mitNext.Enabled = true;
				}
				else
				{
					if(mIsLast)
					{
						tbbFirst.Enabled = true;
						tbbPrev.Enabled = true;
						tbbNext.Enabled = false;
						//tbbLast.Enabled = true;
						
						mitFirst.Enabled = true;
						mitPrev.Enabled = true;
						mitNext.Enabled = false;
					}
					else
					{
						tbbFirst.Enabled = true;
						tbbPrev.Enabled = true;
						tbbNext.Enabled = true;
						
						mitFirst.Enabled = true;
						mitPrev.Enabled = true;
						mitNext.Enabled = true;
					}
				}
			}
		}	
		
		#endregion
		#endregion
		
		#region 获得总页数
		private  int GetSumPage()
		{
			if(_SumCount>0 && _PageSize>0)
				return (_SumCount+_PageSize)/_PageSize;
			else 
				return 0;
		}
		#endregion
		
		private void SetLabPage()
		{
			labPage.Text = string.Format("当前页：{0}     总页数：{1}  总记录数：{2} ", _CurrentPageIndex, mSumPage, _SumCount);
		}
		#endregion
		
		/// <summary>
		/// 行筛选方法
		/// </summary>
		public void RowFilter(string rowFilterWhere)
		{
			if(rowFilterWhere!=null && rowFilterWhere != "")
			{
				mCurrentDataView.RowFilter = rowFilterWhere;
				SerNumPaint();
			}
		}
		
		
		#region 绑定DataGrid

		private void BindGrid()
		{
			if (_CurrentDataSet != null)
			{
				mCurrentDataView = _CurrentDataSet.Tables[0].DefaultView;
				mCurrentDataView.AllowEdit = true;
				mCurrentDataView.AllowDelete = false;
				mCurrentDataView.AllowNew = false;
				mCurrentDataView.RowFilter = _RowFilterWhere;
				_CurrentDataGrid.DataSource = mCurrentDataView;
				_CurrentDataGrid.TableStyles[0].MappingName = _CurrentDataSet.Tables[0].TableName;
			}
			base.Refresh();
		}

		#endregion
		
		#region 刷新窗体
		/// <summary>
		/// 重写基类的刷新函数,异步执行刷新操作
		/// </summary>
		public override void Refresh()
		{
			if (_CurrentDataSet != null)
			{
				mCurrentDataView = _CurrentDataSet.Tables[0].DefaultView;
				//mCurrentDataView.AllowEdit = true;
				//mCurrentDataView.AllowDelete = false;
				////mCurrentDataView.AllowNew = false;
				_CurrentDataGrid.DataSource = mCurrentDataView;
				//_CurrentDataGrid.TableStyles[0].MappingName = _CurrentDataSet.Tables[0].TableName;
			}
			BeginInvoke(new MethodInvoker(BindGrid));
		}
		#endregion
		
		private void SetContextMenu()
		{
			if (_DataGridContextMenu != null)
			{
				_CurrentDataGrid.ContextMenu = _DataGridContextMenu;
			}
		}
		
		
		#region 鼠镖按下时触发
		private bool ShowMsg;
		public virtual void _CurrentDataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			Point CellShow = new Point(e.X, e.Y);
			DataGrid.HitTestInfo CellClick = _CurrentDataGrid.HitTest(CellShow);

			if (CellClick.Type == DataGrid.HitTestType.Cell)
			{
				if(_ShowCheckBox && CheckSavedNum(CellClick))
				{
					//ShowContextMenu(CellShow);
					try
					{
						if(e.Button == MouseButtons.Right)
						{
							_CurrentDataGrid.UnSelect(_CurrentRowIndex);
						}
				
						//多选状态下,鼠标右键不选定行
						if(!_ShowCheckBox || (e.Button != MouseButtons.Right))
						{
							_CurrentRowIndex = CellClick.Row;
							_CurrentDataGrid.Select(CellClick.Row);
						}
				
						if(e.Button == MouseButtons.Left)//左键按下
						{
							SetCheckBox(CellClick);
						}
					}
					catch
					{
					
					}
				}
				else
				{
					ShowMsg = true;
					try
					{
						if(e.Button == MouseButtons.Right)
						{
							_CurrentDataGrid.UnSelect(_CurrentRowIndex);
						}
				
						//多选状态下,鼠标右键不选定行
						if(!_ShowCheckBox || (e.Button != MouseButtons.Right))
						{
							_CurrentRowIndex = CellClick.Row;
							_CurrentDataGrid.Select(CellClick.Row);
						}
				
						if(e.Button == MouseButtons.Left)//左键按下
						{
							//SetCheckBox(CellClick);
						}
					}
					catch
					{
					
					}
					if(!ShowMsg)
						MessageBox.Show("不符合选择的条件！");
					else
						ShowMsg = false;
				}
			}
		}

		private void SetCheckBox(DataGrid.HitTestInfo CellClick)
		{
			if (_ShowCheckBox)
				mCurrentDataView[_CurrentRowIndex].Row["NetlmChoose_2006"] = !bool.Parse(mCurrentDataView[_CurrentRowIndex].Row["NetlmChoose_2006"].ToString());
				//_CurrentDataGrid[CellClick.Row, 0] = !bool.Parse(_CurrentDataGrid[CellClick.Row, 0].ToString());
		}
		
		#endregion
		
		#region 单击单元格时触发的事件
		public virtual void _CurrentDataGrid_CurrentCellChanged(object sender, System.EventArgs e)
		{
			_SelectedKeyID = GetCurrentRowKeyID();
			OnRowClick(_SelectedKeyID);
		}
		#endregion
		
		#region 得到当前行的KeyID

		//得到当前归档单
		private string GetCurrentRowKeyID()
		{
			int RowIndex = _CurrentDataGrid.CurrentRowIndex;
			if (RowIndex > -1)
			{
				if(_PrimaryKeyName !=string.Empty && _PrimaryKeyName != null)
				{
					return GetCurrentRowCellValue(_PrimaryKeyName);
				}
				else
				{
					return _CurrentDataGrid[RowIndex, mPrimaryColumnIndex].ToString();
				}
			}
			else
				return string.Empty;
		}

		#endregion
		
		#region 设置当前行
		public void SetCurrentRow(int rowIndex)
		{
			if(rowIndex>-1)
			{
				_CurrentDataGrid.CurrentRowIndex = rowIndex;
			}
			else 
				throw new ArgumentOutOfRangeException();
		}
		
		
		public void SetCurrentRow(string KeyIdValue)
		{
			int i = 0;
			foreach (DataRowView view in mCurrentDataView)
			{
				if(_PrimaryKeyName !=string.Empty && _PrimaryKeyName != null)
				{
					if(view[_PrimaryKeyName].ToString() == KeyIdValue)
					{
						_CurrentDataGrid.CurrentRowIndex = i;
						break;
					}
				}
				else
				{
					if(view[mPrimaryColumnIndex].ToString() == KeyIdValue)
					{
						_CurrentDataGrid.CurrentRowIndex = i;
						break;
					}
				}
				i++;
			}
		}
		
		
		public void SetCurrentRow(string CellName,string CellValue)
		{
			int i = 0;
			foreach (DataRowView view in mCurrentDataView)
			{
				if(view[CellName].ToString() == CellValue)
				{
					_CurrentDataGrid.CurrentRowIndex = i;
					break;
				}
				
				i++;
			}
		}
		
		public void SetCurrentRow(int CellIndex,string CellValue)
		{
			int i = 0;
			foreach (DataRowView view in mCurrentDataView)
			{
				if(view[CellIndex].ToString() == CellValue)
				{
					_CurrentDataGrid.CurrentRowIndex = i;
					break;
				}
				
				i++;
			}
		}
		#endregion
		
		#region 判断是否有选定的dataGrid中的项

		private bool CheckdgModeSelect()
		{
			if (_CurrentDataGrid.CurrentRowIndex < 0)
			{
				MessageBox.Show("请先选择一条记录！");
				return false;
			}
			else
				return true;
		}

		#endregion
		
		#region 添加自动编号列

		private void AddSerNumColumn()
		{
			if (_CurrentDataSet != null)
			{
				//增加选择列
				DataColumn idcol = new DataColumn("NetlmSerNumUID",System.Type.GetType("System.Int32"));
				_CurrentDataSet.Tables[0].Columns.Add(idcol);

				for(int i = 0;i<mCurrentDataView.Count;i++)
				{
					if(_Pagination)
					{
						mCurrentDataView[i].Row["NetlmSerNumUID"] = (_PageSize*(_CurrentPageIndex-1)+i+1).ToString();
					}
					else 
						mCurrentDataView[i].Row["NetlmSerNumUID"] = (i+1).ToString();
				}
			}
		}
		
		private void AddSerNumColumnToTableStyle()
		{
			DataGridColorTextColumn dgSerNum_temp;
			dgSerNum_temp = new DataGridColorTextColumn();
			
			dgSerNum_temp.HeaderText = "序号";
			dgSerNum_temp.MappingName = "NetlmSerNumUID";
			dgSerNum_temp.Alignment = HorizontalAlignment.Center;
			dgSerNum_temp.Width = _SerNumWidth;

			int size = _CurrentDataGrid.TableStyles[0].GridColumnStyles.Count + 1;
			DataGridColumnStyle[] dgcsarry = new DataGridColumnStyle[size];
			dgcsarry[0] = dgSerNum_temp;
			for (int i = 0; i < size - 1; i++)
			{
				dgcsarry[i + 1] = _CurrentDataGrid.TableStyles[0].GridColumnStyles[i];
			}

			_CurrentDataGrid.TableStyles[0].GridColumnStyles.Clear();
			_CurrentDataGrid.TableStyles[0].GridColumnStyles.AddRange(dgcsarry);
		}
		#endregion
		
		#region 是否存在

		/// <summary>
		/// 判断是否存在
		/// </summary>
		/// <param name="keyValue">传入关主键的值</param>
		/// <returns>如果存在返回TRUE,否则返回false</returns>
		public bool IsExist(string keyValue)
		{
			if(_PrimaryKeyName !=string.Empty && _PrimaryKeyName != null)
			{
				foreach (DataRow dr in _CurrentDataSet.Tables[0].Rows)
				{
					if(dr[_PrimaryKeyName].ToString() == keyValue)
						return true;
				}
				return false;
			}
			else
			{
				foreach (DataRow dr in _CurrentDataSet.Tables[0].Rows)
				{
					if(_ShowCheckBox)
					{
						if(dr[1].ToString() == keyValue)
							return true;
					}
					else
					{
						if(dr[0].ToString() == keyValue)
							return true;
					}
				}
				return false;
			}
		}
		#endregion
				
		#region 删除行
		private bool RemoveRow(int rowIndex)
		{
			_CurrentDataSet.Tables[0].Rows.Remove(mCurrentDataView[rowIndex].Row);
			return true;	
		}
		
		private bool RemoveRow(DataRow dataRow)
		{
			_CurrentDataSet.Tables[0].Rows.Remove(dataRow);
			return true;
		}
		#endregion
		
		private void SerNumPaint()
		{
			if(this._CurrentDataGrid .DataSource != null && _ShowSerNum)
			{
				int row = 0;
				string text;
				while( row < mCurrentDataView.Count)  
				{ 
					if(_Pagination)
					{
						text = string.Format(" {0}", PageSize*(_CurrentPageIndex-1)+row+1);
					}
					else
						text = string.Format(" {0}", row+1);
					mCurrentDataView[row].Row["NetlmSerNumUID"] = text;
					row ++;  
				}
			}
		}
		
		
		#region 行着色
		private void RegeionColorEvent()
		{
			if(_CurrentDataGrid != null &&( _ColorWhere!=null || _ColorWhere!=""))
			{
				for(int i=0;i<_CurrentDataGrid.TableStyles[0].GridColumnStyles.Count ;i++)
				{
					if( _CurrentDataGrid.TableStyles[0].GridColumnStyles[i].GetType()== typeof(DataGridColorBoolColumn))
					{
						DataGridColorBoolColumn dgcbCol = (DataGridColorBoolColumn) _CurrentDataGrid.TableStyles[0].GridColumnStyles[i];
						dgcbCol.CheckCellColor += new CellColorEventHandler(DataGridColorTextColumnCellPaint);
					}
					else
					{
						DataGridColorBaseColumn dgctCol = (DataGridColorBaseColumn) _CurrentDataGrid.TableStyles[0].GridColumnStyles[i] ;
						dgctCol.CheckCellColor +=new CellColorEventHandler(DataGridColorTextColumnCellPaint);
					}
				}
			}
		}
		private void DataGridColorTextColumnCellPaint(object sender, ref DataGridCellColorEventArgs e)
		{
			//			if ((e.drvRow["字段名"].ToString()=="條件") || (e.drvRow["字段"].ToString()=="條件"))
			//			{
			//				e.BackColor = Color.Pink;//粉紅色
			//			}
			if(_ColorWhere!=null && _ColorWhere!="")
			{
				if(GetBoolByWhere(_ColorWhere,mCurrentDataView[e.Row].Row))
				{
					e.BackColor = _RowColor;
				}
			}
		}
		#endregion
		
		#region 判断是否合符选择的条件
		private bool CheckSavedNum(DataGrid.HitTestInfo CellClick)
		{
			if(_ShowCheckBox && _CheckBoxWhere!=null && _CheckBoxWhere!="")
			{
				_CurrentDataGrid .Select(CellClick.Row);
				int RowIndex = this._CurrentDataGrid.CurrentRowIndex;
				DataRow dr = mCurrentDataView[RowIndex].Row;
				return CheckSavedNum(dr);
			}
			return true;
		}
		
		private bool CheckSavedNum(DataRow dr)
		{
			if(_ShowCheckBox && _CheckBoxWhere!=null && _CheckBoxWhere!="")
			{
				if(dr != null)
				{
					if(GetBoolByWhere(_CheckBoxWhere,dr))
						return true;
					else
					{
						return false;
					}
				}
				return false;
			}
			else 
				return true;
		}
		
		private bool GetBoolByWhere(string str,DataRow dr)
		{
			//将表达式分词
			ArrayList ary = StrToBoolExpression.ConvertExpression(str);
			
			for(int i=0;i<ary.Count;i++)
			{
				if(i<ary.Count-1 && !IsOperator(ary[i].ToString()))
				{
					//如果是字段,取出字段所表示的值
					if(ary[i+1].ToString() !="!" && ary[i+1].ToString()!="&&" && ary[i+1].ToString()!="||")
					{
						ary[i] = dr[ary[i].ToString()].ToString();
					}
				}
			}
			try
			{
				return bool.Parse(StrToBoolExpression.ComputePostfix(ary).ToString());
			}
			catch
			{
				return false;
			}
		}
		
		private bool IsOperator(string ax)
		{
			StrToBoolExpression.OperatorMap.Map[] a = StrToBoolExpression.OperatorMap.map();
			for(int i=0;i<a.Length;i++)
			{
				if(ax==a[i].Operator)
					return true;
			}
			return false;
		}
		#endregion

		private void _CurrentDataGrid_DoubleClick(object sender, System.EventArgs e)
		{
			_SelectedKeyID = GetCurrentRowKeyID();
			OnRowDoubleClick(_SelectedKeyID);
		}
	}
	#region 自定义委托

	public delegate void RowClickEventHandler(object sender, EventTableStyleRowArgs e);

	public delegate void RowDoubleClickEventHandler(object sender,EventTableStyleRowArgs e);

	public delegate void PaginationEventHandler(object sender, EventPaginationArgs e);

	#endregion
}