Ejemplo n.º 1
0
        /// <summary>
        /// Initializes combo boxes and customer list
        /// </summary>
        private void InitOther()
        {
            new Thread(() => {
                Thread.CurrentThread.IsBackground = true;
                try
                {
                    Customers = BDManager.GetCustomers();
                    Customers.Sort(delegate(Customer c1, Customer c2) { return(c1.Nombre.CompareTo(c2.Nombre)); });
                    this.ListViewCustomers.Dispatcher.Invoke(delegate
                    {
                        this.ListViewCustomers.ItemsSource = Customers;
                    });
                } catch (Exception)
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Error", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }).Start();
            List <string> searchOps = new List <string>(new string[] { "TODOS", "Cedula", "Nombre", "Apellido", "Telefono", "Celular", "Correo", "Direccion" });

            foreach (var str in searchOps)
            {
                this.SearchBox.Items.Add(str);
            }
        }
        /// <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 pending charges to customer
        /// </summary>
        /// <param name="cedula_cliente">Customer ID</param>
        /// <param name="cargos">Charges</param>
        private void AddPreviousCharges(string cedula_cliente, List <Cargo> cargos)
        {
            List <Cargo> UnpaidCharges = BDManager.GetUnpaidCharges(cedula_cliente);

            foreach (Cargo cargo in UnpaidCharges)
            {
                cargos.Add(cargo);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates a field of a customer (Numeric field)
        /// </summary>
        /// <param name="column"></param>
        /// <param name="customer"></param>
        /// <param name="mandatory"></param>
        private void UpdateFieldNumeric(string column, Customer customer, bool mandatory)
        {
            string ans = Microsoft.VisualBasic.Interaction.InputBox("Digite el nuevo valor de " + column, column);
            int    value;

            if (!(Int32.TryParse(ans.Trim(), out value)))
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("Campo invalido!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                try
                {
                    if (BDManager.UpdateCustomer(column, value, customer.Cedula))
                    {
                        switch (column)
                        {
                        case "nodo":
                            customer.Nodo = value;
                            break;

                        case "megas":
                            customer.Megas = value;
                            break;

                        case "descuento":
                            customer.Descuento = value;
                            break;

                        default:
                            Debugger.Break();
                            break;
                        }
                        SystemSounds.Beep.Play();
                        MessageBox.Show("Valor actualizado!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                        this.ListViewCustomers.Dispatcher.Invoke(delegate
                        {
                            ICollectionView view = CollectionViewSource.GetDefaultView(this.ListViewCustomers.ItemsSource);
                            view.Refresh();
                        });
                    }
                }
                catch (Exception)
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Error!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }).Start();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Removes a service from a customer
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="istv"></param>
        private void RemoveServiceFromCustomer(Customer customer, bool istv)
        {
            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                try
                {
                    SystemSounds.Beep.Play();
                    if (BDManager.RemoveServiceFromCustomer(customer.Cedula, istv))
                    {
                        MessageBox.Show("Cliente actualizado!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Error al actualizar el cliente!", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                } catch (Exception)
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Error!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }


                foreach (Customer _customer in Customers)
                {
                    if (_customer.Cedula == customer.Cedula)
                    {
                        if (istv)
                        {
                            _customer.EstadoTV = Estado.Retirado;
                            _customer.HasTV    = false;
                        }
                        else
                        {
                            _customer.EstadoInternet = Estado.Retirado;
                            _customer.HasInternet    = false;
                        }
                        break;
                    }
                }

                this.ListViewCustomers.Dispatcher.Invoke(delegate
                {
                    ICollectionView view = CollectionViewSource.GetDefaultView(this.ListViewCustomers.ItemsSource);
                    view.Refresh();
                });
            }).Start();
        }
        /// <summary>
        /// Generates invoices
        /// </summary>
        private void GenerateInvoicesWorker()
        {
            List <Customer> customers = BDManager.GetCustomers();
            List <Factura>  facturas  = new List <Factura>();
            List <Tuple <Factura, Customer> > items = new List <Tuple <Factura, Customer> >();

            foreach (Customer customer in customers)
            {
                Factura factura = CreateInvoice(customer);
                if (factura is null)
                {
                    continue;
                }

                facturas.Add(factura);
                foreach (Cargo cargo in factura.cargos)
                {
                    if (!cargo.repeat)
                    {
                        customer.Saldo += cargo.Valor;
                    }
                }
                items.Add(new Tuple <Factura, Customer>(factura, customer));
            }
            GenerateInvociesFiles(items);
            SystemSounds.Beep.Play();
            bool succesful = false;
            int  n         = 0;

            (succesful, n) = BDManager.CreateInvoicesWithCharges(items);
            if (succesful)
            {
                MessageBox.Show("Registro de facturas generados: " + n, Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("No se pudo guardar la informacion en la base de datos!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        /// <summary>
        /// Searches for relevant information
        /// </summary>
        private void Consultar()
        {
            Clean();
            List <Cargo> cargos = null;

            if (this.YearsBox.SelectedItem is null || this.Meses.SelectedItem is null || this.Nodos.SelectedItem is null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("Seleccione un valor valido!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            string year  = this.YearsBox.SelectedItem.ToString();
            string month = this.Meses.SelectedItem.ToString();
            string nodo  = this.Nodos.SelectedItem.ToString();

            int yearInt, mesInt = DateManager.GetMonthNumber(month), nodoInt;

            if (String.IsNullOrEmpty(nodo) || String.IsNullOrEmpty(month) || String.IsNullOrEmpty(year))
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("Busqueda no valida!", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (!(Int32.TryParse(year, out yearInt)))
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("Error!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                if (month == "TODOS")
                {
                    if (nodo == "TODOS")
                    {
                        new Thread(() =>
                        {
                            Thread.CurrentThread.IsBackground = true;
                            cargos = BDManager.GetCargosBasedOn(yearInt);
                            Calcular(cargos);
                        }).Start();
                    }
                    else
                    {
                        if (Int32.TryParse(nodo, out nodoInt))
                        {
                            new Thread(() =>
                            {
                                Thread.CurrentThread.IsBackground = true;
                                cargos = BDManager.GetCargosBasedOn(yearInt, 0, nodoInt);
                                Calcular(cargos);
                            }).Start();
                        }
                        else
                        {
                            SystemSounds.Beep.Play();
                            MessageBox.Show("Error!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                    }
                }
                else if (nodo == "TODOS")
                {
                    new Thread(() =>
                    {
                        Thread.CurrentThread.IsBackground = true;
                        cargos = BDManager.GetCargosBasedOn(yearInt, mesInt);
                        Calcular(cargos);
                    }).Start();
                }
                else
                {
                    if (Int32.TryParse(nodo, out nodoInt))
                    {
                        new Thread(() =>
                        {
                            Thread.CurrentThread.IsBackground = true;
                            cargos = BDManager.GetCargosBasedOn(yearInt, mesInt, nodoInt);
                            Calcular(cargos);
                        }).Start();
                    }
                    else
                    {
                        SystemSounds.Beep.Play();
                        MessageBox.Show("Error!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
            } catch (Exception)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("Error", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        /// <summary>
        /// Initializes combo boxes from data on database
        /// </summary>
        private void InitOther()
        {
            List <int> years = Enumerable.Range(2000, DateTime.Today.Year - 1999).ToList();

            this.YearsBox.ItemsSource = years;

            List <String> months = new List <string> {
                "TODOS", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"
            };

            this.Meses.ItemsSource = months;


            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground        = true;
                Dictionary <string, List <string> > data = null;

                try
                {
                    data = BDManager.GetDistinct(new string[] { "Nodo" });
                }
                catch (MySqlException e)
                {
                    this.Dispatcher.Invoke(delegate
                    {
                        SystemSounds.Beep.Play();
                        MessageBox.Show(Messages.Errors.setErrorCodeMessage(e.Number.ToString()), Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                    });

                    return;
                }

                if (data != null)
                {
                    List <String> nodos;
                    bool valueWasRetrieved = data.TryGetValue("Nodo", out nodos);

                    if (valueWasRetrieved)
                    {
                        foreach (var nodo in nodos)
                        {
                            this.Nodos.Dispatcher.Invoke(() => this.Nodos.Items.Add(nodo));
                        }
                        this.Nodos.Dispatcher.Invoke(() => this.Nodos.Items.Add("TODOS"));
                    }
                    else
                    {
                        this.Dispatcher.Invoke(delegate
                        {
                            SystemSounds.Beep.Play();
                            MessageBox.Show(Messages.Errors.NotNodosKeyFound, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                        });

                        return;
                    }
                }
                else
                {
                    this.Dispatcher.Invoke(delegate
                    {
                        SystemSounds.Beep.Play();
                        MessageBox.Show(Messages.Errors.ConnectionFailed, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                    });

                    return;
                }
            }).Start();
        }
        /// <summary>
        /// Sets the values of different combo boxes
        /// </summary>
        private void InitOtherComponents()
        {
            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground        = true;
                Dictionary <string, List <string> > data = null;

                try
                {
                    data = BDManager.GetDistinct(new string[] { "Barrio", "Nodo", "Megas" });
                }
                catch (MySqlException e)
                {
                    this.Dispatcher.Invoke(delegate
                    {
                        SystemSounds.Beep.Play();
                        MessageBox.Show(Messages.Errors.setErrorCodeMessage(e.Number.ToString()), Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                    });

                    return;
                }

                if (data != null)
                {
                    List <string> barrios;
                    bool valueWasRetrieved = data.TryGetValue("Barrio", out barrios);

                    if (valueWasRetrieved)
                    {
                        foreach (var barrio in barrios)
                        {
                            this.BarrioBox.Dispatcher.Invoke(() => this.BarrioBox.Items.Add(barrio));
                        }
                    }
                    else
                    {
                        this.Dispatcher.Invoke(delegate
                        {
                            SystemSounds.Beep.Play();
                            MessageBox.Show(Messages.Errors.NotBarriosKeyFound, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                        });

                        return;
                    }

                    List <String> nodos;
                    valueWasRetrieved = data.TryGetValue("Nodo", out nodos);

                    if (valueWasRetrieved)
                    {
                        foreach (var nodo in nodos)
                        {
                            this.NodoBox.Dispatcher.Invoke(() => this.NodoBox.Items.Add(nodo));
                        }
                    }
                    else
                    {
                        this.Dispatcher.Invoke(delegate
                        {
                            SystemSounds.Beep.Play();
                            MessageBox.Show(Messages.Errors.NotNodosKeyFound, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                        });

                        return;
                    }

                    List <String> megas;
                    valueWasRetrieved = data.TryGetValue("Megas", out megas);

                    if (valueWasRetrieved)
                    {
                        foreach (var _megas in megas)
                        {
                            this.MegasBox.Dispatcher.Invoke(() => this.MegasBox.Items.Add(_megas));
                        }
                    }
                    else
                    {
                        SystemSounds.Beep.Play();
                        MessageBox.Show(Messages.Errors.NotMegasKeyFound, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                    return;
                }
                else
                {
                    this.Dispatcher.Invoke(delegate
                    {
                        SystemSounds.Beep.Play();
                        MessageBox.Show(Messages.Errors.ConnectionFailed, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                    });

                    return;
                }
            }).Start();
        }
        /// <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);
                });
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Updates an attribute of a customer
        /// </summary>
        /// <param name="column"></param>
        /// <param name="customer"></param>
        /// <param name="mandatory"></param>
        private void UpdateField(string column, Customer customer, bool mandatory)
        {
            string ans = Microsoft.VisualBasic.Interaction.InputBox("Digite el nuevo valor de " + column, column);

            if (ans.Trim() == String.Empty)
            {
                ans = null;
            }

            if (mandatory)
            {
                if (String.IsNullOrEmpty(ans))
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("El campo " + column + " no puede ser vacio!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                try
                {
                    ans = ans.ToUpper();
                    if (BDManager.UpdateCustomer(column, ans, customer.Cedula))
                    {
                        switch (column)
                        {
                        case "telefono":
                            customer.Telefono = ans;
                            break;

                        case "celular":
                            customer.Celular = ans;
                            break;

                        case "correo":
                            customer.Correo = ans;
                            break;

                        case "direccion":
                            customer.Direccion = ans;
                            break;

                        case "barrio":
                            customer.Barrio = ans;
                            break;

                        case "mac":
                            customer.MAC = ans;
                            break;

                        case "precinto":
                            customer.MAC = ans;
                            break;

                        default:
                            Debugger.Break();
                            break;
                        }
                        SystemSounds.Beep.Play();
                        MessageBox.Show("Valor actualizado!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                        this.ListViewCustomers.Dispatcher.Invoke(delegate
                        {
                            ICollectionView view = CollectionViewSource.GetDefaultView(this.ListViewCustomers.ItemsSource);
                            view.Refresh();
                        });
                    }
                } catch (Exception)
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Error!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }).Start();
        }
Ejemplo n.º 12
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);
                }
            }
        }
Ejemplo n.º 13
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);
                    });
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Updates the state of a service
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="estado"></param>
        /// <param name="service"></param>
        /// <param name="updateDate"></param>
        private void UpdateServiceStatus(Customer customer, Estado estado, string service, bool updateDate)
        {
            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                SystemSounds.Beep.Play();
                try
                {
                    if (updateDate)
                    {
                        if (BDManager.UpdateCustomerEstado(customer.Cedula, service, estado, true, DateManager.GetToday()))
                        {
                            MessageBox.Show("Cliente actualizado!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else
                        {
                            MessageBox.Show("Error al actualizar el cliente!", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                    }
                    else
                    {
                        if (BDManager.UpdateCustomerEstado(customer.Cedula, service, estado, false))
                        {
                            MessageBox.Show("Cliente actualizado!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else
                        {
                            MessageBox.Show("Error al actualizar el cliente!", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                    }
                } catch (Exception)
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Error!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                foreach (Customer _customer in Customers)
                {
                    if (_customer.Cedula == customer.Cedula)
                    {
                        if (service == "estadoTV")
                        {
                            if (updateDate)
                            {
                                _customer.FechaAfiliacionTV = DateManager.GetToday();
                            }
                            _customer.EstadoTV = estado;
                        }
                        else
                        {
                            if (updateDate)
                            {
                                _customer.FechaAfiliacionInternet = DateManager.GetToday();
                            }
                            _customer.EstadoInternet = estado;
                        }
                        break;
                    }
                }

                this.ListViewCustomers.Dispatcher.Invoke(delegate
                {
                    ICollectionView view = CollectionViewSource.GetDefaultView(this.ListViewCustomers.ItemsSource);
                    view.Refresh();
                });
            }).Start();
        }
        /// <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);
            }
        }