예제 #1
0
        public MainWindowViewModel(IFilePathProvider filePathProvider)
        {
            CurrentStatus    = "Ready...";
            Progress         = new Progress <int>(UpdateProgressBar);
            AvailableRegions = new Dictionary <string, object>();
            SelectedRegions  = new Dictionary <string, object>();

            foreach (Country country in ReportMappings.SupportedCountries())
            {
                AvailableRegions.Add(country.SheetName, country.SheetName);
            }
        }
예제 #2
0
        public async Task <int> LoadFiles(string dailyReportFilePath, string unallocatedReportFilePath, IProgress <int> progress, CancellationToken token = new CancellationToken())
        {
            ExcelLoader excelLoader = new ExcelLoader(dailyReportFilePath, unallocatedReportFilePath);

            await Task.Run(() => {
                try {
                    lock (myFacade.CollectionLock)
                    {
                        myFacade.Invoices = excelLoader.LoadInvoices();
                    }
                }
                catch (Exception e) { MessageBox.Show(e.Message); }
            }, token);

            progress.Report(60);

            IEnumerable <string> unallocatedReportSheetNames = excelLoader.GetPaymentsSheetNames();

            int paymentOrdinalNumber = 1;

            foreach (string sheetName in unallocatedReportSheetNames)
            {
                if (ReportMappings.SupportedCountries().Select(_ => _.SheetName).Contains(sheetName))
                {
                    List <Payment> paymentsInSheet    = null;
                    List <Payment> paymentsForCountry = new List <Payment>();

                    await Task.Run(() => {
                        try
                        {
                            paymentsInSheet = excelLoader.LoadPaymentsForSheet(sheetName);

                            foreach (Payment payment in paymentsInSheet)
                            {
                                payment.Value   = -payment.Value;
                                payment.Country = sheetName;
                                payment.Type    = PaymentType.x86;
                                payment.PaymentOrdinalNumber = paymentOrdinalNumber++;

                                myFacade.Payments.Add(payment);
                                paymentsForCountry.Add(payment);
                            }

                            foreach (Payment item in myFacade.Payments)
                            {
                                Customer customerItem = myFacade.CustomerDatabase.Where(customer => customer.Country.SheetName == sheetName && customer.Name == item.CustomerName).SingleOrDefault();

                                if (customerItem != null)
                                {
                                    IEnumerable <Invoice> filteredInvoices = myFacade.Invoices.Where(invoice => invoice.Country == customerItem.Country.Name && customerItem.Identifiers.Contains(invoice.CustomerNumber));
                                    item.Invoices = new ObservableCollection <Invoice>(filteredInvoices);
                                }
                            }
                        }
                        catch (Exception e) { MessageBox.Show(e.Message); }
                    }, token);
                }
            }
            progress.Report(100);

            return(42);
        }