-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHighScoreForm.cs
47 lines (42 loc) · 1.35 KB
/
HighScoreForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Windows.Forms;
namespace CarRacingGame
{
public partial class HighScoreForm : Form
{
// Initalize to reuse in this class
HighScoreQuery query = new HighScoreQuery();
public HighScoreForm()
{
InitializeComponent();
}
private void submitBtn_Click(object sender, EventArgs e)
{
// Input validation
if (String.IsNullOrWhiteSpace(userName.Text))
{
MessageBox.Show("Please add a name!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
// Add username and score to database then update dgv
query.AddScore(userName.Text, MainWindow.best);
UpdateDGV();
submitBtn.Enabled = false;
}
}
// On window load dispaly database contents
private void HighScoreForm_Load(object sender, EventArgs e)
{
userScore.Text = MainWindow.best.ToString();
UpdateDGV();
submitBtn.Enabled = true;
}
// Method to dispaly databse info to data grid view
private void UpdateDGV()
{
highScoresBindingSource.DataSource = query.ShowTableData();
dgv.DataSource = highScoresBindingSource;
}
}
}