/// <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>
        /// Creates a customer with an associated registration invoice
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="factura">Invoice</param>
        /// <param name="cargo">Charge</param>
        /// <returns>True if operation was succesful, false otherwise</returns>
        public static bool CreateCustomerWithInitialFinancialInformation(Customer customer, Factura factura, Cargo cargo)
        {
            var dbCon = DBConnection.Instance();
            MySqlTransaction transaction = null;

            string queryCustomer = "INSERT INTO clientes(cedula, nombre, apellido, telefono, celular, correo, direccion, barrio, mac, precinto, nodo, saldo, descuento, tv, internet, megas, fechaAFiliacionTV, fechaAfiliacionInternet, estadoTV, estadoInternet) " +
                                   "VALUES(@cedula, @nombre,@apellido, @telefono,@celular,@correo,@direccion,@barrio,@mac,@precinto,@nodo,@saldo,@descuento,@tv, @internet,@megas,@fechaAfiliacionTV,@fechaAfiliacionInternet,@estadoTV,@estadoInternet)";

            string queryFactura = "INSERT INTO facturas(NumeroFactura, fecha, fechaLimite, mesCargado, clientes_cedula) VALUES(@NumeroFactura, @fecha, @fechaLimite, @mesCargado, @clientes_cedula)";

            string queryCargos = "INSERT INTO cargos(concepto, valor, pagado, facturas_NumeroFactura) VALUES(@concepto, @valor, @pagado, @facturas_NumeroFactura)";

            try
            {
                if (dbCon.IsConnect())
                {
                    MySqlCommand command = dbCon.Connection.CreateCommand();
                    transaction = dbCon.Connection.BeginTransaction();

                    command.Connection  = dbCon.Connection;
                    command.Transaction = transaction;

                    command.CommandText = queryCustomer;
                    command.Parameters.AddWithValue("@cedula", customer.Cedula);
                    command.Parameters.AddWithValue("@nombre", customer.Nombre);
                    command.Parameters.AddWithValue("@apellido", customer.Apellido);
                    command.Parameters.AddWithValue("@telefono", customer.Telefono);
                    command.Parameters.AddWithValue("@celular", customer.Celular);
                    command.Parameters.AddWithValue("@correo", customer.Correo);
                    command.Parameters.AddWithValue("@direccion", customer.Direccion);
                    command.Parameters.AddWithValue("@barrio", customer.Barrio);
                    command.Parameters.AddWithValue("@mac", customer.MAC);
                    command.Parameters.AddWithValue("@precinto", customer.Precinto);
                    command.Parameters.AddWithValue("@nodo", customer.Nodo);
                    command.Parameters.AddWithValue("@saldo", customer.Saldo);
                    command.Parameters.AddWithValue("@descuento", customer.Descuento);
                    command.Parameters.AddWithValue("@tv", customer.HasTV);
                    command.Parameters.AddWithValue("@internet", customer.HasInternet);
                    command.Parameters.AddWithValue("@megas", customer.Megas);
                    command.Parameters.AddWithValue("@fechaAfiliacionTV", customer.FechaAfiliacionTV);
                    command.Parameters.AddWithValue("@fechaAfiliacionInternet", customer.FechaAfiliacionInternet);
                    command.Parameters.AddWithValue("@estadoTV", customer.EstadoTV.ToString());
                    command.Parameters.AddWithValue("@estadoInternet", customer.EstadoInternet.ToString());
                    command.ExecuteNonQuery();

                    command.CommandText = queryFactura;
                    command.Parameters.AddWithValue("@NumeroFactura", factura.NumeroFactura);
                    command.Parameters.AddWithValue("@fecha", factura.Fecha);
                    command.Parameters.AddWithValue("@fechaLimite", factura.FechaLimite);
                    command.Parameters.AddWithValue("@mesCargado", factura.MesCargado);
                    command.Parameters.AddWithValue("@clientes_cedula", customer.Cedula);
                    command.ExecuteNonQuery();

                    command.CommandText = queryCargos;
                    command.Parameters.AddWithValue("@concepto", cargo.Concepto.ToString());
                    command.Parameters.AddWithValue("@valor", cargo.Valor);
                    command.Parameters.AddWithValue("@pagado", cargo.Pagado);
                    command.Parameters.AddWithValue("@facturas_NumeroFactura", factura.NumeroFactura);
                    command.ExecuteNonQuery();

                    transaction.Commit();
                    return(true);
                }
            } catch (MySqlException e)
            {
                try
                {
                    transaction.Rollback();
                } catch (Exception)
                {
                    throw;
                }
                throw;
            }
            return(false);
        }
示例#3
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);
                    });
                }
            }
        }
示例#4
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);
            }
        }