public void ObtenerNumeroFactura()
        {
            //Obtener numeroFactura
            Factura f = HistorialBLL.ultimoRegistro();

            if (f != null)
            {
                lblNumFactura.Text = (f.NumeroFactura + 1).ToString();
            }
            else
            {
                lblNumFactura.Text = "1";
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtNombre.Text == "" || txtCedula.Text == "" || txtVenta.Text == "" || txtDescuento.Text == "" ||
                txtSubTotal.Text == "" || txtIVA.Text == "" || txtTotalVenta.Text == "" || tablaLinea.RowCount <= 0)
            {
                MessageBox.Show("No puedes dejar campos en blanco");
            }
            else
            {
                Factura historial = new Factura
                {
                    Identificacion = txtCedula.Text,
                    Fecha          = DateTime.Now.ToString("yyyy-MM-dd"),
                    Hora           = DateTime.Now.ToString("HH:mm:ss"),
                    TotalVenta     = Convert.ToDouble(txtTotalVenta.Text),
                    Descuento      = Convert.ToDouble(txtDescuento.Text),
                    SubTotal       = Convert.ToDouble(txtSubTotal.Text),
                    IVA            = Convert.ToDouble(txtIVA.Text),
                    PorcentajeIVA  = cmbIVA.SelectedValue.ToString() + "%"
                };

                //Se inserta la factura
                Resultado r = HistorialBLL.InsertarHistorial(historial);

                if (r.Codigo == 1)
                {
                    // insetar linea factura
                    for (int i = 0; i < tablaLinea.RowCount; i++)
                    {
                        LineaDetalle l = new LineaDetalle
                        {
                            NumeroFactura  = Convert.ToInt32(lblNumFactura.Text),
                            IdLinea        = i + 1,
                            IdProducto     = Convert.ToInt32(tablaLinea.Rows[i].Cells["Codigo"].Value),
                            Cantidad       = Convert.ToInt32(tablaLinea.Rows[i].Cells["Cantidad"].Value),
                            PrecioProducto = Convert.ToDouble(tablaLinea.Rows[i].Cells["PrecioUnit"].Value)
                        };
                        ProductoBLL.InsertarLinea(l);
                    }


                    ObtenerNumeroFactura();


                    //llenar objetos para crear el ticket

                    Persona persona = PersonasBLL.BuscarUnaPersona(txtCedula.Text);

                    Factura factura = HistorialBLL.ultimoRegistro();

                    List <ProductosLineaDetalle> ListadoProductosLineaDetalle = ProductoBLL.ListadoProductosLineaDetalle(factura.NumeroFactura);

                    control.CrearTickete(persona, ListadoProductosLineaDetalle, factura);

                    MessageBox.Show("Tomar el tiquete", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    limpiarTxt();

                    this.Visible = false;

                    control.AbrirFormPrincipal();
                }
                else
                {
                    MessageBox.Show(r.Mensaje, "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }