Esempio n. 1
0
        public static ReportExportResult ExportReportToFormat(ReportViewerModel model, string format, int?startPage = 0, int?endPage = 0)
        {
            ReportExportResult exportResult = new ReportExportResult();

            try
            {
                string resultHTML;
                ReportViewerForCore.ReportExecutionService.TrustedUserHeader trusteduserHeader = null;

                var url = AddCharacterStartEnd(model.ServerUrl, false, true, "/") + "ReportExecution2005.asmx";
                var basicHttpBinding = _initializeHttpBinding(url, model);
                var service          = new ReportExecutionService.ReportExecutionServiceSoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url));
                service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                service.ClientCredentials.Windows.ClientCredential          = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultCredentials);

                // https://stackoverflow.com/questions/44036903/using-reporting-services-ssrs-as-a-reference-in-an-asp-net-core-site/49202193
                service.Endpoint.EndpointBehaviors.Add(new ReportingServicesEndpointBehavior());

                var definedReportParameters = GetReportParameters(model, true);
                exportResult.CurrentPage = (startPage.ToInt32() <= 0 ? 1 : startPage.ToInt32());
                exportResult.SetParameters(definedReportParameters, model.Parameters);

                if (startPage == 0)
                {
                    startPage = 1;
                }

                if (endPage == 0)
                {
                    endPage = startPage;
                }

                if (string.IsNullOrWhiteSpace(format))
                {
                    format = "HTML5";
                }

                string outputFormat   = $"<OutputFormat>{format}</OutputFormat>";
                string encodingFormat = $"<Encoding>{model.Encoding.EncodingName}</Encoding>";

                /* Remueve tagas HTML, Body y otros, y retorna tabla para ser ebebida en una pagina */
                string htmlFragment = (((format.ToUpper() == "HTML4.0" || format.ToUpper() == "HTML5") && model.UseCustomReportImagePath == false && model.ViewMode == ReportViewModes.View) ? "<HTMLFragment>true</HTMLFragment>" : "");

                string deviceConfig = "<ExpandContent>true</ExpandContent><AccessibleTablix>g</AccessibleTablix>";
                deviceConfig += "<StyleStream>false</StyleStream><StreamRoot>/</StreamRoot>";
                deviceConfig  = "<Parameters>Collapsed</Parameters>";

                var deviceInfo = $"<DeviceInfo>{outputFormat}{encodingFormat}<Toolbar>false</Toolbar>{htmlFragment}{deviceConfig}</DeviceInfo>";
                if (model.ViewMode == ReportViewModes.View && startPage.HasValue && startPage > 0)
                {
                    if (model.EnablePaging)
                    {
                        deviceInfo = $"<DeviceInfo>{outputFormat}<Toolbar>false</Toolbar>{htmlFragment}{deviceConfig}<Section>{startPage}</Section></DeviceInfo>";
                    }
                    else
                    {
                        deviceInfo = $"<DeviceInfo>{outputFormat}<Toolbar>false</Toolbar>{htmlFragment}{deviceConfig}</DeviceInfo>";
                    }
                }

                var reportParameters = new List <ReportExecutionService.ParameterValue>();
                foreach (var parameter in exportResult.Parameters)
                {
                    bool addedParameter = false;
                    foreach (var value in parameter.SelectedValues)
                    {
                        var reportParameter = new ReportExecutionService.ParameterValue();
                        reportParameter.Name  = parameter.Name;
                        reportParameter.Value = value;
                        reportParameters.Add(reportParameter);

                        addedParameter = true;
                    }

                    if (!addedParameter)
                    {
                        var reportParameter = new ReportExecutionService.ParameterValue();
                        reportParameter.Name = parameter.Name;
                        reportParameters.Add(reportParameter);
                    }
                }

                ReportViewerForCore.ReportExecutionService.ServerInfoHeader serverInfoHeader = new ReportViewerForCore.ReportExecutionService.ServerInfoHeader();
                ReportExecutionService.ExecutionHeader    executionHeader = new ReportExecutionService.ExecutionHeader();
                ReportExecutionService.ExecutionInfo      executionInfo   = new ReportExecutionService.ExecutionInfo();
                ReportExecutionService.LoadReportResponse loadResponse    = new ReportExecutionService.LoadReportResponse();
                ReportExecutionService.Render2Response    render2Response;
                string   historyID = null;
                string   extension = null;
                string   encoding  = null;
                string   mimeType  = null;
                string[] streamIDs = null;
                ReportExecutionService.Warning[] warnings = null;

                try
                {
                    //executionHeader = service.LoadReport(trusteduserHeader, model.ReportPath, historyID, out serverInfoHeader, out executionInfo);

                    loadResponse    = service.LoadReportAsync(trusteduserHeader, model.ReportPath, historyID).Result;
                    executionInfo   = loadResponse.executionInfo;
                    executionHeader = loadResponse.ExecutionHeader;

                    //var executionParameterResult = service.SetReportParameters(executionInfo.ExecutionID, reportParameters.ToArray(), "en-us").Result;
                    serverInfoHeader = service.SetExecutionParameters(executionHeader, trusteduserHeader, reportParameters.ToArray(), "en-us", out executionInfo);

                    if (model.EnablePaging)
                    {
                        var render2Request = new ReportExecutionService.Render2Request(executionHeader, trusteduserHeader, format, deviceInfo, ReportExecutionService.PageCountMode.Actual);
                        //var render2Response = service.Render2(executionInfo.ExecutionID, render2Request).Result;
                        render2Response = service.Render2Async(render2Request).Result;

                        extension = render2Response.Extension;
                        mimeType  = render2Response.MimeType;
                        encoding  = render2Response.Encoding;
                        warnings  = render2Response.Warnings;
                        streamIDs = render2Response.StreamIds;

                        exportResult.ReportData = render2Response.Result;
                    }
                    else
                    {
                        var renderRequest = new ReportExecutionService.RenderRequest(executionHeader, trusteduserHeader, format, deviceInfo);
                        //var renderResponse = service.Render(executionInfo.ExecutionID, renderRequest).Result;
                        var renderResponse = service.RenderAsync(renderRequest).Result;

                        extension = renderResponse.Extension;
                        mimeType  = renderResponse.MimeType;
                        encoding  = renderResponse.Encoding;
                        warnings  = renderResponse.Warnings;
                        streamIDs = renderResponse.StreamIds;

                        exportResult.ReportData = renderResponse.Result;
                    }

                    resultHTML = model.Encoding.GetString(exportResult.ReportData);
                    //executionInfo = service.GetExecutionInfo(executionHeader.ExecutionID).Result;
                }
                catch (Exception ex2)
                {
                    Console.WriteLine(ex2.Message);
                }

                exportResult.ExecutionInfo = executionInfo;
                exportResult.Format        = format;
                exportResult.MimeType      = mimeType;
                exportResult.StreamIDs     = (streamIDs == null ? new List <string>() : streamIDs.ToList());
                exportResult.Warnings      = (warnings == null ? new List <ReportExecutionService.Warning>() : warnings.ToList());

                if (executionInfo != null)
                {
                    exportResult.TotalPages = executionInfo.NumPages;
                }

                resultHTML = model.Encoding.GetString(exportResult.ReportData);

                return(exportResult);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(exportResult);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Searches a specific report for your provided searchText and returns the page that it located the text on.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="searchText">The text that you want to search in the report</param>
        /// <param name="startPage">Starting page for the search to begin from.</param>
        /// <returns></returns>
        public static int?FindStringInReport(ReportViewerModel model, string searchText, int?startPage = 0)
        {
            try
            {
                int endPage;
                ReportViewerForCore.ReportExecutionService.TrustedUserHeader trusteduserHeader = null;

                var url = AddCharacterStartEnd(model.ServerUrl, false, true, "/") + "ReportExecution2005.asmx";

                var basicHttpBinding = _initializeHttpBinding(url, model);
                var service          = new ReportExecutionService.ReportExecutionServiceSoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url));
                service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                service.ClientCredentials.Windows.ClientCredential          = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultCredentials);

                // https://stackoverflow.com/questions/44036903/using-reporting-services-ssrs-as-a-reference-in-an-asp-net-core-site/49202193
                service.Endpoint.EndpointBehaviors.Add(new ReportingServicesEndpointBehavior());

                var definedReportParameters = GetReportParameters(model, true);

                if (!startPage.HasValue || startPage == 0)
                {
                    startPage = 1;
                }

                var exportResult = new ReportExportResult();
                exportResult.CurrentPage = startPage.ToInt32();
                exportResult.SetParameters(definedReportParameters, model.Parameters);

                var format         = "HTML5";
                var outputFormat   = $"<OutputFormat>{format}</OutputFormat>";
                var encodingFormat = $"<Encoding>{model.Encoding.EncodingName}</Encoding>";
                var htmlFragment   = (((format.ToUpper() == "HTML4.0" || format.ToUpper() == "HTML5") && model.UseCustomReportImagePath == false && model.ViewMode == ReportViewModes.View) ? "<HTMLFragment>true</HTMLFragment>" : "");

                var deviceInfo = $"<DeviceInfo>{outputFormat}{encodingFormat}<Toolbar>False</Toolbar>{htmlFragment}</DeviceInfo>";
                if (model.ViewMode == ReportViewModes.View && startPage.HasValue && startPage > 0)
                {
                    deviceInfo = $"<DeviceInfo>{outputFormat}<Toolbar>False</Toolbar>{htmlFragment}<Section>{startPage}</Section></DeviceInfo>";
                }

                var reportParameters = new List <ReportExecutionService.ParameterValue>();
                foreach (var parameter in exportResult.Parameters)
                {
                    bool addedParameter = false;
                    foreach (var value in parameter.SelectedValues)
                    {
                        var reportParameter = new ReportExecutionService.ParameterValue();
                        reportParameter.Name  = parameter.Name;
                        reportParameter.Value = value;
                        reportParameters.Add(reportParameter);

                        addedParameter = true;
                    }

                    if (!addedParameter)
                    {
                        var reportParameter = new ReportExecutionService.ParameterValue();
                        reportParameter.Name = parameter.Name;
                        reportParameters.Add(reportParameter);
                    }
                }

                ReportViewerForCore.ReportExecutionService.ServerInfoHeader serverInfoHeader = new ReportViewerForCore.ReportExecutionService.ServerInfoHeader();
                ReportExecutionService.ExecutionHeader    executionHeader = new ReportExecutionService.ExecutionHeader();
                ReportExecutionService.ExecutionInfo      executionInfo   = new ReportExecutionService.ExecutionInfo();
                ReportExecutionService.LoadReportResponse loadResponse    = new ReportExecutionService.LoadReportResponse();
                ReportExecutionService.Render2Response    render2Response;
                string   historyID = null;
                string   extension = null;
                string   encoding  = null;
                string   mimeType  = null;
                string[] streamIDs = null;
                ReportExecutionService.Warning[] warnings = null;

                try
                {
                    //executionHeader = service.LoadReport(trusteduserHeader, model.ReportPath, historyID, out serverInfoHeader, out executionInfo);
                    loadResponse    = service.LoadReportAsync(trusteduserHeader, model.ReportPath, historyID).Result;
                    executionInfo   = loadResponse.executionInfo;
                    executionHeader = loadResponse.ExecutionHeader;

                    //var executionParameterResult = service.SetReportParameters(executionInfo.ExecutionID, reportParameters.ToArray(), "en-us").Result;
                    serverInfoHeader = service.SetExecutionParameters(executionHeader, trusteduserHeader, reportParameters.ToArray(), "en-us", out executionInfo);

                    var render2Request = new ReportExecutionService.Render2Request(executionHeader, trusteduserHeader, format, deviceInfo, ReportExecutionService.PageCountMode.Actual);
                    //var render2Response = service.Render2(executionInfo.ExecutionID, render2Request).Result;
                    render2Response = service.Render2Async(render2Request).Result;

                    extension = render2Response.Extension;
                    mimeType  = render2Response.MimeType;
                    encoding  = render2Response.Encoding;
                    warnings  = render2Response.Warnings;
                    streamIDs = render2Response.StreamIds;

                    // executionInfo = service.GetExecutionInfo(executionHeader.ExecutionID).Result;

                    endPage = executionInfo.NumPages;
                    if (endPage < 1)
                    {
                        endPage = startPage.Value;
                    }

                    return(service.FindStringAsync(executionHeader, trusteduserHeader, startPage.Value, endPage, searchText).Result.PageNumber);
                }
                catch (Exception ex2)
                {
                    Console.WriteLine(ex2.Message);
                }

                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(0);
            }
        }
Esempio n. 3
0
        protected void btnReporte_Click(object sender, EventArgs e)
        {
            if (DDLFiltroEstado.SelectedValue == "0")
            {
                String vError = String.Empty;
                try
                {
                    ReportExecutionService.ReportExecutionService vRSE = new ReportExecutionService.ReportExecutionService();
                    vRSE.Credentials = new NetworkCredential("report_user", "kEbn2HUzd$Fs2T", "adbancat.hn");
                    vRSE.Url         = "http://10.128.0.52/reportserver/reportexecution2005.asmx";



                    vRSE.ExecutionHeaderValue = new ReportExecutionService.ExecutionHeader();
                    var vEInfo = new ReportExecutionService.ExecutionInfo();
                    vEInfo = vRSE.LoadReport("/STEI/reporteMantenimientoCorGlobal", null);


                    //String vIDEstado = DDLFiltroEstado.SelectedValue;
                    List <ReportExecutionService.ParameterValue> vParametros = new List <ReportExecutionService.ParameterValue>();
                    //vParametros.Add(new ReportExecutionService.ParameterValue { Name = "ID", Value = vIDEstado });



                    vRSE.SetExecutionParameters(vParametros.ToArray(), "en-US");



                    String   deviceinfo = "<DeviceInfo><Toolbar>false</Toolbar></DeviceInfo>";
                    String   mime;
                    String   encoding;
                    string[] stream;
                    ReportExecutionService.Warning[] warning;



                    byte[] vResultado = vRSE.Render("EXCEL", deviceinfo, out mime, out encoding, out encoding, out warning, out stream);
                    //byte[] vResultado = vRSE.Render("pdf", deviceinfo, out mime, out encoding, out encoding, out warning, out stream);

                    //File.WriteAllBytes("c:\\files\\test.pdf", vResultado);

                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
                    //Response.AppendHeader("Content-Type", "application/pdf");
                    byte[] bytFile = vResultado;
                    Response.OutputStream.Write(bytFile, 0, bytFile.Length);
                    Response.AddHeader("Content-disposition", "attachment;filename=EstadoMantenimientoCorGlobal.xls");
                    //Response.AddHeader("Content-disposition", "attachment;filename=DescargaPDFArea.pdf");
                    Response.End();
                }
                catch (Exception Ex) { vError = Ex.Message; }
                DDLFiltroEstado.SelectedValue = "0";
            }
            else
            {
                String vError = String.Empty;
                try
                {
                    ReportExecutionService.ReportExecutionService vRSE = new ReportExecutionService.ReportExecutionService();
                    vRSE.Credentials = new NetworkCredential("report_user", "kEbn2HUzd$Fs2T", "adbancat.hn");
                    vRSE.Url         = "http://10.128.0.52/reportserver/reportexecution2005.asmx";



                    vRSE.ExecutionHeaderValue = new ReportExecutionService.ExecutionHeader();
                    var vEInfo = new ReportExecutionService.ExecutionInfo();
                    vEInfo = vRSE.LoadReport("/STEI/reporteMantenimientoCorrectivo", null);


                    String vIDEstado = DDLFiltroEstado.SelectedValue;
                    List <ReportExecutionService.ParameterValue> vParametros = new List <ReportExecutionService.ParameterValue>();
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "ID", Value = vIDEstado
                    });



                    vRSE.SetExecutionParameters(vParametros.ToArray(), "en-US");



                    String   deviceinfo = "<DeviceInfo><Toolbar>false</Toolbar></DeviceInfo>";
                    String   mime;
                    String   encoding;
                    string[] stream;
                    ReportExecutionService.Warning[] warning;



                    byte[] vResultado = vRSE.Render("EXCEL", deviceinfo, out mime, out encoding, out encoding, out warning, out stream);
                    //byte[] vResultado = vRSE.Render("pdf", deviceinfo, out mime, out encoding, out encoding, out warning, out stream);

                    //File.WriteAllBytes("c:\\files\\test.pdf", vResultado);

                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
                    //Response.AppendHeader("Content-Type", "application/pdf");
                    byte[] bytFile = vResultado;
                    Response.OutputStream.Write(bytFile, 0, bytFile.Length);
                    Response.AddHeader("Content-disposition", "attachment;filename=EstadoMantenimientoCor" + DDLFiltroEstado.SelectedItem.Text + ".xls");
                    //Response.AddHeader("Content-disposition", "attachment;filename=DescargaPDFArea.pdf");
                    Response.End();
                }
                catch (Exception Ex) { vError = Ex.Message; }
                DDLFiltroEstado.SelectedValue = "0";
            }
        }
Esempio n. 4
0
    public string RenderReport(string reportpath, SSRSExportType ExportType)
    {
        using (ReportExecutionService.ReportExecutionServiceSoapClient res = new   ReportExecutionService.ReportExecutionServiceSoapClient("ReportExecutionServiceSoap"))
        {
            ReportExecutionService.ExecutionHeader   ExecutionHeader   = new ReportExecutionService.ExecutionHeader();
            ReportExecutionService.TrustedUserHeader TrusteduserHeader = new ReportExecutionService.TrustedUserHeader();

            res.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

            ReportServerCreds rsc = GetReportCreds();
            res.ClientCredentials.Windows.ClientCredential.Domain   = rsc.Domain;
            res.ClientCredentials.Windows.ClientCredential.UserName = rsc.UserName;
            res.ClientCredentials.Windows.ClientCredential.Password = rsc.Password;


            res.Open();
            ReportExecutionService.ExecutionInfo ei = new ReportExecutionService.ExecutionInfo();

            string format     = null;
            string deviceinfo = null;
            string mimetype   = null;

            if (ExportType.ToString().ToLower() == "html")
            {
                format     = "HTML4.0";
                deviceinfo = @"<DeviceInfo><StreamRoot>/</StreamRoot><HTMLFragment>True</HTMLFragment></DeviceInfo>";
            }
            else if (ExportType.ToString().ToLower() == "pdf")
            {
                format   = "PDF";
                mimetype = "";
            }


            byte[] results   = null;
            string extension = null;
            string Encoding  = null;
            ReportExecutionService.Warning[] warnings;
            string[] streamids = null;
            string   historyid = null;
            ReportExecutionService.ExecutionHeader  Eheader;
            ReportExecutionService.ServerInfoHeader serverinfoheader;
            ReportExecutionService.ExecutionInfo    executioninfo;



            // Get available parameters from specified report.
            ParameterValue[]        paramvalues = null;
            DataSourceCredentials[] dscreds     = null;
            ReportParameter[]       rparams     = null;

            using (ReportService.ReportingService2005SoapClient lrs = new ReportService.ReportingService2005SoapClient("ReportingService2005Soap"))
            {
                lrs.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                lrs.ClientCredentials.Windows.ClientCredential.Domain   = rsc.Domain;
                lrs.ClientCredentials.Windows.ClientCredential.UserName = rsc.UserName;
                lrs.ClientCredentials.Windows.ClientCredential.Password = rsc.Password;


                lrs.GetReportParameters(reportpath, historyid, false, paramvalues, dscreds, out rparams);
            }



            // Set report parameters here
            //List<ReportExecutionService.ParameterValue> parametervalues = new List<ReportExecutionService.ParameterValue>();

            //string enumber = Session["ENumber"] as string;
            //parametervalues.Add(new ReportExecutionService.ParameterValue() { Name = "ENumber", Value = enumber });

            //if (date != null)
            //{
            //    DateTime dt = DateTime.Today;
            //parametervalues.Add(new ReportExecutionService.ParameterValue() { Name = "AttendanceDate", Value = dt.ToString("MM/dd/yyyy")});
            //}

            //if (ContainsParameter(rparams, "DEEWRID"))
            //{
            //parametervalues.Add(new ReportExecutionService.ParameterValue() { Name = "DEEWRID", Value = deewrid });
            //}

            //if (ContainsParameter(rparams, "BaseHostURL"))
            //{
            //                        parametervalues.Add(new ReportExecutionService.ParameterValue() { Name = "BaseHostURL", Value = string.Concat("http://", Request.Url.Authority) });
            //}


            //parametervalues.Add(new ReportExecutionService.ParameterValue() {Name="AttendanceDate",Value=null });
            //parametervalues.Add(new ReportExecutionService.ParameterValue() { Name = "ENumber", Value = "E1013" });



            try
            {
                Eheader          = res.LoadReport(TrusteduserHeader, reportpath, historyid, out serverinfoheader, out executioninfo);
                serverinfoheader = res.SetExecutionParameters(Eheader, TrusteduserHeader, parametervalues.ToArray(), null, out executioninfo);
                res.Render(Eheader, TrusteduserHeader, format, deviceinfo, out results, out extension, out mimetype, out Encoding, out warnings, out streamids);

                string exportfilename = string.Concat(enumber, reportpath);

                if (ExportType.ToString().ToLower() == "html")
                {
                    //write html
                    string html = string.Empty;
                    html = System.Text.Encoding.Default.GetString(results);

                    html = GetReportImages(res, Eheader, TrusteduserHeader, format, streamids, html);

                    return(html);
                }
                else if (ExportType.ToString().ToLower() == "pdf")
                {
                    //write to pdf


                    Response.Buffer = true;
                    Response.Clear();
                    Response.ContentType = mimetype;



                    //Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.pdf", exportfilename));
                    Response.BinaryWrite(results);
                    Response.Flush();
                    Response.End();
                }
            }
            catch (Exception e)
            {
                Response.Write(e.Message);
            }
        }
    }
        protected void BtnConfirmar_Click(object sender, EventArgs e)
        {
            try{
                if (DDLReporte.SelectedValue.Equals("1"))
                {
                    DataTable vDatos     = (DataTable)Session["DOCUMENTO_REPORTE"];
                    string    Parametro1 = vDatos.Rows[0]["idCategoria"].ToString();
                    string    Parametro2 = DDLDocumento.SelectedValue;

                    ReportExecutionService.ReportExecutionService vRSE = new ReportExecutionService.ReportExecutionService();
                    vRSE.Credentials = new NetworkCredential("report_user", "kEbn2HUzd$Fs2T", "adbancat.hn");
                    vRSE.Url         = "http://10.128.0.52/reportserver/reportexecution2005.asmx";

                    vRSE.ExecutionHeaderValue = new ReportExecutionService.ExecutionHeader();
                    var vEInfo = new ReportExecutionService.ExecutionInfo();
                    vEInfo = vRSE.LoadReport("/Recursos Humanos Interno/GestionDocumentalConsultas", null);

                    List <ReportExecutionService.ParameterValue> vParametros = new List <ReportExecutionService.ParameterValue>();
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D1", Value = Parametro1
                    });
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D2", Value = Parametro2
                    });

                    vRSE.SetExecutionParameters(vParametros.ToArray(), "en-US");
                    String   deviceinfo = "<DeviceInfo><Toolbar>false</Toolbar></DeviceInfo>";
                    String   mime;
                    String   encoding;
                    string[] stream;
                    ReportExecutionService.Warning[] warning;

                    byte[] vResultado = vRSE.Render("EXCEL", deviceinfo, out mime, out encoding, out encoding, out warning, out stream);

                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
                    byte[] bytFile = vResultado;
                    Response.OutputStream.Write(bytFile, 0, bytFile.Length);
                    Response.AddHeader("Content-disposition", "attachment;filename=Reporte.xls");
                    Response.End();
                }
                else if (DDLReporte.SelectedValue.Equals("2"))
                {
                    string Parametro1 = DDLTipoPDoc.SelectedValue;

                    ReportExecutionService.ReportExecutionService vRSE = new ReportExecutionService.ReportExecutionService();
                    vRSE.Credentials = new NetworkCredential("report_user", "kEbn2HUzd$Fs2T", "adbancat.hn");
                    vRSE.Url         = "http://10.128.0.52/reportserver/reportexecution2005.asmx";

                    vRSE.ExecutionHeaderValue = new ReportExecutionService.ExecutionHeader();
                    var vEInfo = new ReportExecutionService.ExecutionInfo();
                    vEInfo = vRSE.LoadReport("/Recursos Humanos Interno/GestionDocumentalInventario", null);

                    List <ReportExecutionService.ParameterValue> vParametros = new List <ReportExecutionService.ParameterValue>();
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D1", Value = Parametro1
                    });


                    vRSE.SetExecutionParameters(vParametros.ToArray(), "en-US");
                    String   deviceinfo = "<DeviceInfo><Toolbar>false</Toolbar></DeviceInfo>";
                    String   mime;
                    String   encoding;
                    string[] stream;
                    ReportExecutionService.Warning[] warning;

                    byte[] vResultado = vRSE.Render("EXCEL", deviceinfo, out mime, out encoding, out encoding, out warning, out stream);

                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
                    byte[] bytFile = vResultado;
                    Response.OutputStream.Write(bytFile, 0, bytFile.Length);
                    string nombreExcel = "ReporteInventario" + DDLTipoPDoc.SelectedItem.Text + ".xls";
                    Response.AddHeader("Content-disposition", "attachment;filename=" + nombreExcel);
                    Response.End();
                }
                limpiarDatos();
            }
            catch (Exception Ex) {
                Mensaje(Ex.Message, WarningType.Danger);
            }
        }
Esempio n. 6
0
        protected void BtnDescargarModal_Click(object sender, EventArgs e)
        {
            try {
                if (Session["STEIDREPORTE"].Equals("1"))
                {
                    string Parametro1 = Session["STEPARAMETRO1"].ToString();
                    string Parametro2 = Session["STEPARAMETRO2"].ToString();
                    string Parametro3 = Session["STEPARAMETRO3"].ToString();
                    string Parametro4 = Session["STEPARAMETRO4"].ToString();

                    ReportExecutionService.ReportExecutionService vRSE = new ReportExecutionService.ReportExecutionService();
                    vRSE.Credentials = new NetworkCredential("report_user", "kEbn2HUzd$Fs2T", "adbancat.hn");
                    vRSE.Url         = "http://10.128.0.52/reportserver/reportexecution2005.asmx";

                    vRSE.ExecutionHeaderValue = new ReportExecutionService.ExecutionHeader();
                    var vEInfo = new ReportExecutionService.ExecutionInfo();
                    vEInfo = vRSE.LoadReport("/Recursos Humanos Interno/TiempoExtraordinarioCargaSap", null);

                    List <ReportExecutionService.ParameterValue> vParametros = new List <ReportExecutionService.ParameterValue>();
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D1", Value = Parametro1
                    });
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D2", Value = Parametro2
                    });
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D3", Value = Parametro3
                    });
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D4", Value = Parametro4
                    });

                    vRSE.SetExecutionParameters(vParametros.ToArray(), "en-US");

                    String   deviceinfo = "<DeviceInfo><Toolbar>false</Toolbar></DeviceInfo>";
                    String   mime;
                    String   encoding;
                    string[] stream;
                    ReportExecutionService.Warning[] warning;

                    byte[] vResultado = vRSE.Render("EXCEL", deviceinfo, out mime, out encoding, out encoding, out warning, out stream);

                    //File.WriteAllBytes("c:\\files\\test.pdf", vResultado);

                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
                    byte[] bytFile = vResultado;
                    Response.OutputStream.Write(bytFile, 0, bytFile.Length);
                    Response.AddHeader("Content-disposition", "attachment;filename=CargaSap.xls");
                    Response.End();
                }
                else if (Session["STEIDREPORTE"].Equals("2"))
                {
                    string Parametro1 = Session["STEPARAMETRO1"].ToString();
                    string Parametro2 = Session["STEPARAMETRO2"].ToString();
                    string Parametro3 = Session["STEPARAMETRO3"].ToString();
                    string Parametro4 = Session["STEPARAMETRO4"].ToString();

                    ReportExecutionService.ReportExecutionService vRSE = new ReportExecutionService.ReportExecutionService();
                    vRSE.Credentials = new NetworkCredential("report_user", "kEbn2HUzd$Fs2T", "adbancat.hn");
                    vRSE.Url         = "http://10.128.0.52/reportserver/reportexecution2005.asmx";

                    vRSE.ExecutionHeaderValue = new ReportExecutionService.ExecutionHeader();
                    var vEInfo = new ReportExecutionService.ExecutionInfo();
                    vEInfo = vRSE.LoadReport("/Recursos Humanos Interno/TiempoExtraordinarioFacturacionBanco", null);

                    List <ReportExecutionService.ParameterValue> vParametros = new List <ReportExecutionService.ParameterValue>();
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D1", Value = Parametro1
                    });
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D2", Value = Parametro2
                    });
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D3", Value = Parametro3
                    });
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "D4", Value = Parametro4
                    });

                    vRSE.SetExecutionParameters(vParametros.ToArray(), "en-US");

                    String   deviceinfo = "<DeviceInfo><Toolbar>false</Toolbar></DeviceInfo>";
                    String   mime;
                    String   encoding;
                    string[] stream;
                    ReportExecutionService.Warning[] warning;

                    byte[] vResultado = vRSE.Render("EXCEL", deviceinfo, out mime, out encoding, out encoding, out warning, out stream);

                    //File.WriteAllBytes("c:\\files\\test.pdf", vResultado);

                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
                    byte[] bytFile = vResultado;
                    Response.OutputStream.Write(bytFile, 0, bytFile.Length);
                    Response.AddHeader("Content-disposition", "attachment;filename=FactBanco.xls");
                    Response.End();
                }
                else if (Session["STEIDREPORTE"].Equals("3"))
                {
                    SmtpService vService = new SmtpService();

                    string Parametro1 = Session["STEPARAMETRO1"].ToString();
                    string Parametro2 = Session["STEPARAMETRO2"].ToString();
                    string Parametro3 = Session["STEPARAMETRO3"].ToString();
                    string Parametro4 = Session["STEPARAMETRO4"].ToString();

                    DataTable vDatos = new DataTable();
                    String    vQuery = "RSP_TiempoExtraordinarioConsolidado 1,'" + Parametro1 + "','" + Parametro2 + "','" + Parametro3 + "','" + Parametro4 + "'";
                    vDatos = vConexion.obtenerDataTable(vQuery);

                    DataTable vDatosSolicitudes = new DataTable();
                    for (int i = 0; i < vDatos.Rows.Count; i++)
                    {
                        string vCodigoSAP = vDatos.Rows[i]["codigo"].ToString();

                        String vQuerySolicitudes = "RSP_TiempoExtraordinarioConsolidado 2,'" + Parametro1 + "','" + Parametro2 + "','" + Parametro3 + "','" + Parametro4 + "','" + vCodigoSAP + "'";
                        vDatosSolicitudes = vConexion.obtenerDataTable(vQuerySolicitudes);
                        vService.EnviarMensaje(
                            vDatos.Rows[i]["emailEmpresa"].ToString(),
                            typeBody.Reporte,
                            vDatos.Rows[i]["nombre"].ToString(),
                            "REPORTE DE CONSOLIDADO DE TIEMPO EXTRAORDINARIO.",
                            null,
                            ConfigurationManager.AppSettings["RHMail"].ToString(),
                            vDatosSolicitudes
                            );
                    }
                }
            }catch (Exception Ex) {
                Mensaje(Ex.Message, WarningType.Danger);
            }
        }
        protected void btnReporteMotivoViaje_Click(object sender, EventArgs e)
        {
            if (DDLMotivoViaje.SelectedValue == "0")
            {
                DDLMotivoViaje.SelectedValue = "0";
                Mensaje("Debe seleccionar motivo de viaje al que generará reporte", WarningType.Warning);
            }
            else
            {
                String vError = String.Empty;
                try
                {
                    ReportExecutionService.ReportExecutionService vRSE = new ReportExecutionService.ReportExecutionService();
                    vRSE.Credentials = new NetworkCredential("report_user", "kEbn2HUzd$Fs2T", "adbancat.hn");
                    vRSE.Url         = "http://10.128.0.52/reportserver/reportexecution2005.asmx";



                    vRSE.ExecutionHeaderValue = new ReportExecutionService.ExecutionHeader();
                    var vEInfo = new ReportExecutionService.ExecutionInfo();
                    vEInfo = vRSE.LoadReport("/Recursos Humanos/viaticosMotivoViaje", null);


                    String vMotivo = DDLMotivoViaje.SelectedValue;
                    List <ReportExecutionService.ParameterValue> vParametros = new List <ReportExecutionService.ParameterValue>();
                    vParametros.Add(new ReportExecutionService.ParameterValue {
                        Name = "Motivo", Value = vMotivo
                    });



                    vRSE.SetExecutionParameters(vParametros.ToArray(), "en-US");



                    String   deviceinfo = "<DeviceInfo><Toolbar>false</Toolbar></DeviceInfo>";
                    String   mime;
                    String   encoding;
                    string[] stream;
                    ReportExecutionService.Warning[] warning;



                    //byte[] vResultado = vRSE.Render("EXCEL", deviceinfo, out mime, out encoding, out encoding, out warning, out stream);
                    byte[] vResultado = vRSE.Render("pdf", deviceinfo, out mime, out encoding, out encoding, out warning, out stream);

                    //File.WriteAllBytes("c:\\files\\test.pdf", vResultado);

                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    //Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
                    Response.AppendHeader("Content-Type", "application/pdf");
                    byte[] bytFile = vResultado;
                    Response.OutputStream.Write(bytFile, 0, bytFile.Length);
                    //Response.AddHeader("Content-disposition", "attachment;filename=DescargaPDFTest.xls");
                    Response.AddHeader("Content-disposition", "attachment;filename=DescargaPDFMotivoViaje.pdf");
                    Response.End();
                }
                catch (Exception Ex) { vError = Ex.Message; }
                DDLMotivoViaje.SelectedValue = "0";
            }
        }