/
FormMain.cs
70 lines (62 loc) · 2.23 KB
/
FormMain.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.Windows.Forms;
using FootballLibrary;
namespace WindowsFormsApp1
{
public enum WhatMainAction
{
Add,
Change
}
public partial class FormMain : Form
{
public Control Control { get; set; }
public FormObjectFields FormObjectFields { get; set; }
public FormMain()
{
InitializeComponent();
this.Control = new Control();
this.comboBoxAvailableTypes.Items.AddRange(Control.FootballFactories);
this.FormObjectFields = new FormObjectFields(Control, this);
Control.CreateStartObjects();
foreach (var obj in Control.ApplicationObjects)
{
listBox.Items.Add(obj);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
Control.CreateObject(comboBoxAvailableTypes.SelectedIndex);
FormObjectFields.WhatMainAction = WhatMainAction.Add;
FormObjectFields.CreateObjectFields();
FormObjectFields.ShowDialog();
}
public void AddObject(IFootball footballObject)
{
Control.AddObject(footballObject);
listBox.Items.Add(footballObject);
listBox.SelectedItem = footballObject;
}
private void ButtonChange_Click(object sender, EventArgs e)
{
if (listBox.SelectedItem != null)
{
int selectedIndex = listBox.SelectedIndex;
Control.CurrObject = listBox.SelectedItem as IFootball;
FormObjectFields.WhatMainAction = WhatMainAction.Change;
FormObjectFields.CreateObjectFields();
FormObjectFields.ShowDialog();
listBox.Items[selectedIndex] = Control.CurrObject;
}
}
private void ButtonDelete_Click(object sender, EventArgs e)
{
if (listBox.SelectedItem != null)
{
IFootball footballObject = listBox.SelectedItem as IFootball;
Control.RemoveObject(footballObject);
listBox.Items.Remove(listBox.SelectedItem);
}
}
}
}