-
Notifications
You must be signed in to change notification settings - Fork 14
/
ChooseExistingCommodityDialog.cs
70 lines (56 loc) · 2.11 KB
/
ChooseExistingCommodityDialog.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EliteDangerousTradingAssistant
{
public partial class ChooseExistingCommodityDialog : Form
{
private List<StarSystem> systems;
private string result;
private List<string> uniqueCommodityNames;
public string Result
{
get { return result; }
}
public ChooseExistingCommodityDialog(List<StarSystem> systems)
{
InitializeComponent();
this.Icon = new Icon("Graphics\\EliteDangerousIcon.ico");
this.systems = systems;
result = string.Empty;
uniqueCommodityNames = new List<string>();
foreach (StarSystem system in systems)
foreach(Station station in system.Stations)
foreach(Commodity commodity in station.Commodities)
if (uniqueCommodityNames.Contains(commodity.Name) == false)
uniqueCommodityNames.Add(commodity.Name);
if (uniqueCommodityNames.Count == 0)
{
MessageBox.Show("No commodities have been found. Please add some commodities to systems and stations.", "Error: No commodities found.", MessageBoxButtons.OK);
this.Close();
}
CommodityComboBox.Items.Add("Please select one...");
uniqueCommodityNames.Sort();
foreach (string uniqueCommodityName in uniqueCommodityNames)
CommodityComboBox.Items.Add(uniqueCommodityName);
CommodityComboBox.SelectedIndex = 0;
}
private void SelectButton_Click(object sender, EventArgs e)
{
if (CommodityComboBox.SelectedIndex == 0)
return;
result = CommodityComboBox.SelectedItem.ToString();
this.Close();
}
private void CancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}