Sunteți pe pagina 1din 2

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ProyectoGrifo.Models;
using CrystalDecisions.CrystalReports.Engine;
using System.IO;

namespace ProyectoGrifo.Controllers
{
public class Rpt_TrabajadorController : Controller
{
BD_PalucoEntities2 context = new BD_PalucoEntities2();
//
// GET: /Rpt_Trabajador/

public ActionResult Index()


{
ViewBag.trabajador = context.TRABAJADOR.ToList();
return View();
}

public ActionResult Exportar()


{
ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(Server.MapPath("~/Reports/CR_Trabajador.rpt")));
rd.SetDataSource(context.TRABAJADOR.Select(E => new
{
id_trab = E.id_trab,
dni_trab = E.dni_trab,
nombres_trab = E.nombres_trab,
apellidos_trab = E.apellidos_trab,
direccion_trab = E.direccion_trab,
telefono_trab = E.telefono_trab,
}).ToList());
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
Stream stream = rd.ExportToStream
(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", "INFORME(TRABAJADOR).pdf");
}

}
}

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body align="center" style="background-color: #a6dbed">
<h3>LISTA DE TODO LOA TRABAJADORES</h3>
<a href="@Url.Action("Exportar", "Rpt_Trabajador")"> EXPORTAR (PDF) </a>
<table cellpadding="0" cellspacing="0" border="1">
<tr>
<th>N</th>
<th>DNI</th>
<th>NOMBRES</th>
<th>APELLIDOS</th>
<th>DIRECCION</th>
<th>TELEFONO</th>
</tr>
@foreach (var E in ViewBag.trabajador)
{<tr>
<td>@E.id_trab</td>
<td>@E.dni_trab</td>
<td>@E.nombres_trab</td>
<td>@E.apellidos_trab</td>
<td>@E.direccion_trab</td>
<td>@E.telefono_trab</td>
</tr>}
</table>
<br>
<br />

</body>
</html>

S-ar putea să vă placă și