OpenPetra
Free Administration Software for Non-Profits
Ict.Common.Data.DataUtilities Class Reference

Contains Utility functions for ADO.NET Data operations. More...

Classes

struct  TColumnDifference
 small structure for comparing 2 DataRows by columns, used by CompareAllColumnValues More...
 

Static Public Member Functions

static int GetDataViewIndexByDataTableIndex (DataView ADataView, DataTable ADataTable, int ARowNumberInTable)
 Gets the 0-based index in the specified DataView by specifying an index in a Datatable More...
 
static string DateToSQLString (DateTime ? ADateTime)
 Gets the SQL friendly text for a date formatted as "yyyy-MM-dd" More...
 
static int GetDataTableIndexByDataRowView (DataTable ADataTable, DataRowView ADataRowView)
 Gets the 0-based index of a row in a DataTable by specifying a DataRowView More...
 
static void RemoveColumnsNotInTableTemplate (DataTable ATable, DataTable ATableTemplate)
 Remove the columns from the table that are not part of the template table More...
 
static Object[] DestinationSaveItemArray (DataRow ADestinationRow, DataRow ACopyRow)
 get an array of the values ordered by the columns in the destination table More...
 
static void ChangeDataTableToTypedDataTable (ref DataTable ADataTable, System.Type ATypedDataTableType, string ATableName)
 convert a normal datatable to a typed datatable using reflection More...
 
static void CalculateHashAndSize (DataTable AHashDT, out String AHash, out Int32 ASize)
 Calculates a Hash value for a DataTable and calculates the size of the DataTable, too. More...
 
static void CalculateHashAndSize (DataView AHashDV, out String AHash, out Int32 ASize)
 Calculate a Hash for a DataView and the calculates the size of the DataView, too. More...
 
static Boolean HaveDataRowsIdenticalValues (DataRow ADataRow1, DataRow ADataRow2)
 compare the values of two rows More...
 
static Boolean HaveDataRowsIdenticalValues (object[] ADataRow1, object[] ADataRow2)
 compare the values of two data rows expressed as object arrays More...
 
static bool IsReallyChanged (DataRow ADataRow)
 compare the changed columns of a row. for some reasons, on the client the values are read from the controls, and despite the row has not changed, the row is marked modified More...
 
static Boolean DataRowColumnsHaveChanged (DataRow ADataRow)
 Check if non-system bound data columns have actually changed in the given row. Only system fields begin 's_' More...
 
static void CopyModificationIDsOver (DataRow ADestinationDR, DataRow ACopyDR)
 copy the modification ids from one datarow to another More...
 
static void CopyModificationIDsOver (DataTable ADestinationDT, DataTable ACopyDT)
 copy the modification ids from one datatable to another More...
 
static void CopyAllColumnValues (DataRow ASourceRow, DataRow ADestinationRow)
 Copy all values from one row to the other. Only copies columns with matching column names. More...
 
static void CopyDataSet (DataSet ANewDS, DataSet AOrigDS)
 
static void CopyAllColumnValuesWithoutPK (DataRow ASourceRow, DataRow ADestinationRow)
 Copy all values from one row to the other; omit Primary Key Columns Only copies columns with matching column names More...
 
static void CompareAllColumnValues (DataRow ASourceRow, DataRow ADestinationRow, out List< TColumnDifference >ADifferences)
 compare the values of two rows; must have the same columns More...
 
static void CopyTo (DataTable ASrc, DataTable ADest)
 
static Int32 AcceptChangesForUnmodifiedRows (DataTable AInspectDT, Int32 AMaxColumn, Boolean AExcludeLocation0)
 make sure that unmodified rows are marked as accepted More...
 
static Int32 AcceptChangesForUnmodifiedRows (DataTable AInspectDT, Int32 AMaxColumn)
 make sure that unmodified rows are marked as accepted More...
 
static Int32 AcceptChangesForUnmodifiedRows (DataTable AInspectDT)
 make sure that unmodified rows are marked as accepted More...
 
static void RemoveRowsNotPresentInDT (DataTable ASourceDT, DataTable ADestinationDT, bool ADontAttemptToProcessDTsWithoutPKs=false)
 Removes any DataRow from the Destination DataTable that isn't found in the Source DataTable. More...
 
static object[] GetPKValuesFromDataRow (DataRow ADataRow)
 Returns the values of the DataColumns that make up the Primary Key of the DataTable that the passed in DataRow is part of. More...
 
static bool ChangeDataColumnDataType (DataTable ATable, string AColumnName, Type ANewType)
 Changes a DataColumns' DataType to the desired DataType. This works even when the DataTable already holds data! More...
 

Detailed Description

Contains Utility functions for ADO.NET Data operations.

Member Function Documentation

◆ AcceptChangesForUnmodifiedRows() [1/3]

static Int32 Ict.Common.Data.DataUtilities.AcceptChangesForUnmodifiedRows ( DataTable  AInspectDT)
inlinestatic

make sure that unmodified rows are marked as accepted

Parameters
AInspectDT
Returns

◆ AcceptChangesForUnmodifiedRows() [2/3]

static Int32 Ict.Common.Data.DataUtilities.AcceptChangesForUnmodifiedRows ( DataTable  AInspectDT,
Int32  AMaxColumn 
)
inlinestatic

make sure that unmodified rows are marked as accepted

Parameters
AInspectDT
AMaxColumn
Returns

◆ AcceptChangesForUnmodifiedRows() [3/3]

static Int32 Ict.Common.Data.DataUtilities.AcceptChangesForUnmodifiedRows ( DataTable  AInspectDT,
Int32  AMaxColumn,
Boolean  AExcludeLocation0 
)
inlinestatic

make sure that unmodified rows are marked as accepted

Parameters
AInspectDT
AMaxColumn
AExcludeLocation0
Returns

◆ CalculateHashAndSize() [1/2]

static void Ict.Common.Data.DataUtilities.CalculateHashAndSize ( DataTable  AHashDT,
out String  AHash,
out Int32  ASize 
)
inlinestatic

Calculates a Hash value for a DataTable and calculates the size of the DataTable, too.

Do not use for creation of a password hash - this Method uses the SHA1 algorithm for speed reasons but this is not deemed safe enough for password hashing! --> Use PasswordHelper.GetPasswordHash() for this instead!!!

Parameters
AHashDTThe DataTable to be analysed.
AHashReturns the Hash value of the DataTable.
ASizeReturns the size of the DataTable.

◆ CalculateHashAndSize() [2/2]

static void Ict.Common.Data.DataUtilities.CalculateHashAndSize ( DataView  AHashDV,
out String  AHash,
out Int32  ASize 
)
inlinestatic

Calculate a Hash for a DataView and the calculates the size of the DataView, too.

Do not use for creation of a password hash - this Method uses the SHA1 algorithm for speed reasons but this is not deemed safe enough for password hashing! --> Use PasswordHelper.GetPasswordHash() for this instead!!!

Parameters
AHashDVThe DataView to be analysed.
AHashReturns the Hash value of the DataView.
ASizeReturns the size of the DataView.

◆ ChangeDataColumnDataType()

static bool Ict.Common.Data.DataUtilities.ChangeDataColumnDataType ( DataTable  ATable,
string  AColumnName,
Type  ANewType 
)
inlinestatic

Changes a DataColumns' DataType to the desired DataType. This works even when the DataTable already holds data!

The Method traverses the full DataRows Collection of the DataTable to copy data to the new DataType. This is likely not very efficient on huge DataTables!

The Method utilises System.Convert.ChangeType(object, Type) for the conversion of the type. Only conversions that System.Convert.ChangeType(object, Type) supports will work. If System.Convert.ChangeType(object, Type) throws an Exception then the ChangeDataColumnDataType Method will return false.

Parameters
ATableDataTable that holds the DataColumn whose DataType should be changed.
AColumnNameName of the DataColumn whose DataType should be changed.
ANewTypeDesired type that the DataColumn whose DataType should be changed should be changed to.
Returns
true if the change of DataType was successful or if the DataColumns' DataType was already the requested DataType, otherwise false.

◆ ChangeDataTableToTypedDataTable()

static void Ict.Common.Data.DataUtilities.ChangeDataTableToTypedDataTable ( ref DataTable  ADataTable,
System.Type  ATypedDataTableType,
string  ATableName 
)
inlinestatic

convert a normal datatable to a typed datatable using reflection

Parameters
ADataTablethe table to be converted
ATypedDataTableTypethe type of the typed datatable
ATableNamethe name for the table

◆ CompareAllColumnValues()

static void Ict.Common.Data.DataUtilities.CompareAllColumnValues ( DataRow  ASourceRow,
DataRow  ADestinationRow,
out List< TColumnDifference ADifferences 
)
inlinestatic

compare the values of two rows; must have the same columns

Parameters
ASourceRow
ADestinationRow
ADifferences

◆ CopyAllColumnValues()

static void Ict.Common.Data.DataUtilities.CopyAllColumnValues ( DataRow  ASourceRow,
DataRow  ADestinationRow 
)
inlinestatic

Copy all values from one row to the other. Only copies columns with matching column names.

Parameters
ASourceRow
ADestinationRow

◆ CopyAllColumnValuesWithoutPK()

static void Ict.Common.Data.DataUtilities.CopyAllColumnValuesWithoutPK ( DataRow  ASourceRow,
DataRow  ADestinationRow 
)
inlinestatic

Copy all values from one row to the other; omit Primary Key Columns Only copies columns with matching column names

Parameters
ASourceRow
ADestinationRow

◆ CopyDataSet()

static void Ict.Common.Data.DataUtilities.CopyDataSet ( DataSet  ANewDS,
DataSet  AOrigDS 
)
inlinestatic

Copy all values from the new dataset into the original dataset this is used for the data that comes from the JS client

◆ CopyModificationIDsOver() [1/2]

static void Ict.Common.Data.DataUtilities.CopyModificationIDsOver ( DataRow  ADestinationDR,
DataRow  ACopyDR 
)
inlinestatic

copy the modification ids from one datarow to another

Parameters
ADestinationDRdatarow to be modified
ACopyDRoriginal values

◆ CopyModificationIDsOver() [2/2]

static void Ict.Common.Data.DataUtilities.CopyModificationIDsOver ( DataTable  ADestinationDT,
DataTable  ACopyDT 
)
inlinestatic

copy the modification ids from one datatable to another

Parameters
ADestinationDTdatatable to be modified
ACopyDToriginal values

◆ CopyTo()

static void Ict.Common.Data.DataUtilities.CopyTo ( DataTable  ASrc,
DataTable  ADest 
)
inlinestatic

delete the destination table, copy all rows from the source table; we assume both tables have the same columns, same type. this is needed for datasets, when the table is readonly and cannot be assigned directly

◆ DataRowColumnsHaveChanged()

static Boolean Ict.Common.Data.DataUtilities.DataRowColumnsHaveChanged ( DataRow  ADataRow)
inlinestatic

Check if non-system bound data columns have actually changed in the given row. Only system fields begin 's_'

Parameters
ADataRow
Returns

◆ DateToSQLString()

static string Ict.Common.Data.DataUtilities.DateToSQLString ( DateTime ?  ADateTime)
inlinestatic

Gets the SQL friendly text for a date formatted as "yyyy-MM-dd"

Parameters
ADateTimeThe DataView to search
Returns
string in format "yyy-MM-dd"

◆ DestinationSaveItemArray()

static Object[] Ict.Common.Data.DataUtilities.DestinationSaveItemArray ( DataRow  ADestinationRow,
DataRow  ACopyRow 
)
inlinestatic

get an array of the values ordered by the columns in the destination table

Parameters
ADestinationRowdefines the desired order
ACopyRowthe values to be ordered
Returns
an array of ordered values

◆ GetDataTableIndexByDataRowView()

static int Ict.Common.Data.DataUtilities.GetDataTableIndexByDataRowView ( DataTable  ADataTable,
DataRowView  ADataRowView 
)
inlinestatic

Gets the 0-based index of a row in a DataTable by specifying a DataRowView

Parameters
ADataTableThe DataTable to search
ADataRowViewThe DataRowView that is the DataRow to find
Returns
The 0-based index in the DataTable

◆ GetDataViewIndexByDataTableIndex()

static int Ict.Common.Data.DataUtilities.GetDataViewIndexByDataTableIndex ( DataView  ADataView,
DataTable  ADataTable,
int  ARowNumberInTable 
)
inlinestatic

Gets the 0-based index in the specified DataView by specifying an index in a Datatable

Parameters
ADataViewThe DataView to search
ADataTableThe DataTable containing the known record
ARowNumberInTableThe 0-based row in the DataTable
Returns
0-based index in the DataView

◆ GetPKValuesFromDataRow()

static object[] Ict.Common.Data.DataUtilities.GetPKValuesFromDataRow ( DataRow  ADataRow)
inlinestatic

Returns the values of the DataColumns that make up the Primary Key of the DataTable that the passed in DataRow is part of.

Parameters
ADataRowDataRow from which to return the values of the DataColumns that make up the Primary Key of the DataTable that this DataRow is part of.
Returns
The values of the DataColumns that make up the Primary Key of the DataTable that the passed in DataRow is part of.

◆ HaveDataRowsIdenticalValues() [1/2]

static Boolean Ict.Common.Data.DataUtilities.HaveDataRowsIdenticalValues ( DataRow  ADataRow1,
DataRow  ADataRow2 
)
inlinestatic

compare the values of two rows

Parameters
ADataRow1first row
ADataRow2second row
Returns
true if identical values

◆ HaveDataRowsIdenticalValues() [2/2]

static Boolean Ict.Common.Data.DataUtilities.HaveDataRowsIdenticalValues ( object[]  ADataRow1,
object[]  ADataRow2 
)
inlinestatic

compare the values of two data rows expressed as object arrays

Parameters
ADataRow1first row
ADataRow2second row
Returns
true if identical values

◆ IsReallyChanged()

static bool Ict.Common.Data.DataUtilities.IsReallyChanged ( DataRow  ADataRow)
inlinestatic

compare the changed columns of a row. for some reasons, on the client the values are read from the controls, and despite the row has not changed, the row is marked modified

◆ RemoveColumnsNotInTableTemplate()

static void Ict.Common.Data.DataUtilities.RemoveColumnsNotInTableTemplate ( DataTable  ATable,
DataTable  ATableTemplate 
)
inlinestatic

Remove the columns from the table that are not part of the template table

Parameters
ATabletable to be modified
ATableTemplatetemplate with requested columns

◆ RemoveRowsNotPresentInDT()

static void Ict.Common.Data.DataUtilities.RemoveRowsNotPresentInDT ( DataTable  ASourceDT,
DataTable  ADestinationDT,
bool  ADontAttemptToProcessDTsWithoutPKs = false 
)
inlinestatic

Removes any DataRow from the Destination DataTable that isn't found in the Source DataTable.

Both DataTables must have the same Primary Key for this Method to work!

A possible use for this Method is the removing of DataRows from a DataTable that is held on the Client side when the DataTable is re-loaded from the DB and the reloaded DataTable may contains less rows. Performing a DataSet.Merge operation (DataTable reloaded from the DB merged into client-side DataSet) does not remove DataRows that don't exist in the DataTable that got reloaded from the DB, but calling this Method after the DataSet.Merge does that.

Parameters
ASourceDTSource DataTable.
ADestinationDTDestination DataTable.
ADontAttemptToProcessDTsWithoutPKsSet this to true to not attemt to process DataTables that don't have Primary Keys. If this Argument is set to true, no Exception is thrown and the Method simply doesn't do any work, as it would need Primary Keys for performing its work (default=false).

The documentation for this class was generated from the following file: