public void TransformData(DataSet DataSet, DataProperties DataProp) { //Reset the counts of Rows accepted vs rejected rowsAcceptedCount = 0; rowsRejectedCount = 0; DataTable Table = new DataTable(); MetaDataRules = DataProp.Meta; bool rowAcceptable = true; bool nullsAcceptable = false; bool replaceNull = false; string CurrentColumnName; string Errors = ""; string rowId = ""; if (DataProp.ImportType.Equals("Direct Connect")) { Table = DataSet.Tables[DataProp.SourceTableName]; } else { Table = DataSet.Tables[DataProp.DataSetName]; } acceptedData = Table.Clone(); for (int i = 0; i < Table.Rows.Count; i++) { DataRow row = Table.Rows[i]; //Identify the row for the error list foreach (var item in row.ItemArray) { rowId += item + "|"; } for (int j = 0; j < Table.Columns.Count; j++) { //Copy Current Column Name to feed to different methods CurrentColumnName = Table.Columns[j].ToString(); //Check 1.0 - check if value is null if (string.IsNullOrEmpty(row[j].ToString())) { // Check 1.1 Check if Null is Permitted? nullsAcceptable = CheckIfNullIsPermitted(row[j].ToString(), CurrentColumnName); if (!nullsAcceptable) { //Check1.2 Check what action to take against Null Values. replaceNull = NullAction(CurrentColumnName); if (replaceNull) { //Replace the Null value with default value for this field Table.Rows[i][j] = UpdateNullValue(CurrentColumnName); } else { //Reject the data Row rowAcceptable = false; Errors += " Column: " + j.ToString() + " Has a null value|"; } } } //If after the first check the value is null the remain check for data type can be skipped //If the value is not null proceed with the checks if (!string.IsNullOrEmpty(row[j].ToString())) { //Check 2.0 Is the intended data type a string if (MetaDataRules.DataType[CurrentColumnName].Equals("Text")) { //Check 2.1 - check min length if (!CheckMinLength(Table.Rows[i][j], CurrentColumnName)) { rowAcceptable = false; Errors += " Column: " + j.ToString() + " value below minimum threshold|"; } //Check 2.1 - check max length if (!CheckMaxLength(Table.Rows[i][j], CurrentColumnName)) { rowAcceptable = false; Errors += " Column: " + j.ToString() + " value above maximum threshold|"; } } //Check 3.0 Is the intended data type an integer value if (MetaDataRules.DataType[CurrentColumnName].Equals("Int")) { //Check 2.1 - check it can be converted to int if (!CheckValueCanBeConvertedToInt(Table.Rows[i][j].ToString())) { rowAcceptable = false; Errors += " Column: " + j.ToString() + " value cannot be converted to int|"; } } //check 4.0 Is the intended data type an Big Int if (MetaDataRules.DataType[CurrentColumnName].Equals("BitInt")) { if (!CheckValueCanBeConvertedToBigInt(Table.Rows[i][j].ToString())) { rowAcceptable = false; Errors += " Column: " + j.ToString() + " value cannot be converted to Big int|"; } } //Check 5.0 Is the intended data type a decimal value if (MetaDataRules.DataType[CurrentColumnName].Equals("Decimal")) { //Check 2.1 - check it can be converted to decimal if (!CheckValueCanBeConvertedToFloat(Table.Rows[i][j].ToString())) { rowAcceptable = false; Errors += " Column: " + j.ToString() + " value cannot be converted to decimal|"; } //Action - Convert value ??? } //Check 6.0 Is the intended data type a date value if (MetaDataRules.DataType[CurrentColumnName].Equals("Date")) { //Check 2.1 - check it can be converted to date if (!CheckValueCanBeConvertedToDate(Table.Rows[i][j].ToString())) { rowAcceptable = false; Errors += " Column: " + j.ToString() + " value cannot be converted to date|"; } else { //Action - Convert value to date format Table.Rows[i][j] = ConvertValueToDateFormat(Table.Rows[i][j].ToString()); } } } //if (rowAcceptable) //{ // acceptedData.ImportRow(Table.Rows[i]); // rowsAcceptedCount++; // //Reset row acceptable value // rowAcceptable = true; // rowId = ""; // Errors = ""; //} //else //{ // errorsList.Add("Row: " + rowId, Errors); // rowsRejectedCount++; // //Reset row acceptable value // rowAcceptable = true; // rowId = ""; // Errors = ""; //} } if (rowAcceptable) { acceptedData.ImportRow(Table.Rows[i]); rowsAcceptedCount++; //Reset row acceptable value rowAcceptable = true; rowId = ""; Errors = ""; } else { errorsList.Add("Row: " + rowId, Errors); rowsRejectedCount++; //Reset row acceptable value rowAcceptable = true; rowId = ""; Errors = ""; } } }
public FeedFileExtraction(DataProperties DataProp) : base(DataProp) { }
public DataBaseExtraction(DataProperties DataProp) : base(DataProp) { }