ReportViewerForMVC
git-tfs-id: [http://192.168.1.10:8080/tfs/AyA]$/SINORT;C340
This commit is contained in:
parent
34d2ed703f
commit
f1636d6d43
1 changed files with 153 additions and 0 deletions
153
AYA.SlnSynor/AYA.SlnSynor/Controllers/ReportesController.cs
Normal file
153
AYA.SlnSynor/AYA.SlnSynor/Controllers/ReportesController.cs
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Microsoft.Reporting.WebForms;
|
||||||
|
using System.Web.UI.WebControls;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
|
||||||
|
namespace AYA.SlnSinort.Controllers
|
||||||
|
{
|
||||||
|
public class ReportesController : BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
private DataSet tds = new DataSet();
|
||||||
|
|
||||||
|
#region Controllers
|
||||||
|
|
||||||
|
// GET: Reportes
|
||||||
|
public ActionResult Index()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Aplicacion
|
||||||
|
public ActionResult Aplicacion()
|
||||||
|
{
|
||||||
|
InitControllers();
|
||||||
|
SetLocalReport("Aplicacion");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Configuracion y Parametrizacion
|
||||||
|
|
||||||
|
private void SetLocalReport(string Reporte)
|
||||||
|
{
|
||||||
|
ReportViewer reportViewer = new ReportViewer();
|
||||||
|
reportViewer.ProcessingMode = ProcessingMode.Local;
|
||||||
|
reportViewer.SizeToReportContent = true;
|
||||||
|
reportViewer.Width = Unit.Percentage(100);
|
||||||
|
reportViewer.Height = Unit.Percentage(100);
|
||||||
|
|
||||||
|
FillDataSet(Reporte);
|
||||||
|
|
||||||
|
switch (Reporte)
|
||||||
|
{
|
||||||
|
|
||||||
|
case "Aplicacion":
|
||||||
|
reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"\Reportes\rdlc\repSolicitud.rdlc";
|
||||||
|
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("dtsSolicitud", tds.Tables["Datos"]));
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case "Estados":
|
||||||
|
reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reportes\repEstados.rdlc";
|
||||||
|
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("dtsEstados", tds.Tables["Datos"]));
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
reportViewer.LocalReport.SetParameters(GetParametersLocal(Reporte));
|
||||||
|
|
||||||
|
ViewBag.ReportViewer = reportViewer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FillDataSet(string Reporte)
|
||||||
|
{
|
||||||
|
string connectionString = GetConnectionString();
|
||||||
|
|
||||||
|
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
|
||||||
|
{
|
||||||
|
string queryString = GetQueryString(Reporte);
|
||||||
|
|
||||||
|
SqlDataAdapter sqlDataAapter = new SqlDataAdapter(queryString, sqlConnection);
|
||||||
|
|
||||||
|
sqlDataAapter.Fill(tds, "Datos");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetConnectionString()
|
||||||
|
{
|
||||||
|
return "data source=192.168.1.37;initial catalog=SinortAyA;user id=sinort;password=sinort2018";
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetQueryString(string Reporte)
|
||||||
|
{
|
||||||
|
|
||||||
|
string Respuesta = "";
|
||||||
|
|
||||||
|
switch (Reporte)
|
||||||
|
{
|
||||||
|
|
||||||
|
case "Aplicacion":
|
||||||
|
Respuesta = "SELECT "
|
||||||
|
+ " [IdAplicacion] ,[Descripcion] FROM "
|
||||||
|
+ " [Catalogos].[Aplicacion]";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Estados":
|
||||||
|
Respuesta = "SELECT "
|
||||||
|
+ " [IdEstado] ,[Descripcion] FROM "
|
||||||
|
+ " [Catalogos].[Estado]";
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return Respuesta;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReportParameter[] GetParametersLocal(string Reporte)
|
||||||
|
{
|
||||||
|
|
||||||
|
ReportParameter[] Respuesta = new ReportParameter[] { };
|
||||||
|
ReportParameter p1 = new ReportParameter();
|
||||||
|
ReportParameter p2 = new ReportParameter();
|
||||||
|
|
||||||
|
switch (Reporte)
|
||||||
|
{
|
||||||
|
|
||||||
|
case "Aplicacion":
|
||||||
|
|
||||||
|
p1 = new ReportParameter("prmTitulo1", "SINORT");
|
||||||
|
p2 = new ReportParameter("prmTitulo2", "ATESA");
|
||||||
|
|
||||||
|
Respuesta = new ReportParameter[] { p1, p2 };
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Estados":
|
||||||
|
|
||||||
|
p1 = new ReportParameter("prmTitulo1", "SINORT");
|
||||||
|
p2 = new ReportParameter("prmTitulo2", "ATESA");
|
||||||
|
|
||||||
|
Respuesta = new ReportParameter[] { p1, p2 };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return Respuesta;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue