Exemplo n.º 1
0
        private void PrintReport(DebitoPagoStruct reg)
        {
            ReportDocument crystalReport = new ReportDocument();

            crystalReport.Load(Server.MapPath("~/Report/ComprovantePagamento.rpt"));

            Tributario_bll tributario_Class = new Tributario_bll("GTIconnection");
            int            _numero_certidao = tributario_Class.Retorna_Codigo_Certidao(modelCore.TipoCertidao.Comprovante_Pagamento);
            int            _ano_certidao    = DateTime.Now.Year;

            string      _nome = "", _cpfcnpj = "";
            Sistema_bll sistema_Class          = new Sistema_bll("GTIConnection");
            Contribuinte_Header_Struct _header = sistema_Class.Contribuinte_Header(reg.Codigo);

            _nome    = _header.Nome;
            _cpfcnpj = _header.Cpf_cnpj;

            Comprovante_pagamento cpv = new Comprovante_pagamento();

            cpv.Ano            = _ano_certidao;
            cpv.Numero         = _numero_certidao;
            cpv.Banco          = reg.Banco_Nome + " Agência: " + reg.Codigo_Agencia ?? "";
            cpv.Controle       = _numero_certidao.ToString("00000") + _ano_certidao.ToString("0000") + "/" + reg.Codigo.ToString() + "-PG";
            cpv.Cpfcnpj        = _cpfcnpj;
            cpv.Data_emissao   = DateTime.Now;
            cpv.Data_pagamento = reg.Data_Pagamento;
            cpv.Documento      = Documento.Text;
            cpv.Nome           = _nome;
            cpv.Valor          = (decimal)reg.Valor_Pago_Real;
            Exception ex = tributario_Class.Insert_Comprovante_Pagamento(cpv);

            if (ex != null)
            {
                throw ex;
            }
            else
            {
                crystalReport.SetParameterValue("NUMCOMPROVANTE", _numero_certidao.ToString("00000") + "/" + _ano_certidao.ToString("0000"));
                crystalReport.SetParameterValue("DATAEMISSAO", DateTime.Now.ToString("dd/MM/yyyy") + " às " + DateTime.Now.ToString("HH:mm:ss"));
                crystalReport.SetParameterValue("CONTROLE", _numero_certidao.ToString("00000") + _ano_certidao.ToString("0000") + "/" + reg.Codigo.ToString() + "-PG");
                crystalReport.SetParameterValue("BANCO", reg.Banco_Nome + " Agência: " + reg.Codigo_Agencia ?? "");
                crystalReport.SetParameterValue("CADASTRO", reg.Codigo.ToString("000000"));
                crystalReport.SetParameterValue("NOME", _nome);
                crystalReport.SetParameterValue("DATAPAGAMENTO", reg.Data_Pagamento);
                crystalReport.SetParameterValue("VALOR", reg.Valor_Pago_Real);
                crystalReport.SetParameterValue("DOCUMENTO", Documento.Text);
                crystalReport.SetParameterValue("CPFCNPJ", _cpfcnpj);

                HttpContext.Current.Response.Buffer = false;
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.ClearHeaders();

                try {
                    crystalReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, HttpContext.Current.Response, true, "cpv_pagto" + _numero_certidao.ToString() + _ano_certidao.ToString());
                } catch {
                } finally {
                    crystalReport.Close();
                    crystalReport.Dispose();
                }
            }
        }