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; } } }