Beispiel #1
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            using (PokemonEntities context = new PokemonEntities())
            {
                string check;

                var max = context.Trainers.DefaultIfEmpty().Max(r => r == null ? 0 : r.TrainerID);
                max = Convert.ToInt16(max) + 1;

                short NextID = Convert.ToInt16(max);

                Trainer trainer = new Trainer
                {
                    TrainerID    = NextID,
                    TName        = tbUsername.Text,
                    Password     = tbPassword.Text,
                    Email        = tbEmail.Text,
                    CreationDate = DateTime.Now
                };

                context.Trainers.Add(trainer);
                context.SaveChanges();

                for (int i = 0; i < 5; i++)
                {
                    context.getNewPokemon(NextID);
                    context.SaveChanges();
                }

                MessageBox.Show("You did it...well done kid!");
                this.Hide();
                var nextForm = new ViewTeam(NextID, parent);
                nextForm.Show();
            }
        }
Beispiel #2
0
        private void ViewTeam_Load(object sender, EventArgs e)
        {
            using (PokemonEntities context = new PokemonEntities())
            {
                var result = (from t in context.TrainerPokemons
                              join p in context.Pokemons on t.PokemonID equals p.PokemonID
                              where t.TrainerID == trainerID && t.Team == true
                              select new { t.PokemonID, p.Name, p.Attack, p.Defence, p.SpecialAttack, p.SpecialDefence, p.Speed, p.Image }).ToList();

                dataGridView1.DataSource = result;

                var result2 = (from t in context.TrainerPokemons
                               join p in context.Pokemons on t.PokemonID equals p.PokemonID
                               where t.TrainerID == trainerID && t.Team == false
                               select new { t.PokemonID, p.Name, p.Attack, p.Defence, p.SpecialAttack, p.SpecialDefence, p.Speed, p.Image }).ToList();

                dataGridView2.DataSource = result2;
            }
        }
Beispiel #3
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            short PokeOut = Convert.ToInt16(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value);

            short PokeIn = Convert.ToInt16(dataGridView2.Rows[dataGridView2.CurrentCell.RowIndex].Cells[0].Value);


            using (PokemonEntities context = new PokemonEntities())
            {
                context.updateTeam(trainerID, PokeOut, PokeIn);

                var result = (from t in context.TrainerPokemons
                              join p in context.Pokemons on t.PokemonID equals p.PokemonID
                              where t.TrainerID == trainerID && t.Team == true
                              select new { t.PokemonID, p.Name, p.Attack, p.Defence, p.SpecialAttack, p.SpecialDefence, p.Speed, p.Image }).ToList();

                dataGridView1.DataSource = result;

                //dataGridView2.DataSource = context.getTeam(Convert.ToInt16(txtID.Text));
                dataGridView2.Rows[0].Cells[0].Selected = false;

                var result2 = (from t in context.TrainerPokemons
                               join p in context.Pokemons on t.PokemonID equals p.PokemonID
                               where t.TrainerID == trainerID && t.Team == false
                               select new { t.PokemonID, p.Name, p.Attack, p.Defence, p.SpecialAttack, p.SpecialDefence, p.Speed, p.Image }).ToList();

                dataGridView2.DataSource = result2;

                //dataGridView1.DataSource = context.getCollection(Convert.ToInt16(txtID.Text));


                if (dataGridView1.Rows.Count >= 2)
                {
                    dataGridView1.Rows[0].Cells[0].Selected = false;
                }

                context.SaveChanges();
            }
        }
Beispiel #4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string user;

            using (PokemonEntities context = new PokemonEntities()) {
                user = Convert.ToString(tbUsername.Text);

                var result = context.Trainers
                             .Where(t => t.TName == user)
                             .Select(t => new { t.TrainerID }).ToList();

                dataGridView1.DataSource = result;



                if (context.Trainers.Any(t => t.TName == user))
                {
                    if (dataGridView1.RowCount == 0)
                    {
                        MessageBox.Show(user + " does not use the password you have entered");
                        tbPassword.Clear();
                    }
                    else
                    {
                        short trainerID = Convert.ToInt16(dataGridView1.Rows[0].Cells[0].Value);
                        this.Hide();
                        var nextForm = new ViewTeam(trainerID, parent);
                        nextForm.Show();
                    }
                }
                else
                {
                    MessageBox.Show(user + " does not exist in the system create an account");
                }
            }
        }