Example #1
0
        private void btnRG_Click_1(object sender, EventArgs e)
        {
            bool         success      = true;
            UserEntities playerEntity = new UserEntities();
            Player       player1      = new Player();
            var          pl           =
                from p in playerEntity.Players
                select p;

            //Kiem tra username trong database
            foreach (var p in pl)
            {
                if (this.txtUS.Text.Trim() == p.P_Username.Trim())
                {
                    success = false;
                    MessageBox.Show("Username have been taken!");
                }
            }
            if (success)
            {
                player1.P_Username = this.txtUS.Text.Trim();
                player1.P_Password = this.txtPW.Text.Trim();
                player1.P_Score    = 0;
                player1.P_State    = false;
                playerEntity.Players.Add(player1);
                playerEntity.SaveChanges();
                MessageBox.Show("Register successfully!");
                this.txtUS.ResetText();
                this.txtPW.ResetText();
                this.txtConfirm.ResetText();
            }
        }
Example #2
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     MENU = new Menu();
     try
     {
         UserEntities playerEntity = new UserEntities();
         Player       player1      = new Player();
         var          pl           = (from player in playerEntity.Players
                                      where player.P_Username == this.txtUsername.Text.Trim()
                                      select player).SingleOrDefault();
         if (pl != null)
         {
             if (this.txtPassword.Text.Trim() == pl.P_Password.Trim())
             {
                 pl.P_State = true;
                 playerEntity.SaveChanges();
                 DialogResult a;
                 a = MessageBox.Show("Login Success! Click Ok to play game", "Success", MessageBoxButtons.OK);
                 if (a == DialogResult.OK)
                 {
                     this.Close();
                     this.Visible = false;
                     MENU.ptPlayNow_Click(sender, e);
                 }
             }
         }
         else
         {
             MessageBox.Show("Username is not defined");
         }
     }
     catch
     {
     }
 }
Example #3
0
        private void ptTetris_Click(object sender, EventArgs e)
        {
            UserEntities playerEntity = new UserEntities();
            Player       player1      = new Player();
            var          pl           = (from player in playerEntity.Players
                                         where player.P_State == true
                                         select player).SingleOrDefault();

            if (pl != null)
            {
                pl.P_State = false;
                playerEntity.SaveChanges();
            }
            MENU.Show();
            this.Close();
        }