Ejemplo n.º 1
0
        /// <summary>
        /// Compare two rows using Comparable and Ignorable columns by string representation of values. If Comparable columns are empty, compare all columns.
        /// </summary>
        /// <param name="whatRow">What row compare</param>
        /// <param name="withRow">With what row compare</param>
        /// <returns>True if all values are the same</returns>
        public bool RowCompareDataRows(DataRow whatRow, DataRow withRow)
        {
            if (ComparableColumns.Count > 0)
            {
                foreach (var cc in ComparableColumns)
                {
                    if (IgnorableColumns.Contains(cc)) continue;

                    var wav = whatRow[cc, true];
                    var wiv = withRow[cc, true];
                    if (wav != wiv) return false;
                }
                return true;
            }

            var columns = whatRow.Columns;
            foreach (var column in columns)
            {
                if (IgnorableColumns.Contains(column)) continue;

                var wav = whatRow[column, true];
                var wiv = withRow[column, true];
                if (wav != wiv) return false;
            }

            var diffs = RowGetDiffValues(whatRow, withRow);
            return diffs.Count == 0;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Clone current DataRow
 /// </summary>
 /// <returns></returns>
 public DataRow Clone()
 {
     var dataRow = new DataRow(_values);
     return dataRow;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Add DataRow
 /// </summary>
 /// <param name="row">DataRow to add</param>
 public void Add(DataRow row)
 {
     Rows.Add(row);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Get dictionary of DataRow values for specified columns in string representation
        /// </summary>
        /// <param name="columnNames">List of column names</param>
        /// <param name="whereRow">From what row</param>
        /// <returns>Dictionary of DataRow values for specified columns in string representation</returns>
        public Dictionary<string, string> RowGetColumnValues(List<string> columnNames, DataRow whereRow)
        {
            var vals = new Dictionary<string, string>();

            foreach (var column in columnNames)
            {
                vals.Add(column, whereRow[column, true]);
            }
            return vals;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Search simmilar (bu unique column values) DataRow in specified table
 /// </summary>
 /// <param name="whatRow">What DataRow</param>
 /// <param name="whereTable">In what DataTable</param>
 /// <returns>DataRow with the same unique field values</returns>
 public DataRow TableFindSimmilarRow(DataRow whatRow, DataTable whereTable)
 {
     foreach (var row in whereTable.Rows)
     {
         if (RowIsUniqsSame(whatRow, row))
             return row;
     }
     return null;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Get Dictionary of Missed values. (Missed values from whatRow that are not contained in withRow)
        /// </summary>
        /// <param name="whatRow">What row compare</param>
        /// <param name="withRow">With what row compare</param>
        /// <returns>Dictionary of Extra values</returns>
        public Dictionary<string, object> RowGetMissedValues(DataRow whatRow, DataRow withRow)
        {
            var missed = new Dictionary<string, object>();

            var columns = whatRow.Columns;
            foreach (var column in columns)
            {
                if (IgnorableColumns.Contains(column)) continue;

                var wiv = withRow[column, true];
                if (wiv == null) missed.Add(column, whatRow[column]);
            }
            return missed;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get Dictionary of Extra values. (Additional values from withRow that are not contained in whatRow)
        /// </summary>
        /// <param name="whatRow">What row compare</param>
        /// <param name="withRow">With what row compare</param>
        /// <returns>Dictionary of Extra values</returns>
        public Dictionary<string, object> RowGetExtraValues(DataRow whatRow, DataRow withRow)
        {
            var extra = new Dictionary<string, object>();

            var columns = withRow.Columns;
            foreach (var column in columns)
            {
                if (IgnorableColumns.Contains(column)) continue;

                var wav = whatRow[column, true];
                if (wav == null) extra.Add(column, withRow[column]);
            }
            return extra;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get list of DataRowDiff objects.
        /// </summary>
        /// <param name="whatRow">What row compare</param>
        /// <param name="withRow">With what row compare</param>
        /// <param name="withoutExtraAndMissed">True if need to compare just columns from what rows. Default: false</param>
        /// <returns>List of DataRowDiff objects</returns>
        public List<DataRowDiff> RowGetDiffValues(DataRow whatRow, DataRow withRow, bool withoutExtraAndMissed = false)
        {
            var difs = new List<DataRowDiff>();

            if (ComparableColumns.Count > 0)
            {
                foreach (var cc in ComparableColumns)
                {
                    if (IgnorableColumns.Contains(cc)) continue;

                    var wav = whatRow[cc, true];
                    var wiv = withRow[cc, true];
                    if (withoutExtraAndMissed && ((wav == null && wiv != null) || (wav != null && wiv == null))) continue;
                    if (wav != wiv) difs.Add(new DataRowDiff { Column = cc, ExpectedValue = whatRow[cc], ActualValue = withRow[cc] });
                }
                return difs;
            }

            var columns = whatRow.Columns;
            foreach (var column in columns)
            {
                if (IgnorableColumns.Contains(column)) continue;

                var wav = whatRow[column, true];
                var wiv = withRow[column, true];
                if (withoutExtraAndMissed && ((wav == null && wiv != null) || (wav != null && wiv == null))) continue;
                if (wav != wiv) difs.Add(new DataRowDiff { Column = column, ExpectedValue = whatRow[column], ActualValue = withRow[column] });
            }
            return difs;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Compare values of Unique columns
 /// </summary>
 /// <param name="whatRow">What row compare</param>
 /// <param name="withRow">With what row compare</param>
 /// <returns>True if values of Unique columns are the same</returns>
 public bool RowIsUniqsSame(DataRow whatRow, DataRow withRow)
 {
     foreach (var uc in UniqueColumns)
     {
         var wav = whatRow[uc, true];
         var wiv = withRow[uc, true];
         if (wav != wiv) return false;
     }
     return true;
 }