コード例 #1
0
        private static void ReadExcel(string[] files, DonerCollection data)
        {

            List<string> ErrorFiles = new List<string>();
            foreach (var item in files)
            {
                logger.WriteInfo("\n___________________________________START READ__________________________________________");
                ExcelFileReader xRead = new ExcelFileReader(item, reportingYear);
                DonerCollection currentSheet = xRead.Deserialize();
                //currentSheet.Print();

                double currentFileCalcTotal = xRead.Total.CalculateTotal();
                double currentFileSumTotal = xRead.Total.SummarizedTotal();
                double currentFileDepTotal = xRead.Total.DepositTotal();
                double collectionCalcTotal = currentSheet.CalculateTotal();
                double collectionSumTotal = currentSheet.SummarizedTotal();
                
                // Run some validation to compare all the donations received per user against the "Totals" row and also
                // against a running total of values read (regardless of their category)
                if (!CompareDbls(currentFileCalcTotal, collectionCalcTotal) ||
                    !CompareDbls(collectionCalcTotal, currentFileDepTotal) ||
                    !CompareDbls(currentFileDepTotal, currentFileSumTotal) ||
                    !CompareDbls(currentFileSumTotal, collectionSumTotal))
                {
                    logger.WriteInfo("\tSpreadsheet       Calculated Total:  {0:C}", currentFileCalcTotal);
                    logger.WriteInfo("\tCollections Data  Calculated Total:  {0:C}", collectionCalcTotal);
                    logger.WriteInfo("\tSpreadsheet       Total Deposit Row: {0:C}", currentFileDepTotal);
                    logger.WriteInfo("\tSpreadsheet       Grand Totals Row:  {0:C}", currentFileSumTotal);
                    logger.WriteInfo("\tCollections Data  Grant Totals Row:  {0:C}", collectionSumTotal);
                    logger.WriteError("Totals do not add up correctly. Check the file for consistencies: {0}", item);
                    ErrorFiles.Add(item);
                }
                logger.WriteInfo("\n");
                xRead.Close();

                double dataCollectionCalcTotalBefore = data.CalculateTotal();
                data.MergeDonerCollection(currentSheet);

                double dataCollectionCalcTotalAfter = data.CalculateTotal();


                // One last validation to make sure the data merged into the overall collection maintains a consistent summary
                if (!CompareDbls(dataCollectionCalcTotalAfter, (dataCollectionCalcTotalBefore + collectionCalcTotal)))
                {
                    logger.WriteInfo("INFO: Post Merge");
                    logger.WriteInfo("\tCalculated Total in Data Collection before Merge: {0}", dataCollectionCalcTotalBefore);
                    logger.WriteInfo("\tCalculated Total from the new current Collection: {0}", collectionCalcTotal);
                    logger.WriteInfo("\tCalculated Total in Data Collection after  Merge: {0}", dataCollectionCalcTotalAfter);
                    logger.WriteInfo("Problem occurred after merge. Data did not propagate correctly");
                }

                logger.WriteInfo("___________________________________FINISH READ___________________________________________\n");


            }
            logger.WriteInfo("___________________________________START SUMMARY OF ALL DATA______________________________\n");
            //data.Print();
            logger.WriteInfo("___________________________________END SUMMARY____________________________________________\n");


            logger.WriteInfo("Summary of Results");
            logger.WriteInfo("Below is the list of filenames which had a problem importing: ");
            ErrorFiles.ForEach(file => logger.WriteInfo("\t {0}", file));
            if (ErrorFiles.Count() == 0)
                logger.WriteInfo("\t No Files...");
        }