-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefinitionForm.cs
96 lines (83 loc) · 3.38 KB
/
DefinitionForm.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DictionaryEditor
{
public partial class DefinitionForm : Form
{
Definition definition;
Headword theHeadword; // A reference to the headword in the main program.
public DefinitionForm(DictionaryForm dictionaryEditorForm, String strHeadword)
{
InitializeComponent();
theHeadword = dictionaryEditorForm.Headword;
tb_Headword.Text = strHeadword;
// Create a new Definition with the a new ID number;
definition = new Definition(theHeadword.Definitions.Count + 1);
// If the user selected a POS for the headword use it.
if (dictionaryEditorForm.CB_PartOfSpeech.Text != "")
cb_POS.SelectedIndex = dictionaryEditorForm.CB_PartOfSpeech.SelectedIndex;
}
// Controls adding an illustration to a definition and to a headword.
private void btn_AddIllustration_Click(object sender, EventArgs e)
{
// Make sure there is a short definition before adding any illustrations.
if (tb_ShortDef.Text != "")
{
// Open up a dialog box to add a new Illustration to our defintion.
// If the user presses OK then store the information in the current illustration.
IllustrationForm newIllustrationForm = new IllustrationForm(this, tb_ShortDef.Text);
if (newIllustrationForm.ShowDialog(this) == DialogResult.OK )
{
if (newIllustrationForm.Translation == "" || newIllustrationForm.Illustration == "")
{
MessageBox.Show("Please enter both fields before pressing enter","Error",MessageBoxButtons.OK);
}
else
{
// Create a new Illustration with a unique ID number, get the illustration and translation.
Illustration newIllustration = new Illustration(theHeadword.Illustrations.Count + 1);
newIllustration.IllDescription = newIllustrationForm.Illustration;
newIllustration.Translation = newIllustrationForm.Translation;
// Add remaining data to the illustration.
newIllustration.Headword = tb_Headword.Text;
// Add the illustration to theHeadword object and the definition.
definition.Illustrations.Add(newIllustration);
tb_NumberOfIllustrations.Text = theHeadword.Illustrations.Count.ToString();
}
// Close the window.
newIllustrationForm.Dispose();
}
}
else
{
MessageBox.Show("Enter a Short Definition before adding any Illustrations",
"Error", MessageBoxButtons.OK);
}
}
private void btn_OK_Click(object sender, EventArgs e)
{
if (tb_Definition.Text != "")
{
// Add all the data to the definition.
definition.HeadwordProp = tb_Headword.Text;
definition.PartOfSpeech = cb_POS.Text;
definition.ShortDefinition = tb_ShortDef.Text;
definition.DefinitionProp = tb_Definition.Text;
// Add the definition to the Headword object in DictionaryForm.
theHeadword.Definitions.Add(definition);
theHeadword.Illustrations = definition.Illustrations;
this.Close();
}
}
private void btn_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}