コード例 #1
0
    /// <summary>
    /// hecho por cesar pulido
    /// el dia 19 de diciembre de 2012
    /// para generar el archivo del contrato
    /// </summary>
    /// <param name="filaInfoContrato"></param>
    /// <returns></returns>
    private byte[] ImprimirContratoO_L_COMPLETO(DataRow filaInfoContrato)
    {
        tools _tools = new tools();

        Boolean CarnetIncluido = false;

        //En esta variable cargamos el documento plantilla segun la empresa de session
        StreamReader archivo;

        if (Session["idEmpresa"].ToString() == "1")
        {
            if (CarnetIncluido == true)
            {
                archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_sertempo_obra_labor.htm"));
            }
            else
            {
                archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_sertempo_obra_labor_carnet_aparte.htm"));
            }
        }
        else
        {
            if (CarnetIncluido == true)
            {
                archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_eys_labor_contratada.htm"));
            }
            else
            {
                archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_eys_labor_contratada_carnet_aparte.htm"));
            }
        }

        String html = archivo.ReadToEnd();

        archivo.Dispose();
        archivo.Close();

        if (Session["idEmpresa"].ToString() == "1")
        {
            html = html.Replace("[DIR_LOGO_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/logo_sertempo.png");
            html = html.Replace("[MENSAJE_LOGO]", "SERVICIOS TEMPORALES PROFESIONALES");
            html = html.Replace("[NOMBRE_EMPLEADOR]", tabla.VAR_NOMBRE_SERTEMPO);
            html = html.Replace("[DOMICILO_EMPLEADOR]", tabla.VAR_DOMICILIO_SERTEMPO);
            html = html.Replace("[DESCRIPCION_CARGO]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper());
            html = html.Replace("[SERVICIO_RESPECTIVO]", filaInfoContrato["DESCRIPCION"].ToString().Trim().ToUpper());
            html = html.Replace("[EMPRESA_USUARIA]", filaInfoContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper());
            html = html.Replace("[DIR_FIRMA_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/firma_contrato_empleador_sertempo.jpg");
        }
        else
        {
            html = html.Replace("[DIR_LOGO_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/logo_eficiencia.jpg");
            html = html.Replace("[NOMBRE_EMPLEADOR]", tabla.VAR_NOMBRE_EYS);
            html = html.Replace("[DOMICILO_EMPLEADOR]", tabla.VAR_DOMICILIO_EYS);
            html = html.Replace("[FUNCION_CARGO]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper());
            html = html.Replace("[ACTIVIDAD_CONTRATADA]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper());
            html = html.Replace("[EMPRESA_DESTACA]", filaInfoContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper());
            html = html.Replace("[DIR_FIRMA_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/firma_contrato_empleador_eys.jpg");
        }

        html = html.Replace("[CARGO_TRABAJADOR]", filaInfoContrato["NOM_OCUPACION"].ToString().Trim().ToUpper());
        html = html.Replace("[NOMBRE_TRABAJADOR]", filaInfoContrato["APELLIDOS"].ToString().Trim().ToUpper() + " " + filaInfoContrato["NOMBRES"].ToString().Trim().ToUpper());
        html = html.Replace("[TIPO_DOCUMENTO_IDENTIDAD]", filaInfoContrato["TIP_DOC_IDENTIDAD"].ToString().Trim().ToUpper());
        html = html.Replace("[DOC_IDENTIFICACION]", filaInfoContrato["NUM_DOC_IDENTIDAD"].ToString().Trim().ToUpper());
        html = html.Replace("[SALARIO]", Convert.ToDecimal(filaInfoContrato["SALARIO"]).ToString());
        html = html.Replace("[PERIODO_PAGO]", "??");
        html = html.Replace("[FECHA_INICIACION]", Convert.ToDateTime(filaInfoContrato["FECHA_INICIA"]).ToLongDateString());
        html = html.Replace("[CARNE_VALIDO_HASTA]", Convert.ToDateTime(filaInfoContrato["FECHA_TERMINA"]).ToLongDateString());

        //esto es para obtener la ciudad de impresión del contrato
        //OBTENEMOS LA CIUDAD DE FIRMA, DESDE LA CIUDAD DEL USU_LOG
        usuario _usuario = new usuario(Session["idEmpresa"].ToString());
        DataTable tablaInfoUsuario = _usuario.ObtenerInicioSesionPorUsuLog(Session["USU_LOG"].ToString());
        if (tablaInfoUsuario.Rows.Count <= 0)
        {
            html = html.Replace("[CIUDAD_FIRMA]", "Desconocida");
        }
        else
        {
            DataRow filaInfoUsuario = tablaInfoUsuario.Rows[0];
            html = html.Replace("[CIUDAD_FIRMA]", filaInfoUsuario["NOMBRE_CIUDAD"].ToString());
        }

        DateTime fechaHoy = DateTime.Now;
        html = html.Replace("[DIAS_FIRMA]", fechaHoy.Day.ToString());
        html = html.Replace("[MES_FIRMA]", _tools.obtenerNombreMes(fechaHoy.Month));
        html = html.Replace("[ANNO_FIRMA]", fechaHoy.Year.ToString());

        //creamos un configuramos el documento de pdf
        //(tamaño de la hoja,margen izq, margen der, margin arriba margen abajo)
        iTextSharp.text.Document document = new iTextSharp.text.Document(new Rectangle(612, 936), 15, 15, 5, 15);

        using (MemoryStream streamArchivo = new MemoryStream())
        {
            iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(document, streamArchivo);

            // Our custom Header and Footer is done using Event Handler
            pdfEvents PageEventHandler = new pdfEvents();
            writer.PageEvent = PageEventHandler;

            PageEventHandler.tipoDocumento = "contrato";

            document.Open();

            //capturamos el archivo temporal del response
            String tempFile = Path.GetTempFileName();

            //y lo llenamos con el html de la plantilla
            using (StreamWriter tempwriter = new StreamWriter(tempFile, false))
            {
                tempwriter.Write(html);
            }

            //leeemos el archivo temporal y lo colocamos en el documento de pdf
            List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StreamReader(tempFile), new StyleSheet());

            foreach (IElement element in htmlarraylist)
            {
                if (element.Chunks.Count > 0)
                {
                    if (element.Chunks[0].Content == "linea para paginacion de pdf")
                    {
                        document.NewPage();
                    }
                    else
                    {
                        document.Add(element);
                    }
                }
                else
                {
                    document.Add(element);
                }
            }

            //limpiamos todo
            document.Close();

            writer.Close();

            return streamArchivo.ToArray();
        }
    }
コード例 #2
0
    private void ImprimirContratoO_L_COMPLETO(DataRow filaInfoContrato)
    {
        tools _tools = new tools();

        Boolean CarnetIncluido = CheckBox_CON_CARNET_APARTE.Checked;

        StreamReader archivo;

        if (Session["idEmpresa"].ToString() == "1")
        {
            if (CarnetIncluido == true)
            {
                archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_sertempo_obra_labor.htm"));
            }
            else
            {
                archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_sertempo_obra_labor_carnet_aparte.htm"));
            }
        }
        else
        {
            if (CarnetIncluido == true)
            {
                archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_eys_labor_contratada.htm"));
            }
            else
            {
                archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_eys_labor_contratada_carnet_aparte.htm"));
            }
        }

        String html = archivo.ReadToEnd();

        archivo.Dispose();
        archivo.Close();

        String filename;

        if (Session["idEmpresa"].ToString() == "1")
        {
            html = html.Replace("[DIR_LOGO_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/logo_sertempo.png");
            html = html.Replace("[MENSAJE_LOGO]", "SERVICIOS TEMPORALES PROFESIONALES");
            html = html.Replace("[NOMBRE_EMPLEADOR]", tabla.VAR_NOMBRE_SERTEMPO);
            html = html.Replace("[DOMICILO_EMPLEADOR]", tabla.VAR_DOMICILIO_SERTEMPO);
            html = html.Replace("[DESCRIPCION_CARGO]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper());
            html = html.Replace("[SERVICIO_RESPECTIVO]", filaInfoContrato["DESCRIPCION"].ToString().Trim().ToUpper());
            html = html.Replace("[EMPRESA_USUARIA]", filaInfoContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper());
            html = html.Replace("[DESCRIPCION_SALARIO]", filaInfoContrato["DESCRIPCION_SALARIO"].ToString().Trim().ToUpper());
            html = html.Replace("[DIR_FIRMA_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/firma_autos_recomendacion.jpg");
            filename = "contrato_sertempo";
        }
        else
        {
            html = html.Replace("[DIR_LOGO_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/logo_eficiencia.jpg");
            html = html.Replace("[NOMBRE_EMPLEADOR]", tabla.VAR_NOMBRE_EYS);
            html = html.Replace("[DOMICILO_EMPLEADOR]", tabla.VAR_DOMICILIO_EYS);
            html = html.Replace("[FUNCION_CARGO]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper());
            html = html.Replace("[ACTIVIDAD_CONTRATADA]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper());
            html = html.Replace("[EMPRESA_DESTACA]", filaInfoContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper());
            html = html.Replace("[DESCRIPCION_SALARIO]", filaInfoContrato["DESCRIPCION_SALARIO"].ToString().Trim().ToUpper());
            html = html.Replace("[DIR_FIRMA_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/firma_autos_recomendacion.jpg");
            filename = "contrato_eys";
        }

        html = html.Replace("[CARGO_TRABAJADOR]", filaInfoContrato["NOM_OCUPACION"].ToString().Trim().ToUpper());
        html = html.Replace("[NOMBRE_TRABAJADOR]", filaInfoContrato["APELLIDOS"].ToString().Trim().ToUpper() + " " + filaInfoContrato["NOMBRES"].ToString().Trim().ToUpper());
        html = html.Replace("[TIPO_DOCUMENTO_IDENTIDAD]", filaInfoContrato["TIP_DOC_IDENTIDAD"].ToString().Trim().ToUpper());
        html = html.Replace("[DOC_IDENTIFICACION]", filaInfoContrato["NUM_DOC_IDENTIDAD"].ToString().Trim().ToUpper());
        html = html.Replace("[SALARIO]", String.Format("$ {0:N2}", Convert.ToDecimal(filaInfoContrato["SALARIO"]).ToString()));
        html = html.Replace("[PERIODO_PAGO]", DropDownList_PERIODO_PAGO.SelectedItem.Text);
        html = html.Replace("[FECHA_INICIACION]", Convert.ToDateTime(filaInfoContrato["FECHA_INICIA"]).ToLongDateString());
        html = html.Replace("[CARNE_VALIDO_HASTA]", Convert.ToDateTime(filaInfoContrato["FECHA_TERMINA"]).ToLongDateString());

        usuario _usuario = new usuario(Session["idEmpresa"].ToString());
        DataTable tablaInfoUsuario = _usuario.ObtenerInicioSesionPorUsuLog(Session["USU_LOG"].ToString());
        if (tablaInfoUsuario.Rows.Count <= 0)
        {
            html = html.Replace("[CIUDAD_FIRMA]", "Desconocida");
        }
        else
        {
            DataRow filaInfoUsuario = tablaInfoUsuario.Rows[0];
            html = html.Replace("[CIUDAD_FIRMA]", filaInfoUsuario["NOMBRE_CIUDAD"].ToString());
        }

        DateTime fechaHoy = DateTime.Now;
        html = html.Replace("[DIAS_FIRMA]", fechaHoy.Day.ToString());
        html = html.Replace("[MES_FIRMA]", _tools.obtenerNombreMes(fechaHoy.Month));
        html = html.Replace("[ANNO_FIRMA]", fechaHoy.Year.ToString());

        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;FileName=" + filename + ".pdf");

        Response.Clear();
        Response.ContentType = "application/pdf";

        iTextSharp.text.Document document = new iTextSharp.text.Document(new Rectangle(612, 936), 15, 15, 10, 10);

        iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);

        pdfEvents PageEventHandler = new pdfEvents();
        writer.PageEvent = PageEventHandler;

        PageEventHandler.tipoDocumento = "contrato";

        document.Open();

        String tempFile = Path.GetTempFileName();

        using (StreamWriter tempwriter = new StreamWriter(tempFile, false))
        {
            tempwriter.Write(html);
        }

        List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StreamReader(tempFile), new StyleSheet());
        foreach (IElement element in htmlarraylist)
        {
            document.Add(element);
        }

        document.Close();
        writer.Close();

        Response.End();

        File.Delete(tempFile);
    }
コード例 #3
0
    private void previsualizar_clausula(Decimal ID_CON_REG_CLAUSULAS_PERFIL)
    {
        condicionesContratacion _condicionesContratacion = new condicionesContratacion(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
        DataTable tablaInfoClausula = _condicionesContratacion.obtenerClausulasPorIdCluasula(ID_CON_REG_CLAUSULAS_PERFIL);
        DataRow filaInfo = tablaInfoClausula.Rows[0];

        StreamReader archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\clausulas.htm"));

        tools _tools = new tools();

        String html_completo = "<html><body>";
        html_completo += archivo.ReadToEnd();
        html_completo += "</body></html>";

        archivo.Dispose();
        archivo.Close();

        if (Session["idEmpresa"].ToString() == "1")
        {
            html_completo = html_completo.Replace("[NOMBRE_EMPRESA]", tabla.VAR_NOMBRE_SERTEMPO);
        }
        else
        {
            html_completo = html_completo.Replace("[NOMBRE_EMPRESA]", tabla.VAR_NOMBRE_EYS);
        }
        html_completo = html_completo.Replace("[NOMBRE_TRABAJADOR]", "NOMBRE DEL TRABAJADOR");
        html_completo = html_completo.Replace("[NOMBRE_CLAUSULA]", filaInfo["NOMBRE"].ToString());
        html_completo = html_completo.Replace("[ENCABEZADO_CLAUSULA]", filaInfo["ENCABEZADO"].ToString());
        html_completo = html_completo.Replace("[CONTENIDO_CLAUSULA]", filaInfo["DESCRIPCION"].ToString());

        usuario _usuario = new usuario(Session["idEmpresa"].ToString());
        DataTable tablaInfoUsuario = _usuario.ObtenerInicioSesionPorUsuLog(Session["USU_LOG"].ToString());
        if (tablaInfoUsuario.Rows.Count <= 0)
        {
            html_completo = html_completo.Replace("[CIUDAD_FIRMA]", "Desconocida");
        }
        else
        {
            DataRow filaInfoUsuario = tablaInfoUsuario.Rows[0];
            html_completo = html_completo.Replace("[CIUDAD_FIRMA]", filaInfoUsuario["NOMBRE_CIUDAD"].ToString());
        }

        html_completo = html_completo.Replace("[DIAS]", DateTime.Now.Day.ToString());
        html_completo = html_completo.Replace("[MES]", _tools.obtenerNombreMes(DateTime.Now.Month));
        html_completo = html_completo.Replace("[ANNO]", DateTime.Now.Year.ToString());

        String filename = "previsulizador_clausula";

        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;FileName=" + filename + ".pdf");

        Response.Clear();
        Response.ContentType = "application/pdf";

        iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.A4, 40, 40, 80, 40);

        iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);

        pdfEvents PageEventHandler = new pdfEvents();
        writer.PageEvent = PageEventHandler;

        if (Session["idEmpresa"].ToString() == "1")
        {
            PageEventHandler.dirImagenHeader = Server.MapPath("~/imagenes/reportes/logo_sertempo.png");
        }
        else
        {
            PageEventHandler.dirImagenHeader = Server.MapPath("~/imagenes/reportes/logo_eficiencia.png");
        }

        PageEventHandler.fechaImpresion = DateTime.Now;
        PageEventHandler.tipoDocumento = "clausula";

        document.Open();

        String tempFile = Path.GetTempFileName();

        using (StreamWriter tempwriter = new StreamWriter(tempFile, false))
        {
            tempwriter.Write(html_completo);
        }

        List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StreamReader(tempFile), new StyleSheet());
        foreach (IElement element in htmlarraylist)
        {
            document.Add(element);
        }

        document.Close();
        writer.Close();

        Response.End();

        File.Delete(tempFile);
    }