/// <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>
        /// Adds an item to the shopping list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PagarCargo_Click(object sender, RoutedEventArgs e)
        {
            if (this.ListViewCargos.SelectedIndex > -1)
            {
                CargoView cargo  = this.ListViewCargos.SelectedItem as CargoView;
                String    item   = new StringBuilder(cargo.Concepto.ToString().ToUpper()).Append("-").Append(cargo.MesCargado.ToString().ToUpper()).ToString();
                int       valor  = int.Parse(cargo.Valor, NumberStyles.Currency);
                int       pagado = int.Parse(cargo.Pagado, NumberStyles.Currency);
                int       pago   = valor - pagado;
                string    _pago  = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", pago);
                string    _valor = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", valor);
                cargo.Pagado = _valor;
                this.ListViewCompras.Items.Add(new Compra(item, _pago, cargo));
                this.ListViewCargos.Items.Remove(this.ListViewCargos.SelectedItem);

                UpdateTotal();
            }
        }
        /// <summary>
        /// Adds an item to the shopping list.
        /// This methods is called when the payment to be made is not complete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AbonarCargo_Click(object sender, RoutedEventArgs e)
        {
            if (this.ListViewCargos.SelectedIndex > -1)
            {
                string ans = Microsoft.VisualBasic.Interaction.InputBox("Digite el valor a abonar", "Abono");
                if (Int32.TryParse(ans, out int pago))
                {
                    CargoView cargo   = this.ListViewCargos.SelectedItem as CargoView;
                    String    item    = new StringBuilder(cargo.Concepto.ToString().ToUpper()).Append("-").Append(cargo.MesCargado.ToString().ToUpper()).ToString();
                    int       valor   = int.Parse(cargo.Valor, NumberStyles.Currency);
                    int       pagado  = int.Parse(cargo.Pagado, NumberStyles.Currency);
                    int       maxPago = valor - pagado;
                    pagado += pago;

                    if (pago > maxPago)
                    {
                        SystemSounds.Beep.Play();
                        MessageBox.Show("No puede pagar mas de lo debido!", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }

                    string _pago  = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", pago);
                    string _valor = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", pagado);
                    this.ListViewCompras.Items.Add(new Compra(item, _pago, cargo));
                    cargo.Pagado = _valor;

                    if (pagado == valor)
                    {
                        this.ListViewCargos.Items.Remove(this.ListViewCargos.SelectedItem);
                    }
                    else
                    {
                        this.ListViewCargos.Items.Refresh();
                    }
                    UpdateTotal();
                }
                else
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Valor no valido!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        /// <summary>
        /// Removes an item from the shopping list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RemoverCompra_Click(object sender, RoutedEventArgs e)
        {
            if (this.ListViewCompras.SelectedIndex > -1)
            {
                SystemSounds.Beep.Play();
                var result = MessageBox.Show("Todas las compras relacionadas con este cargo seran removidas. Desea continuar?", "Informacion", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result.Equals(MessageBoxResult.Yes))
                {
                    Compra compra = this.ListViewCompras.SelectedItem as Compra;
                    foreach (Cargo cargo in cargos)
                    {
                        if (cargo.ID == compra.CargoView.ID)
                        {
                            CargoView RecoveredCargo = (CargoView)cargo;
                            this.ListViewCargos.Items.Add(RecoveredCargo);
                            break;
                        }
                    }
                    List <Compra> comprasRemover = new List <Compra>();
                    foreach (Compra _compra in this.ListViewCompras.Items)
                    {
                        if (_compra.CargoView.ID == compra.CargoView.ID)
                        {
                            comprasRemover.Add(_compra);
                        }
                    }

                    foreach (Compra _compra in comprasRemover)
                    {
                        this.ListViewCompras.Items.Remove(_compra);
                    }

                    UpdateTotal();
                }
            }
        }
 public Compra(string item, string valor, CargoView cargo)
 {
     Item      = item;
     Valor     = valor;
     CargoView = cargo;
 }
 public Compra(string item, string valor)
 {
     Item      = item;
     Valor     = valor;
     CargoView = null;
 }