Пример #1
0
        private void addGameBtn_Click(object sender, EventArgs e)
        {
            #region Test Code
            //var p1 = new VideoGame()
            //{
            //    Title = "GTA 5",
            //    Price = 19.99 ,
            //    Rating = "ESRB Mature"
            //};

            //VideoGameDb.Insert(p1);

            //var p2 = new VideoGame()
            //{
            //    Title = "GenShin Impact",
            //    Price = 0 ,
            //    Rating = "ESRB Teen"
            //};

            //VideoGameDb.Insert(p2);

            //p1.Price = 15.50;

            //VideoGameDb.Update(p1);

            //List<VideoGame> prods = VideoGameDb.GetVideoGames();

            //VideoGameDb.Delete(p1);

            //prods = VideoGameDb.GetVideoGames();
            //foreach(VideoGame v in prods)
            //{
            //    gameLstBox.Items.Add(v.Title);
            //}
            #endregion

            if (priceTxt.Text != "" ||
                titleTxt.Text != "" ||
                ratingCmbBxox.SelectedIndex != -1)
            {
                VideoGame game = new VideoGame()
                {
                    Title  = titleTxt.Text,
                    Price  = Convert.ToDouble(priceTxt.Text),
                    Rating = ratingCmbBxox.Text
                };
                gameLstBox.Items.Clear();
                VideoGameDb.Insert(game);
                List <VideoGame> games = VideoGameDb.GetVideoGames();
                foreach (VideoGame g in games)
                {
                    gameLstBox.Items.Add(g);
                }
            }
            ClearData();
        }
Пример #2
0
        public Form1()
        {
            InitializeComponent();
            List <VideoGame> games = VideoGameDb.GetVideoGames();

            foreach (VideoGame g in games)
            {
                gameLstBox.Items.Add(g);
            }
        }
Пример #3
0
        private void gameLstBox_MouseClick(object sender, MouseEventArgs e)
        {
            VideoGame clickedItem = (VideoGame)gameLstBox.SelectedItem;

            List <VideoGame> games = VideoGameDb.GetVideoGames();

            foreach (VideoGame g in games)
            {
                titleTxt.Text      = clickedItem.Title;
                priceTxt.Text      = Convert.ToString(clickedItem.Price);
                ratingCmbBxox.Text = clickedItem.Rating;
            }
        }
Пример #4
0
 private void deleteGameBtn_Click(object sender, EventArgs e)
 {
     if (gameLstBox.SelectedItem != null)
     {
         VideoGame gameToBeDeleted = (VideoGame)gameLstBox.SelectedItem;
         VideoGameDb.Delete(gameToBeDeleted);
         gameLstBox.Items.Clear();
         List <VideoGame> games = VideoGameDb.GetVideoGames();
         foreach (VideoGame g in games)
         {
             gameLstBox.Items.Add(g);
         }
     }
 }
Пример #5
0
        private void updateGameBtn_Click(object sender, EventArgs e)
        {
            if (titleTxt.Text != "" && priceTxt.Text != "")
            {
                VideoGame updateGame = (VideoGame)gameLstBox.SelectedItem;
                updateGame.Title  = titleTxt.Text;
                updateGame.Price  = Convert.ToDouble(priceTxt.Text);
                updateGame.Rating = ratingCmbBxox.Text;
                VideoGameDb.Update(updateGame);
                gameLstBox.Items.Clear();
                List <VideoGame> games = VideoGameDb.GetVideoGames();
                foreach (VideoGame g in games)
                {
                    gameLstBox.Items.Add(g);
                }

                ClearData();
            }
        }