Exemple #1
0
        private void btnImprimir_Click(object sender, EventArgs e)
        {
            string nit_cliente    = dgvVentas.CurrentRow.Cells[6].Value.ToString();
            string nombre_cliente = dgvVentas.CurrentRow.Cells[7].Value.ToString();
            string fecha_venta    = dgvVentas.CurrentRow.Cells[2].Value.ToString();
            string numero_recibo  = dgvVentas.CurrentRow.Cells[1].Value.ToString().PadLeft(7, '0');
            string numero_nit     = "7473186019";
            int    id_venta       = Convert.ToInt32(dgvVentas.CurrentRow.Cells[0].Value.ToString());

            recibo.Imprimir(nit_cliente, nombre_cliente, fecha_venta, numero_recibo, numero_nit, id_venta);
        }
Exemple #2
0
        private void btnVender_Click(object sender, EventArgs e)
        {
            if (dgvVenta.RowCount <= 0)
            {
                MessageBox.Show("Debe existir por lo menos 1 producto en la venta");
                txtCodigoProducto.Focus();
            }
            else
            {
                if (txtNITCI.Text.Equals("") || txtNombreCliente.Text.Equals(""))
                {
                    MessageBox.Show("Debe completar los datos del cliente antes de continuar");
                }
                else
                {
                    decimal   descuento = Convert.ToDecimal(txtDescuento.Text);
                    FrmPagado frm       = new FrmPagado(total - descuento);
                    frm.ShowDialog();
                    decimal importe_pagado = frm.Importe_pagado;

                    if (importe_pagado > 0)
                    {
                        //Insertar o actualizar datos del cliente
                        if (txtNITCI.Text.Equals("") || txtNombreCliente.Text.Equals(""))
                        {
                            MessageBox.Show("Los datos del cliente deben ser completados antes de proceder con la venta");
                        }
                        else
                        {
                            string nit_ci = txtNITCI.Text;
                            string nombre = txtNombreCliente.Text;

                            if (txtNITCI.Text.Equals("0"))
                            {
                                nuevoCliente = true;
                            }

                            if (nuevoCliente)
                            {
                                this.clienteTableAdapter.InsertarCliente(nombre, nit_ci);
                            }
                            else
                            {
                                int id = Convert.ToInt32(this.clienteTableAdapter.ObtenerID(nombre, nit_ci));
                                this.clienteTableAdapter.EditarCliente(nombre, nit_ci, id);
                            }
                            nuevoCliente = true;
                        }

                        //Insertar nueva venta

                        int id_cliente = Convert.ToInt32(this.clienteTableAdapter.ObtenerID(txtNombreCliente.Text, txtNITCI.Text));

                        DateTime fecha = DateTime.Now;

                        this.ventaTableAdapter.InsertarVenta(fecha, total, descuento, importe_pagado, "00-00-00-00-00", "", id_cliente, id_usuario);

                        int id_venta = Convert.ToInt32(this.ventaTableAdapter.ObtenerID(fecha, total, descuento, importe_pagado, "00-00-00-00-00", "", id_cliente, id_usuario));

                        //Insertar detalle de venta

                        foreach (DataGridViewRow row in dgvVenta.Rows)
                        {
                            string  codigo_producto = row.Cells[0].Value.ToString();
                            string  nombre_producto = row.Cells[1].Value.ToString();
                            int     cantidad        = Convert.ToInt32(row.Cells[2].Value);
                            decimal precio          = Convert.ToDecimal(row.Cells[3].Value);
                            decimal subtotal        = Convert.ToDecimal(row.Cells[4].Value);

                            int id_producto = Convert.ToInt32(this.productoTableAdapter.ObtenerID(codigo_producto, nombre_producto));

                            this.productoTableAdapter.ActualizarStock(cantidad, id_producto);

                            this.detalle_ventaTableAdapter.InsertarDetalleVenta(id_producto, precio, cantidad, subtotal, id_venta);
                        }

                        DialogResult confirmacion = MessageBox.Show("¿Desea imprimir el recibo?", "Pregunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (confirmacion == DialogResult.Yes)
                        {
                            //Imprimir recibo
                            string numero_nit = "7473186019";
                            recibo.Imprimir(txtNITCI.Text, txtNombreCliente.Text, fecha.ToString(), id_venta.ToString().PadLeft(7, '0'), numero_nit, id_venta);
                        }

                        //Limpiar datos del cliente
                        LimpiarCamposCliente();

                        //Limpiar datos de productos en venta;
                        LimpiarDetalle();

                        //Reiniciar el total de la venta a 0
                        total             = 0;
                        txtTotal.Text     = total.ToString("#0.00#");
                        txtDescuento.Text = total.ToString("#0.00#");
                    }
                }
            }
        }