/// <summary> /// On click handler File -> ReadInvoice /// </summary> /// <param name="sender">object sending request</param> /// <param name="e">event arguments of request</param> private void ReadInvoiceMenuItem_Click(object sender, RoutedEventArgs e) { OpenFileDialog oFildDialog = new OpenFileDialog(); oFildDialog.Title = "Select invoice to read into the program"; oFildDialog.InitialDirectory = System.IO.Path.GetFullPath($"{Directory.GetCurrentDirectory()} ..\\..\\InvoiceToFilesToRead"); oFildDialog.Filter = "Text files (*.txt)|*.txt"; if (oFildDialog.ShowDialog() == true) { fileReader = new FileReader(invoiceMapper); string[] invoiceFileLines = fileReader.ReadFile(oFildDialog.FileName); invoiceMapper = new InvoiceMapper(invoiceFileLines); invoiceMapper.AddErrorsIfAnyInFile(); if (invoiceMapper.InvoiceErrors.Count() == 0) { invoice = invoiceMapper.StartToMappInvoice(); WriteInvoiceGeneralsToGUI(invoice); PopulateTableOfInvoiceItems(invoice.Products); totalInvoicePrice = invoiceCalculator.CalculatePriceInvoice(invoice.Products); } else { OutPutInvoiceErrors(); } } }
/// <summary> /// Constructor, getting an invoiceMapper object from the main window /// </summary> /// <param name="invoiceMapper">invoice mapper to use when reading files</param> public FileReader(InvoiceMapper invoiceMapper) { mapper = invoiceMapper; }