123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data;
- namespace Bowin.Common.Utility
- {
- /// <summary>
- /// DataRowCollection 的扩展
- /// </summary>
- public static class DataRowCollectionExtension
- {
- /// <summary>
- /// 移除所有空行。
- /// </summary>
- /// <param name="dataRowCollection"></param>
- public static void RemoveAllEmpty(this DataRowCollection dataRowCollection)
- {
- if (dataRowCollection == null)
- {
- throw new ArgumentNullException("dataRowCollection");
- }
- List<DataRow> emptyRows = new List<DataRow>();
- foreach (DataRow dr in dataRowCollection)
- {
- var temp = 0;
- for (int i = 0; i < dr.Table.Columns.Count; i++)
- {
- if (dr[i] == null || string.IsNullOrWhiteSpace(dr[i].ToString()))
- {
- temp += 1;
- }
- }
- if (temp == dr.Table.Columns.Count)
- {
- emptyRows.Add(dr);
- }
- }
- dataRowCollection.RemoveRange(emptyRows);
- }
- /// <summary>
- /// 将指定的 System.Data.DataRow集合 添加到 System.Data.DataRowCollection 对象中。
- /// </summary>
- /// <param name="dataRowCollection"></param>
- /// <param name="collection"></param>
- public static void AddRange(this DataRowCollection dataRowCollection, IEnumerable<DataRow> collection)
- {
- if (dataRowCollection == null)
- {
- throw new ArgumentNullException("dataRowCollection");
- }
- if (collection == null)
- {
- throw new ArgumentNullException("collection");
- }
- foreach (DataRow dr in collection)
- {
- dataRowCollection.Add(dr);
- }
- }
- /// <summary>
- /// 从集合中移除指定的 System.Data.DataRow 集合。
- /// </summary>
- /// <param name="dataRowCollection"></param>
- /// <param name="collection"></param>
- public static void RemoveRange(this DataRowCollection dataRowCollection, IEnumerable<DataRow> collection)
- {
- if (dataRowCollection == null)
- {
- throw new ArgumentNullException("dataRowCollection");
- }
- if (collection == null)
- {
- throw new ArgumentNullException("collection");
- }
- foreach (DataRow dr in collection)
- {
- dataRowCollection.Remove(dr);
- }
- }
- }
- }
|