Exemplo n.º 1
0
        protected void ButtonExportarPdf_Click(object sender, EventArgs e)
        {
            AcuseFolio objAcuseOpinionFolio;

            strTipoArrendamiento = Request.QueryString["TipoArrto"];
            int  intFolio;
            bool ConversionOK; //esta nos dice si es un número válido

            try
            {
                StringBuilder  sb  = new StringBuilder();
                StringWriter   sw  = new StringWriter(sb);
                HtmlTextWriter htw = new HtmlTextWriter(sw);

                Page     page = new Page();
                HtmlForm form = new HtmlForm();
                page.EnableEventValidation = false;
                page.DesignerInitialize();
                form = this.form1;
                form.FindControl("ButtonExportarPdf").Visible = false;
                page.Controls.Add(form);
                page.RenderControl(htw);

                //string strCabecero ="<!DOCTYPE html> <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/><title></title><meta charset='utf-8' /></head><body>";
                string strCabecero = "<!DOCTYPE html> <html xmlns='http://www.w3.org/1999/xhtml'> <head runat='server'> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/> <title></title> <link href='https://framework-gb.cdn.gob.mx/assets/styles/main.css' rel='stylesheet'/> <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,600,300' rel='stylesheet' type='text/css'/> <link href='https://framework-gb.cdn.gob.mx/favicon.ico' rel='shortcut icon'/> <style> @media print { #ZonaNoImrpimible {display:none;} } nav,aside  { display: none; } .auto-style1 { height: 119px; } </style> <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script> </head> <body>";
                string strPie      = "</body> </html>";


                string strBotonExportar = "<asp:Button ID=\"ButtonExportarPdf\" runat=\"server\" CssClass=\"btn btn-default\" OnClick=\"ButtonExportarPdf_Click\" Text=\"Exportar a PDF\" ToolTip=\"Exportar a PDF.\" />";
                string strBotonImprimir = "<input type=\"button\" id=\"ButtonImprimir\" value=\"Imprimir\" onclick=\"javascript: window.print()\" class=\"btn\" />";
                string strBrakePage     = "page-break-before: always;";



                string strCuerpoOriginal  = sb.ToString();
                string strPaginaConCuerpo = strCabecero + strCuerpoOriginal + strPie;
                //string strCuerpoFormateado = especialesHTML(strPaginaConCuerpo).Replace(strImagenLogoIndaabinHtml, strImagenLogoIndaabinFisica).Replace(strImagenEscudoNacionalHtml, strImagenEscudoNacionalFisica).Replace(strBotonImprimir, "").Replace(strBotonExportar, "").Replace(strBrakePage, "");
                string strCuerpoFormateado = especialesHTML(strPaginaConCuerpo);

                //poner la url del nuevo logo si pasa del 1 de diciembre de 2018
                ConversionOK = int.TryParse(Request.QueryString["IdFolio"].ToString(), out intFolio);
                if (ConversionOK)
                {
                    objAcuseOpinionFolio = new NGConceptoRespValor().ObtenerAcuseSolicitudOpinionConInmueble(intFolio, strTipoArrendamiento);

                    string fecha = objAcuseOpinionFolio.FechaAutorizacion.ToString();

                    string[] nuevafecha = fecha.Split('/');

                    string[] ano = nuevafecha[2].Split(' ');

                    string dia = nuevafecha[0];

                    string mes = nuevafecha[1];

                    string year = ano[0];

                    strCuerpoFormateado = strCuerpoFormateado.Replace("src=\"http://sistemas.indaabin.gob.mx/ImagenesComunes/INDAABIN_01.jpg\"", "src=\"https://sistemas.indaabin.gob.mx/ImagenesComunes/SHCP-INDAABINREDUCIDO.PNG");

                    strCuerpoFormateado = strCuerpoFormateado.Replace("url(http://sistemas.indaabin.gob.mx/ImagenesComunes/aguila.png);", "url(https://sistemas.indaabin.gob.mx/ImagenesComunes/nuevoescudo.png);");

                    strCuerpoFormateado = strCuerpoFormateado.Replace("background-position: center;", "background-position: left;");

                    strCuerpoFormateado = strCuerpoFormateado.Replace("##font##", "font-family: Montserrat;");

                    strCuerpoFormateado = strCuerpoFormateado.Replace("##Viejo##", "display:none;");

                    //if (Convert.ToInt32(year) >= 2018)
                    //{
                    //    if (Convert.ToInt32(mes) >= 12)
                    //    {
                    //        if (Convert.ToInt32(dia) >= 1)
                    //        {

                    //            strCuerpoFormateado = strCuerpoFormateado.Replace("src=\"http://sistemas.indaabin.gob.mx/ImagenesComunes/INDAABIN_01.jpg\"", "src=\"https://sistemas.indaabin.gob.mx/ImagenesComunes/SHCP-INDAABINREDUCIDO.PNG");

                    //            strCuerpoFormateado = strCuerpoFormateado.Replace("url(http://sistemas.indaabin.gob.mx/ImagenesComunes/aguila.png);", "url(https://sistemas.indaabin.gob.mx/ImagenesComunes/nuevoescudo.png);");

                    //            strCuerpoFormateado = strCuerpoFormateado.Replace("background-position: center;", "background-position: left;");

                    //            strCuerpoFormateado = strCuerpoFormateado.Replace("##font##", "font-family: Montserrat;");

                    //            strCuerpoFormateado = strCuerpoFormateado.Replace("##Viejo##", "display:none;");
                    //        }
                    //        else
                    //        {
                    //            strCuerpoFormateado = strCuerpoFormateado.Replace("##Nuevo##", "display:none;");
                    //        }
                    //    }
                    //    else
                    //    {
                    //        strCuerpoFormateado = strCuerpoFormateado.Replace("##Nuevo##", "display:none;");
                    //    }
                    //}
                    //else
                    //{
                    //    strCuerpoFormateado = strCuerpoFormateado.Replace("##Nuevo##", "display:none;");
                    //}
                }



                ExportHTML exportar = new ExportHTML();
                exportar.CanPrint = true;

                //RCA 10/18/2017
                exportar.GenerarPDF(strCuerpoFormateado);
                //exportar.GenerarPDF(strCuerpoFormateado, Server.MapPath("~"));
            }
            catch (Exception ex)
            {
                Msj = "Ha ocurrido un error al exportar a PDF. Contacta al área de sistemas.";
                this.LabelInfo.Text = "<div class='alert alert-danger'><strong> Error </strong>" + Msj + "</div>";
                MostrarMensajeJavaScript(Msj);

                BitacoraExcepcion BitacoraExcepcionAplictivo = new BitacoraExcepcion
                {
                    CadenaconexionBD = System.Configuration.ConfigurationManager.ConnectionStrings["cnArrendamientoInmueble"].ConnectionString,
                    Aplicacion       = "ContratosArrto",
                    Modulo           = MethodInfo.GetCurrentMethod().DeclaringType.ToString() + ".aspx",
                    Funcion          = MethodBase.GetCurrentMethod().Name + "()",
                    DescExcepcion    = ex.InnerException == null ? ex.Message : ex.InnerException.Message,
                    Usr = ((SSO)Session["Contexto"]).UserName.ToString()
                };
                BitacoraExcepcionAplictivo.RegistrarBitacoraExcepcion();
                BitacoraExcepcionAplictivo = null;
            }
        }
Exemplo n.º 2
0
        protected void ButtonExportarPdf_Click(object sender, EventArgs e)
        {
            ModeloNegocios.AcuseContrato objAcuseContrato;
            int  intFolio;
            bool ConversionOK; //esta nos dice si es un número válido

            ConversionOK = int.TryParse(Request.QueryString["IdFolio"], out intFolio);

            StringBuilder  sb  = new StringBuilder();
            StringWriter   sw  = new StringWriter(sb);
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            Page     page = new Page();
            HtmlForm form = new HtmlForm();

            page.EnableEventValidation = false;
            page.DesignerInitialize();
            form = this.form1;
            form.FindControl("ButtonExportarPdf").Visible = false;
            page.Controls.Add(form);
            page.RenderControl(htw);


            string strCabecero = "<!DOCTYPE html> <html xmlns='http://www.w3.org/1999/xhtml'> <head runat='server'> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/> <title></title> <link href='https://framework-gb.cdn.gob.mx/assets/styles/main.css' rel='stylesheet'/> <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,600,300' rel='stylesheet' type='text/css'/> <link href='https://framework-gb.cdn.gob.mx/favicon.ico' rel='shortcut icon'/> <style> @media print { #ZonaNoImrpimible {display:none;} } nav,aside  { display: none; } .auto-style1 { height: 119px; } </style> <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script> </head> <body>";
            string strPie      = "</body> </html>";


            string strBotonExportar = "<asp:Button ID=\"ButtonExportarPdf\" runat=\"server\" CssClass=\"btn btn-default\" OnClick=\"ButtonExportarPdf_Click\" Text=\"Exportar a PDF\" ToolTip=\"Exportar a PDF.\" />";
            string strBotonImprimir = "<input type=\"button\" id=\"ButtonImprimir\" value=\"Imprimir\" onclick=\"javascript: window.print()\" class=\"btn\" />";

            //RCA 10/08/2017

            string strImagenLogoIndaabinHtml   = "url('http://sistemas.indaabin.gob.mx/ImagenesComunes/INDAABIN_01.jpg')";
            string strImagenLogoIndaabinFisica = "../Imagenes/logoindaabin.jpg";

            string strBrakePage = "page-break-before: always;";

            //RCA 10/08/2017
            //cambio de ruta a rutas relativas

            string strImagenEscudoNacionalHtml   = "url('http://sistemas.indaabin.gob.mx/ImagenesComunes/aguila.png')";
            string strImagenEscudoNacionalFisica = "../Imagenes/EscudoNacional.png";

            string strCuerpoOriginal   = sb.ToString();
            string strPaginaConCuerpo  = strCabecero + strCuerpoOriginal + strPie;
            string strCuerpoFormateado = especialesHTML(strPaginaConCuerpo).Replace(strImagenLogoIndaabinHtml, strImagenLogoIndaabinFisica).Replace(strImagenEscudoNacionalHtml, strImagenEscudoNacionalFisica).Replace(strBotonImprimir, "").Replace(strBotonExportar, "").Replace(strBrakePage, "");

            //cambiamos formato si pasa del 1/12/2018
            //poner la url del nuevo logo si pasa del 1 de diciembre de 2018
            if (ConversionOK)
            {
                objAcuseContrato = new NG_ContratoArrto().ObtenerAcuseContrato(intFolio);

                string fecha = objAcuseContrato.FechaAutorizacion.ToString();

                string[] nuevafecha = fecha.Split('/');

                string[] ano = nuevafecha[2].Split(' ');

                string dia = nuevafecha[0];

                string mes = nuevafecha[1];

                string year = ano[0];


                if (Convert.ToInt32(year) >= 2018)
                {
                    if (Convert.ToInt32(mes) >= 12)
                    {
                        if (Convert.ToInt32(dia) >= 1)
                        {
                            strCuerpoFormateado = strCuerpoFormateado.Replace("src=\"http://sistemas.indaabin.gob.mx/ImagenesComunes/INDAABIN_01.jpg\"", "src=\"https://sistemas.indaabin.gob.mx/ImagenesComunes/SHCP-INDAABINREDUCIDO.PNG\"");

                            strCuerpoFormateado = strCuerpoFormateado.Replace("url(http://sistemas.indaabin.gob.mx/ImagenesComunes/aguila.png);", "url(https://sistemas.indaabin.gob.mx/ImagenesComunes/nuevoescudo.png);");

                            strCuerpoFormateado = strCuerpoFormateado.Replace("background-position: center;", "background-position: left;");

                            strCuerpoFormateado = strCuerpoFormateado.Replace("##font##", "font-family: Montserrat;");

                            strCuerpoFormateado = strCuerpoFormateado.Replace("##Viejo##", "display:none;");
                        }
                        else
                        {
                            strCuerpoFormateado = strCuerpoFormateado.Replace("##Nuevo##", "display:none;");
                        }
                    }
                    else
                    {
                        strCuerpoFormateado = strCuerpoFormateado.Replace("##Nuevo##", "display:none;");
                    }
                }
                else
                {
                    strCuerpoFormateado = strCuerpoFormateado.Replace("##Nuevo##", "display:none;");
                }
            }

            ExportHTML exportar = new ExportHTML();

            exportar.CanPrint = true;

            //RCA 10/18/2017
            exportar.GenerarPDF(strCuerpoFormateado);
        }