public ActionResult ProposalReport(ProposalRepotViewModels model) { ViewBag.projecttype = Common.getprojecttype(); ReportDocument rd = new ReportDocument(); rd.Load(Path.Combine(Server.MapPath("~/CrystalReport"), "Proposalsponsored.rpt")); Response.Buffer = false; Response.ClearContent(); Response.ClearHeaders(); ViewBag.report = CrystalReportService.Getproposal(model); rd.SetDataSource(ViewBag.report); rd.SetParameterValue("Fromdate", model.FromDate); rd.SetParameterValue("Todate", model.ToDate); if (model.ProjecttypeId == 1) { rd.SetParameterValue("heading", "SPONSORED PROJECT PROPOSALS"); } else { rd.SetParameterValue("heading", "CONSULTANCY PROJECT PROPOSALS"); } Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); stream.Seek(0, SeekOrigin.Begin); Response.AddHeader("Content-Disposition", "inline; filename=Proposal_Report.pdf"); return(File(stream, "application/pdf")); }
public static List <ProposalRepotViewModels> Getproposal(ProposalRepotViewModels model) { try { using (var context = new IOASDBEntities()) { List <ProposalRepotViewModels> datelistproposal = new List <ProposalRepotViewModels>(); if (model.keysearch != null) { var query = (from PR in context.tblProposal from PI in context.tblUser from PD in context.tblPIDepartmentMaster where (PR.InwardDate >= model.FromDate && PR.InwardDate <= model.ToDate && PI.UserId == PR.PI && PR.Department == PD.DepartmentId && PR.ProjectType == model.ProjecttypeId) && (PI.FirstName.Contains(model.keysearch) || PR.ProposalTitle.Contains(model.keysearch) || PD.Department.Contains(model.keysearch) || PR.ProposalNumber.Contains(model.keysearch)) select new { PR.ProposalNumber, PI.FirstName, PR.ProposalTitle, PD.Department, PR.InwardDate, PR.Crtd_TS, PR.DurationOfProjectYears, PR.DurationOfProjectMonths }).ToList(); if (query.Count > 0) { for (int i = 0; i < query.Count; i++) { datelistproposal.Add(new ProposalRepotViewModels() { Proposalnumber = query[i].ProposalNumber, PI = query[i].FirstName, ProposalTitle = query[i].ProposalTitle, Department = query[i].Department, InwardDate = (DateTime)query[i].InwardDate, Crtd_TS = (DateTime)query[i].Crtd_TS, Durationofprojectyears = (Int32)query[i].DurationOfProjectYears, Durationofprojectmonths = (Int32)query[i].DurationOfProjectMonths }); } } return(datelistproposal); } else { var query = (from PR in context.tblProposal from PI in context.tblUser from PD in context.tblPIDepartmentMaster where (PR.InwardDate >= model.FromDate && PR.InwardDate <= model.ToDate && PI.UserId == PR.PI && PR.Department == PD.DepartmentId && PR.ProjectType == model.ProjecttypeId) select new { PR.ProposalNumber, PI.FirstName, PR.ProposalTitle, PD.Department, PR.InwardDate, PR.Crtd_TS, PR.DurationOfProjectYears, PR.DurationOfProjectMonths }).ToList(); if (query.Count > 0) { for (int i = 0; i < query.Count; i++) { datelistproposal.Add(new ProposalRepotViewModels() { Proposalnumber = query[i].ProposalNumber, PI = query[i].FirstName, ProposalTitle = query[i].ProposalTitle, Department = query[i].Department, InwardDate = (DateTime)query[i].InwardDate, Crtd_TS = (DateTime)query[i].Crtd_TS, Durationofprojectyears = (Int32)query[i].DurationOfProjectYears, Durationofprojectmonths = (Int32)query[i].DurationOfProjectMonths }); } } return(datelistproposal); } } } catch (Exception ex) { List <ProposalRepotViewModels> datelistproposal = new List <ProposalRepotViewModels>(); return(datelistproposal); } }