Пример #1
0
        public void LoadViewGrid(StockItem item)
        {
            viewGamePanel.Visible = true;

            stockID.Text = item.StockID.ToString();
            gameID.Text = item.Game.GameID.ToString();
            title.Text = item.Game.Title;
            category.Text = item.Game.Category;
            released.Text = item.Game.ReleaseYear;
            agecat.Text = item.Game.AgeCategory.ToString();

            custID.Text = item.Customer.CustID == 0 ? "N/A" : item.Customer.CustID.ToString();
            fname.Text = item.Customer.FirstName == " " ? "N/A" : item.Customer.FirstName;
            sname.Text = item.Customer.Surname == " " ? "N/A" : item.Customer.Surname;
            address.Text = item.Customer.Address == " " ? "N/A" : item.Customer.Address;
            age.Text = item.Customer.Age == 0 ? "N/A" : item.Customer.Age.ToString();
            mobile.Text = item.Customer.Mobile == " " ? "N/A" : item.Customer.Mobile;

            issue.Text = item.IssueDate.ToShortDateString() == "1/1/0001" ? "N/A" : item.IssueDate.ToString("dd/M/yyyy");
            due.Text = item.DueDate.ToShortDateString() == "1/1/0001" ? "N/A" : item.DueDate.ToString("dd/M/yyyy");
            rented.Text = item.IsRented.ToString();
            reserved.Text = item.IsReserved.ToString();
        }
Пример #2
0
        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();
                }

            }
        }
Пример #3
0
        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)
                {

                }
            }
        }