private void generatesGames(int amount)
        {
            FileAccessModule FAM            = new FileAccessModule();
            List <Game>      libraryofGames = new List <Game>();

            FAM.FromGameFile("", libraryofGames);
            FAM.initateGames(amount, libraryofGames);
            FAM.ToGameFile("", libraryofGames);
        }
Beispiel #2
0
        public LoginPage()
        {
            InitializeComponent();
            this.FormClosed += our_FormClosed;
            FileAccessModule FAM = new FileAccessModule();


            RandomizeGame RandomGame = new RandomizeGame();

            FAM.ToGameFile(FAM.CreateGame(200));
        }
        /*
         * 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";
                }
            }
        }