/// <summary> /// Adds other charges to a customer /// </summary> private void AddOtros() { Customer customer = this.ListViewCustomers.SelectedItem as Customer; List <Cargo> cargos = new List <Cargo>(); SystemSounds.Beep.Play(); var r = MessageBox.Show("¿Esta seguro de que desea generar un cargo por otros para el cliente con cedula " + customer.Cedula + " ?", "Informacion", MessageBoxButton.YesNo, MessageBoxImage.Question); if ((r == MessageBoxResult.Yes)) { string numeroFactura = new StringBuilder(customer.Cedula).Append("-").Append(TypeOfRecibos.OTROS).Append("-").Append(DateManager.GetDateInSpanish()).ToString(); string ans = Microsoft.VisualBasic.Interaction.InputBox("Digite el valor del cargo", "Cargo"); if (Int32.TryParse(ans, out int pago)) { Cargo cargo = new Cargo(pago, pago, Concepto.Otros); cargos.Add(cargo); Factura factura = new Factura(numeroFactura, DateManager.GetToday(), null, null, cargos, customer.Cedula); 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 = cargo.Valor; LoadingWindow loadingWindow = new LoadingWindow(); loadingWindow.Show(); loadingWindow.StartWorking((object sender, DoWorkEventArgs e) => { recibosManager.GenerateFiles(info, TypeOfRecibos.OTROS, sender, loadingWindow.Status); try { if (BDManager.AddChargeSimple(factura)) { this.Dispatcher.Invoke(delegate { loadingWindow.Hide(); SystemSounds.Beep.Play(); MessageBox.Show("Cargo generado exitosamente!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information); }); } } catch (MySqlException ex) { this.Dispatcher.Invoke(delegate { loadingWindow.Hide(); SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.setErrorCodeMessage(ex.Number.ToString()), Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); } catch (Exception ex) { this.Dispatcher.Invoke(delegate { loadingWindow.Hide(); SystemSounds.Beep.Play(); MessageBox.Show(ex.Message, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); } } ); } catch (Exception) { this.Dispatcher.Invoke(delegate { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.CouldntReadFile, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning); }); } } else { SystemSounds.Beep.Play(); MessageBox.Show("Valor no valido!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); } } }
/// <summary> /// Adds a traslado to a customer /// </summary> private void AddTraslado() { Customer customer = this.ListViewCustomers.SelectedItem as Customer; List <Cargo> cargos = new List <Cargo>(); SystemSounds.Beep.Play(); var r = MessageBox.Show("¿Esta seguro de que desea generar un traslado para el cliente con cedula " + customer.Cedula + " ?", "Informacion", MessageBoxButton.YesNo, MessageBoxImage.Question); if ((r == MessageBoxResult.Yes)) { string numeroFactura = new StringBuilder(customer.Cedula).Append("-").Append(TypeOfRecibos.TRASLADO).Append("-").Append(DateManager.GetDateInSpanish()).ToString(); int traslado_value = UserPreferences.GetTrasladoValue(); Cargo cargo = new Cargo(traslado_value, traslado_value, Concepto.Traslado); cargos.Add(cargo); Factura factura = new Factura(numeroFactura, DateManager.GetToday(), null, null, cargos, customer.Cedula); 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 = cargo.Valor; LoadingWindow loadingWindow = new LoadingWindow(); loadingWindow.Show(); loadingWindow.StartWorking((object sender, DoWorkEventArgs e) => { recibosManager.GenerateFiles(info, TypeOfRecibos.TRASLADO, sender, loadingWindow.Status); try { if (BDManager.AddChargeSimple(factura)) { this.Dispatcher.Invoke(delegate { loadingWindow.Hide(); SystemSounds.Beep.Play(); MessageBox.Show("Traslado generado exitosamente!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information); }); } } catch (MySqlException ex) { this.Dispatcher.Invoke(delegate { loadingWindow.Hide(); SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.setErrorCodeMessage(ex.Number.ToString()), Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); } catch (Exception ex) { this.Dispatcher.Invoke(delegate { loadingWindow.Hide(); SystemSounds.Beep.Play(); MessageBox.Show(ex.Message, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); } } ); } catch (Exception) { this.Dispatcher.Invoke(delegate { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.CouldntReadFile, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning); }); } } }