/// <summary> /// Deletes a selected game from the listbox and the system. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDelete_Click(object sender, EventArgs e) { //Instantiate a DBConnect class called connect. DBConnect connect = new DBConnect(); //Check if the selected game is a ps4. if (lbxGames.SelectedItem is PS4) { //Cast the selected item into a ps4 class. PS4 toDelete = (PS4)lbxGames.SelectedItem; //Use the .DeleteGame method to delete the game from the system. connect.DeleteGame(toDelete.ID); } //Check if the selected game is a xbone. else if (lbxGames.SelectedItem is XBONE) { //Cast the selected item into a xbone class. XBONE toDelete = (XBONE)lbxGames.SelectedItem; //Use the .DeleteGame method to delete the game from the system. connect.DeleteGame(toDelete.ID); } //Check if the selected game is a wiiu. else if (lbxGames.SelectedItem is WII_U) { //Cast the selected item into a wiiu class. WII_U toDelete = (WII_U)lbxGames.SelectedItem; //Use the .DeleteGame method to delete the game from the system. connect.DeleteGame(toDelete.ID); } //Refresh the data shown in the listbox. RefreshData(); }
/// <summary> /// Get the selected item from the listbox and use the details as properties for a game class to edit. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEdit_Click(object sender, EventArgs e) { //Check if the selected item is a ps4 game. if (lbxGames.SelectedItem is PS4) { //Create a ps4 class to edit. PS4 editGame = new PS4(); //Cast the selected item in the listbox into a ps4 class. editGame = (PS4)lbxGames.SelectedItem; //Set the radio button to ps4. rdoPS4.Checked = true; //Set the texts in the textboxes to the properties of the ps4 class. tbxTitle.Text = editGame.Title; tbxYear.Text = editGame.Year.ToString(); tbxPublisher.Text = editGame.Publisher; tbxQuantity.Text = editGame.Quantity.ToString(); tbxPrice.Text = editGame.Price.ToString(); tbxOther.Text = editGame.PsMove; } //Check if the selected item is a xbone game. else if (lbxGames.SelectedItem is XBONE) { //Create a xbone class to edit. XBONE editGame = new XBONE(); //Cast the selected item in the listbox into a xbone class. editGame = (XBONE)lbxGames.SelectedItem; //Set the radio button to xbone. rdoXBONE.Checked = true; //Set the texts in the textboxes to the properties of the xbone class. tbxTitle.Text = editGame.Title; tbxYear.Text = editGame.Year.ToString(); tbxPublisher.Text = editGame.Publisher; tbxQuantity.Text = editGame.Quantity.ToString(); tbxPrice.Text = editGame.Price.ToString(); tbxOther.Text = editGame.Kinect; } //Check if the selected item is a wiiu game. else if (lbxGames.SelectedItem is WII_U) { //Create a wiiu class to edit. WII_U editGame = new WII_U(); //Cast the selected item in the listbox into a wiiu class. editGame = (WII_U)lbxGames.SelectedItem; //Set the radio button to wiiu. rdoWIIU.Checked = true; //Set the texts in the textboxes to the properties of the wiiu class. tbxTitle.Text = editGame.Title; tbxYear.Text = editGame.Year.ToString(); tbxPublisher.Text = editGame.Publisher; tbxQuantity.Text = editGame.Quantity.ToString(); tbxPrice.Text = editGame.Price.ToString(); tbxOther.Text = editGame.GamePad; } }
/// <summary> /// Method to convert a string array to a xbone game. /// </summary> /// <param name="gameSpecs"></param> /// <returns> Returns a game class. </returns> public Game ConvertToXBONE(string[] gameSpecs) { //Create a new xbone class. XBONE xboneGame = new XBONE(); //Check if the game is a xbone game. if (gameSpecs[2] == "XBONE") { //Use the string array as properties for the game. xboneGame.ID = int.Parse(gameSpecs[0]); xboneGame.Title = gameSpecs[1]; xboneGame.Platform = gameSpecs[2]; xboneGame.Year = int.Parse(gameSpecs[3]); xboneGame.Publisher = gameSpecs[4]; xboneGame.Quantity = int.Parse(gameSpecs[5]); xboneGame.Price = int.Parse(gameSpecs[6]); xboneGame.Kinect = gameSpecs[7]; } //Return game. return(xboneGame); }