Ejemplo n.º 1
0
        public formMainMenu(formUserAccount gameScreen)
        {
            InitializeComponent();
            this.gameScreen = gameScreen;

            //to make sure the window screen is display at centre
            this.StartPosition = FormStartPosition.CenterScreen;
        }
Ejemplo n.º 2
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            MarioCraftModel ctx = new MarioCraftModel();
            //gameUser = ctx.GAMEUSERs.First();

            var user = from u in ctx.GAMEUSERs where u.USEREMAIL == txtEmail.Text select u;

            //var gu = from u in ctx.GAMEUSERs where u.USERPASSWORD == txtPassword.Text select u;

            //if either email or password field empty display error message
            if (txtEmail.Text.Equals("") && txtPassword.Text.Equals(""))
            {
                MessageBox.Show("Email and Password field cannot be empty", "Email or Password field empty",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtEmail.Focus();
                return;
            }


            //https://dotprogramming.blogspot.com/2015/09/login-form-using-entity-framework-in.html
            //check if user email matches database
            var userExist = user.FirstOrDefault(a => a.USEREMAIL.Equals(txtEmail.Text));

            //if email match record in database
            if (userExist != null)
            {
                //if password matches records in database
                if (userExist.USERPASSWORD.Equals(txtPassword.Text))
                {
                    MessageBox.Show("Log in success!", "Log In Confirmation",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);


                    formUserAccount gameScreen = new formUserAccount(txtEmail.Text);
                    this.Close();
                    gameScreen.Show();
                }
                else
                {
                    errorProvider1.SetError(txtPassword, "Password does not match record,please try again");
                    txtPassword.Focus();
                    return;
                }
            }
            else
            {
                MessageBox.Show("Game user not found",
                                "Invalid Email address",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtEmail.Focus();
                return;
            }
        }