Exemplo n.º 1
0
        public void addNewUserInformation()
        {
            using (ScoreTrendDataClassesDataContext dbNewUser = new ScoreTrendDataClassesDataContext())
            {
                try
                {
                    user newUser = new user();  //create new user table row with this object

                    newUser.username = u;   //set new username as u;
                    newUser.password = p;   //set new password as p;
                    newUser.teamid = intTeamIdSelected;     //send the rest of the information to the user table
                    newUser.leagueid = intLeagueIdSelected;
                    newUser.firstname = firstname;
                    newUser.lastname = lastname;

                    if (radYesAuth.Checked) //if authorized scorekeeper
                    {
                        newUser.authorized = 1;
                    }
                    else
                    {
                        newUser.authorized = 0;
                    }

                    dbNewUser.users.InsertOnSubmit(newUser);
                    dbNewUser.SubmitChanges();  //submit changes

                    if (radYesIAmAPlayer.Checked)   //if user is a player
                    {
                        player newPlayer = new player();    //create new player table row with this object

                        newPlayer.teamid = intTeamIdSelected;   //insert new player information
                        newPlayer.firstname = firstname;
                        newPlayer.lastname = lastname;

                        dbNewUser.players.InsertOnSubmit(newPlayer);
                        dbNewUser.SubmitChanges();  //submit changes

                        var newPlayerIdGiven1 = from players in context.players where players.firstname == firstname && players.lastname == lastname select players;

                        //update player id for new player from the users table player id
                        var newPlayerIdGiven2 = (from players in context.players where players.firstname == firstname && players.lastname == lastname select players).Single();
                        newPlayerIdGiven2.playerid = 3012;

                        context.SubmitChanges();

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Cannot communicate with database. Application will now close.","ScoreTrend" + ex);
                    Application.Exit();
                }
            }
        }
		private void detach_players(player entity)
		{
			this.SendPropertyChanging();
			entity.team = null;
		}
		private void attach_players(player entity)
		{
			this.SendPropertyChanging();
			entity.team = this;
		}
 partial void Deleteplayer(player instance);
 partial void Updateplayer(player instance);
 partial void Insertplayer(player instance);