-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
52 lines (44 loc) · 1.65 KB
/
Form1.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
48
49
50
51
52
using PrimeMinisters;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Web.Script.Serialization;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Windows.Forms.VisualStyles;
namespace PrimeMinsters
{
public partial class frmPrimeMinisters : Form
{
private Dictionary<string, PrimeMinister> primeMinisters = new Dictionary<string, PrimeMinister>();
public frmPrimeMinisters()
{
InitializeComponent();
}
private void frmPrimeMinisters_Load(object sender, EventArgs e)
{
StreamReader reader = new StreamReader("PrimeMinisters.json");
primeMinisters = JsonSerializer.Deserialize<Dictionary<string, PrimeMinister>>(reader.ReadToEnd());
reader.Close();
lstPrimeMinisters.DataSource = primeMinisters.Keys.ToList<string>();
}
private void lstPrimeMinisters_SelectedValueChanged(object sender, EventArgs e)
{
string selectedPMKey = lstPrimeMinisters.SelectedValue.ToString();
PrimeMinister primeMinister = primeMinisters[selectedPMKey];
lblName.Text = primeMinister.FirstName + " " + primeMinister.LastName;
lblTerm.Text = "Term: " + primeMinister.Term;
lblParty.Text = "Party: " + primeMinister.Party;
string filename = primeMinister.LastName + ".jpg";
picPhoto.ImageLocation = filename;
}
}
}