private void GenerateDataToUse()
        {
            var excelHander = new ExcelXlsHandler();

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

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

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

            excelHander.ReadExcelSheet(
                ExcelSettings.Default.ModelsDataFileLocation,
                "Locations$",
                reader => { this.purchaseLocations.Add((string)reader["Name"]); });
        }
        private void GenerateDataToUse()
        {
            var excelHander = new ExcelXlsHandler();

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

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

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

            excelHander.ReadExcelSheet(
                ExcelSettings.Default.ModelsDataFileLocation,
                "Locations$",
                reader => { this.purchaseLocations.Add((string)reader["Name"]); });
        }
        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, StringComparison.Ordinal) - 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);
        }
Example #4
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, StringComparison.Ordinal) - 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);
        }