Exemple #1
0
        protected void BuscarButton_Click(object sender, EventArgs e)
        {
            if (Funciones.SessionTimeOut(Session))
            {
                Response.Redirect("~/SessionTimeout.aspx");
            }
            else
            {
                try
                {
                    MensajeLabel.Text = "";
                    bool                         monedasExtranjeras = false;
                    Entidades.Sesion             sesion             = (Entidades.Sesion)Session["Sesion"];
                    List <Entidades.Comprobante> listaC             = new List <Entidades.Comprobante>();

                    List <Entidades.Estado> estados = new List <Entidades.Estado>();
                    Entidades.Estado        es      = new Entidades.Estado();
                    es.Id = "Vigente";
                    estados.Add(es);
                    Entidades.Persona persona          = new Entidades.Persona();
                    Entidades.NaturalezaComprobante nc = new Entidades.NaturalezaComprobante();
                    nc.Id  = "Venta";
                    listaC = RN.Comprobante.ListaFiltradaIvaYMovimientos(estados, FechaDesdeTextBox.Text, FechaHastaTextBox.Text, persona, nc, false, "", sesion);

                    Entidades.VentasXArticulo ventas = new Entidades.VentasXArticulo();

                    ventas.Cuit       = sesion.Cuit.Nro;
                    ventas.RazSoc     = sesion.Cuit.RazonSocial;
                    ventas.PeriodoDsd = FechaDesdeTextBox.Text.Substring(6, 2) + "/" + FechaDesdeTextBox.Text.Substring(4, 2) + "/" + FechaDesdeTextBox.Text.Substring(0, 4);
                    ventas.PeriodoHst = FechaHastaTextBox.Text.Substring(6, 2) + "/" + FechaHastaTextBox.Text.Substring(4, 2) + "/" + FechaHastaTextBox.Text.Substring(0, 4);

                    System.Xml.Serialization.XmlSerializer x;
                    byte[] bytes;
                    System.IO.MemoryStream ms;
                    FeaEntidades.InterFacturas.lote_comprobantes lote;

                    ventas.VentasXArticuloDetalle = new List <Entidades.VentasXArticuloDetalle>();
                    List <Entidades.VentasXArticuloDetalle> lvd = new List <Entidades.VentasXArticuloDetalle>();
                    Entidades.VentasXArticuloDetalle        vd;
                    foreach (Entidades.Comprobante comprobante in listaC)
                    {
                        lote = new FeaEntidades.InterFacturas.lote_comprobantes();
                        x    = new System.Xml.Serialization.XmlSerializer(lote.GetType());

                        comprobante.Response = comprobante.Response.Replace("iso-8859-1", "utf-16");
                        bytes = new byte[comprobante.Response.Length * sizeof(char)];
                        System.Buffer.BlockCopy(comprobante.Response.ToCharArray(), 0, bytes, 0, bytes.Length);
                        ms = new System.IO.MemoryStream(bytes);
                        ms.Seek(0, System.IO.SeekOrigin.Begin);
                        lote = (FeaEntidades.InterFacturas.lote_comprobantes)x.Deserialize(ms);

                        //Totales por artículo
                        if (lote.comprobante[0].detalle.linea != null)
                        {
                            for (int z = 0; z < lote.comprobante[0].detalle.linea.Length; z++)
                            {
                                double signo = 1;
                                if (("/3/8/13/").IndexOf("/" + Convert.ToInt32(lote.comprobante[0].cabecera.informacion_comprobante.tipo_de_comprobante).ToString().Trim() + "/") != -1)
                                {
                                    signo = -1;
                                }

                                //Verificar el articulo ya existe en la lista.
                                //List<Entidades.VentasXArticuloDetalle> listaAux = lvd.FindAll(delegate(Entidades.VentasXArticuloDetalle vxad)
                                //{
                                //    return vxad.IdArticulo == lote.comprobante[0].detalle.linea[z].codigo_producto_vendedor;
                                //});
                                //if (listaAux.Count == 0 || lote.comprobante[0].detalle.linea[z].codigo_producto_vendedor.Trim() == "")
                                //{
                                //}
                                vd               = new Entidades.VentasXArticuloDetalle();
                                vd.IdArticulo    = lote.comprobante[0].detalle.linea[z].codigo_producto_vendedor;
                                vd.GTIN          = lote.comprobante[0].detalle.linea[z].GTIN.ToString();
                                vd.IdArticuloEmp = lote.comprobante[0].detalle.linea[z].codigo_producto_comprador;
                                if (lote.comprobante[0].detalle.linea[z].indicacion_exento_gravado != null)
                                {
                                    vd.IndicacionExentoGravado = lote.comprobante[0].detalle.linea[z].indicacion_exento_gravado;
                                }
                                else
                                {
                                    vd.IndicacionExentoGravado = "";
                                }
                                vd.NumeroLinea = lote.comprobante[0].detalle.linea[z].numeroLinea;
                                vd.UnidadCod   = lote.comprobante[0].detalle.linea[z].unidad;
                                vd.UnidadDescr = lote.comprobante[0].detalle.linea[z].unidadDescripcion;
                                vd.CompTipo    = lote.comprobante[0].cabecera.informacion_comprobante.tipo_de_comprobante.ToString();
                                vd.CompNro     = lote.comprobante[0].cabecera.informacion_comprobante.numero_comprobante.ToString();
                                vd.CompPtoVta  = lote.comprobante[0].cabecera.informacion_comprobante.punto_de_venta.ToString();
                                vd.CompFecEmi  = lote.comprobante[0].cabecera.informacion_comprobante.fecha_emision.Substring(6, 2) + "/" + lote.comprobante[0].cabecera.informacion_comprobante.fecha_emision.Substring(4, 2) + "/" + lote.comprobante[0].cabecera.informacion_comprobante.fecha_emision.Substring(0, 4);

                                vd.EmpNroDoc   = lote.comprobante[0].cabecera.informacion_comprador.nro_doc_identificatorio.ToString();
                                vd.EmpCodDoc   = lote.comprobante[0].cabecera.informacion_comprador.codigo_doc_identificatorio.ToString();
                                vd.EmpDescrDoc = ""; //Obtener la descripcion;
                                vd.EmpNombre   = lote.comprobante[0].cabecera.informacion_comprador.denominacion;

                                if (lote.comprobante[0].detalle.linea[z].descripcion.Length > 0 && lote.comprobante[0].detalle.linea[z].descripcion.Substring(0, 1) == "%")
                                {
                                    vd.Descr = RN.Funciones.HexToString(lote.comprobante[0].detalle.linea[z].descripcion);
                                }
                                else
                                {
                                    vd.Descr = lote.comprobante[0].detalle.linea[z].descripcion;
                                }
                                vd.ImporteTotal = lote.comprobante[0].detalle.linea[z].importe_total_articulo * signo;
                                if (lote.comprobante[0].detalle.linea[z].cantidadSpecified == true && lote.comprobante[0].detalle.linea[z].precio_unitarioSpecified == true)
                                {
                                    vd.Cantidad       = lote.comprobante[0].detalle.linea[z].cantidad * signo;
                                    vd.PrecioUnitario = lote.comprobante[0].detalle.linea[z].precio_unitario * signo;
                                }
                                if (lote.comprobante[0].detalle.linea[z].alicuota_ivaSpecified == true && lote.comprobante[0].detalle.linea[z].importe_ivaSpecified == true)
                                {
                                    vd.AlicuotaIVA = lote.comprobante[0].detalle.linea[z].alicuota_iva;
                                    vd.ImporteIVA  = lote.comprobante[0].detalle.linea[z].importe_iva * signo;
                                }
                                lvd.Add(vd);
                            }
                        }
                    }
                    //Si se muestran artículos vigentes no vendidos.
                    List <Entidades.Articulo> listaArt = new List <Entidades.Articulo>();
                    if (VerTodosLosArticulosCheckBox.Enabled == true && VerTodosLosArticulosCheckBox.Checked == true)
                    {
                        listaArt = RN.Articulo.ListaPorCuit(true, false, sesion);
                        if (listaArt.Count != 0)
                        {
                            foreach (Entidades.Articulo art in listaArt)
                            {
                                bool existeArt = false;
                                if (lvd.Count != 0)
                                {
                                    System.Collections.Generic.List <Entidades.VentasXArticuloDetalle> listaVXArt = lvd.FindAll(delegate(Entidades.VentasXArticuloDetalle vxart)
                                    {
                                        return(vxart.IdArticulo == art.Id);
                                    });
                                    if (listaVXArt.Count != 0)
                                    {
                                        existeArt = true;
                                    }
                                }
                                if (!existeArt)
                                {
                                    vd                         = new Entidades.VentasXArticuloDetalle();
                                    vd.IdArticulo              = art.Id;
                                    vd.Descr                   = art.Descr;
                                    vd.CompFecEmi              = "";
                                    vd.CompNro                 = "";
                                    vd.CompPtoVta              = "";
                                    vd.CompTipo                = "";
                                    vd.UnidadCod               = "";
                                    vd.UnidadDescr             = "";
                                    vd.IndicacionExentoGravado = "";
                                    vd.EmpNroDoc               = "";
                                    vd.EmpCodDoc               = "";
                                    vd.EmpDescrDoc             = "";
                                    vd.EmpNombre               = "";
                                    lvd.Add(vd);
                                }
                            }
                        }
                    }
                    if (lvd.Count != 0)
                    {
                        ventas.VentasXArticuloDetalle = lvd;
                    }
                    Session["formatoRptExportar"]         = FormatosRptExportarDropDownList.SelectedValue;
                    Session["mostrarFechaYHora"]          = FechaYHoraCheckBox.Checked;
                    Session["mostrarDetalleComprobantes"] = DetalleComprobanteCheckBox.Checked;
                    Session["monedasExtranjeras"]         = monedasExtranjeras;
                    if (ventas.VentasXArticuloDetalle.Count != 0)
                    {
                        Session["ventasXArticulo"] = ventas;
                        Response.Redirect("~/Facturacion/Electronica/Reportes/VentasXArticuloWebForm.aspx", true);
                    }
                    else
                    {
                        MensajeLabel.Text = "No hay información.";
                    }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    Trace.Warn("Thread abortado");
                }
                catch (Exception ex)
                {
                    WebForms.Excepciones.Redireccionar(ex, "~/NotificacionDeExcepcion.aspx");
                }
            }
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            try
            {
                var culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");
                culture.NumberFormat.CurrencySymbol = string.Empty;
                System.Threading.Thread.CurrentThread.CurrentCulture = culture;
                System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
                base.InitializeCulture();

                string lcomp = Server.MapPath("~/Facturacion/Electronica/Reportes/Ventas_XArticulo.xsd");
                System.IO.File.Copy(lcomp, @System.IO.Path.GetTempPath() + "Ventas_XArticulo.xsd", true);

                oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

                bool HayME = false;
                string reportPath = "";
                if (Session["monedasExtranjeras"] != null)
                {
                    HayME = (bool)Session["monedasExtranjeras"];
                }
                if (!HayME)
                {
                    reportPath = Server.MapPath("~/Facturacion/Electronica/Reportes/VentasXArticulo.rpt");
                }
                else
                {
                    reportPath = Server.MapPath("~/Facturacion/Electronica/Reportes/VentasXArticuloME.rpt");
                }
                oRpt.Load(reportPath);
                Entidades.VentasXArticulo ventasXArticulo = new Entidades.VentasXArticulo();
                if (Session["ventasXArticulo"] != null)
                {
                    ventasXArticulo = (Entidades.VentasXArticulo)Session["ventasXArticulo"];
                    DataSet ds = new DataSet();
                    XmlSerializer objXS = new XmlSerializer(ventasXArticulo.GetType());
                    StringWriter objSW = new StringWriter();
                    objXS.Serialize(objSW, ventasXArticulo);
                    StringReader objSR = new StringReader(objSW.ToString());
                    ds.ReadXml(objSR);
                    oRpt.SetDataSource(ds);
                }
                else
                {
                    Response.Redirect("~/Facturacion/Electronica/Reportes/VentasXArticuloFiltros.aspx", true);
                }
                string formatoRptExportar = "";
                if (Session["formatoRptExportar"] != null)
                {
                    formatoRptExportar = (string)Session["formatoRptExportar"];
                }
                if (Session["mostrarFechaYHora"] != null)
                {
                    if ((bool)Session["mostrarFechaYHora"] == false)
                    {
                        oRpt.DataDefinition.FormulaFields["MostrarFechaYHora"].Text = "'N'";
                    }
                }
                if (Session["mostrarDetalleComprobantes"] != null)
                {
                    if ((bool)Session["mostrarDetalleComprobantes"] == false)
                    {
                        oRpt.DataDefinition.FormulaFields["MostrarDetalleComprobantes"].Text = "'N'";
                    }
                }
                oRpt.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperLetter;
                oRpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait;
                //oRpt.DataDefinition.FormulaFields["RazSoc"].Text = "'" + ((Entidades.Sesion)Session["Sesion"]).Cuit.RazonSocial + "'";
                if (formatoRptExportar == "")
                {
                    CrystalReportViewer1.GroupTreeStyle.ShowLines = false;
                    CrystalReportViewer1.HasToggleGroupTreeButton = false;
                    CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
                    CrystalReportViewer1.ReportSource = oRpt;
                    CrystalReportViewer1.HasPrintButton = true;
                }
                else
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    sb.Append(ventasXArticulo.Cuit);
                    sb.Append("-");
                    sb.Append(Convert.ToDateTime(ventasXArticulo.PeriodoDsd).ToString("yyyyMMdd"));
                    sb.Append("-");
                    sb.Append(Convert.ToDateTime(ventasXArticulo.PeriodoHst).ToString("yyyyMMdd"));

                    if (formatoRptExportar == "PDF")
                    {
                        CrystalDecisions.Shared.ExportOptions exportOpts = new CrystalDecisions.Shared.ExportOptions();
                        CrystalDecisions.Shared.PdfRtfWordFormatOptions pdfOpts = CrystalDecisions.Shared.ExportOptions.CreatePdfRtfWordFormatOptions();
                        exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                        exportOpts.ExportFormatOptions = pdfOpts;
                        oRpt.ExportToHttpResponse(exportOpts, Response, true, sb.ToString());
                    }
                    if (formatoRptExportar == "Excel")
                    {
                        CrystalDecisions.Shared.ExportOptions exportOpts = new CrystalDecisions.Shared.ExportOptions();
                        CrystalDecisions.Shared.ExcelFormatOptions pdfOpts = CrystalDecisions.Shared.ExportOptions.CreateExcelFormatOptions();
                        exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                        exportOpts.ExportFormatOptions = pdfOpts;
                        oRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.Excel, Server.MapPath("~/TempExcel/") + sb.ToString() + ".xls");
                        
                        System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                        response.ClearContent();
                        response.Clear();
                        response.ContentType = "application/vnd.ms-excel";
                        response.AddHeader("Content-Disposition", "attachment; filename=" + sb.ToString() + ".xls" + ";");
                        response.TransmitFile(Server.MapPath("~/TempExcel/" + sb.ToString() + ".xls"));
                        response.Flush();
                        response.End();  
                    }
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
                Trace.Warn("Thread abortado");
            }
            catch (Exception ex)
            {
                WebForms.Excepciones.Redireccionar(ex, "~/NotificacionDeExcepcion.aspx");
            }
        }
        protected void BuscarButton_Click(object sender, EventArgs e)
        {
            if (Funciones.SessionTimeOut(Session))
            {
                Response.Redirect("~/SessionTimeout.aspx");
            }
            else
            {
                try
                {
                    MensajeLabel.Text = "";
                    bool monedasExtranjeras = false;
                    Entidades.Sesion sesion = (Entidades.Sesion)Session["Sesion"];
                    List<Entidades.Comprobante> listaC = new List<Entidades.Comprobante>();

                    List<Entidades.Estado> estados = new List<Entidades.Estado>();
                    Entidades.Estado es = new Entidades.Estado();
                    es.Id = "Vigente";
                    estados.Add(es);
                    Entidades.Persona persona = new Entidades.Persona();
                    Entidades.NaturalezaComprobante nc = new Entidades.NaturalezaComprobante();
                    nc.Id = "Venta";
                    listaC = RN.Comprobante.ListaFiltradaIvaYMovimientos(estados, FechaDesdeTextBox.Text, FechaHastaTextBox.Text, persona, nc, false, "", sesion);

                    Entidades.VentasXArticulo ventas = new Entidades.VentasXArticulo();

                    ventas.Cuit = sesion.Cuit.Nro;
                    ventas.RazSoc = sesion.Cuit.RazonSocial;
                    ventas.PeriodoDsd = FechaDesdeTextBox.Text.Substring(6, 2) + "/" + FechaDesdeTextBox.Text.Substring(4, 2) + "/" + FechaDesdeTextBox.Text.Substring(0, 4);
                    ventas.PeriodoHst = FechaHastaTextBox.Text.Substring(6, 2) + "/" + FechaHastaTextBox.Text.Substring(4, 2) + "/" + FechaHastaTextBox.Text.Substring(0, 4);

                    System.Xml.Serialization.XmlSerializer x;
                    byte[] bytes;
                    System.IO.MemoryStream ms;
                    FeaEntidades.InterFacturas.lote_comprobantes lote;

                    ventas.VentasXArticuloDetalle = new List<Entidades.VentasXArticuloDetalle>();
                    List<Entidades.VentasXArticuloDetalle> lvd = new List<Entidades.VentasXArticuloDetalle>();
                    Entidades.VentasXArticuloDetalle vd;
                    foreach (Entidades.Comprobante comprobante in listaC)
                    {
                        lote = new FeaEntidades.InterFacturas.lote_comprobantes();
                        x = new System.Xml.Serialization.XmlSerializer(lote.GetType());

                        comprobante.Response = comprobante.Response.Replace("iso-8859-1", "utf-16");
                        bytes = new byte[comprobante.Response.Length * sizeof(char)];
                        System.Buffer.BlockCopy(comprobante.Response.ToCharArray(), 0, bytes, 0, bytes.Length);
                        ms = new System.IO.MemoryStream(bytes);
                        ms.Seek(0, System.IO.SeekOrigin.Begin);
                        lote = (FeaEntidades.InterFacturas.lote_comprobantes)x.Deserialize(ms);

                        //Totales por artículo
                        if (lote.comprobante[0].detalle.linea != null)
                        {
                            for (int z = 0; z < lote.comprobante[0].detalle.linea.Length; z++)
                            {
                                double signo = 1;
                                if (("/3/8/13/").IndexOf("/" + Convert.ToInt32(lote.comprobante[0].cabecera.informacion_comprobante.tipo_de_comprobante).ToString().Trim() + "/") != -1)
                                {
                                    signo = -1;
                                }

                                //Verificar el articulo ya existe en la lista.
                                //List<Entidades.VentasXArticuloDetalle> listaAux = lvd.FindAll(delegate(Entidades.VentasXArticuloDetalle vxad)
                                //{
                                //    return vxad.IdArticulo == lote.comprobante[0].detalle.linea[z].codigo_producto_vendedor;
                                //});
                                //if (listaAux.Count == 0 || lote.comprobante[0].detalle.linea[z].codigo_producto_vendedor.Trim() == "")
                                //{
                                //}
                                vd = new Entidades.VentasXArticuloDetalle();
                                vd.IdArticulo = lote.comprobante[0].detalle.linea[z].codigo_producto_vendedor;
                                vd.GTIN = lote.comprobante[0].detalle.linea[z].GTIN.ToString();
                                vd.IdArticuloEmp = lote.comprobante[0].detalle.linea[z].codigo_producto_comprador;
                                if (lote.comprobante[0].detalle.linea[z].indicacion_exento_gravado != null)
                                {
                                    vd.IndicacionExentoGravado = lote.comprobante[0].detalle.linea[z].indicacion_exento_gravado;
                                }
                                else
                                {
                                    vd.IndicacionExentoGravado = "";
                                }
                                vd.NumeroLinea = lote.comprobante[0].detalle.linea[z].numeroLinea;
                                vd.UnidadCod = lote.comprobante[0].detalle.linea[z].unidad;
                                vd.UnidadDescr = lote.comprobante[0].detalle.linea[z].unidadDescripcion;
                                vd.CompTipo = lote.comprobante[0].cabecera.informacion_comprobante.tipo_de_comprobante.ToString();
                                vd.CompNro = lote.comprobante[0].cabecera.informacion_comprobante.numero_comprobante.ToString();
                                vd.CompPtoVta = lote.comprobante[0].cabecera.informacion_comprobante.punto_de_venta.ToString();
                                vd.CompFecEmi = lote.comprobante[0].cabecera.informacion_comprobante.fecha_emision.Substring(6, 2) + "/" + lote.comprobante[0].cabecera.informacion_comprobante.fecha_emision.Substring(4, 2) + "/" + lote.comprobante[0].cabecera.informacion_comprobante.fecha_emision.Substring(0, 4);

                                vd.EmpNroDoc = lote.comprobante[0].cabecera.informacion_comprador.nro_doc_identificatorio.ToString();
                                vd.EmpCodDoc = lote.comprobante[0].cabecera.informacion_comprador.codigo_doc_identificatorio.ToString();
                                vd.EmpDescrDoc = ""; //Obtener la descripcion; 
                                vd.EmpNombre = lote.comprobante[0].cabecera.informacion_comprador.denominacion;

                                if (lote.comprobante[0].detalle.linea[z].descripcion.Length > 0 && lote.comprobante[0].detalle.linea[z].descripcion.Substring(0, 1) == "%")
                                {
                                    vd.Descr = RN.Funciones.HexToString(lote.comprobante[0].detalle.linea[z].descripcion);
                                }
                                else
                                {
                                    vd.Descr = lote.comprobante[0].detalle.linea[z].descripcion;
                                }
                                vd.ImporteTotal = lote.comprobante[0].detalle.linea[z].importe_total_articulo * signo;
                                if (lote.comprobante[0].detalle.linea[z].cantidadSpecified == true && lote.comprobante[0].detalle.linea[z].precio_unitarioSpecified == true)
                                {
                                    vd.Cantidad = lote.comprobante[0].detalle.linea[z].cantidad * signo;
                                    vd.PrecioUnitario = lote.comprobante[0].detalle.linea[z].precio_unitario * signo;
                                }
                                if (lote.comprobante[0].detalle.linea[z].alicuota_ivaSpecified == true && lote.comprobante[0].detalle.linea[z].importe_ivaSpecified == true)
                                {
                                    vd.AlicuotaIVA = lote.comprobante[0].detalle.linea[z].alicuota_iva;
                                    vd.ImporteIVA = lote.comprobante[0].detalle.linea[z].importe_iva * signo;
                                }
                                lvd.Add(vd); 
                            }
                        }
                    }
                    //Si se muestran artículos vigentes no vendidos. 
                    List<Entidades.Articulo> listaArt = new List<Entidades.Articulo>();
                    if (VerTodosLosArticulosCheckBox.Enabled == true && VerTodosLosArticulosCheckBox.Checked == true)
                    {
                        listaArt = RN.Articulo.ListaPorCuit(true, false, sesion);
                        if (listaArt.Count != 0)
                        {
                            foreach (Entidades.Articulo art in listaArt)
                            {
                                bool existeArt = false;
                                if (lvd.Count != 0)
                                {
                                    System.Collections.Generic.List<Entidades.VentasXArticuloDetalle> listaVXArt = lvd.FindAll(delegate(Entidades.VentasXArticuloDetalle vxart)
                                    {
                                        return vxart.IdArticulo == art.Id;
                                    });
                                    if (listaVXArt.Count != 0)
                                    {
                                        existeArt = true;
                                    }
                                }
                                if (!existeArt)
                                {
                                    vd = new Entidades.VentasXArticuloDetalle();
                                    vd.IdArticulo = art.Id;
                                    vd.Descr = art.Descr;
                                    vd.CompFecEmi = "";
                                    vd.CompNro = "";
                                    vd.CompPtoVta = "";
                                    vd.CompTipo = "";
                                    vd.UnidadCod = "";
                                    vd.UnidadDescr = "";
                                    vd.IndicacionExentoGravado = "";
                                    vd.EmpNroDoc = "";
                                    vd.EmpCodDoc = "";
                                    vd.EmpDescrDoc = "";
                                    vd.EmpNombre = "";
                                    lvd.Add(vd);
                                }
                            }

                        }
                    }
                    if (lvd.Count != 0)
                    {
                        ventas.VentasXArticuloDetalle = lvd;
                    }
                    Session["formatoRptExportar"] = FormatosRptExportarDropDownList.SelectedValue;
                    Session["mostrarFechaYHora"] = FechaYHoraCheckBox.Checked;
                    Session["mostrarDetalleComprobantes"] = DetalleComprobanteCheckBox.Checked;
                    Session["monedasExtranjeras"] = monedasExtranjeras;
                    if (ventas.VentasXArticuloDetalle.Count != 0)
                    {
                        Session["ventasXArticulo"] = ventas;
                        Response.Redirect("~/Facturacion/Electronica/Reportes/VentasXArticuloWebForm.aspx", true);
                    }
                    else
                    {
                        MensajeLabel.Text = "No hay información.";
                    }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    Trace.Warn("Thread abortado");
                }
                catch (Exception ex)
                {
                    WebForms.Excepciones.Redireccionar(ex, "~/NotificacionDeExcepcion.aspx");
                }
            }
        }
Exemple #4
0
        protected void Page_Init(object sender, EventArgs e)
        {
            try
            {
                var culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");
                culture.NumberFormat.CurrencySymbol = string.Empty;
                System.Threading.Thread.CurrentThread.CurrentCulture   = culture;
                System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
                base.InitializeCulture();

                string lcomp = Server.MapPath("~/Facturacion/Electronica/Reportes/Ventas_XArticulo.xsd");
                System.IO.File.Copy(lcomp, @System.IO.Path.GetTempPath() + "Ventas_XArticulo.xsd", true);

                oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

                bool   HayME      = false;
                string reportPath = "";
                if (Session["monedasExtranjeras"] != null)
                {
                    HayME = (bool)Session["monedasExtranjeras"];
                }
                if (!HayME)
                {
                    reportPath = Server.MapPath("~/Facturacion/Electronica/Reportes/VentasXArticulo.rpt");
                }
                else
                {
                    reportPath = Server.MapPath("~/Facturacion/Electronica/Reportes/VentasXArticuloME.rpt");
                }
                oRpt.Load(reportPath);
                Entidades.VentasXArticulo ventasXArticulo = new Entidades.VentasXArticulo();
                if (Session["ventasXArticulo"] != null)
                {
                    ventasXArticulo = (Entidades.VentasXArticulo)Session["ventasXArticulo"];
                    DataSet       ds    = new DataSet();
                    XmlSerializer objXS = new XmlSerializer(ventasXArticulo.GetType());
                    StringWriter  objSW = new StringWriter();
                    objXS.Serialize(objSW, ventasXArticulo);
                    StringReader objSR = new StringReader(objSW.ToString());
                    ds.ReadXml(objSR);
                    oRpt.SetDataSource(ds);
                }
                else
                {
                    Response.Redirect("~/Facturacion/Electronica/Reportes/VentasXArticuloFiltros.aspx", true);
                }
                string formatoRptExportar = "";
                if (Session["formatoRptExportar"] != null)
                {
                    formatoRptExportar = (string)Session["formatoRptExportar"];
                }
                if (Session["mostrarFechaYHora"] != null)
                {
                    if ((bool)Session["mostrarFechaYHora"] == false)
                    {
                        oRpt.DataDefinition.FormulaFields["MostrarFechaYHora"].Text = "'N'";
                    }
                }
                if (Session["mostrarDetalleComprobantes"] != null)
                {
                    if ((bool)Session["mostrarDetalleComprobantes"] == false)
                    {
                        oRpt.DataDefinition.FormulaFields["MostrarDetalleComprobantes"].Text = "'N'";
                    }
                }
                oRpt.PrintOptions.PaperSize        = CrystalDecisions.Shared.PaperSize.PaperLetter;
                oRpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait;
                //oRpt.DataDefinition.FormulaFields["RazSoc"].Text = "'" + ((Entidades.Sesion)Session["Sesion"]).Cuit.RazonSocial + "'";
                if (formatoRptExportar == "")
                {
                    CrystalReportViewer1.GroupTreeStyle.ShowLines = false;
                    CrystalReportViewer1.HasToggleGroupTreeButton = false;
                    CrystalReportViewer1.ToolPanelView            = CrystalDecisions.Web.ToolPanelViewType.None;
                    CrystalReportViewer1.ReportSource             = oRpt;
                    CrystalReportViewer1.HasPrintButton           = true;
                }
                else
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    sb.Append(ventasXArticulo.Cuit);
                    sb.Append("-");
                    sb.Append(Convert.ToDateTime(ventasXArticulo.PeriodoDsd).ToString("yyyyMMdd"));
                    sb.Append("-");
                    sb.Append(Convert.ToDateTime(ventasXArticulo.PeriodoHst).ToString("yyyyMMdd"));

                    if (formatoRptExportar == "PDF")
                    {
                        CrystalDecisions.Shared.ExportOptions           exportOpts = new CrystalDecisions.Shared.ExportOptions();
                        CrystalDecisions.Shared.PdfRtfWordFormatOptions pdfOpts    = CrystalDecisions.Shared.ExportOptions.CreatePdfRtfWordFormatOptions();
                        exportOpts.ExportFormatType    = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                        exportOpts.ExportFormatOptions = pdfOpts;
                        oRpt.ExportToHttpResponse(exportOpts, Response, true, sb.ToString());
                    }
                    if (formatoRptExportar == "Excel")
                    {
                        CrystalDecisions.Shared.ExportOptions      exportOpts = new CrystalDecisions.Shared.ExportOptions();
                        CrystalDecisions.Shared.ExcelFormatOptions pdfOpts    = CrystalDecisions.Shared.ExportOptions.CreateExcelFormatOptions();
                        exportOpts.ExportFormatType    = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                        exportOpts.ExportFormatOptions = pdfOpts;
                        oRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.Excel, Server.MapPath("~/TempExcel/") + sb.ToString() + ".xls");

                        System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                        response.ClearContent();
                        response.Clear();
                        response.ContentType = "application/vnd.ms-excel";
                        response.AddHeader("Content-Disposition", "attachment; filename=" + sb.ToString() + ".xls" + ";");
                        response.TransmitFile(Server.MapPath("~/TempExcel/" + sb.ToString() + ".xls"));
                        response.Flush();
                        response.End();
                    }
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
                Trace.Warn("Thread abortado");
            }
            catch (Exception ex)
            {
                WebForms.Excepciones.Redireccionar(ex, "~/NotificacionDeExcepcion.aspx");
            }
        }