public StockItem(int newStockID, DateTime newIssueDate, DateTime newDueDate, bool newIsRented, bool newIsReserved, bool newIsDamaged, Game newGame, Customer newCustomer) { stockID = newStockID; game = newGame; customer = newCustomer; isRented = newIsRented; isReserved = newIsReserved; issueDate = newIssueDate; dueDate = newDueDate; }
public StockItem(int newStockID, Game newGame, Customer newCustomer) { stockID = newStockID; game = newGame; customer = newCustomer; isRented = false; isReserved = false; issueDate = new DateTime(); dueDate = new DateTime(); }
private void searchGameButton_Click(object sender, EventArgs e) { //Hide Labels searchIDCheck.Visible = false; searchTitleCheck.Visible = false; notFoundLabel.Visible = false; Game editGame = new Game(0, "", "", "", 0, 0); if (searchIDRadio.Checked == true) { int gameID; bool isNumeric = Int32.TryParse(searchIDTextBox.Text, out gameID); //Find the game with corresponding GameID editGame = Program.gameList.Find(game => game.HasID(gameID)); if (searchIDTextBox.Text == "Search By GameID") { searchIDCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); searchIDCheck.Visible = true; } else if (searchIDTextBox.Text.Trim().Length == 0) { searchIDCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); searchIDCheck.Visible = true; } else if (!isNumeric) { searchIDCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); searchIDCheck.Visible = true; } else if (editGame == null) { notFoundLabel.Visible = true; } else { gameDetailsPanel.Visible = true; titleTextBox.Text = editGame.Title; categoryComboBox.SelectedItem = editGame.Category; releaseComboBox.SelectedItem = editGame.ReleaseYear; ageComboBox.SelectedItem = editGame.AgeCategory.ToString(); numCopiesTextBox.Minimum = editGame.NumCopies; numCopiesTextBox.Value = editGame.NumCopies; searchGameButton.Visible = false; updateGameButton.Visible = true; } } else { //Find the game with corresponding Title editGame = Program.gameList.Find(game => game.HasTitle(searchTitleTextBox.Text)); if (searchTitleTextBox.Text == "Search By Title") { searchTitleCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); searchTitleCheck.Visible = true; } else if (searchTitleTextBox.Text.Trim().Length == 0) { searchTitleCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); searchTitleCheck.Visible = true; } else if (editGame == null) { notFoundLabel.Visible = true; } else { gameDetailsPanel.Visible = true; titleTextBox.Text = editGame.Title; categoryComboBox.SelectedItem = editGame.Category; releaseComboBox.SelectedItem = editGame.ReleaseYear; ageComboBox.SelectedItem = editGame.AgeCategory.ToString(); numCopiesTextBox.Minimum = editGame.NumCopies; searchGameButton.Visible = false; updateGameButton.Visible = true; } } }
private void updateGameButton_Click(object sender, EventArgs e) { int copies; bool isNumeric = Int32.TryParse(numCopiesTextBox.Text, out copies); if (titleTextBox.Text.Trim().Length == 0) { titleCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); titleCheck.Visible = true; } else if (!isNumeric) { numCopiesCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); numCopiesCheck.Visible = true; } else { titleCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.tick)); titleCheck.Visible = true; categoryCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.tick)); categoryCheck.Visible = true; releaseCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.tick)); releaseCheck.Visible = true; ageCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.tick)); ageCheck.Visible = true; numCopiesCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.tick)); numCopiesCheck.Visible = true; string newTitle, newCategory, newReleaseYear; int newAgeCategory, newNumCopies, currentNumCopies = 0, addToStock = 0, location = 0; Game newGame = new Game(0,"","","",0,0); newAgeCategory = Int32.Parse(ageComboBox.Text); newNumCopies = (int)numCopiesTextBox.Value; newTitle = titleTextBox.Text; newCategory = categoryComboBox.Text; newReleaseYear = releaseComboBox.Text; if (searchIDRadio.Checked == true) location = Program.gameList.FindIndex(game => game.HasID(Int32.Parse(searchIDTextBox.Text))); else location = Program.gameList.FindIndex(game => game.HasTitle(searchTitleTextBox.Text)); currentNumCopies = Program.gameList[location].NumCopies; if (newNumCopies != currentNumCopies) { addToStock = (newNumCopies - currentNumCopies); } Program.gameList[location].Title = newTitle; Program.gameList[location].Category = newCategory; Program.gameList[location].ReleaseYear = newReleaseYear; Program.gameList[location].AgeCategory = newAgeCategory; Program.gameList[location].NumCopies = newNumCopies; newGame = Program.gameList[location]; //Update current stock if (searchIDRadio.Checked == true) { for (int i = 0; i < Program.stockList.Count(); i++) { if (Program.stockList[i].Game.HasID(Int32.Parse(searchIDTextBox.Text))) { Program.stockList[i].Game.Title = newTitle; Program.stockList[i].Game.Category = newCategory; Program.stockList[i].Game.ReleaseYear = newReleaseYear; Program.stockList[i].Game.AgeCategory = newAgeCategory; Program.stockList[i].Game.NumCopies = newNumCopies; } } } else { for (int i = 0; i < Program.stockList.Count(); i++) { if (Program.stockList[i].Game.HasTitle(searchTitleTextBox.Text)) { Program.stockList[i].Game.Title = newTitle; Program.stockList[i].Game.Category = newCategory; Program.stockList[i].Game.ReleaseYear = newReleaseYear; Program.stockList[i].Game.AgeCategory = newAgeCategory; Program.stockList[i].Game.NumCopies = newNumCopies; } } } //Create fake customer Customer cust = new Customer(0, " ", " ", " ", 0, " "); //Add Stock Items for (int i = 0; i < addToStock; i++) { int nextID = Program.GetNextStockID(); StockItem newStockItem = new StockItem(nextID, newGame, cust); Program.stockList.Add(newStockItem); } DialogResult dialogResult = MessageBox.Show("Game was successfully Updated.", "Success!", MessageBoxButtons.OK); if (dialogResult == DialogResult.OK) { this.Close(); } } }
private void addGameButton_Click(object sender, EventArgs e) { titleCheck.Visible = false; categoryCheck.Visible = false; releaseCheck.Visible = false; ageCheck.Visible = false; numCopiesCheck.Visible = false; int copies; bool isNumeric = Int32.TryParse(numCopiesTextBox.Text, out copies); if (titleTextBox.Text.Length == 0 || titleTextBox.Text == "Title") { titleCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); titleCheck.Visible = true; } else if (categoryComboBox.Text == "Category") { categoryCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); categoryCheck.Visible = true; } else if (releaseComboBox.Text == "Release Year") { releaseCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); releaseCheck.Visible = true; } else if (ageComboBox.Text == "Age Category") { ageCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); ageCheck.Visible = true; } else if(numCopiesTextBox.Text == "Number of Copies") { numCopiesCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); numCopiesCheck.Visible = true; } else if(!isNumeric) { numCopiesCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.x)); numCopiesCheck.Visible = true; } else { titleCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.tick)); titleCheck.Visible = true; categoryCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.tick)); categoryCheck.Visible = true; releaseCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.tick)); releaseCheck.Visible = true; ageCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.tick)); ageCheck.Visible = true; numCopiesCheck.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.tick)); numCopiesCheck.Visible = true; try { string title, category, releaseYear; int gameID, ageCategory, numCopies; gameID = Int32.Parse(gameIDTextBox.Text); ageCategory = Int32.Parse(ageComboBox.Text); numCopies = Int32.Parse(numCopiesTextBox.Text); title = titleTextBox.Text; category = categoryComboBox.Text; releaseYear = releaseComboBox.Text; Game newGame = new Game(gameID, title, category, releaseYear, ageCategory, numCopies); Program.gameList.Add(newGame); //Create fake customer Customer cust = new Customer(0, " ", " ", " ", 0, " "); //Add Stock Items for (int i = 0; i < numCopies; i++) { int nextID = Program.GetNextStockID(); StockItem newStockItem = new StockItem(nextID, newGame, cust); Program.stockList.Add(newStockItem); } DialogResult dialogResult = MessageBox.Show("Game was successfully added. Add another one ?", "Success!", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { AddGameForm anotherGame = new AddGameForm(); anotherGame.Show(); this.Close(); } else { this.Close(); } } catch (Exception ex) { } } }