Esempio n. 1
0
        /// <summary>
        /// Agrega el producto que se selecciona desde el DataTable a la compra, y actualiza el ticket para que muestre los datos
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            try
            {
                int indice = this.dgvGrilla.SelectedRows[0].Index;

                DataRow fila = this.dt.Rows[indice];

                string tipo   = fila["Tipo"].ToString();
                Marca  marca  = MapeoTipoMarca(fila["Marca"].ToString());
                float  precio = float.Parse(fila["Precio"].ToString());
                string nombre = fila["Nombre"].ToString();

                switch (tipo)
                {
                case "Teclado":
                    Teclado t = new Teclado(marca, precio, nombre);
                    compra.Agregar(t);
                    break;

                case "Mouse":
                    Mouse m = new Mouse(marca, precio, nombre);
                    compra.Agregar(m);
                    break;
                }

                txtVisorTickets.Text  = "";
                txtVisorTickets.Text += compra.MostrarCompra(compra);

                if (compra.PrecioTotal > 20000)
                {
                    compra.PremioAlcanzado  = null;
                    compra.PremioAlcanzado += compra_EventoPrecio;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void btnComprar_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtDPI.Text))
            {
                MessageBox.Show("Es obligatorio llenar el campo DPI Del Cliente.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                if (cbxLugar.SelectedItem == null)
                {
                    MessageBox.Show("Debe seleccionar el LUGAR donde se realiza la compra.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    if (string.IsNullOrEmpty(txtCompra.Text))
                    {
                        MessageBox.Show("Es obligatorio ingresar la cantidad de libras a comprar.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(txtQ.Text))
                        {
                            MessageBox.Show("Es obligatorio llenar el campo QUETZALES.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(txtCtv.Text))
                            {
                                MessageBox.Show("Es obligatorio llenar el campo CENTAVOS.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            else
                            {
                                if (int.Parse(txtQ.Text) >= 10 || int.Parse(txtQ.Text) <= 0)
                                {
                                    MessageBox.Show("Debe pedir autorización para ingresar este precio.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                                else
                                {
                                    if (int.Parse(txtCtv.Text) > 99 || int.Parse(txtCtv.Text) < 10)
                                    {
                                        MessageBox.Show("Debe ingresar una cifra de 2 digitos en el campo CENTAVOS.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                    else
                                    {
                                        if (cbxFormaPago.SelectedItem == null)
                                        {
                                            MessageBox.Show("Debe seleccionar una FORMA DE PAGO.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                        else
                                        {
                                            if (cbxFormaPago.Text != "EFECTIVO" && cbxBanco.SelectedItem == null)
                                            {
                                                MessageBox.Show("Debe seleccionar un BANCO.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                            }
                                            else
                                            {
                                                try
                                                {
                                                    int acum = int.Parse(objcliente.getAcumulado(txtDPI.Text));
                                                    int pend = acum - int.Parse(txtCompra.Text);

                                                    string banco;

                                                    if (cbxBanco.SelectedValue == null)
                                                    {
                                                        banco = "";
                                                    }
                                                    else
                                                    {
                                                        banco = cbxBanco.SelectedValue.ToString();
                                                    }

                                                    Compra objcompra = new Compra(txtDPI.Text, cbxFormaPago.SelectedValue.ToString(), banco, acum.ToString(), txtCompra.Text, txtQ.Text + "." + txtCtv.Text, pend.ToString(), cbxLugar.SelectedValue.ToString(), usuario);
                                                    objcompra.Agregar();

                                                    int actual    = int.Parse(objcliente.getAcumulado(txtDPI.Text));
                                                    int comprado  = int.Parse(txtCompra.Text);
                                                    int acumulado = actual - comprado;

                                                    objcliente.setAcumulado(acumulado.ToString(), txtDPI.Text);

                                                    int actualcomprado = int.Parse(objcliente.getComprado(txtDPI.Text));
                                                    int agregado       = int.Parse(txtCompra.Text);
                                                    int nuevo          = actualcomprado + agregado;

                                                    objcliente.setComprado(nuevo.ToString(), txtDPI.Text);

                                                    MessageBox.Show("La compra se ha registrado con éxito.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                    txtDPI.Clear();
                                                    cbxLugar.SelectedItem = null;
                                                    txtQ.Clear();
                                                    txtCtv.Clear();
                                                    txtCompra.Clear();
                                                    lblNomClie.Text           = null;
                                                    lblAcumClie.Text          = null;
                                                    lblTotal.Text             = "0.00";
                                                    cbxFormaPago.SelectedItem = null;
                                                    cbxBanco.DataSource       = null;
                                                }
                                                catch (Exception error)
                                                {
                                                    MessageBox.Show("Error al intentar conectarse con la base de datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //Se prueba la creacion de un teclado
            Teclado teclado = new Teclado(Periferico.Marca.Gigabyte, 123, "Prueba Teclado");

            try
            {
                Console.WriteLine(teclado.ToString());

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            //Se prueba la creacion de un mouse
            Mouse mouse = new Mouse(Periferico.Marca.Gigabyte, 456, "Prueba Mouse");

            try
            {
                Console.WriteLine(mouse.ToString());

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            //Se crea una compra y se le agregan el mouse y el teclado
            Compra <Periferico> c_perif = new Compra <Periferico>();

            try
            {
                c_perif.Agregar(teclado);
                c_perif.Agregar(mouse);

                Console.WriteLine("Se agregaron los perifericos a la compra");

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            //Se imprime la informacion de la compra
            try
            {
                Console.WriteLine(c_perif.MostrarCompra(c_perif));

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            //Se guarda el archivo de tecto con la informacion de la compra
            try
            {
                Texto aux = new Texto();
                aux.Guardar("TicketTest.txt", c_perif.MostrarCompra(c_perif));
                Console.WriteLine("Se guardo el archivo de texto");

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            //Se obtiene la info del teclado a traves del metodo de extension
            try
            {
                Console.WriteLine(teclado.ObtenerInfoExtendida());

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            //Se traen los datos de la BBDD y se almacenan en una lista de perifericos
            c_perif.Elementos = ConexionBD <Periferico> .GetProductos();

            try
            {
                Console.WriteLine(c_perif.MostrarCompra(c_perif));

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.ReadLine();
        }