private void btnCreateAccount_Click(object sender, EventArgs e) { using (PokemonEntities5 context = new PokemonEntities5()) { 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 = txtUsername.Text, Password = txtPassword.Text, Email = txtEmail.Text, CreationDate = DateTime.Now }; context.Trainers.Add(trainer); context.SaveChanges(); for (int x = 0; x < 5; x++) { context.getNewPokemon(NextID); context.SaveChanges(); } this.Hide(); var form2 = new Team(NextID); form2.Closed += (s, args) => this.Close(); form2.Show(); } }
private void btnChoosePokemon_Click(object sender, EventArgs e) { if (grdTrainerTeam.CurrentCell != null) { short AIPok = Convert.ToInt16(grdAiTeam.Rows[Convert.ToInt16(txtRound.Text) - 1].Cells[0].Value); short TrainerPok = Convert.ToInt16(grdTrainerTeam.Rows[grdTrainerTeam.CurrentCell.RowIndex].Cells[0].Value); using (PokemonEntities5 context = new PokemonEntities5()) { context.initiateRound(Convert.ToInt16(txt.Text), Convert.ToInt16(txtAI.Text), Convert.ToInt16(txtBattleID.Text), TrainerPok, AIPok); context.SaveChanges(); int cell = (grdTrainerTeam.CurrentCell.RowIndex); grdTrainerTeam.CurrentCell = null; grdAiTeam.CurrentCell = null; grdAiTeam.Rows[Convert.ToInt16(txtRound.Text) - 1].Visible = false; txtRound.Text = Convert.ToString(Convert.ToInt16(txtRound.Text) + 1); grdTrainerTeam.Rows[cell].Visible = false; var trainerID = Convert.ToInt16(txt.Text); var AiID = Convert.ToInt16(txtAI.Text); var BattleID = Convert.ToInt16(txtBattleID.Text); var TrainerScore = context.Rounds .Where(t => t.WinnerID == trainerID && t.BattleID == BattleID) .Select(t => new { t.RoundID }).Count(); var AiScore = context.Rounds .Where(t => t.WinnerID == AiID && t.BattleID == BattleID) .Select(t => new { t.RoundID }).Count(); if (TrainerScore >= 3 || AiScore >= 3 || Convert.ToInt16(txtRound.Text) > 5) { MessageBox.Show("game over"); if (TrainerScore >= 3) { MessageBox.Show("Congradulations You Won"); context.getNewPokemon(Convert.ToInt16(txt.Text)); context.SaveChanges(); } this.Hide(); var form = new Team(Convert.ToInt16(txt.Text)); form.Closed += (s, args) => this.Close(); form.Show(); } } } }
public battlePage(short trainerID) { InitializeComponent(); txt.Text = Convert.ToString(trainerID); using (PokemonEntities5 context = new PokemonEntities5()) { var max = context.Trainers.DefaultIfEmpty().Max(r => r == null ? 0 : r.TrainerID); max = Convert.ToInt16(max) + 1; short NextID = Convert.ToInt16(max); var UI = "Ui"; txtAI.Text = Convert.ToString(max); Trainer trainer = new Trainer { TrainerID = NextID, TName = UI, Password = UI, Email = UI, CreationDate = DateTime.Now }; context.Trainers.Add(trainer); context.SaveChanges(); for (int x = 0; x < 5; x++) { context.getNewPokemon(NextID); context.SaveChanges(); } grdAiTeam.DataSource = context.getTeam(NextID); grdTrainerTeam.DataSource = context.getTeam(trainerID); var battleid = context.Battles.DefaultIfEmpty().Max(r => r == null ? 0 : r.BattleID); battleid = Convert.ToInt16(battleid) + 1; short shortBattleID = Convert.ToInt16(battleid); txtBattleID.Text = Convert.ToString(shortBattleID); context.initiateBattle(trainerID, NextID, shortBattleID); context.SaveChanges(); } }
private void button1_Click(object sender, EventArgs e) { short PokIn = Convert.ToInt16(grdCollection.Rows[grdCollection.CurrentCell.RowIndex].Cells[0].Value); short PokOut = Convert.ToInt16(grdTeam.Rows[grdTeam.CurrentCell.RowIndex].Cells[0].Value); short trainerID = Convert.ToInt16(txtID.Text); using (PokemonEntities5 context = new PokemonEntities5()) { context.updateTeam(trainerID, PokOut, PokIn); grdTeam.DataSource = context.getTeam(Convert.ToInt16(txtID.Text)); grdTeam.Rows[0].Cells[0].Selected = false; grdCollection.DataSource = context.getCollection(Convert.ToInt16(txtID.Text)); if (grdCollection.Rows.Count >= 2) { grdCollection.Rows[0].Cells[0].Selected = false; } } }
public Team(short TrainerID) { using (PokemonEntities5 context = new PokemonEntities5()) { InitializeComponent(); txtID.Text = Convert.ToString(TrainerID); grdTeam.DataSource = context.getTeam(TrainerID); grdTeam.Rows[0].Cells[0].Selected = false; grdCollection.DataSource = context.getCollection(TrainerID); if (grdCollection.Rows.Count >= 2) { grdCollection.Rows[0].Cells[0].Selected = false; } if (grdCollection.RowCount == 0) { grdCollection.Visible = false; button1.Visible = false; } } }
private void btnLogin_Click(object sender, EventArgs e) { using (PokemonEntities5 context = new PokemonEntities5()) { var username = Convert.ToString(txtLoginUsername.Text); var password = Convert.ToString(txtLoginPassword.Text); //https://stackoverflow.com/questions/1802286/best-way-to-check-if-object-exists-in-entity-framework var result = context.Trainers .Where(t => t.TName == username && t.Password == password) .Select(t => new { t.TrainerID }).ToList(); dataGridView1.DataSource = result; if (context.Trainers.Any(t => t.TName == username)) { if (dataGridView1.RowCount == 0) { MessageBox.Show(username + " does not use the password you have entered"); txtLoginPassword.Clear(); } else { short shortId = Convert.ToInt16(dataGridView1.Rows[0].Cells[0].Value); this.Hide(); var form2 = new Team(shortId); form2.Closed += (s, args) => this.Close(); form2.Show(); } } else { MessageBox.Show(username + " does not exist in the system create an account"); } } }