/// <summary>
        /// Loads user preferences and displays them
        /// </summary>
        private void LoadPreferences()
        {
            DescuentoValue        = UserPreferences.GetDescuento();
            DescuentoInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", DescuentoValue);

            NumeroReciboValue        = UserPreferences.GetNumeroRecibo();
            NumeroReciboInitialValue = NumeroReciboValue;

            UbicacionValue        = UserPreferences.GetPreferredLocation();
            UbicacionInitialValue = UbicacionValue;

            RecibosValue        = UserPreferences.GetRecibosLocation();
            RecibosInitialValue = RecibosValue;

            FacturasValue        = UserPreferences.GetFacturasLocation();
            FacturasInitialValue = FacturasValue;

            ReconexionValue        = UserPreferences.GetReconexionValue();
            ReconexionInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ReconexionValue);

            AfiliacionValue        = UserPreferences.GetAfiliacionValue();
            AfiliacionInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", AfiliacionValue);

            DerivacionValue        = UserPreferences.GetDerivacionValue();
            DerivacionInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", DerivacionValue);

            TrasladoValue        = UserPreferences.GetTrasladoValue();
            TrasladoInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", TrasladoValue);

            TVvalue        = UserPreferences.GetTVValue();
            TVInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", TVvalue);

            Megas3Value        = UserPreferences.Get3MegasValue();
            Megas3InitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", Megas3Value);

            Megas5Value        = UserPreferences.Get5MegasValue();
            Megas5InitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", Megas5Value);

            Megas7Value        = UserPreferences.Get7MegasValue();
            Megas7InitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", Megas7Value);

            Megas10Value        = UserPreferences.Get10MegasValue();
            Megas10InitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", Megas10Value);

            (ComboTV3Value, ComboInternet3Value) = UserPreferences.GetCombo3();
            Combo3TVInitialValue       = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboTV3Value);
            Combo3InternetInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboInternet3Value);

            (ComboTV5Value, ComboInternet5Value) = UserPreferences.GetCombo5();
            Combo5TVInitialValue       = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboTV5Value);
            Combo5InternetInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboInternet5Value);

            (ComboTV7Value, ComboInternet7Value) = UserPreferences.GetCombo7();
            Combo7TVInitialValue       = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboTV7Value);
            Combo7InternetInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboInternet7Value);

            (ComboTV10Value, ComboInternet10Value) = UserPreferences.GetCombo10();
            Combo10TVInitialValue       = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboTV10Value);
            Combo10InternetInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboInternet10Value);
        }
        /// <summary>
        /// Creates a customer based on input data
        /// </summary>
        private void CreateCustomer()
        {
            String   cedula, nombre, apellido, telefono, celular, correo, direccion, barrio, mac, precinto;
            int      nodo, megas, saldo, descuento;
            bool     internet, tv;
            DateTime?fechaAfiliacionTv, fechaAfiliacionInternet;
            Estado   estadoTv, estadoInternet;

            cedula    = this.CedulaText.Text != string.Empty ? this.CedulaText.Text.Trim() : null;
            nombre    = this.NombresText.Text != String.Empty ? this.NombresText.Text.Trim() : null;
            apellido  = this.ApellidosText.Text != String.Empty ? this.ApellidosText.Text.Trim() : null;
            telefono  = this.TelefonoText.Text != String.Empty ? this.TelefonoText.Text.Trim() : null;
            celular   = this.CelularText.Text != String.Empty ? this.CelularText.Text.Trim() : null;
            correo    = this.CorreoText.Text != String.Empty ? this.CorreoText.Text.Trim() : null;
            direccion = this.DireccionText.Text != String.Empty ? this.DireccionText.Text.Trim() : null;
            barrio    = this.BarrioBox.Text != String.Empty ? this.BarrioBox.Text : null;
            mac       = this.MACText.Text != String.Empty ? this.MACText.Text.Trim() : null;
            precinto  = this.PrecintoText.Text != String.Empty ? this.PrecintoText.Text.Trim() : null;
            nodo      = Int32.TryParse(this.NodoBox.Text.Trim(), out nodo) ? nodo : -1;
            megas     = Int32.TryParse(this.MegasBox.Text.Trim(), out megas) ? megas : -1;
            descuento = Int32.TryParse(this.DescuentoText.Text.Trim(), out descuento) ? descuento : 0;
            internet  = this.InternetRadioButton.IsChecked ?? false;
            tv        = this.TelevisionRadioButton.IsChecked ?? false;

            fechaAfiliacionTv       = null;
            fechaAfiliacionInternet = null;

            estadoTv       = Estado.Pendiente;
            estadoInternet = Estado.Pendiente;

            saldo = 0;

            if (cedula == null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.CedulaIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (nombre == null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.NombreIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (apellido == null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.ApellidoIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (direccion == null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.DireccionIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (barrio == null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.BarrioIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (nodo == -1)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.NodoIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (megas == -1)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.MegasIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }


            if (!(internet || tv))
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.AtLeastOneServiceMustBeProvided, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (megas != 0 && !internet)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.MegasOnlyApplyForInternetService, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }


            Customer      customer      = new Customer(cedula, nombre, apellido, telefono, celular, correo, direccion, barrio, mac, precinto, nodo, megas, saldo, descuento, tv, internet, fechaAfiliacionTv, fechaAfiliacionInternet, estadoTv, estadoInternet);
            StringBuilder numeroFactura = new StringBuilder(cedula).Append("-").Append(TypeOfRecibos.AFILIACION).Append("-").Append(DateManager.GetDateInSpanish());
            List <Cargo>  cargos        = new List <Cargo>();
            Cargo         cargo         = new Cargo(UserPreferences.GetAfiliacionValue(), UserPreferences.GetAfiliacionValue(), Concepto.Afiliacion);

            cargos.Add(cargo);
            Factura factura = new Factura(numeroFactura.ToString(), 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.AFILIACION, sender, loadingWindow.Status);

                    try
                    {
                        if (BDManager.CreateCustomerWithInitialFinancialInformation(customer, factura, cargo))
                        {
                            this.Dispatcher.Invoke(delegate
                            {
                                loadingWindow.Hide();
                                SystemSounds.Beep.Play();
                                MessageBox.Show(Messages.SuccesfulOperation.customerWasSuccesfullyCreated, Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                                Clean();
                            });
                        }
                    }
                    catch (MySqlException ex)
                    {
                        if (ex.Number == (int)MySqlErrorCode.DuplicateKeyEntry)
                        {
                            this.Dispatcher.Invoke(delegate
                            {
                                loadingWindow.Hide();
                                SystemSounds.Beep.Play();
                                MessageBox.Show(Messages.Errors.CustomerAlreadyExists, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                            });
                        }
                        else if (ex.Number == (int)MySqlErrorCode.DataTooLong)
                        {
                            this.Dispatcher.Invoke(delegate
                            {
                                loadingWindow.Hide();
                                SystemSounds.Beep.Play();
                                MessageBox.Show("Uno de los campos no es valido. La informacion es demasiado larga!", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                            });
                        }
                        else
                        {
                            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)
            {
                this.Dispatcher.Invoke(delegate
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show(Messages.Errors.CouldntReadFile, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                });
            }
        }