コード例 #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>
        /// 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);
            }
        }