/// <summary> /// Searches for invoices associated with the customer /// </summary> private void SearchInvoicesWorker() { CedulaCliente = this.CedulaText.Text.Trim(); List <CargoView> cargosViews = new List <CargoView>(); this.cargos = BDManager.GetUnpaidCharges(CedulaCliente); if (cargos.Count == 0) { CedulaCliente = null; SystemSounds.Beep.Play(); MessageBox.Show("No se encontro ningun cargo pendiente o la cedula no esta registrada", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Exclamation); Clean(); return; } Clean(); Customer customer = BDManager.GetCustomer(CedulaCliente); UserName = customer.Nombre + " " + customer.Apellido; foreach (Cargo cargo in cargos) { CargoView cargoView = (CargoView)cargo; cargosViews.Add(cargoView); } foreach (CargoView cargoView in cargos) { this.ListViewCargos.Items.Add(cargoView); } }
/// <summary> /// Processes the payment /// </summary> private void Pay() { if (CedulaCliente is null) { SystemSounds.Beep.Play(); MessageBox.Show("Cedula invalida", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning); return; } List <Cargo> cargosActualizados = new List <Cargo>(); foreach (Compra _compra in this.ListViewCompras.Items) { Cargo cargo = (Cargo)_compra.CargoView; cargosActualizados.Add(cargo); } int pagoTotal = int.Parse(this.TotalText.Content.ToString(), NumberStyles.Currency); try { Factura factura = new Factura(); //In this case NumeroFactura is used for the name of the file, so its safe not to provide the object with more values //Must add number of file to the name of the file to avoid file from being removed if two or more payments happen the same day factura.NumeroFactura = new StringBuilder(CedulaCliente).Append("-").Append(DateManager.GetMonthInSpanish()).Append("-").Append(UserPreferences.GetNumeroRecibo()).ToString(); factura.cargos = cargosActualizados; Customer customer = BDManager.GetCustomer(CedulaCliente); if (customer is null) { SystemSounds.Beep.Play(); MessageBox.Show("Error inesperado", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); return; } RecibosManager recibosManager = new RecibosManager(); Tuple <Factura, Customer> pair = new Tuple <Factura, Customer>(factura, customer); List <Tuple <Factura, Customer> > info = new List <Tuple <Factura, Customer> >(); info.Add(pair); try { recibosManager.Valor = pagoTotal; LoadingWindow loadingWindow = new LoadingWindow(); loadingWindow.Show(); loadingWindow.StartWorking((object sender, DoWorkEventArgs e) => { recibosManager.GenerateFiles(info, TypeOfRecibos.PAGO, sender, loadingWindow.Status); this.Dispatcher.Invoke(delegate { loadingWindow.Hide(); SystemSounds.Beep.Play(); MessageBox.Show("Archivo creado exitosamente", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information); }); } ); } catch (Exception) { this.Dispatcher.Invoke(delegate { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.CouldntReadFile, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning); }); return; } try { if (descuento == 0) { if (BDManager.Pay(cargosActualizados, CedulaCliente, pagoTotal)) { SystemSounds.Beep.Play(); MessageBox.Show("Pago exitoso!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information); Clean(); } } else { if (BDManager.Pay(cargosActualizados, CedulaCliente, pagoTotal, descuento, descuentoCargo)) { SystemSounds.Beep.Play(); MessageBox.Show("Pago exitoso!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information); Clean(); } } } catch (Exception) { SystemSounds.Beep.Play(); MessageBox.Show("No se pudo efectuar el pago", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning); int resetNumeber = UserPreferences.GetNumeroRecibo(); UserPreferences.SaveNumeroRecibo(--resetNumeber); } } catch (Exception e) { SystemSounds.Beep.Play(); MessageBox.Show("Error inesperado. Elimine el archivo generado!" + "\n" + e.Message, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); } }