コード例 #1
0
        //public ActionResult GameDetailsReport()
        //{
        //    using (CVGSModelsEntities cvgs = new CVGSModelsEntities())
        //    {
        //        var v = cvgs.Games.ToList();
        //        return View("~/Views/Reports/GamesDetailsReport.cshtml", v);
        //    }
        //}
        //public ActionResult MemberDetailsReport()
        //{
        //    using (CVGSModelsEntities cvgs = new CVGSModelsEntities())
        //    {
        //        var v = cvgs.MemberDetails.ToList();
        //        return View("~/Views/Reports/MemberDetailsReport.cshtml", v);
        //    }
        //}
        //public ActionResult MemberListReport()
        //{
        //    using (CVGSModelsEntities cvgs = new CVGSModelsEntities())
        //    {
        //        var v = cvgs.MemberDetails.ToList();
        //        return View("~/Views/Reports/ListOfMembersReport.cshtml", v);
        //    }
        //}
        public ActionResult Report(string id, string reportName, int? memberId, int? gameId)
        {
            List<MemberDetails> md = new List<MemberDetails>();
            //ListOfGamesReport gd = new ListOfGamesReport();
            List<GameDetailsReport> gd = new List<GameDetailsReport>();
            //Member member = new Member();
            ReportDataSource rd = new ReportDataSource();
            string reportPath = reportName + ".rdlc";
            LocalReport lr = new LocalReport();
            string path = Path.Combine(Server.MapPath("~/Reports"), reportPath);
            string pageWidth = "";

            if (System.IO.File.Exists(path))
            {
                lr.ReportPath = path;
            }
            else
            {
                return View("Index");
            }
            if (reportName == "MemberDetailsReport")
            {

                using (CVGSModelsEntities cvgs = new CVGSModelsEntities())
                {
                    var member = UoW.Members.GetAll().FirstOrDefault(m => m.UserId == memberId);
                    string gender = "";

                    if (member.MemberDetails.IsMale.HasValue)
                    {
                        if (member.MemberDetails.IsMale.Value == true)
                        {
                            gender = "Male";
                        }
                        else
                        {
                            gender = "Female";
                        }
                    }

                    string newsletter = "";
                    if (member.MemberDetails.ReceiveNewsletter.HasValue)
                    {
                        if (member.MemberDetails.ReceiveNewsletter.Value == true)
                        {
                            newsletter = "Yes";
                        }
                        else
                        {
                            newsletter = "No";
                        }
                    }

                    string lastName = "";
                    string firstName = "";
                    string dateOfBirth = "";
                    string platformName = "";
                    string category = "";
                    string provinceStateName = "";
                    string country = "";
                    string postalZipCode = "";
                    string street1 = "";
                    string street2 = "";
                    string city = "";

                    if (member.MemberDetails.LastName != null)
                    {
                        lastName = member.MemberDetails.LastName;
                    }
                    if (member.MemberDetails.FirstName != null)
                    {
                        firstName = member.MemberDetails.FirstName;
                    }
                    if (member.MemberDetails.DateOfBirth != null)
                    {
                        dateOfBirth = member.MemberDetails.DateOfBirth.Value.ToString("MM/dd/yyyy");
                    }
                    if (member.MemberDetails.PlatformId != null)
                    {
                        platformName = member.MemberDetails.Platform.PlatformName;
                    }
                    if (member.MemberDetails.CategoryId != null)
                    {
                        category = member.MemberDetails.Category.CategoryName;
                    }
                    if (member.MemberDetails.HomeAddress != null)
                    {
                        provinceStateName = member.MemberDetails.HomeAddress.ProvinceState.Name;
                        country = member.MemberDetails.HomeAddress.Country.Name;
                        postalZipCode = member.MemberDetails.HomeAddress.PostalZipCode;
                        street1 = member.MemberDetails.HomeAddress.Street1;
                        street2 = member.MemberDetails.HomeAddress.Street2;
                        city = member.MemberDetails.HomeAddress.City;
                    }

                    var memberDetailsReport = new MemberDetailsReport()
                    {
                        UserId = member.UserId,
                        LastName = lastName,
                        FirstName = firstName,
                        Email = member.Email,
                        DateOfBirth = dateOfBirth,
                        DisplayName = member.DisplayName,
                        IsMale = gender,
                        PlatformName = platformName,
                        Category = category,
                        ReceiveNewsletter = newsletter,
                        MemberSince = member.MemberSince.ToString("MM/dd/yyyy"),
                        Name = provinceStateName,
                        Expr1 = country,
                        PostalZipCode = postalZipCode,
                        Street1 = street1,
                        Street2 = street2,
                        City = city,
                    };

                    List<MemberDetailsReport> members = new List<MemberDetailsReport>();
                    members.Add(memberDetailsReport);
                    rd = new ReportDataSource("DataSet1", members);
                    pageWidth = "14in";
                }
            }
            else if (reportName == "ListOfMembersReport")
            {
                using (CVGSModelsEntities cvgs = new CVGSModelsEntities())
                {
                    md = cvgs.MemberDetails.ToList();
                    rd = new ReportDataSource("DataSet1", md);
                    pageWidth = "8.5in";
                }
            }
            else if (reportName == "ListOfEmployeesReport")
            {
                var listOfEmployees = UoW.Employees.GetAll()
                    .ToList()
                     .Select(m => new ListOfEmployeesReport()
                     {
                           UserId = m.UserId,
                          LastName = m.LastName,
                          FirstName = m.FirstName,
                          DisplayName = m.DisplayName
                      });
                using (CVGSModelsEntities cvgs = new CVGSModelsEntities())
                {
                    rd = new ReportDataSource("DataSet1", listOfEmployees);
                    pageWidth = "8.5in";
                }
            }
            else if (reportName == "ListOfGamesReport")
            {
                var listOfGames = UoW.Games.GetAll()
                .ToList()
                .Select(g => new ListOfGamesReport()
                {
                    GameId = g.GameId,
                    PlatformName = g.Platform.PlatformName,
                    Title = g.Title
                });

                using (CVGSModelsEntities cvgs = new CVGSModelsEntities())
                {
                    //gd.Add(listOfGames);
                    rd = new ReportDataSource("DataSet1", listOfGames);
                    pageWidth = "8.5in";
                }
            }
            else if (reportName == "GameDetailsReport")
            {
                var game = UoW.Games.GetAll().FirstOrDefault(g => g.GameId == gameId);

                var gameDetailsReport = new GameDetailsReport()
                {
                    GameId = game.GameId,
                    Title = game.Title,
                    PlatformName = game.Platform.PlatformName,
                    CategoryName = game.Category.CategoryName,
                    Price = game.Price,
                    Name = game.Publisher.Name,
                    ReleaseDate = game.ReleaseDate.ToString("MM/dd/yyyy"),
                    Expr1 = game.ESRBRating.Name
                };

                using (CVGSModelsEntities cvgs = new CVGSModelsEntities())
                {
                    List<GameDetailsReport> gameDetails = new List<GameDetailsReport>();
                    gameDetails.Add(gameDetailsReport);
                    rd = new ReportDataSource("DataSet1", gameDetails);
                    pageWidth = "9in";
                }
            }
            else if (reportName == "SalesReport")
            {
                 var salesReport = UoW.Orders.GetAll()
                                     .ToList()
                                 .Select(g => new SalesReport()
                                {
                                    OrderDate = g.OrderDate,
                                    OrderId = g.OrderId,
                                    Total = g.Total,
                                    Username = g.Username
                                });
                using (CVGSModelsEntities cvgs = new CVGSModelsEntities())
                {
                    rd = new ReportDataSource("DataSet1", salesReport);
                    pageWidth = "8.5in";
                }
            }
            else if (reportName == "WishListReport")
            {
                var wishLists = UoW.WishLists.GetAll().ToList();

                var distinctGames = wishLists.GroupBy(g => g.GameId);

                var wishListReport = new List<WishListReport>();

                foreach (var game in distinctGames)
                {
                    var list = new WishListReport();

                    foreach (var wishList in wishLists)
                    {
                        if (wishList.GameId == game.Key)
                        {
                            list.GameId = game.Key;
                            list.Count += wishList.Count;
                            list.Title = game.FirstOrDefault().Game.Title;
                        }
                    }

                    wishListReport.Add(list);
                }

                using (CVGSModelsEntities cvgs = new CVGSModelsEntities())
                {
                    rd = new ReportDataSource("DataSet1", wishListReport);
                    pageWidth = "8.5in";
                }
            }

            lr.DataSources.Add(rd);
            string reportType = id;
            string mimeType;
            string encoding;
            string fileNameExtension;

            string deviceInfo =
                "<DeviceInfo>" +
                " <OutputFormat>" + id + "</OutputFormat>" +
                "<PageWidth>" + pageWidth + "</PageWidth>" +
                "<PageHeight>11.5in</PageHeight>" +
                "<MarginTop>0.5in</MarginTop>" +
                "<MarginLeft>0in</MarginLeft>" +
                "<MarginRight>0in</MarginRight>" +
                "<MarginBottom>0.5in</MarginBottom>" +
                "</DeviceInfo>";

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            renderedBytes = lr.Render(
                reportType,
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);

            return File(renderedBytes, mimeType);
        }
コード例 #2
0
        public ActionResult MemberDetailsReport()
        {
            int memberID = (int)Session["memberId"];
            var member = UoW.Members.GetAll().FirstOrDefault(m => m.UserId == memberID);
            var dob = member.MemberDetails.DateOfBirth;
            var format = String.Format("{0:MM/dd/yyyy}", dob);

            var memberDetailsReport = new MemberDetailsReport()
            {
                UserId = member.UserId,
                LastName = member.MemberDetails.LastName,
                FirstName = member.MemberDetails.FirstName,
                Email = member.Email,
                DateOfBirth = format,
                Address = member.MemberDetails.HomeAddress
            };

            return View(memberDetailsReport);
        }