/// <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);
                });
            }
        }
Пример #2
0
        /// <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);
                    });
                }
            }
        }
Пример #3
0
        /// <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>
        /// 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);
            }
        }