/// <summary> /// Get clone object of current DataTable /// </summary> /// <returns>Clone object of current DataTable</returns> public DataTable Clone() { var dataTable = new DataTable(); foreach (var dr in Rows) dataTable.Add(dr.Clone()); return dataTable; }
/// <summary> /// Get list of Extra DataRows. DataRows from withTable that don't present in wathTable (just by unique values) /// </summary> /// <param name="whatTable">What DataTable</param> /// <param name="withTable">With what DataTable</param> /// <returns>List of Extra DataRows</returns> public List<DataRow> TableGetExtraRows(DataTable whatTable, DataTable withTable) { var extra = new List<DataRow>(); foreach (var wir in withTable.Rows) { if (TableFindSimmilarRow(wir, whatTable) == null) extra.Add(wir); } return extra; }
/// <summary> /// Get list of Missed DataRows. DataRows from whatTable that don't present in withTable (just by unique values) /// </summary> /// <param name="whatTable">What DataTable</param> /// <param name="withTable">With what DataTable</param> /// <returns>List of Missed DataRows</returns> public List<DataRow> TableGetMissedRows(DataTable whatTable, DataTable withTable) { var missed = new List<DataRow>(); foreach (var war in whatTable.Rows) { if (TableFindSimmilarRow(war, withTable) == null) missed.Add(war); } return missed; }
/// <summary> /// Get list of DataTableDiff objects. /// </summary> /// <param name="whatTable">What DataTable</param> /// <param name="withTable">With what DataTable</param> /// <returns>List of DataTableDiff objects. Contains rows with the same uniques but different any other column values</returns> public List<DataTableDiff> TableGetDiffRows(DataTable whatTable, DataTable withTable) { var diffs = new List<DataTableDiff>(); foreach (var war in whatTable.Rows) { var wir = TableFindSimmilarRow(war, withTable); if (wir != null) { if (!RowCompareDataRows(war, wir)) diffs.Add(new DataTableDiff { ExpectRow = war, ActualRow = wir }); } } return diffs; }
/// <summary> /// Compare two tables by searching similar rows. /// </summary> /// <param name="whatTable">What DataTable</param> /// <param name="withTable">With what DataTable</param> /// <returns>True if all DataRows from whatTable present in withTable (JUST has the same unique column values)</returns> public bool TableCompareWithTable(DataTable whatTable, DataTable withTable) { foreach (var war in whatTable.Rows) { if (TableFindSimmilarRow(war, withTable) == null) return false; } return true; }
/// <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; }