public static DataRow FindFirstOrDefault(this DataTable dataTable, string columnName, string needleValue)
 {
     DataRow result = null;
     var dc = dataTable.Columns[columnName];
     var columnType = dc.DataType;
     var chunk = new FilterChunk(needleValue);
     foreach (DataRow dataRow in dataTable.Rows)
     {
         var chunkMatchesAtLeastOneColumn = false;
         var cellValue = dataRow[dc];
         if (columnType == typeof(int))
         {
             if (chunk.Integer.HasValue)
             {
                 var v = (int) cellValue;
                 chunkMatchesAtLeastOneColumn = v == chunk.Integer.Value;
             }
         }
         else
         {
             if (cellValue != null)
             {
                 var v = cellValue.ToString();
                 chunkMatchesAtLeastOneColumn = v == chunk.Text;
             }
         }
         if (chunkMatchesAtLeastOneColumn)
         {
             result = dataRow;
             break;
         }
     }
     return result;
 }
        public static DataRow FindFirstOrDefault(this DataTable dataTable, string columnName, string needleValue)
        {
            DataRow result     = null;
            var     dc         = dataTable.Columns[columnName];
            var     columnType = dc.DataType;
            var     chunk      = new FilterChunk(needleValue);

            foreach (DataRow dataRow in dataTable.Rows)
            {
                var chunkMatchesAtLeastOneColumn = false;
                var cellValue = dataRow[dc];
                if (columnType == typeof(int))
                {
                    if (chunk.Integer.HasValue)
                    {
                        var v = (int)cellValue;
                        chunkMatchesAtLeastOneColumn = v == chunk.Integer.Value;
                    }
                }
                else
                {
                    if (cellValue != null)
                    {
                        var v = cellValue.ToString();
                        chunkMatchesAtLeastOneColumn = v == chunk.Text;
                    }
                }
                if (chunkMatchesAtLeastOneColumn)
                {
                    result = dataRow;
                    break;
                }
            }
            return(result);
        }
        public static bool Matches(this DataRow row, IList<Type> columnTypes, IList<bool> columnSearchable, FilterChunk chunk)
        {
            var chunkMatchesAtLeastOneColumn = false;
            for (var c = 0; c < columnTypes.Count; c++)
            {
                if (!columnSearchable[c])
                {
                    continue;
                }
                var columnType = columnTypes[c];
                var cellValue = row[c];

                if (columnType == typeof(int))
                {
                    if (chunk.Integer.HasValue)
                    {
                        var v = (int) cellValue;
                        chunkMatchesAtLeastOneColumn = v == chunk.Integer.Value;
                    }
                }
                else
                {
                    if (cellValue != null)
                    {
                        var v = cellValue.ToString();
                        chunkMatchesAtLeastOneColumn = v.ContainsInvariantIgnoreCase(chunk.Text);
                    }
                }

                if (chunkMatchesAtLeastOneColumn)
                {
                    break;
                }
            }
            return chunkMatchesAtLeastOneColumn;
        }
Пример #4
0
        public static bool Matches(this DataRow row, IList <Type> columnTypes, IList <bool> columnSearchable, FilterChunk chunk)
        {
            var chunkMatchesAtLeastOneColumn = false;

            for (var c = 0; c < columnTypes.Count; c++)
            {
                if (!columnSearchable[c])
                {
                    continue;
                }
                var columnType = columnTypes[c];
                var cellValue  = row[c];

                if (columnType == typeof(int))
                {
                    if (chunk.Integer.HasValue)
                    {
                        var v = (int)cellValue;
                        chunkMatchesAtLeastOneColumn = v == chunk.Integer.Value;
                    }
                }
                else
                {
                    if (cellValue != null)
                    {
                        var v = cellValue.ToString();
                        chunkMatchesAtLeastOneColumn = v.ContainsInvariantIgnoreCase(chunk.Text);
                    }
                }

                if (chunkMatchesAtLeastOneColumn)
                {
                    break;
                }
            }
            return(chunkMatchesAtLeastOneColumn);
        }