protected void ExportarXLS()
        {
            ReportViewer rvExporter = new ReportViewer();

            rvExporter.ProcessingMode = ProcessingMode.Local;
            rvExporter.LocalReport.ReportPath = Server.MapPath(@"~\Reports\ListadeCompras.rdlc");
            rvExporter.LocalReport.DataSources.Add(new ReportDataSource("Lista", GetDados()));
            rvExporter.LocalReport.Refresh();

            Resultado resultado = new Resultado();
            Ped_ItemFacade oPedFacade = new Ped_ItemFacade();

            int CategoriaID = Convert.ToInt32(Request.QueryString["categoriaid"]);
            int CC_ID = Convert.ToInt32(Request.QueryString["CC"]);
            resultado = new Ped_ItemFacade().AtualizaProcessoCompra(CategoriaID, CC_ID);

            ////Exportar para PDF
            string mimeType;
            string encoding;
            string fileNameExtension;
            Warning[] warnings;
            string[] streamids;
            byte[] exportBytes = rvExporter.LocalReport.Render("Excel", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);

            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.{1}",  DateTime.Now.ToString("yyyy-MM-dd") + "Planilha Processo de Compra Numero " + resultado.Id.ToString().PadLeft(6,'0') , fileNameExtension));
            Response.BinaryWrite(exportBytes);
            Response.Flush();
            Response.End();

            rvExporter.Dispose();
        }
예제 #2
0
        protected void ExportarXLS(int Cod)
        {
            ReportViewer rvExporter = new ReportViewer();

            rvExporter.ProcessingMode         = ProcessingMode.Local;
            rvExporter.LocalReport.ReportPath = Server.MapPath(@"~\Reports\ListadeCompras.rdlc");
            rvExporter.LocalReport.DataSources.Add(new ReportDataSource("Lista", GetDados(Cod)));
            rvExporter.LocalReport.Refresh();

            Resultado      resultado  = new Resultado();
            Ped_ItemFacade oPedFacade = new Ped_ItemFacade();

            ////Exportar para PDF
            string mimeType;
            string encoding;
            string fileNameExtension;

            Warning[] warnings;
            string[]  streamids;
            byte[]    exportBytes = rvExporter.LocalReport.Render("Excel", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);

            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.{1}", DateTime.Now.ToString("yyyy-MM-dd") + "Planilha Processo de Compra Numero " + resultado.Id.ToString().PadLeft(6, '0') + "R", fileNameExtension));
            Response.BinaryWrite(exportBytes);
            Response.Flush();
            Response.End();

            rvExporter.Dispose();
        }
        public void Dispose()
        {
            foreach (var stream in _streams)
            {
                try
                {
                    stream.DiscardBufferedData();
                }
                catch { }
                stream.Close();
                stream.Dispose();
            }

            _streams.Clear();

            if (_reportViewer != null)
            {
                if (_reportViewer.LocalReport != null)
                {
                    _reportViewer.LocalReport.Dispose();
                }

                try
                {
                    _reportViewer.Dispose();
                }
                catch
                {
                    // Empty catch here to get unit tests to execute. Dispose fails when called from non-web context.
                }

                _reportViewer = null;
            }
        }
예제 #4
0
        public static void OutputReport()
        {
            Warning[] warnings;
            string[]  streamids;
            string    mimeType;
            string    encoding;
            string    filenameExtension;

            // レポートの作成
            using (LocalReport localReport = new ReportViewer().LocalReport)
            {
                // レポート定義を設定
                localReport.ReportPath = @"TestReport.rdlc";

                // パラメータの設定
                List <ReportParameter> reportParams = new List <ReportParameter>();
                reportParams.Add(new ReportParameter("ReportParameter1", "ReportParameter1 - TEST"));
                reportParams.Add(new ReportParameter("ReportParameter2", "ReportParameter2 - TEST"));
                localReport.SetParameters(reportParams);

                // 定義した(.Net)データセットに値を設定する。
                DataTable member2DataTable = new ReportSample02DataSet.Member2DataTable(); // データセットからテーブルを取得
                DataRow   memberDataRow    = member2DataTable.NewRow();
                memberDataRow["Member2Id"] = 1;
                memberDataRow["Name"]      = "習志野太郎";
                memberDataRow["Address"]   = "千葉県習志野市";
                memberDataRow["Age"]       = 34;

                DataRow memberDataRow2 = member2DataTable.NewRow();
                memberDataRow2["Member2Id"] = 2;
                memberDataRow2["Name"]      = "習志野太郎2 - 2件テスト";
                memberDataRow2["Address"]   = "千葉県習志野市2 - 2件テスト";
                memberDataRow2["Age"]       = 44;

                member2DataTable.Rows.Add(memberDataRow);
                member2DataTable.Rows.Add(memberDataRow2);

                DataTable accountDataTable = new ReportSample02DataSet.AccountDataTable(); // データセットからテーブルを取得
                DataRow   accountDataRow   = accountDataTable.NewRow();
                accountDataRow["AccountId"]   = 12;
                accountDataRow["Member2Id"]   = 1;
                accountDataRow["SystemId"]    = 120;
                accountDataRow["UserAccount"] = "UserAccountTest";
                accountDataRow["Password"]    = "******";

                accountDataTable.Rows.Add(accountDataRow);

                //// Set Report Properties
                //var rds = new ReportDataSource("CustomersTable", (DataTable)dt);
                //this.reportViewer1.LocalReport.DataSources.Add(rds);
                //this.reportViewer1.LocalReport.ReportPath
                //  = @"C:\test\Report1.rdlc";

                // (.Net)データセットに設定した値が、レポートのデータソースとして使われるよう
                // 設定する。
                localReport.DataSources.Add(new ReportDataSource("Member2", member2DataTable));
                localReport.DataSources.Add(new ReportDataSource("Account2", accountDataTable));

                // Byteの配列(PDF)への変換
                byte[] bytes = localReport.Render(
                    "PDF", null, out mimeType, out encoding, out filenameExtension,
                    out streamids, out warnings);

                // ファイル名・ファイルパスの決定
                string tempPath = @"C:\";
                string saveAs   = string.Format("{0}.pdf", Path.Combine(tempPath, "myfilename"));

                int idx = 0;
                while (File.Exists(saveAs))
                {
                    idx++;
                    saveAs = string.Format("{0}.{1}.pdf", Path.Combine(tempPath, "myfilename"), idx);
                }


                // レポートの出力
                using (FileStream fs = new FileStream(saveAs, FileMode.Create))
                {
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Close();
                }
                localReport.Dispose();
            }
        }
예제 #5
0
        public void GerarRelatorioGerencial(List <NotaFiscalEntity> notasPeriodo, List <NotaInutilizadaTO> notasInutilizadas, DateTime mesAno, string startPath)
        {
            Warning[] warnings;
            string[]  streamIds;
            string    mimeType  = string.Empty;
            string    encoding  = string.Empty;
            string    extension = string.Empty;

            var emitenteEntity = _emitenteRepository.GetEmitente();
            var emitente       = new RelatorioGerencial.Emitente()
            {
                RazaoSocial = emitenteEntity.RazaoSocial,
                CNPJ        = emitenteEntity.CNPJ
            };

            IEnumerable <RelatorioGerencial.NotaFiscal> nfceAutorizadas = notasPeriodo
                                                                          .Where(n => n.Modelo.Equals("65") && n.Status == (int)Status.ENVIADA)
                                                                          .Select(nota => new RelatorioGerencial.NotaFiscal()
            {
                ValorDesconto   = nota.ValorDesconto,
                DataAutorizacao = nota.DataAutorizacao,
                DataEmissao     = nota.DataEmissao,
                Modelo          = nota.Modelo,
                Numero          = nota.Numero,
                Protocolo       = nota.Protocolo,
                Serie           = nota.Serie,
                TipoEmissao     = nota.TipoEmissao,
                ValorDespesas   = nota.ValorDespesas,
                ValorFrete      = nota.ValorFrete,
                ValorICMS       = nota.ValorICMS,
                ValorICMSST     = nota.ValorICMSST,
                ValorIPI        = nota.ValorIPI,
                ValorISS        = nota.ValorISS,
                ValorProdutos   = nota.ValorProdutos,
                ValorSeguro     = nota.ValorSeguro,
                ValorServicos   = nota.ValorServicos,
                ValorTotal      = nota.ValorTotal
            });

            IEnumerable <RelatorioGerencial.NotaFiscal> nfeAutorizadas = notasPeriodo.Where(n => n.Modelo.Equals("55") && n.Status == (int)Status.ENVIADA).Select(nota => new RelatorioGerencial.NotaFiscal()
            {
                ValorDesconto   = nota.ValorDesconto,
                DataAutorizacao = nota.DataAutorizacao,
                DataEmissao     = nota.DataEmissao,
                Modelo          = nota.Modelo,
                Numero          = nota.Numero,
                Protocolo       = nota.Protocolo,
                Serie           = nota.Serie,
                TipoEmissao     = nota.TipoEmissao,
                ValorDespesas   = nota.ValorDespesas,
                ValorFrete      = nota.ValorFrete,
                ValorICMS       = nota.ValorICMS,
                ValorICMSST     = nota.ValorICMSST,
                ValorIPI        = nota.ValorIPI,
                ValorISS        = nota.ValorISS,
                ValorProdutos   = nota.ValorProdutos,
                ValorSeguro     = nota.ValorSeguro,
                ValorServicos   = nota.ValorServicos,
                ValorTotal      = nota.ValorTotal
            });

            IEnumerable <RelatorioGerencial.NotaFiscal> nfceCanceladas = notasPeriodo.Where(n => n.Modelo.Equals("65") && n.Status == (int)Status.CANCELADA).Select(nota => new RelatorioGerencial.NotaFiscal()
            {
                Id              = nota.Id,
                ValorDesconto   = nota.ValorDesconto,
                DataAutorizacao = nota.DataAutorizacao,
                DataEmissao     = nota.DataEmissao,
                Modelo          = nota.Modelo,
                Numero          = nota.Numero,
                Protocolo       = nota.Protocolo,
                Serie           = nota.Serie,
                TipoEmissao     = nota.TipoEmissao,
                ValorDespesas   = nota.ValorDespesas,
                ValorFrete      = nota.ValorFrete,
                ValorICMS       = nota.ValorICMS,
                ValorICMSST     = nota.ValorICMSST,
                ValorIPI        = nota.ValorIPI,
                ValorISS        = nota.ValorISS,
                ValorProdutos   = nota.ValorProdutos,
                ValorSeguro     = nota.ValorSeguro,
                ValorServicos   = nota.ValorServicos,
                ValorTotal      = nota.ValorTotal
            });
            IEnumerable <RelatorioGerencial.NotaFiscal> nfeCanceladas = notasPeriodo.Where(n => n.Modelo.Equals("55") && n.Status == (int)Status.CANCELADA).Select(nota => new RelatorioGerencial.NotaFiscal()
            {
                Id              = nota.Id,
                ValorDesconto   = nota.ValorDesconto,
                DataAutorizacao = nota.DataAutorizacao,
                DataEmissao     = nota.DataEmissao,
                Modelo          = nota.Modelo,
                Numero          = nota.Numero,
                Protocolo       = nota.Protocolo,
                Serie           = nota.Serie,
                TipoEmissao     = nota.TipoEmissao,
                ValorDespesas   = nota.ValorDespesas,
                ValorFrete      = nota.ValorFrete,
                ValorICMS       = nota.ValorICMS,
                ValorICMSST     = nota.ValorICMSST,
                ValorIPI        = nota.ValorIPI,
                ValorISS        = nota.ValorISS,
                ValorProdutos   = nota.ValorProdutos,
                ValorSeguro     = nota.ValorSeguro,
                ValorServicos   = nota.ValorServicos,
                ValorTotal      = nota.ValorTotal
            });

            var eventoCancelamentoNFCe = _eventoRepository.GetEventosPorNotasId(nfceCanceladas.Select(n => n.Id));
            var eventoCancelamentoNFe  = _eventoRepository.GetEventosPorNotasId(nfeCanceladas.Select(n => n.Id));

            List <RelatorioGerencial.NotaInutilizada> nfceInutilizadas = notasInutilizadas.Where(n => n.Modelo.Equals(65)).Select(
                nota => new RelatorioGerencial.NotaInutilizada()
            {
                Serie            = nota.Serie,
                Numero           = nota.Numero,
                Protocolo        = nota.Protocolo,
                DataInutilizacao = nota.DataInutilizacao,
                Motivo           = nota.Motivo
            }
                ).ToList();

            List <RelatorioGerencial.NotaInutilizada> nfeInutilizadas = notasInutilizadas.Where(n => n.Modelo.Equals(55)).Select(
                nota => new RelatorioGerencial.NotaInutilizada()
            {
                Serie            = nota.Serie,
                Numero           = nota.Numero,
                Protocolo        = nota.Protocolo,
                DataInutilizacao = nota.DataInutilizacao,
                Motivo           = nota.Motivo
            }
                ).ToList();

            var NFeCanceladas = new List <NotaCancelada>();

            foreach (var nfe in nfeCanceladas)
            {
                var eventoCancelamento = eventoCancelamentoNFe.FirstOrDefault(e => e.NotaId == nfe.Id);

                var nfeCancelada = new NotaCancelada();
                nfeCancelada.DataCancelamento      = eventoCancelamento.DataEvento.ToString();
                nfeCancelada.DataEmissao           = nfe.DataEmissao.ToString();
                nfeCancelada.Numero                = nfe.Numero;
                nfeCancelada.MotivoCancelamento    = eventoCancelamento.MotivoCancelamento;
                nfeCancelada.ProtocoloCancelamento = eventoCancelamento.ProtocoloCancelamento;
                nfeCancelada.Serie = nfe.Serie;

                NFeCanceladas.Add(nfeCancelada);
            }

            List <NotaCancelada> NFCeCanceladas = new List <NotaCancelada>();

            foreach (var nfce in nfceCanceladas)
            {
                var eventoCancelamento = eventoCancelamentoNFCe.FirstOrDefault(e => e.NotaId == nfce.Id);

                var nfceCancelada = new NotaCancelada
                {
                    DataCancelamento      = eventoCancelamento.DataEvento.ToString(),
                    DataEmissao           = nfce.DataEmissao.ToString(),
                    Numero                = nfce.Numero,
                    MotivoCancelamento    = eventoCancelamento.MotivoCancelamento,
                    ProtocoloCancelamento = eventoCancelamento.ProtocoloCancelamento,
                    Serie = nfce.Serie
                };

                NFCeCanceladas.Add(nfceCancelada);
            }

            SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

            ReportViewer reportViewer = new ReportViewer();

            reportViewer.LocalReport.ReleaseSandboxAppDomain();

            ReportDataSource nfceAutorizadasDataSource = new ReportDataSource()
            {
                Name  = "NFCe",
                Value = nfceAutorizadas
            };

            ReportDataSource nfeAutorizadasDataSource = new ReportDataSource()
            {
                Name  = "NFe",
                Value = nfeAutorizadas
            };

            ReportDataSource nfceCanceladasDataSource = new ReportDataSource()
            {
                Name  = "NFCeCanceladas",
                Value = NFCeCanceladas
            };

            ReportDataSource nfeCanceladasDataSource = new ReportDataSource()
            {
                Name  = "NFeCanceladas",
                Value = NFeCanceladas
            };

            ReportDataSource emitenteDataSource = new ReportDataSource()
            {
                Name  = "Emitente",
                Value = new List <Emitente>()
                {
                    emitente
                }
            };

            ReportDataSource periodoDataSource = new ReportDataSource()
            {
                Name  = "Periodo",
                Value = new List <DateTime>()
                {
                    mesAno
                }
            };

            ReportDataSource nfeInutilizadasDataSource = new ReportDataSource()
            {
                Name  = "NFeInutilizadas",
                Value = nfeInutilizadas
            };

            ReportDataSource nfceInutilizadasDataSource = new ReportDataSource()
            {
                Name  = "NFCeInutilizadas",
                Value = nfceInutilizadas
            };

            reportViewer.LocalReport.DataSources.Add(nfceAutorizadasDataSource);
            reportViewer.LocalReport.DataSources.Add(nfeAutorizadasDataSource);
            reportViewer.LocalReport.DataSources.Add(emitenteDataSource);
            reportViewer.LocalReport.DataSources.Add(periodoDataSource);
            reportViewer.LocalReport.DataSources.Add(nfceCanceladasDataSource);
            reportViewer.LocalReport.DataSources.Add(nfeCanceladasDataSource);
            reportViewer.LocalReport.DataSources.Add(nfeInutilizadasDataSource);
            reportViewer.LocalReport.DataSources.Add(nfceInutilizadasDataSource);

            reportViewer.ProcessingMode         = ProcessingMode.Local;
            reportViewer.LocalReport.ReportPath = Path.Combine(Directory.GetCurrentDirectory(), @"Reports\RelatorioGerencial.rdlc");

            byte[] bytes = reportViewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

            string pathToPdf = Path.Combine(startPath, "RelatorioGerencial.pdf");

            File.WriteAllBytes(pathToPdf, bytes);
            reportViewer.Dispose();
        }
예제 #6
0
 private void FormReport_FormClosed(object sender, FormClosedEventArgs e)
 {
     rv.Dispose();
 }
예제 #7
0
        private static void GenerateReport(string nameRTP, ReportDataSource dataSource, string pathReports, string pathPrints, string numeroCentro, string siglas, int linea, int tipo, bool dinamometros, bool microbancas, bool opacimetros, bool tacometros)
        {
            Warning[]    warnings;
            string[]     streamids;
            ReportViewer ReportViewer1 = new ReportViewer();

            try
            {
                ReportViewer1.ProcessingMode = ProcessingMode.Local;
                ReportViewer1.Reset();
                ReportViewer1.LocalReport.Dispose();
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.ReportPath = pathReports + nameRTP;

                ReportViewer1.LocalReport.DataSources.Add(dataSource);
                ReportViewer1.LocalReport.Refresh();

                string mimeType = string.Empty;
                string encoding = string.Empty;
                string ext      = string.Empty;
                string format   = string.Empty;

                string fileName = string.Empty;
                string prefix   = string.Empty;

                switch (nameRTP)
                {
                case "dinamometro.rdlc":
                    prefix = "Dinamometro_";
                    break;

                case "microbancas.rdlc":
                    prefix = "Microbanca_";
                    break;

                case "opacimetros.rdlc":
                    prefix = "Opacimetros_";
                    break;

                case "tacometros.rdlc":
                    prefix = "Tacometro_";
                    break;
                }

                // Word, PDF, Excel and Image.
                if (tipo == 1)
                {
                    byte[] bytes = ReportViewer1.LocalReport.Render("Word", null, out mimeType, out encoding, out ext, out streamids, out warnings);

                    fileName = fileName = pathPrints + prefix + siglas + numeroCentro + "_" + linea + "_" + Guid.NewGuid().ToString() + ".doc";

                    using (FileStream fs = File.Create(fileName))
                    {
                        fs.Write(bytes, 0, bytes.Length);
                        fs.Flush();
                        fs.Close();
                    }

                    bytes = null;
                }
                else
                {
                    byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out ext, out streamids, out warnings);

                    fileName = fileName = pathPrints + prefix + siglas + numeroCentro + "_" + linea + "_" + Guid.NewGuid().ToString() + ".pdf";

                    using (FileStream fs = File.Create(fileName))
                    {
                        fs.Write(bytes, 0, bytes.Length);
                        fs.Flush();
                        fs.Close();
                    }

                    bytes = null;
                }
            }
            catch (Exception ex)
            {
                LogErrores.Write("Error en GenerateReport() de Reporting.", ex);
                throw ex;
            }
            finally
            {
                warnings  = null;
                streamids = null;
                ReportViewer1.Dispose();
                GC.Collect();
            }
        }