Ejemplo n.º 1
0
        private DataTable getTable(int selectedIndex)
        {
            DataTable dt = new DataTable();

            // Game List
            if (selectedIndex == 1)
            {
                IList <GameModel> games = null;
                using (var context = new CVGSEntities())
                {
                    games = context.games.Select(s => new GameModel()
                    {
                        name = s.name
                    }).ToList <GameModel>();
                }
                dt.Columns.Add("Name", typeof(string));
                dt.Rows.Add("Name");
                foreach (GameModel row in games)
                {
                    dt.Rows.Add(row.name.ToString());
                }
            }
            // Game Detail
            else if (selectedIndex == 2)
            {
                IList <GameModel> games = null;
                using (var context = new CVGSEntities())
                {
                    games = context.games.Select(s => new GameModel()
                    {
                        name        = s.name,
                        description = s.description,
                        publisher   = s.publisher,
                        publishDate = s.publishDate,
                        genre       = s.genre,
                        rating      = s.rating,
                        price       = s.price
                    }).ToList <GameModel>();
                }
                dt.Columns.Add("Name", typeof(string));
                dt.Columns.Add("Description", typeof(string));
                dt.Columns.Add("Publisher", typeof(string));
                dt.Columns.Add("PublishDate", typeof(DateTime));
                dt.Columns.Add("Genre", typeof(string));
                dt.Columns.Add("Rating", typeof(string));
                dt.Columns.Add("Price", typeof(decimal));

                foreach (GameModel row in games)
                {
                    dt.Rows.Add(row.name.ToString(), row.description.ToString(), row.publisher.ToString(),
                                row.publishDate.ToString(), row.genre.ToString(), row.rating.ToString(), row.price.ToString());
                }
            }
            // Member List
            else if (selectedIndex == 3)
            {
                IList <UserModel> users = null;
                using (var context = new CVGSEntities())
                {
                    users = context.users.Select(s => new UserModel()
                    {
                        firstName = s.firstName,
                        lastname  = s.lastName
                    }).ToList <UserModel>();
                }
                dt.Columns.Add("Name", typeof(string));
                dt.Rows.Add("Name");
                foreach (UserModel user in users)
                {
                    dt.Rows.Add(user.firstName.ToString() + ' ' + user.lastname.ToString());
                }
            }
            // Member Detail
            else if (selectedIndex == 4)
            {
                IList <UserModel> users = null;
                using (var context = new CVGSEntities())
                {
                    users = context.users.Select(s => new UserModel()
                    {
                        username  = s.username,
                        firstName = s.firstName,
                        lastname  = s.lastName,
                        email     = s.email,
                        age       = s.age
                    }).ToList <UserModel>();
                }
                dt.Columns.Add("username", typeof(string));
                dt.Columns.Add("firstName", typeof(string));
                dt.Columns.Add("lastname", typeof(string));
                dt.Columns.Add("email", typeof(string));
                dt.Columns.Add("age");
                dt.Rows.Add("Name", "Firest Name", "Last Name", "Email", "Age");

                foreach (UserModel row in users)
                {
                    dt.Rows.Add(row.username.ToString(), row.firstName.ToString(), row.lastname.ToString(),
                                row.email.ToString(), row.age.ToString());
                }
            }
            // wishList
            else if (selectedIndex == 5)
            {
                IList <WishListModel> wish = null;
                using (var context = new CVGSEntities())
                {
                    wish = context.wishLists.Select(s => new WishListModel()
                    {
                        username = s.username,
                    }).ToList <WishListModel>();
                }
                dt.Columns.Add("Name", typeof(string));
                dt.Rows.Add("Name");
                foreach (WishListModel row in wish)
                {
                    dt.Rows.Add(row.username.ToString());
                }
            }
            // Sales Report
            else if (selectedIndex == 6)
            {
                IList <SalesModel> sales = null;
                using (var context = new CVGSEntities())
                {
                    sales = context.orders.Select(s => new SalesModel()
                    {
                        username  = s.username,
                        gameId    = s.gameId,
                        orderDate = s.orderDate
                    }).ToList <SalesModel>();
                }
                dt.Columns.Add("Name");
                dt.Columns.Add("Game Id");
                dt.Columns.Add("Order Date");
                dt.Rows.Add("Name", "Game Id", "Order Date");

                foreach (SalesModel row in sales)
                {
                    dt.Rows.Add(row.username.ToString(), row.gameId.ToString(), row.orderDate.ToString());
                }
            }
            return(dt);
        }