Fw: Prog Reports
Autor: Elton | Publicado: 2011-10-23T18:27:00-07:00

  &nbsp;   &nbsp;  From: Elton Doerner  Sent: Friday, September 23, 2011 11:07 AM To: Elton Doerner  Subject: Prog Reports &nbsp;    1.&nbsp;&nbsp;&nbsp; CRIAR UM DATASET COM O SQL DO RELATÓRIO &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (o sql não pode ter campos  nullos) &nbsp; 2.&nbsp;&nbsp;&nbsp; CRIAR UM RPT UTILIZANDO O DATASET &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (utilizado somente para o desing  do relatório) &nbsp; 3.&nbsp;&nbsp;&nbsp; CRIAR UMA CLASSE QUE REPRESENTE OS DADOS DO RELATÓRIO  (dataset) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (o tipo da propriedade não pode  ser nullable (ex: int?)) &nbsp; using System; namespace FmgaWeb.Areas.Report.Views.ControllerName { &nbsp;&nbsp;&nbsp; public class ContaCorrenteClass &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public int Codigo { get; set;  } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string Nome { get; set;  } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... &nbsp;&nbsp;&nbsp; } } &nbsp; 4.&nbsp;&nbsp;&nbsp; CRIAR O CONTROLLER &nbsp; using System.Linq; using System.Web.Mvc; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; using Dados; using FmgaWeb.Controllers; namespace FmgaWeb.Areas.Report.Controllers { &nbsp;&nbsp;&nbsp; public class ContaCorrenteController :  BaseController &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public ActionResult  ExtratoMensal() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var mes  = Me.ObterMesAberto(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var list  = ContaCorrente.ListAllFromMes(mes).ToList(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if  (list.Count &gt; 0) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  ReportClass rpt = new Views.ContaCorrente.ContaCorrenteExtrato();&nbsp; //  arquivo rpt &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  rpt.Load(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  rpt.SetDataSource(list); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  rpt.SetParameterValue("Usuario", Contexto.UsuarioLogado.Nome); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  rpt.SetParameterValue("Titulo", "Título da Relatório"); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  var stream = rpt.ExportToStream(ExportFormatType.PortableDocFormat); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  return File(stream, "application/pdf"); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return  null; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } } &nbsp; 5.&nbsp;&nbsp;&nbsp; CRIAR O MÉTODO QUE CARREGA OS DADOS UTILIZANDO O SQL  DO DATASET &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (nenhum campo pode retornar  valor null) &nbsp; public static IEnumerable&lt;ContaCorrenteClass&gt; ListAllFromMes(Me  mes) { &nbsp;&nbsp;&nbsp; return  ContextoDados.Db.ExecuteStoreQuery&lt;ContaCorrenteClass&gt;(@" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT&nbsp;&nbsp;&nbsp;&nbsp;  ..."); } &nbsp; &nbsp; &nbsp;