Exemplo n.º 1
0
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            bool   buscar   = false;
            string cedula   = "";
            string producto = "";
            string numFact  = Microsoft.VisualBasic.Interaction.InputBox("Ingrese el Número de Factura", "Mensaje de Busqueda");

            f = MetodosBD.cargarFacturaC(numFact);
            foreach (FacturaC x in f)
            {
                buscar          = true;
                lblNumFact.Text = x.NumF;
                cedula          = x.CedulaC;

                txtEmpleado.Text = x.CedulaE;
                dateTime.Value   = Convert.ToDateTime(x.Fecha);
                txtSubTotal.Text = Convert.ToString(x.SubTotal);
                txtIva.Text      = Convert.ToString(x.Iva);
                txtTotal.Text    = Convert.ToString(x.Total);
                if (x.Anulado)
                {
                    // significa que esta anulada la factura
                    lblAnulada.Text = "Anulado";
                }
                else
                {
                    lblAnulada.Text = "";
                }
            }

            if (buscar)
            {
                dataGridViewFactura.Rows.Clear();
                List <Cliente> cliente = MetodosBD.cargarClienteF(cedula);
                foreach (Cliente cl in cliente)
                {
                    txtCliente.Text   = cl.Nombre + " " + cl.Apellido;
                    txtDireccion.Text = cl.Direccion;
                    txtRUC.Text       = cl.Cedula;
                    txtTelefono.Text  = cl.Telefono;
                }

                List <DetalleFactura> detalle = MetodosBD.cargarDetalleFactura(numFact);
                foreach (DetalleFactura d in detalle)
                {
                    producto = MetodosBD.buscarProducto(d.CodProducto);


                    dataGridViewFactura.Rows.Add(d.Cantidad, producto, d.Precio, d.Total);
                }


                buscar = false;
            }


            Console.WriteLine(numFact);
        }
Exemplo n.º 2
0
        private void btnAnular_Click(object sender, EventArgs e)
        {
            string numFact = Microsoft.VisualBasic.Interaction.InputBox("Ingrese el Número de Factura", "Mensaje de Busqueda");

            result = MessageBox.Show("¿Desea Anular esta Factura?", "Mensaje de confimación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result.Equals(DialogResult.Yes))
            {
                bool anulado = MetodosBD.facturaAnulada(numFact);
                if (anulado)
                {
                    MessageBox.Show("Error la Factura esta anulada");
                }
                else
                {
                    int resultado = MetodosBD.ActualizarAnulacionFactura(numFact, true);
                    if (resultado >= 1)
                    {
                        string producto;
                        List <DetalleFactura> detalle = MetodosBD.cargarDetalleFactura(numFact);
                        foreach (DetalleFactura d in detalle)
                        {
                            producto = MetodosBD.buscarProducto(d.CodProducto);
                            int stockViejo = MetodosBD.buscarStock2(producto);
                            int newStock   = stockViejo + d.Cantidad;

                            MetodosBD.ActualizarStock2(producto, newStock);
                        }
                        MessageBox.Show("Factura anulada");
                    }
                    else
                    {
                        MessageBox.Show("Factura no encontrada");
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void btnAgregarProducto_Click(object sender, EventArgs e)
        {
            string cantidad = txtCantidad.Text;

            contador = 0;
            subTotal = 0;

            bool   bandera1 = false;
            bool   bandera2 = false;
            double total    = 0;
            string producto = "";
            double precio   = 0;

            if (codigoProducto.Equals(""))
            {
                MessageBox.Show("Debe elegir un producto", "Mensaje de advertencia");
            }
            else
            {
                bandera1 = true;

                if (cantidad == "")
                {
                    MessageBox.Show("No puede dejar en blanco la cantidad", "Mensaje de advertencia");
                }
                else
                {
                    cantidad2 = Convert.ToInt32(txtCantidad.Text);


                    if (cantidad2 <= stock)
                    {
                        bandera2 = true;
                    }
                    else
                    {
                        MessageBox.Show("Stock Insuficiente", "Mensaje de advertencia");
                        txtCantidad.Text = "";
                        txtCantidad.Focus();
                    }
                }
            }

            if (bandera2 && bandera1)
            {
                string product = "";
                int    cant    = 0;
                int    cant2   = 0;
                Console.Write(" SubTotal antes del for " + subTotal);
                for (int count = 0; count < dataGridViewFactura.Rows.Count; count++)
                {
                    product = (string)dataGridViewFactura.Rows[count].Cells["columnProducto"].Value;

                    Console.Write("entro 0");
                    if (p.Equals(product))
                    {
                        Console.Write("entro 1");
                        banderaTabla = false;
                        cant         = (int)dataGridViewFactura.Rows[count].Cells["columnCantidad"].Value;
                        total        = (double)dataGridViewFactura.Rows[count].Cells["columnTotal"].Value;



                        precio = MetodosBD.buscarPrecio(codigoProducto);

                        Console.Write("stock " + stock);
                        Console.Write("cantidad " + cantidad2);
                        nuevoStock = stock - cantidad2;


                        cant2 = cant + cantidad2;
                        dataGridViewFactura.Rows[count].Cells["columnCantidad"].Value = cant2;
                        total = precio * cant2;
                        dataGridViewFactura.Rows[count].Cells["columnTotal"].Value = total;
                        // subTotal = subTotal + total;



                        MetodosBD.ActualizarStock(codigoProducto, nuevoStock);

                        dataGridViewProducto.DataSource = MetodosBD.cargarProductos2();
                        dataGridViewProducto.ClearSelection();
                    }
                    subTotal = subTotal + (double)dataGridViewFactura.Rows[count].Cells["columnTotal"].Value;
                    Console.Write(" SubTotal despues  del for " + subTotal);
                    iva              = subTotal * 0.12;
                    totalFinal       = iva + subTotal;
                    txtSubTotal.Text = Convert.ToString(subTotal);
                    txtIva.Text      = Convert.ToString(iva);
                    txtTotal.Text    = Convert.ToString(totalFinal);
                }
                if (banderaTabla)
                {
                    Console.Write("entro 2");
                    producto = MetodosBD.buscarProducto(codigoProducto);
                    precio   = MetodosBD.buscarPrecio(codigoProducto);
                    total    = precio * cantidad2;


                    dataGridViewFactura.Rows.Add(cantidad2, producto, precio, total);
                    Console.Write("stock " + stock);
                    Console.Write("cantidad " + cantidad2);

                    nuevoStock = stock - cantidad2;
                    MetodosBD.ActualizarStock(codigoProducto, nuevoStock);
                    dataGridViewProducto.DataSource = MetodosBD.cargarProductos2();
                    dataGridViewProducto.ClearSelection();
                    Console.Write(" SubTotal antes del for " + subTotal);
                    //for (int count = 0; count < dataGridViewFactura.Rows.Count; count++)
                    //{
                    subTotal = subTotal + total;
                    //}

                    Console.Write(" SubTotal despues  del for " + subTotal);


                    // subTotal = subTotal + total;
                    iva              = subTotal * 0.12;
                    totalFinal       = iva + subTotal;
                    txtSubTotal.Text = Convert.ToString(subTotal);
                    txtIva.Text      = Convert.ToString(iva);
                    txtTotal.Text    = Convert.ToString(totalFinal);



                    banderaTabla = true;
                }



                txtCantidad.Text = "";
                txtCantidad.Focus();
                bandera1       = false;
                bandera2       = false;
                codigoProducto = "";
            }
        }