Exemplo n.º 1
0
        public void ReadAllPurchases(string zipFileLocation, Action <int, int, decimal, string, DateTime> action)
        {
            const string TempFolderName = @"UnzippedSalesReports";

            var excelXlsHander = new ExcelXlsHandler();

            var zip = new ZipFileHandler();

            zip.UnzipFolder(zipFileLocation, TempFolderName);

            foreach (var subfolder in Directory.GetDirectories(TempFolderName))
            {
                var dateAsString = subfolder.Substring(subfolder.LastIndexOf('\\') + 1);
                var date         = DateTime.ParseExact(dateAsString, "dd-MMM-yyyy", CultureInfo.InvariantCulture);

                foreach (var file in Directory.GetFiles(subfolder))
                {
                    if (file.EndsWith(".xls"))
                    {
                        var slashIndex   = file.LastIndexOf('\\') + 1;
                        var locationName = file.Substring(slashIndex, file.IndexOf("-Purchases-Report", slashIndex) - slashIndex);

                        excelXlsHander.ReadExcelSheet(file, row =>
                        {
                            if (row[0] != DBNull.Value)
                            {
                                action((int)(double)row[0], (int)(double)row[1], (decimal)(double)row[2], locationName, date);
                            }
                        });
                    }
                }
            }

            Directory.Delete(TempFolderName, true);
        }
        private void GenerateDataToUse()
        {
            var excelHander = new ExcelXlsHandler();

            this.productsWithPrices = new Dictionary <int, double>();

            excelHander.ReadExcelSheet(ExcelSettings.Default.InitialProductsFileLocation, "Products$", reader =>
            {
                productsWithPrices.Add((int)(double)reader["Id"], (double)reader["Base Price"]);
            });

            this.purchaseLocations = new List <string>();

            excelHander.ReadExcelSheet(ExcelSettings.Default.InitialProductsFileLocation, "Locations$", reader =>
            {
                purchaseLocations.Add((string)reader["Name"]);
            });
        }