public FrmGameRecords(FrmMenu frmMenu) { InitializeComponent(); FormSettings.SetSetting(this); MenuForm = frmMenu; try { using (var context = new RoadFighterDataEnt()) { var records = context.GameRecords.Select(x => new { x.Name, x.Score, x.Crash, x.GameID }) .OrderByDescending(x => x.Score) .ToList(); dtgRecords.DataSource = records; } } catch (Exception) { MessageBox.Show("Nie udało się połączyć z bazą danych"); } }
private void BtnConfirm_Click(object sender, EventArgs e) { string playerName; if (txbYourName.Text == "Your name") { playerName = "Guest"; } else { playerName = txbYourName.Text; } try { using (var context = new RoadFighterDataEnt()) { var score = new GameRecords { Name = playerName, Score = (short)GameScore, Crash = (short)GameCrash }; context.GameRecords.Add(score); context.SaveChanges(); MessageBox.Show("Score saved!", "Score", MessageBoxButtons.OK, MessageBoxIcon.Information); btnConfirm.Enabled = false; txbYourName.Enabled = false; } } catch (Exception) { MessageBox.Show("Nie udało się połączyć z bazą danych"); } }