Exemplo n.º 1
0
        private DiscrepancyType InitialMatch(TableData[] datas, DiscrepancyOutputter outputter)
        {
            string query = BuildOnlyMatchableRowsQuiery();
            MatchedRecordComparer comparer = new MatchedRecordComparer(data, settings, outputter);
            Recordset             matches  = db.QueryResult(query);
            DiscrepancyType       result   = DiscrepancyType.NONE;

            while (matches.Read())
            {
                string[] matchedRecord    = new string[matches.GetFieldCount() - HASH_FIELDS_COUNT];
                int      nextIndexToWrite = 0;
                for (int i = 0; i < matches.GetFieldCount(); i++)
                {
                    // Skip hash fields.
                    if (i == HASH_FIELD_INDEX || i == datas[0].columnCount + 2)
                    {
                        continue;
                    }

                    matchedRecord[nextIndexToWrite++] = matches.GetString(i);
                }

                string[] first, second;
                ExtractRecords(matchedRecord, datas[0].columnCount + 1, datas[1].columnCount + 1, out first, out second);
                DiscrepancyType type = comparer.Compare(first, second);

                if (type > result)
                {
                    result = type;
                }
            }
            matches.Close();

            return(result);
        }
Exemplo n.º 2
0
        private DiscrepancyType RecordsAreEqual(string[] first, string[] second)
        {
            DiscrepancyType result = DiscrepancyType.NONE;

            string[] comparedRecord = new string[first.Length];
            for (int i = 0; i < first.Length; i++)
            {
                string value1 = first[i];
                string value2 = second[i];

                string value1Formatted = string.Empty,
                       value2Formatted = string.Empty;

                bool            columnIsIgnored = ColumnIsIgnored(i);
                DiscrepancyType type;
                if (columnIsIgnored)
                {
                    type = DiscrepancyType.NONE;
                }
                else
                {
                    type = ValuesAreEqual(value1, value2, out value1Formatted, out value2Formatted);
                }

                if (type == DiscrepancyType.DISCREPANCY)
                {
                    comparedRecord[i] = string.Format("'{0}|{1}'", value1Formatted, value2Formatted);
                }
                else if (type == DiscrepancyType.ROUNDING)
                {
                    comparedRecord[i] = string.Format("'{0}||{1}'", value1Formatted, value2Formatted);
                }
                else
                {
                    if (columnIsIgnored)
                    {
                        comparedRecord[i] = value1;
                    }
                    else
                    {
                        comparedRecord[i] = value1Formatted;
                    }
                }


                if (i == ID_COLUMN_INDEX)
                {
                    type = DiscrepancyType.NONE;
                }

                if (type > result)
                {
                    result = type;
                }
            }
            outputter.Record(comparedRecord, result);

            return(result);
        }
Exemplo n.º 3
0
        private DiscrepancyType AdditionalMatch(TableData[] datas, DiscrepancyOutputter outputter)
        {
            DiscrepancyType result = DiscrepancyType.NONE;

            MatchedRecordComparer          comparer = new MatchedRecordComparer(data, settings, outputter);
            AdditionalSQLHashRecordMatcher matcher  = new AdditionalSQLHashRecordMatcher(srcTables, data, db);

            matcher.Match(datas, comparer, outputter);

            return(result);
        }
Exemplo n.º 4
0
        public DiscrepancyType Match(TableData[] datas, DiscrepancyOutputter outputter)
        {
            PrepareTables();

            DiscrepancyType result = DiscrepancyType.NONE;
            DiscrepancyType type;

            type = InitialMatch(datas, outputter);
            if (type > result)
            {
                result = type;
            }

            type = AdditionalMatch(datas, outputter);
            if (type > result)
            {
                result = type;
            }

            return(result);
        }
Exemplo n.º 5
0
        public void Record(string[] comparedRecord, DiscrepancyType type)
        {
            writer.SetWorksheet("Discrepancies");

            if (type == DiscrepancyType.DISCREPANCY)
            {
                rowsWithDiscrepanciesCount++;
            }
            if (type == DiscrepancyType.ROUNDING)
            {
                rowsWithRoundingCount++;
            }

            for (int i = 0; i < comparedRecord.Length; i++)
            {
                if (i == ID_COLUMN_INDEX)
                {
                    continue;
                }

                if (comparedRecord[i].IndexOf("|") >= 0 && comparedRecord[i].IndexOf("||") < 0)
                {
                    writer.WriteInline(comparedRecord[i], Styles.YELLOW);
                    NoteColumnDiscrepancy(i);
                }
                else if (comparedRecord[i].IndexOf("||") > 0)
                {
                    writer.WriteInline(comparedRecord[i].Replace("||", "|"), Styles.GRAY);
                    NoteColumnRounding(i);
                }
                else
                {
                    writer.WriteInline(comparedRecord[i]);
                }
            }

            string id = comparedRecord[ID_COLUMN_INDEX];

            if (id.IndexOf("|") >= 0)
            {
                writer.WriteInline(id, Styles.GRAY);
            }
            else
            {
                writer.WriteInline(id);
            }

            if (type == DiscrepancyType.DISCREPANCY)
            {
                writer.WriteInline("DISCREPANCY", Styles.YELLOW);
            }
            else if (type == DiscrepancyType.ROUNDING)
            {
                writer.WriteInline("ROUNDING", Styles.GRAY);
            }
            else
            {
                writer.WriteInline("OK", Styles.GREEN);
            }

            writer.NewRow();
        }