Ejemplo n.º 1
0
        public bool ValidateUsername()
        {
            // Check account database for existing username
            AccountDatabase database = new AccountDatabase();

            database.OpenConnection();
            // If there is an existing account, update the validation message
            if (database.LookUpAccountRecord(Username, Password).ErrorString != "no record found")
            {
                usernameValidationMessage = "\u2022 Username already exists. \n";
            }
            else if (Username == null || Username.Trim().Length == 0)
            {
                UsernameValidationMessage = "\u2022 Username cannot be empty. \n";
            }
            else
            {
                UsernameValidationMessage = null;
                if (Username.Trim().Length < 7)
                {
                    UsernameValidationMessage += "\u2022 Username must be at least 7 characters long. \n";
                }
                if (Username.Trim().Length > 20)
                {
                    UsernameValidationMessage += "\u2022 Username cannot be more than 20 characters long. \n";
                }
                if ((Username.Any(char.IsWhiteSpace)))
                {
                    UsernameValidationMessage += "\u2022 Username cannot contain spaces. \n";
                }
            }
            // Close connection to Account Database
            database.CloseConnection();
            // If username has not been disqualified, send an "acceptable" message
            if (UsernameValidationMessage == null)
            {
                UsernameValidationMessage = "\u2022 Username is acceptable. \n";
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public void CreateAccount()
        {
            // Open a connection to the Account Database
            AccountDatabase database = new AccountDatabase();

            database.OpenConnection();
            // Send the request to generate a new account and store result in accountCreated property
            AccountRecord newlyCreatedAccount = new AccountRecord();

            newlyCreatedAccount.Username = Username;
            AccountCreated = database.AddAccountRecord(newlyCreatedAccount, Password);
            // Close connection to the Account Database
            database.CloseConnection();
            AccountCreated = true;
            if (AccountCheck && AccountCreated)
            {
                AccountValidationMessage = "\u2022 Account created.  Log in to play!";
            }
        }
Ejemplo n.º 3
0
        public void ValidateAccountAndLogin()
        {
            // Open connection to the Account Database
            AccountDatabase database = new AccountDatabase();

            database.OpenConnection();
            // Check whether the username/password combination is valid or not
            AccountRecord loginAccount = database.LookUpAccountRecord(Username, Password);

            if (loginAccount.ErrorString == "valid record")
            {
                AccountValidationMessage = "Successful login";
                LoginCompleted           = true;
            }
            else
            {
                AccountValidationMessage = "Failed login. Check username and password and try again.";
                LoginCompleted           = false;
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            // Choose Test
            Console.WriteLine("account or gameElements?");
            string response1 = Console.ReadLine();

            // Test Accounts
            if (response1 == "account")
            {
                Console.WriteLine("read or write?");
                string response2 = Console.ReadLine();
                // Test Writing a New Account
                if (response2 == "write")
                {
                    Console.WriteLine("Beginning Write Test...");
                    AccountRecord   testRecord = new AccountRecord();
                    AccountDatabase database   = new AccountDatabase();
                    database.OpenConnection();
                    //request dummy data
                    Console.WriteLine("Please provide a username:"******"Please provide a password:"******"A duplicate exists.  No account was created.  Try a different name.");
                    }
                    database.CloseConnection();
                }
                // Test Reading an Existing Account
                else
                {
                    Console.WriteLine("Beginning Read Test...");
                    AccountRecord   testRecord = new AccountRecord();
                    AccountDatabase database   = new AccountDatabase();
                    database.OpenConnection();
                    //request dummy data
                    Console.WriteLine("Please provide a username:"******"Please provide a password:"******"Hello {testRecord.Username}!");
                    Console.WriteLine(testRecord.ErrorString);
                    database.CloseConnection();
                }
            }
            // Test Other Database Activity
            else
            {
                Console.WriteLine("Beginning Other Database Test...");
                CardDatabase  database = new CardDatabase();
                List <string> names    = new List <string>();
                database.OpenConnection();
                // Test Pull All String Names
                names = database.RequestAllGameElementNames();
                foreach (string name in names)
                {
                    Console.WriteLine(name);
                }
                Console.WriteLine("Test 1 Complete.");
                CardDealer  dealer = new CardDealer();
                List <Card> cards1 = dealer.ListAllCards();
                // Test Pull All Card Records
                List <Card> moreCards = new List <Card>();
                foreach (Card card2 in cards1)
                {
                    Console.WriteLine(card2.Name);
                }
                Console.WriteLine("Test 2 Complete.");
                // Test Pull a Specific Card Record
                SystemCard  sensor = dealer.ChooseRandomSensor();
                List <Card> cards6 = dealer.DealCardsForSensor(sensor);
                foreach (Card carde in cards6)
                {
                    Console.WriteLine(carde.Name);
                }
                Console.WriteLine(sensor.Name);
                Console.WriteLine("Please Provide the name of one of the cards above (type exactly):");
                CardRecord card = database.RequestCardByName(Console.ReadLine());
                Console.WriteLine($"{card.Name},{card.ADCType},{card.IsMultiplexed},{card.SignalConditioning}");

                database.CloseConnection();
            }
            Console.WriteLine("Nothing went wrong in this tests");
            Console.ReadLine();
        }