protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var weekid = int.Parse(Request.QueryString["weekid"]); // Set report mode for local processing. rv1.ProcessingMode = ProcessingMode.Local; rv1.LocalReport.DataSources.Clear(); var ds = new LeaguesDS(); var WeekDate = ""; bool IsBye = false; bool isCancelled = false; using (LeaguesEntities db = new LeaguesEntities()) { var week = db.WednesdaySchedules.Find(weekid); WeekDate = week.GameDateFormatted; if (!week.IsCancelled) { var list = db.WednesdayMatches.Where(x => x.GameDate == weekid && x.Rink != -1) .OrderBy(x => x.Rink).ToList(); foreach (var item in list) { var forfeit = ""; switch (item.Forfeit) { case 2: forfeit = item.Team1.ToString(); break; case 3: forfeit = item.Team2.ToString(); break; } ds.Game.AddGameRow(item.Team1, item.WednesdayTeam.Player.NickName + ", " + item.WednesdayTeam.Player1.NickName + ", " + item.WednesdayTeam.Player2.NickName, item.Team2.Value, item.WednesdayTeam1.Player.NickName + ", " + item.WednesdayTeam1.Player1.NickName + ", " + item.WednesdayTeam1.Player2.NickName, item.Team1Score, item.Team2Score, item.Rink, forfeit); } var matches = db.WednesdayMatches.Where(x => x.Rink == -1 && x.GameDate == weekid); if (matches.Any()) { var match = matches.First(); ds.Byes.AddByesRow(match.WednesdaySchedule.GameDateFormatted, match.Team1, match.WednesdayTeam.Player.NickName + ", " + match.WednesdayTeam.Player1.NickName + ", " + match.WednesdayTeam.Player2.NickName); rv1.LocalReport.DataSources.Add(new ReportDataSource("Bye", ds.Byes.Rows)); IsBye = true; } else { rv1.LocalReport.DataSources.Add(new ReportDataSource("Bye", new System.Data.DataTable())); } rv1.LocalReport.DataSources.Add(new ReportDataSource("Game", ds.Game.Rows)); } else { isCancelled = true; rv1.LocalReport.DataSources.Add(new ReportDataSource("Game", new System.Data.DataTable())); rv1.LocalReport.DataSources.Add(new ReportDataSource("Bye", new System.Data.DataTable())); } } rv1.LocalReport.DataSources.Add(new ReportDataSource("Stand", CalculateStandings.Wednesday(weekid).Rows)); var p1 = new ReportParameter("WeekDate", WeekDate); var p2 = new ReportParameter("League", "Wednesday"); var p3 = new ReportParameter("IsBye", IsBye?"1":"0"); var p4 = new ReportParameter("Cancelled", isCancelled ? "1" : "0"); rv1.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3, p4 }); //parameters rv1.ShowToolBar = true; // Refresh the ReportViewer. rv1.LocalReport.Refresh(); } }
public ActionResult StandingsReport(int id, int weekid) { var reportViewer = new ReportViewer() { ProcessingMode = ProcessingMode.Local, Width = Unit.Pixel(800), Height = Unit.Pixel(1000), ShowExportControls = true }; ViewBag.WeekId = weekid; ViewBag.Id = id; var league = _db.Leagues.Find(id); if (league == null) { return(HttpNotFound()); } var ds = new TournamentDS(); bool IsBye = false; bool isCancelled = false; var week = _db.Schedules.Find(weekid); if (week == null) { return(HttpNotFound()); } var weekDate = week.WeekDate; if (!week.Cancelled) { foreach (var item in _db.Matches.Include(x => x.Team1).Include(x => x.Team).Include(x => x.Schedule).Where(x => x.WeekId == weekid && x.Rink != -1) .OrderBy(x => x.Rink)) { var forfeit = ""; if (item.ForFeitId > 0) { if (item.ForFeitId == item.Team.TeamNo) { forfeit = item.Team.TeamNo.ToString(); } else { forfeit = item.Team1.TeamNo.ToString(); } } else if (item.ForFeitId == -1) { forfeit = "Both"; } else { if (item.Team1Score + item.Team2Score == 0) { ViewBag.Error = "Some matches were not scored"; reportViewer.LocalReport.ReportPath = Server.MapPath("/ReportFiles/Empty.rdlc"); var p11 = new ReportParameter("Message", "Some matches were not scored"); reportViewer.LocalReport.SetParameters(new ReportParameter[] { p11 }); ViewBag.ReportViewer = reportViewer; return(View()); } } ds.Game.AddGameRow(item.Team.TeamNo, Players(item.Team, league.TeamSize), item.Team1.TeamNo, Players(item.Team1, league.TeamSize), item.Team1Score, item.Team2Score, item.Rink, forfeit); } // check for byes var matches = _db.Matches.Where(x => x.Rink == -1 && x.WeekId == weekid); if (matches.Any()) { var match = matches.First(); ds.Byes.AddByesRow(match.Schedule.WeekDate, match.Team.TeamNo, Players(match.Team, league.TeamSize)); reportViewer.LocalReport.DataSources.Add(new ReportDataSource("Bye", ds.Byes.Rows)); IsBye = true; } else { reportViewer.LocalReport.DataSources.Add(new ReportDataSource("Bye", new System.Data.DataTable())); } } else { isCancelled = true; reportViewer.LocalReport.DataSources.Add(new ReportDataSource("Game", new System.Data.DataTable())); reportViewer.LocalReport.DataSources.Add(new ReportDataSource("Bye", new System.Data.DataTable())); } reportViewer.LocalReport.DataSources.Add(new ReportDataSource("Stand", CalculateStandings.Doit(weekid, league).Rows)); reportViewer.LocalReport.ReportPath = Server.MapPath("/ReportFiles/Standings.rdlc"); reportViewer.LocalReport.DataSources.Add(new ReportDataSource("Game", ds.Game.Rows)); var p1 = new ReportParameter("WeekDate", weekDate); var p2 = new ReportParameter("Description", league.LeagueName); var p3 = new ReportParameter("IsBye", IsBye ? "1" : "0"); var p4 = new ReportParameter("IsCancelled", isCancelled ? "1" : "0"); var p5 = new ReportParameter("PointsCount", league.PointsCount ? "1" : "0"); var p6 = new ReportParameter("TiesAllowed", league.TiesAllowed ? "1" : "0"); reportViewer.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3, p4, p5, p6 }); ViewBag.ReportViewer = reportViewer; return(View()); }