Пример #1
0
        private void CustomItem_MouseClick(object sender, EventArgs e)
        {
            if (sender is Button)
            {
                Button suspect = (Button)sender;
                if (suspect.Name.Equals(this.GameBuyButton.Name))
                {
                    DialogResult result = MessageBox.Show("Buy " + checkout.Count + " games?", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                    if (result == DialogResult.Yes)
                    {
                        Console.WriteLine("GameCart. Yes");

                        //LINQ testing
                        double total = checkout.Sum(a => a.Price);

/*                        double total = 0;
 *                      for (int i = 0; i < checkout.Count; i++)
 *                      {
 *                          total += checkout[i].Price;
 *                      }*/
                        if (loggedBuyer.Funds >= total)
                        {
                            loggedBuyer.Funds -= total;
                            loggedBuyer.gameLibrary.AddRange(checkout);
                            checkout.Clear();
                            GamePanels(this.InCartPanel, checkout);
                            FileAccessModule FAM = new FileAccessModule();
                            FAM.saveUser(loggedBuyer);
                            updatePage();
                        }
                        else
                        {
                        }
                    }
                    else if (result == DialogResult.No)
                    {
                        Console.WriteLine("GameCart. No");
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        Console.WriteLine("GameCart. Cancelled");
                    }
                }
            }
            else if (sender is Panel)
            {
                Panel suspect = (Panel)sender;
                if (Int32.TryParse(suspect.Name, out int x))
                {
                    checkout.Remove(checkout[x]);
                    updatePage();
                }
            }
        }
Пример #2
0
        private void Register_Click(object sender, EventArgs e)
        {
            //Check the textboxes first
            string ign      = this.IGNBox.Text;
            string username = this.UsernameBox.Text;
            string pass1    = this.PasswordBox.Text;
            string pass2    = this.PasswordConfirmBox.Text;

            Label userwarning = this.UserWarning;
            Label passwarning = this.PasswordWarning;

            if (ign.Length >= IGNLength)
            {
                if (username.Length >= UsernameLength)
                {
                    if (!FAM.checkUsernameExist(username))
                    {
                        userwarning.Text = "Available";
                        if (pass1.Length >= PasswordLength)
                        {
                            if (pass1.Equals(pass2))
                            {
                                Console.WriteLine("RegisterPage. Logged in");
                                passwarning.Visible = true;
                                passwarning.Text    = "Password match";
                                User newOne = new User(ign, username, pass1);
                                FAM.saveUser(newOne);
                                LoginPage goback = new LoginPage();
                                goback.Show();
                                goback.UsernameBox.Text    = newOne.UserName;
                                goback.UserWarning.Text    = "Registration autofill";
                                goback.UserWarning.Visible = true;
                                this.Dispose();
                                this.Close();
                            }
                            else
                            {
                                passwarning.Visible = true;
                                passwarning.Text    = "Password not matching";
                            }
                        }
                        else
                        {
                            passwarning.Visible = true;
                            passwarning.Text    = "At least " + PasswordLength + " characters";
                        }
                    }
                    else
                    {
                        userwarning.Text = "Already Exist";
                    }
                }
            }
        }
Пример #3
0
        //Listeners
        //Listener for double clicking
        private void CustomItem_DoubleClick(object sender, EventArgs e)
        {
            if (sender is Panel)
            {
                Panel suspect = (Panel)sender;
                Console.WriteLine(suspect.Name);
                if (Int32.TryParse(suspect.Name, out int x))
                {
                    //It's a game label, since its a number
                    //Console.WriteLine(PersonalLibrary[x].myInfo());
                    GamePage newPage = new GamePage(PersonalLibrary[x], LoggedIn, this, null);

                    //newPage.beOwned();      //game is owned by someone

                    newPage.Show();
                }
                else
                {
                    Console.WriteLine("Other label");
                }
            }
            else if (sender is Label)
            {
                Label suspect = (Label)sender;
                if (suspect.Name.Equals(this.UserFunds.Name))
                {
                    //Going to add money
                    string answer = Microsoft.VisualBasic.Interaction.InputBox("Enter how much money you would like to add",
                                                                               "Adding Funds",
                                                                               "Default",
                                                                               MousePosition.X,
                                                                               MousePosition.Y);
                    double addedmoney = 0;
                    //hello there
                    try {
                        addedmoney = Math.Round(Convert.ToDouble(answer), 2);
                    }
                    catch {
                        Console.WriteLine("Some error");
                    }
                    LoggedIn.Funds     += addedmoney;
                    this.UserFunds.Text = string.Format("{0:C}", (LoggedIn.Funds));
                    FAM.saveUser(LoggedIn);
                }
                else if (suspect.Name.Equals(this.BackButtonLabel.Name))
                {
                    //Go back to the previous page
                    parentForm.SetDesktopLocation(this.Location.X, this.Location.Y);
                    parentForm.Show();
                    CloseUp = false;
                    this.Close();
                }
            }
        }
Пример #4
0
        /*
         * Modes:
         *  Add Game    done
         *  Edit Game   done
         *  Remove Game done
         *  Add User    done
         *  Edit User
         *  Remove User
         */

        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            String selection = this.ModeSelection.Text;

            if (selection.Equals("Add Game"))
            {
                if (this.radioButton1.Checked)
                {
                    Game newGame = new Game(0 + "",
                                            this.TextBox1.Text,
                                            this.TextBox2.Text,
                                            this.ComboBoxLayOut.Text,
                                            Convert.ToDouble(this.TextBox4.Text),
                                            DateTime.Today,
                                            Convert.ToInt32(this.TextBox5.Text),
                                            0,
                                            0);

                    FAM.CreateGame(newGame);
                    this.Notification.Text = "Made Game";
                }
                else if (this.radioButton2.Checked)
                {
                    if (Int32.TryParse(this.TextBox1.Text, out int GameAmount))
                    {
                        FAM.ToGameFile(FAM.CreateGame(GameAmount));
                        this.Notification.Text = "Made " + GameAmount + " games";
                    }
                }
            }
            else if (selection.Equals("Edit Game"))
            {
                String searchbox = this.TextBox6.Text;
                if (Int32.TryParse(searchbox, out int searchresult))        //Redundancy.
                {
                    List <Game> GameLibrary = FAM.GetGameLibrary();
                    var         FindGame    = GameLibrary.Find(a => a.GameID.Equals(searchresult.ToString()));
                    if (FindGame != null)
                    {
                        try
                        {
                            if (FindGame.GameID.Equals(FocusedGame.GameID))     //more redundancy.
                                                                                //check if the game that's searched, is the same as the game that is saved in memory
                            {
                                double price = Convert.ToDouble(this.TextBox4.Text);
                                if (price < 0)
                                {
                                    price = .99;
                                    this.TextBox4.Text = price.ToString();
                                }

                                int rating = Convert.ToInt32(this.TextBox5.Text);

                                if (rating < 0)
                                {
                                    rating = 1;
                                }
                                else if (rating > 100)
                                {
                                    rating = 100;
                                }

                                Console.WriteLine("Found Game");
                                FocusedGame.Name    = this.TextBox1.Text;
                                FocusedGame.Studio  = this.TextBox2.Text;
                                FocusedGame.Genre   = this.ComboBoxLayOut.Text;
                                FocusedGame.Price   = price;
                                FocusedGame.Ratings = rating;



                                FAM.UpdateGameFile(FocusedGame);

                                FocusedGame = null;
                                updateTable();

                                this.TextBox1.ReadOnly = true;
                                this.TextBox2.ReadOnly = true;
                                this.TextBox4.ReadOnly = true;
                                this.TextBox5.ReadOnly = true;
                                this.TextBox6.ReadOnly = false;

                                this.TextBox1.Text = "";
                                this.TextBox2.Text = "";
                                this.TextBox4.Text = "";
                                this.TextBox5.Text = "";
                                this.TextBox6.Text = "";
                            }
                        }
                        catch
                        {
                            this.Notification.Text = "Search first";
                        }
                    }
                }
            }
            else if (selection.Equals("Remove Game"))
            {
                String searchbox = this.TextBox6.Text;
                if (Int32.TryParse(searchbox, out int searchresult))        //Redundancy.
                {
                    List <Game> GameLibrary = FAM.GetGameLibrary();
                    var         FindGame    = GameLibrary.Find(a => a.GameID.Equals(searchresult.ToString()));
                    if (FindGame != null)
                    {
                        try
                        {
                            if (FindGame.GameID.Equals(FocusedGame.GameID))     //more redundancy.
                                                                                //check if the game that's searched, is the same as the game that is saved in memory
                            {
                                FAM.RemoveGame(FocusedGame);

                                FocusedGame = null;
                                updateTable();

                                this.TextBox1.ReadOnly = true;
                                this.TextBox2.ReadOnly = true;
                                this.TextBox4.ReadOnly = true;
                                this.TextBox5.ReadOnly = true;
                                this.TextBox6.ReadOnly = false;

                                this.TextBox1.Text = "";
                                this.TextBox2.Text = "";
                                this.TextBox4.Text = "";
                                this.TextBox5.Text = "";
                                this.TextBox6.Text = "";
                            }
                        }
                        catch
                        {
                            this.Notification.Text = "Search First";
                        }
                    }
                }
            }
            else if (selection.Equals("Add User"))
            {
                if (FAM.checkUsernameExist(this.TextBox1.Text))
                {
                    this.Notification.Text = "Username exist";
                }
                else
                {
                    User newUser = new User(this.TextBox1.Text,
                                            this.TextBox2.Text,
                                            this.TextBox4.Text);
                    newUser.Funds = Convert.ToInt32(this.TextBox5.Text);

                    this.TextBox1.Text = "";
                    this.TextBox2.Text = "";
                    this.TextBox4.Text = "";
                    this.TextBox5.Text = "";

                    this.Notification.Text = "";

                    FAM.saveUser(newUser);
                }
            }
            else if (selection.Equals("Edit User"))
            {
                String searchbox = this.TextBox6.Text;
                if (FAM.checkUsernameExist(searchbox))      //Check that it's still the same thing
                {
                    if (FocusedUser != null)
                    {
                        if (FocusedUser.UserName != this.TextBox2.Text)
                        {
                            if (!FAM.checkUsernameExist(this.TextBox2.Text))
                            {
                                string oldUser = FocusedUser.UserName;              //old user name
                                FocusedUser.IGName   = this.TextBox1.Text;
                                FocusedUser.UserName = this.TextBox2.Text;          //updated username
                                FocusedUser.Password = this.TextBox4.Text;
                                FocusedUser.Funds    = Convert.ToDouble(this.TextBox5.Text);

                                FAM.RenamedUserSave(FocusedUser, oldUser);
                                FAM.saveUser(FocusedUser);

                                if (this.checkBox1.Checked)
                                {
                                    FAM.makeUserAdmin(FocusedUser);
                                }

                                this.TextBox1.Text = "";
                                this.TextBox2.Text = "";
                                this.TextBox4.Text = "";
                                this.TextBox5.Text = "";
                                this.TextBox6.Text = "";
                                FocusedGame        = null;
                            }
                            else
                            {
                                this.Notification.Text = "Username Exist.";
                            }
                        }
                        else
                        {
                            this.TextLabel1.Text = "IG Name: ";
                            this.TextLabel2.Text = "Username: "******"Password: "******"Funds: ";
                            this.TextLabel6.Text = "Search Username: "******"";
                            this.TextBox2.Text = "";
                            this.TextBox4.Text = "";
                            this.TextBox5.Text = "";
                            this.TextBox6.Text = "";
                            FocusedGame        = null;
                        }
                    }
                }
            }
            else if (selection.Equals("Remove User"))
            {
                String searchbox = this.TextBox6.Text;
                if (FAM.checkUsernameExist(searchbox))      //Check that it's still the same thing
                {
                    if (FocusedUser != null)
                    {
                        FAM.RemoveUser(FocusedUser);

                        FocusedUser            = null;
                        this.TextBox1.Text     = "";
                        this.TextBox2.Text     = "";
                        this.TextBox4.Text     = "";
                        this.TextBox5.Text     = "";
                        this.TextBox6.Text     = "";
                        this.Notification.Text = "Removed User";
                    }
                }
            }
            else if (selection.Equals("Add Pictures"))
            {
                if (Int32.TryParse(this.TextBox1.Text, out int amount))
                {
                    this.Notification.Text = "Loading. Please wait.";
                    FAM.GenerateImages(amount);
                    this.Notification.Text = "Made: " + amount + " Pictures";
                    this.TextBox1.Text     = "";
                }
                else
                {
                    this.Notification.Text = "Enter Number";
                }
            }
        }
Пример #5
0
 private void CustomItem_DoubleClick(object sender, EventArgs e)
 {
     if (sender is Panel)
     {
         Panel suspect = (Panel)sender;
         //Console.WriteLine(suspect.Name);
         if (Int32.TryParse(suspect.Name, out int x))
         {
             //USER HAS CLICKED ON A GAME PANEL
             //we Go in the game library
             //Console.WriteLine(StoreLibrary[x].myInfo());
             if (Application.OpenForms.OfType <GamePage>().Count() >= 1)
             {
                 Application.OpenForms.OfType <GamePage>().First().Close();
             }
             GamePage gamePage = new GamePage(StoreLibrary[x], LoggedIn, this, InCart);
             gamePage.Show();
         }
         else
         {
             Console.WriteLine("WelcomePage.  Other label");
         }
     }
     else if (sender is Label)
     {
         Label suspect = (Label)sender;
         if (suspect.Name.Equals(this.LogOutLabel.Name))
         {
             mainform.SetDesktopLocation(this.Location.X, this.Location.Y);
             mainform.Show();
             CloseUp = false;
             this.Close();
         }
         else if (suspect.Name.Equals(this.UserFunds.Name))
         {
             //Going to add money
             string answer = Microsoft.VisualBasic.Interaction.InputBox("Enter how much money you would like to add",
                                                                        "Adding Funds",
                                                                        "0.00",
                                                                        MousePosition.X,
                                                                        MousePosition.Y);
             double addedmoney = 0;
             try
             {
                 addedmoney = Math.Round(Convert.ToDouble(answer), 2);
             }
             catch
             {
                 Console.WriteLine("WelcomePage. Some error");
             }
             LoggedIn.Funds     += addedmoney;
             this.UserFunds.Text = string.Format("{0:C}", (LoggedIn.Funds));
             FAM.saveUser(LoggedIn);
         }
         else if (suspect.Name.Equals(this.InCartLabel.Name))
         {
             if (Application.OpenForms.OfType <GameCart>().Count() >= 1)
             {
                 Application.OpenForms.OfType <GameCart>().First().Close();
             }
             MakeCart(this, LoggedIn, InCart);
         }
     }
 }