Пример #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Login);

            Button   LoginButton     = FindViewById <Button>(Resource.Id.LoginButton);
            Button   newPlayerButton = FindViewById <Button>(Resource.Id.NewPlayerButton);
            EditText userName        = FindViewById <EditText>(Resource.Id.userName);
            EditText password        = FindViewById <EditText>(Resource.Id.password);
            TextView userErr         = FindViewById <TextView>(Resource.Id.userErr);
            UserDatabaseController databaseController = new UserDatabaseController();
            PageController         pageController     = new PageController(this.BaseContext);

            LoginButton.Click += (sender, e) =>
            {
                pageController.CloseKeyboard(userName);
                pageController.CloseKeyboard(password);
                //search the db for the user
                int reply = databaseController.checkUserPassword(userName.Text, password.Text);
                if ((reply == (int)UserDatabaseController.UserCheckErr.USERNAME_ERR) ||
                    (reply == (int)UserDatabaseController.UserCheckErr.PASSWORD_ERR)) //user accepted
                {
                    userErr.Text = ((UserDatabaseController.UserCheckErr)reply).ToString();
                    userErr.SetTextColor(Android.Graphics.Color.Red);
                }
                else
                {
                    pageController.GotoPage(typeof(MenuActivity), reply, Common.USERID);
                }
            };
            newPlayerButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(NewPlayerActivity));
            };
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.NewPlayer);

            //
            databaseController = new UserDatabaseController();
            EditText       userNameInput       = FindViewById <EditText>(Resource.Id.newUserName);
            EditText       userPassword        = FindViewById <EditText>(Resource.Id.userPassword);
            Button         checkUserNameButton = FindViewById <Button>(Resource.Id.checkUserNameButton);
            Button         toMenuButton        = FindViewById <Button>(Resource.Id.toMenuButton);
            Button         registerButton      = FindViewById <Button>(Resource.Id.registerButton);
            Button         beginButton         = FindViewById <Button>(Resource.Id.beginButton);
            TextView       illegalUserName     = FindViewById <TextView>(Resource.Id.illegalUsername);
            CheckBox       adminBox            = FindViewById <CheckBox>(Resource.Id.adminBox);
            EditText       adminPassword       = FindViewById <EditText>(Resource.Id.adminPassword);
            PageController pageController      = new PageController(this.BaseContext);
            bool           isAdmin             = false;
            int            newUserId           = 0;

            //check if username is legal and unique
            checkUserNameButton.Click += (sender, e) =>
            {
                pageController.CloseKeyboard(userNameInput);
                if (databaseController.checkUsername(userNameInput.Text))
                {
                    illegalUserName.Text = "Name exists - try a different one";
                    illegalUserName.SetTextColor(Android.Graphics.Color.Red);
                }
                else if ((userNameInput.Length() > MAX_USERNAME_LENGTH) || (userNameInput.Length() < MIN_USERNAME_LENGTH))
                {
                    illegalUserName.Text = string.Format("Name must be between {0}-{1} characters", MIN_USERNAME_LENGTH, MAX_USERNAME_LENGTH);
                    illegalUserName.SetTextColor(Android.Graphics.Color.Red);
                }
                else
                {
                    illegalUserName.Text = "GOOD!";
                    illegalUserName.SetTextColor(Android.Graphics.Color.Green);
                    userPassword.Enabled = true;
                }
            };

            //opens the admin password dialog if the admin checkbox is clicked
            adminBox.Click += (sender, e) =>
            {
                if (adminBox.Checked)
                {
                    adminPassword.Visibility = ViewStates.Visible;
                }
                else
                {
                    adminPassword.Visibility = ViewStates.Invisible;
                }
            };

            //try to insert a new player and informs of the outcome
            registerButton.Click += (sender, e) =>
            {
                pageController.CloseKeyboard(userPassword);
                if ((!adminBox.Checked) ||
                    (adminPassword.Text == ADMIN_PASSWORD))
                {
                    isAdmin = adminBox.Checked;
                    if ((userPassword.Length() > MAX_PASSWORD_LENGTH) || (userPassword.Length() < MIN_PASSWORD_LENGTH))
                    {
                        illegalUserName.Text = string.Format("Password must be between {0}-{1} characters", MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH);
                        illegalUserName.SetTextColor(Android.Graphics.Color.Red);
                    }
                    else
                    {
                        newUserId = databaseController.saveUser(userNameInput.Text, userPassword.Text, isAdmin);
                        if (newUserId != 0)
                        {
                            beginButton.Enabled = true;
                        }
                        else
                        {
                            illegalUserName.Text = "registration failed";
                            illegalUserName.SetTextColor(Android.Graphics.Color.Red);
                        }
                    }
                }
                else
                {
                    illegalUserName.Text = "admin password error";
                    illegalUserName.SetTextColor(Android.Graphics.Color.Red);
                }
            };

            beginButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(MenuActivity), newUserId, Common.USERID);
            };

            toMenuButton.Click += (sender, e) =>
            {
                Intent intent = new Intent(this, typeof(LoginActivity));
                StartActivity(intent);
            };
        }