예제 #1
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        //Instantiate the CustomerCart object

        if (Session["CustomerCart"] == null)
        {
            Session["CustomerCart"] = new ShopCart();
        }

        //Access the ProductPK from the DataKeys collection of the DataList

        int intID = Convert.ToInt32(dlGame.DataKeys[0]);

        //Get details about the game from the database
        //Note: These details could have been obtained from the DataList too

        using (GameTableAdapter aAdapter = new GameTableAdapter())
        {
            GameDataTable aTable;

            aTable = aAdapter.GetDataByGameID(intID);

            if (aTable.Rows.Count == 1)
            {
                GameRow aRow = aTable.Rows[0] as GameRow;

                //Add the CartItem

                if (aRow.stock <= 0)
                {
                    Response.Redirect("~/home.aspx");
                }

                ShopCart aCart = Session["CustomerCart"] as ShopCart;

                aCart.AddCartItem(aRow.gameID, aRow.name, aRow.boxImage, 1, aRow.price, aRow.stock);
            }
        }
        Response.Redirect("~/ShoppingCart.aspx");
    }
예제 #2
0
파일: DataAccess.cs 프로젝트: hmatland/Quiz
 public static void UpdateGame(Game game)
 {
     var tableAdapter = new GameTableAdapter();
     tableAdapter.Update(game.UserId, game.Score,game.QuizId,game.Id);
 }
예제 #3
0
파일: DataAccess.cs 프로젝트: hmatland/Quiz
 public static long? SaveGameToDb(Game game)
 {
     long? insertedId = 0;
     var tableAdapter = new GameTableAdapter();
     tableAdapter.Insert(game.UserId, game.Score, game.QuizId, ref insertedId);
     return insertedId;
 }
예제 #4
0
파일: DataAccess.cs 프로젝트: hmatland/Quiz
        public static List<Game> GetHighScoreList(long quizId)
        {
            var tableAdapter = new GameTableAdapter();
            var dataTable = tableAdapter.GetTopTenGames(quizId);
            var list = new List<Game>();
            foreach (var row in dataTable)
            {
                var game = new Game()
                {
                    Id = row.GameId,
                    QuizId = row.QuizId,
                    Score = row.Score,
                };
                if (row.IsNull("UserId"))
                {
                    game.UserId = null;
                    game.UserName = null;
                }
                else
                {
                    game.UserId = row.UserId;
                    game.UserName = GetUserName(row.UserId);
                }
                list.Add(game);

            }
            return list;
        }
예제 #5
0
파일: DataAccess.cs 프로젝트: hmatland/Quiz
        public static Game GetGame(long gameId)
        {
            var tableadapter = new GameTableAdapter();
            var datatable = tableadapter.GetGame(gameId);
            foreach (var row in datatable)
            {
                var game = new Game
                {
                    QuizId = row.QuizId,
                    Score = row.Score,
                    Id = gameId
                };
                if (row.IsUserIdNull())
                    game.UserId = null;
                else
                    game.UserId = row.UserId;
                return game;
            }
            return null;

            /*using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                var quizCmd = new SqlCommand("SELECT * FROM Game WHERE GameId = @GameId", connection);
                quizCmd.Parameters.Add("@GameId", SqlDbType.BigInt).Value = gameId;
                quizCmd.Prepare();
                var reader = quizCmd.ExecuteReader();

                while (reader.Read())
                {
                    var game = new Game
                    {
                        UserId = reader["UserId"] as int?,
                        QuizId = (long) reader["QuizId"],
                        Score = (int) reader["Score"],
                        Id = (long) reader["GameId"]
                    };
                    return game;
                }
                return null;
            }*/
        }