GetEnumerator() публичный Метод

public GetEnumerator ( ) : IEnumerator
Результат IEnumerator
        private static DataTable GetTableFromView(DataView dataView, bool rowOrdinals, int top, ref string ordinalColumnName)
        {
            DataTable dataTable = dataView.ToTable();

            if (rowOrdinals)
            {
                ordinalColumnName = "_ordinal";
                while (dataTable.Columns.Contains(ordinalColumnName))
                {
                    ordinalColumnName = "_" + ordinalColumnName;
                }
                dataTable.Columns.Add(ordinalColumnName, typeof(int));

                var it         = dataView.GetEnumerator();
                int rowCounter = -1;
                while (it.MoveNext())
                {
                    rowCounter++;
                    if (top > 0 && rowCounter >= top)
                    {
                        break;
                    }
                    DataRow dataRow = ((DataRowView)it.Current).Row;
                    dataTable.Rows[rowCounter][ordinalColumnName] = dataRow.Table.Rows.IndexOf(dataRow);
                }
            }

            return(dataTable);
        }
Пример #2
0
        internal static DataTable ConvertDataViewToDataTable(DataView obDataView)
        {
            if (null == obDataView)
                throw new GridException("Invalid DataView object specified",null);

            DataTable obNewDt = obDataView.Table.Clone();
            int idx = 0;
            string[] strColNames = new string[obNewDt.Columns.Count];
            foreach (DataColumn col in obNewDt.Columns)
            {
                strColNames[idx++] = col.ColumnName;
            }

            IEnumerator viewEnumerator = obDataView.GetEnumerator();
            while (viewEnumerator.MoveNext())
            {
                DataRowView drv = (DataRowView)viewEnumerator.Current;
                DataRow dr = obNewDt.NewRow();
                try
                {
                    foreach (string strName in strColNames)
                    {
                        dr[strName] = drv[strName];
                    }
                }
                catch (Exception ex)
                {
                    throw new GridException("Error converting DataView to table.", ex);
                }
                obNewDt.Rows.Add(dr);
            }

            return obNewDt;
        }
Пример #3
0
        private static void CreateValueList(UltraGrid dataGrid1, string valueListName, System.Data.DataView dataList, string Id, string Name)
        {
            ValueList list = null;

            if (dataGrid1.DisplayLayout.ValueLists.Exists(valueListName) && (dataGrid1.DisplayLayout.ValueLists[valueListName].ValueListItems.Count != dataList.Count))
            {
                dataGrid1.DisplayLayout.ValueLists.Remove(valueListName);
                list = dataGrid1.DisplayLayout.ValueLists.Add(valueListName);
            }
            if (!dataGrid1.DisplayLayout.ValueLists.Exists(valueListName))
            {
                list = dataGrid1.DisplayLayout.ValueLists.Add(valueListName);
            }
            if (list != null)
            {
                IEnumerator enumerator = null;
                try
                {
                    enumerator = dataList.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        DataRowView   current = (DataRowView)enumerator.Current;
                        DataRow       row     = current.Row;
                        ValueListItem item    = new ValueListItem {
                            DataValue   = RuntimeHelpers.GetObjectValue(row[Id]),
                            DisplayText = row[Name].ToString()
                        };
                        list.ValueListItems.Add(item);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                list.Tag = dataList;
            }
        }
Пример #4
0
        /// <summary>
        /// DataView转为datatable
        /// </summary>
        /// <param name="obDataView"></param>
        /// <returns></returns>
        public static DataTable DataView2DataTable(DataView obDataView)
        {
            if (null == obDataView)
            {
                throw new ArgumentNullException
                ("DataView", "Invalid DataView object specified");
            }

            DataTable obNewDt = obDataView.Table.Clone();
            int idx = 0;
            string[] strColNames = new string[obNewDt.Columns.Count];

            foreach (DataColumn col in obNewDt.Columns)
            {
                strColNames[idx++] = col.ColumnName;
            }

            IEnumerator viewEnumerator = obDataView.GetEnumerator();
            while (viewEnumerator.MoveNext())
            {
                DataRowView drv = (DataRowView)viewEnumerator.Current;
                DataRow dr = obNewDt.NewRow();
                try
                {
                    foreach (string strName in strColNames)
                    {
                        dr[strName] = drv[strName];
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                obNewDt.Rows.Add(dr);
            }

            return obNewDt;
        }
Пример #5
0
		private DataTable CreateTable(DataView obDataView, int startRecord, int pageSize)
		{
			int endRecord = startRecord + pageSize - 1;
			if (null == obDataView)
			{
				throw new ArgumentNullException
					("DataView", "Invalid DataView object specified");
			}

			DataTable obNewDt = obDataView.Table.Clone();
			int idx = 0;
			string [] strColNames = new string[obNewDt.Columns.Count];
			foreach (DataColumn col in obNewDt.Columns)
			{
				strColNames[idx++] = col.ColumnName;
			}

			int _currentRecordCount = 0;
			IEnumerator viewEnumerator = obDataView.GetEnumerator();
			while (viewEnumerator.MoveNext())
			{
				if (_currentRecordCount > endRecord)
				{
					break;
				}
				if (_currentRecordCount >= startRecord)
				{
					DataRowView drv = (DataRowView)viewEnumerator.Current;
					DataRow dr = obNewDt.NewRow();
					try
					{
						foreach (string strName in strColNames)
						{
							dr[strName] = drv[strName];
						}
					}
					catch (Exception)
					{
					}
					obNewDt.Rows.Add(dr);
				}
				_currentRecordCount ++;
			}

			return obNewDt;
		}	
Пример #6
0
		//Activate This Construntor to log All To Standard output
		//public TestClass():base(true){}

		//Activate this constructor to log Failures to a log file
		//public TestClass(System.IO.TextWriter tw):base(tw, false){}

		//Activate this constructor to log All to a log file
		//public TestClass(System.IO.TextWriter tw):base(tw, true){}

		//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES

		[Test] public void GetEnumerator()
		{
			//create the source datatable
			DataTable dt = DataProvider.CreateChildDataTable();

			//create the dataview for the table
			DataView dv = new DataView(dt);

			IEnumerator ienm = null;

			// GetEnumerator != null
			ienm = dv.GetEnumerator();
			Assert.AreEqual(true, ienm != null, "DV53");

			int i=0;
			while (ienm.MoveNext() )
			{
				// Check item i
				Assert.AreEqual(dv[i], (DataRowView)ienm.Current , "DV54");
				i++;
			}
		}
Пример #7
0
	//Activate This Construntor to log All To Standard output
	//public TestClass():base(true){}

	//Activate this constructor to log Failures to a log file
	//public TestClass(System.IO.TextWriter tw):base(tw, false){}


	//Activate this constructor to log All to a log file
	//public TestClass(System.IO.TextWriter tw):base(tw, true){}

	//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES

	public void run()
	{
		Exception exp = null;
				
		//create the source datatable
		DataTable dt = GHTUtils.DataProvider.CreateChildDataTable();

		//create the dataview for the table
		DataView dv = new DataView(dt);

		System.Collections.IEnumerator ienm = null;

		try
		{
			BeginCase("GetEnumerator != null");
			ienm = dv.GetEnumerator();
			Compare(ienm != null, true);
		} 
		catch(Exception ex)
		{
			exp = ex;
		}
		finally
		{
			EndCase(exp);
			exp = null;
		}

		int i=0;
		while (ienm.MoveNext() )
		{
			try
			{
				BeginCase("Check item" + i.ToString() );
				Compare((DataRowView)ienm.Current ,dv[i]);
				i++;
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}
		}

	}
Пример #8
0
        /// <summary>
        /// CreateTable
        /// </summary>
        /// <param name="obDataView"></param>
        /// <returns></returns>
        public static DataTable CreateTable(DataView obDataView)
        {
            DataTable obNewDt = obDataView.Table.Clone();
            int idx = 0;
            string[] strColNames = new string[obNewDt.Columns.Count];
            foreach (DataColumn col in obNewDt.Columns)
            {
                strColNames[idx++] = col.ColumnName;
            }

            IEnumerator viewEnumerator = obDataView.GetEnumerator();
            while (viewEnumerator.MoveNext())
            {
                DataRowView drv = (DataRowView)viewEnumerator.Current;
                DataRow dr = obNewDt.NewRow();
                try
                {
                    foreach (string strName in strColNames)
                    {
                        dr[strName] = drv[strName];
                    }
                }
                catch
                {

                }
                obNewDt.Rows.Add(dr);
            }
            return obNewDt;
        }
Пример #9
0
        /// <summary>
        /// Converts a dataview's rows to a datatable holding those rows.  Preserves filtering
        /// and sorting that was set in the view.
        /// </summary>
        /// <param name="dataView"></param>
        /// <returns></returns>
        public static DataTable viewToTable(DataView dataView)
        {
            if (null == dataView)
             {
            throw new ArgumentNullException
               ("DataView", "Invalid DataView object specified");
             }

             DataTable dataTable = dataView.Table.Clone();
             int idx = 0;
             string [] strColNames = new string[dataTable.Columns.Count];
             foreach (DataColumn col in dataTable.Columns)
             {
            strColNames[idx++] = col.ColumnName;
             }

             IEnumerator viewEnumerator = dataView.GetEnumerator();
             while (viewEnumerator.MoveNext())
             {
            DataRowView drv = (DataRowView)viewEnumerator.Current;
            DataRow dr = dataTable.NewRow();

            foreach (string strName in strColNames)
            {
               dr[strName] = drv[strName];
            }

            dataTable.Rows.Add(dr);
             }

             return dataTable;
        }