private void menureimpresion_Click(object sender, EventArgs e)
        {
            DataGridViewRow row             = dataLista.CurrentRow;
            Reporteventa    miformnotaventa = new Reporteventa();

            //Reporteventa mireporteventa = new Reporteventa();
            //  Frmimpnotaventa mireporteventa = new Frmimpnotaventa();
            // Frmimpventicket miformticket = new Frmimpventicket();

            if (NegocioConfigEmpresa.confsistema("imprimirventa").ToString() == "True")
            {
                if (NegocioConfigEmpresa.confsistema("tipoimpresion").ToString() == "tipocarro")
                {
                    //miformnotaventa.Tipoimp = Convert.ToString(NegocioConfigEmpresa.confsistema("modoimpventa"));
                    miformnotaventa.Idventa = Convert.ToInt32(row.Cells["codigo"].Value.ToString());
                    miformnotaventa.ShowDialog();
                    //mireporteventa.Tipoimp = Convert.ToString(NegocioConfigEmpresa.confsistema("modoimpventa"));
                    //mireporteventa.Codventa = Convert.ToInt32(row.Cells["codigo"].Value.ToString());
                    //mireporteventa.Show();
                }

                else
                {
                    //  Ticketventa miticket = new Ticketventa(Convert.ToInt32(row.Cells["codigo"].Value.ToString()));
                    //miticket.ShowDialog();
                    Ticketventa miticket = new Formreportes.Ticketventa(Convert.ToInt32(row.Cells["codigo"].Value.ToString()));
                    if (NegocioConfigEmpresa.marcafiscal == "elec" && row.Cells["Letra"].Value.ToString() != "X")
                    {
                        miticket = new Formreportes.Ticketventa(Convert.ToInt32(row.Cells["codigo"].Value.ToString()));
                        miticket.ShowDialog();
                    }
                    else if (row.Cells["Letra"].Value.ToString() == "X")
                    {
                        TicketProforma miticketproforma = new Formreportes.TicketProforma(Convert.ToInt32(row.Cells["codigo"].Value.ToString()));
                        miticketproforma.ShowDialog();
                    }



                    // reportName is the Assembly Qualified Name of the report



                    //       miformticket.Tipoimp = Convert.ToString(NegocioConfigEmpresa.confsistema("modoimpventa"));
                    //     miformticket.Codventa = Convert.ToInt32(row.Cells["codigo"].Value.ToString());
                    //   miformticket.Show();
                }
            }
        }
        public void guardarventa()
        {
            int     nroterminal    = 0;
            int     codtarjeta     = 0;
            string  cupon          = "";
            string  lote           = "";
            decimal importe        = 0;
            int     cuota          = 0;
            int     codformapago   = 1;
            string  msg            = "ok";
            string  precioneto     = "";
            string  cantidad       = "";
            decimal var            = 0;
            Char    estadofactura  = 'P'; //P : pendiente de factura F : facturado
            string  nrocomprobante = "";

            totales();
            NegocioVenta objventa = new NegocioVenta();
            DataTable    dt       = new DataTable();

            dt.Columns.Add("Codigo", typeof(string));
            dt.Columns.Add("Precio", typeof(decimal));
            dt.Columns.Add("Cantidad", typeof(string));
            dt.Columns.Add("Descuento", typeof(decimal));
            dt.Columns.Add("Importe", typeof(decimal));
            dt.Columns.Add("Producto", typeof(string));
            dt.Columns.Add("Precioneto", typeof(string));
            dt.Columns.Add("Pesable", typeof(int));

            DataTable DTOrdenpedido = new DataTable();

            DTOrdenpedido.Columns.Add("Codigo", typeof(string));
            DTOrdenpedido.Columns.Add("cantidadparcial", typeof(string));
            DTOrdenpedido.Columns.Add("cantidadtotal", typeof(string));
            DTOrdenpedido.Columns.Add("detalle", typeof(string));

            decimal IVA = 21;

            if (formapago == "tarjeta")
            {
                codtarjeta   = this.codtarjeta;
                cupon        = txtCupon.Text == "" ? "0":txtCupon.Text;
                lote         = txtLote.Text == "" ? "0" : txtLote.Text;
                cuota        = Convert.ToInt32(lblCuota.Text);
                importe      = Convert.ToDecimal(lblImportecuota.Text);
                codformapago = 2;
            }
            if (formapago == "ctacte")
            {
                codformapago = 3;
            }


            /*IMPORTANTE HACER NOTA DE VENTA PARA IMPRIMIR*/
            //if (MessageBox.Show("Desea Imprimir Venta?", "Imprimir"
            //   , MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes)
            //{
            //    FrmImpVenta venta = new FrmImpVenta(totalAPagar);
            //    venta.Show();
            //}
            //else {
            //    this.Close();
            //}

            try
            {
                //LISTA DE PRODUCTOS SE LE ASIGNA EN EL MOMENTO QUE SE MUESTRA EL FORMULARIO

                // NumberFormatInfo asociado con la cultura en-US.
                NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat;



                foreach (DataGridViewRow fila in listadoDeProducto.Rows)
                {
                    if (responsableiva != "EX")
                    {
                        var = Decimal.Round(Convert.ToDecimal(fila.Cells["CPrecio"].Value) / Convert.ToDecimal(1.21), 2);
                    }
                    else
                    {
                        var = Decimal.Round(Convert.ToDecimal(fila.Cells["CPrecio"].Value), 2);
                    }

                    //Math.Round(decValue, 2, MidpointRounding.AwayFromZero)
                    // var = Math.Round(var, 2, MidpointRounding.AwayFromZero);

                    precioneto = var.ToString("0.0000", nfi);
                    //var = Convert.ToDecimal(fila.Cells["Cantidad"].Value);
                    //cantidad = var.ToString("0.00", nfi);
                    //recorro la lista pasado por paramentro y asigno al datatable para generar la transaccion
                    //dt.Rows.Add(fila.Cells["Codigo"].Value, fila.Cells["Precio"].Value, fila.Cells["Cantidad"].Value, fila.Cells["Descuento"].Value, fila.Cells["Importe"].Value);
                    dt.Rows.Add(fila.Cells["Codigo"].Value, fila.Cells["CPrecio"].Value, fila.Cells["Cantidad"].Value, fila.Cells["Descuento"].Value, fila.Cells["Importe"].Value, fila.Cells["Producto"].Value, precioneto, fila.Cells["Dpesable"].Value);

                    DTOrdenpedido.Rows.Add(fila.Cells["Codigo"].Value, "0", fila.Cells["Cantidad"].Value, fila.Cells["Producto"].Value);
                }



                try
                {
                    if (NegocioConfigEmpresa.confsistema("facturar").ToString() == "True" && tipo_comprobante == "NOTA DE VENTA" && tipofactura != "X")
                    {
                        if (NegocioConfigEmpresa.marcafiscal != "")
                        {
                            msg = objcomprobante.factura(NegocioConfigEmpresa.marcafiscal, dt, Convert.ToDouble(txtTotalAPagar.Text), NegocioConfigEmpresa.modelofiscal, NegocioConfigEmpresa.puertofiscal,
                                                         1, razonsocial, razonsocial == "CONSUMIDOR FINAL" ? "99999999999" : cuit, domicilio, tipofactura, responsableiva, tipofactura, tipofactura, Convert.ToDouble(neto), Convert.ToDouble(iva), Convert.ToDouble(this.neto105), Convert.ToDouble(this.iva105));
                        }
                        else
                        {
                            UtilityFrm.mensajeError("La marca de la fiscal no se encuentra definido, la factura quedara pendiente");
                        }
                        if (msg.Substring(0, 2) != "ok")
                        {
                            UtilityFrm.mensajeError(msg);
                            UtilityFrm.mensajeConfirm("Se guardara la venta como pendiente de factura la puede encontrar en lista de ventas");
                            estadofactura = 'P';
                        }
                        else
                        {
                            estadofactura = 'F';
                            //corregir para que no genere errores
                            int nrocaracteres = Convert.ToInt32(msg.Length.ToString());
                            nrocomprobante = msg.Substring(2, nrocaracteres - 2);
                        }
                    }
                    else
                    {
                        estadofactura = 'P';
                    }
                }
                catch (Exception e)
                {
                    UtilityFrm.mensajeError(e.Message);
                }
                string Rta = objventa.Insertar(this.idCliente, DateTime.Now, Tipo_comprobante,
                                               objcomprobante.Puntoventa.PadLeft(5, '0'), msg.Substring(0, 2) == "ok" ? nrocomprobante.PadLeft(8, '0') : "0",
                                               IVA, this.concaja, this.constock, NegocioConfigEmpresa.usuarioconectado, dt,
                                               Convert.ToDecimal(txtBonificacion.Text == "" ? txtBonificacion.Text = "0" : txtBonificacion.Text),
                                               Convert.ToDecimal(txtTotalAPagar.Text), Convert.ToDecimal(lblsubtotal.Text), estadofactura,
                                               NegocioConfigEmpresa.confsistema("stock").ToString() == this.Name && pendientedestock == false ? true : false, nroterminal,
                                               codtarjeta, cupon, lote, importe, cuota, codformapago, neto, iva, objcomprobante.Cae, objcomprobante.Fechavto,
                                               objcomprobante.Numerotipofactura.PadLeft(3, '0'), objcomprobante.Puntoventa.PadLeft(5, '0'), this.iva105, this.neto105);

                int objnum = objventa.Idventa;

                if (Rta == "OK" || Rta == "ok")
                {
                    if (pendientedestock == true)
                    {
                        NegocioRetirodeMercaderia.insertar(DateTime.Now, this.idCliente, NegocioConfigEmpresa.idusuario, "VENTA", "PENDIENTE", "", DTOrdenpedido, this.idCliente, 1, objnum);
                    }

                    if (this.concaja == true)
                    {
                        Rta = Negociocaja.insertarmovcaja(4110107, Convert.ToSingle(txtTotalAPagar.Text), 0, Convert.ToString(DateTime.Now), NegocioConfigEmpresa.usuarioconectado, NegocioConfigEmpresa.idusuario, NegocioConfigEmpresa.turno, "Venta nro : " + objventa.Idventa.ToString(), objventa.Idventa, true);
                    }
                    else
                    {
                        Rta = "ok";
                    }

                    if (Rta == "ok")
                    {
                        trans = Rta;

                        Reporteventa mireporteventa = new Reporteventa();
                        // Frmimpnotaventa miformnotaventa = new Frmimpnotaventa();
                        // Frmimpventicket miformticket = new Frmimpventicket();

                        if (NegocioConfigEmpresa.confsistema("imprimirventa").ToString() == "True")
                        {
                            if (NegocioConfigEmpresa.confsistema("tipoimpresion").ToString() == "tipocarro")
                            {
                                //con crystal report
                                //  miformnotaventa.Tipoimp = Convert.ToString(NegocioConfigEmpresa.confsistema("modoimpventa"));
                                //   miformnotaventa.Codventa = objventa.Idventa;
                                //   miformnotaventa.Show();
                                // con reportviewer
                                mireporteventa.Idventa = objventa.Idventa;
                                mireporteventa.ShowDialog();
                            }

                            else
                            {
                                if (NegocioConfigEmpresa.marcafiscal == "elec" && tipofactura != "X")
                                {
                                    Ticketventa miticket = new Formreportes.Ticketventa(objventa.Idventa);
                                    miticket.ShowDialog();
                                }
                                else if (tipofactura == "X")
                                {
                                    TicketProforma miticketproforma = new Formreportes.TicketProforma(objventa.Idventa);
                                    miticketproforma.ShowDialog();
                                }
                                //miformticket.Tipoimp = Convert.ToString(NegocioConfigEmpresa.confsistema("modoimpventa"));
                                //miformticket.Codventa = objventa.Idventa;
                                //miformticket.Show();
                            }
                        }



                        if (facturar == true)
                        {
                            //  NegocioFHasar objhasar = new NegocioFHasar();
                            //objhasar.Comprobantefiscal(1, 1, "CONSUMIDOR FINAL", "9999999", 1, "", dt,Convert.ToDouble (lblPrecioTotal.Text ));
                        }
                        //  crystalReportViewer1.ReportSource = ventasTicket1;

                        this.Close();
                    }
                    else
                    {
                        UtilityFrm.mensajeError("Error en la base de Datos 1");
                    }
                }
                else
                {
                    UtilityFrm.mensajeError("Error en la base de Datos 2");
                }
            }
            catch (Exception ex)
            {
                UtilityFrm.mensajeError(ex.Message);
            }
        }