Exemplo n.º 1
0
        public void addGame(Game obj, int num)
        {
            try
            {
                database = new OleDbConnection(connectionString);
                database.Open();

                string queryString = "INSERT INTO Game (Title, Description, Publisher, ReleaseDate, Rating, PurchasePrice, Copies) " +
                                     "VALUES ('" + obj.Title + "', '" + obj.Description + "', '" + obj.Publisher + "', '" + obj.ReleaseDate + "', '" +
                                     obj.Rating + "', '" + obj.Price + "', '" + obj.Copies + "')";

                string queryString2 = "SELECT * FROM Game WHERE Title = '" + obj.Title + "'";

                string queryString3;

                OleDbCommand cmd = new OleDbCommand(queryString, database);
                OleDbCommand cmd2 = new OleDbCommand(queryString2, database);

                count = cmd.ExecuteNonQuery();

                reader = cmd2.ExecuteReader();

                Game temp = new Game();

                reader.Read();
                temp.Id = Int32.Parse(reader["ID"].ToString());
                temp.Title = reader["Title"].ToString();
                temp.Description = reader["Description"].ToString();
                temp.Publisher = reader["Publisher"].ToString();
                temp.ReleaseDate = reader["ReleaseDate"].ToString();
                temp.Rating = reader["Rating"].ToString();
                temp.Price = Double.Parse(reader["PurchasePrice"].ToString());
                temp.Copies = Int32.Parse(reader["Copies"].ToString());

                queryString3 = "INSERT INTO GameCopy (CheckedOut, GameID) " +
                                 "VALUES (false, '" + temp.Id + "')";

                OleDbCommand cmd3 = new OleDbCommand(queryString3, database);

                for (int i = 0; i < num; i++)
                    count2 = cmd3.ExecuteNonQuery();

                if (count >= 1)
                    MessageBox.Show(obj.Title + " has been added!");
                else
                    MessageBox.Show("Error: Could not add game!");

                reader.Close();
                database.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                reader.Close();
                database.Close();
            }
        }
Exemplo n.º 2
0
 private void okButton_Click_1(object sender, EventArgs e)
 {
     dbIO dataHandler = new dbIO();
     Game newGame = new Game(0, titleTextBox.Text, descriptionTextBox.Text, publisherTextBox.Text, releaseDateMaskedTextBox.Text, ratingTextBox.Text, double.Parse(priceMaskedTextBox.Text), (int)numberOfCopiesUpDown.Value);
     dataHandler.addGame(newGame,(Int32)numberOfCopiesUpDown.Value);
     titleTextBox.Text = "";
     descriptionTextBox.Text = "";
     publisherTextBox.Text = "";
     releaseDateMaskedTextBox.Text = "";
     ratingTextBox.Text = "";
     priceMaskedTextBox.Text = "";
     numberOfCopiesUpDown.Value = 0;
 }
Exemplo n.º 3
0
        public void updateGame(Game obj)
        {
            try
            {
                database = new OleDbConnection(connectionString);
                database.Open();

                string queryString = "UPDATE Game " +
                                     "SET Title = '" +obj.Title+ "', Description = '" +obj.Description+
                                     "', Publisher = '" +obj.Publisher+ "', ReleaseDate = '" +obj.ReleaseDate+
                                     "', Rating = '" +obj.Rating+ "', PurchasePrice = " +obj.Price+
                                     ", Copies = " +obj.Copies+
                                     " WHERE ID = " +obj.Id;

                OleDbCommand cmd = new OleDbCommand(queryString, database);

                count = cmd.ExecuteNonQuery();

                if (count >= 1)
                    MessageBox.Show(obj.Title + "'s record has been updated!");
                else
                    MessageBox.Show("Error: No game by that title!");

                database.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                database.Close();
            }
        }
Exemplo n.º 4
0
        public List<Game> searchGame(string name)
        {
            gameList.Clear();

            try
            {
                database = new OleDbConnection(connectionString);
                database.Open();

                string queryString = "SELECT * FROM Game Where Title LIKE ('%" +name+ "%')";

                OleDbCommand cmd = new OleDbCommand(queryString, database);

                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Game temp = new Game();

                    temp.Id =(Int32) reader["ID"];
                    temp.Title = reader["Title"].ToString();
                    temp.Description = reader["Description"].ToString();
                    temp.Publisher = reader["Publisher"].ToString();
                    temp.ReleaseDate = reader["ReleaseDate"].ToString();
                    temp.Rating = reader["Rating"].ToString();
                    temp.Price =(double) reader["PurchasePrice"];
                    temp.Copies =(Int32) reader["Copies"];

                    gameList.Add(temp);
                }

                reader.Close();
                database.Close();
                return gameList;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                gameList.Clear();
                reader.Close();
                database.Close();
                return gameList;
            }
        }