Beispiel #1
0
        private void Button_add_Click(object sender, EventArgs e)
        {
            if (button_add.Text.Equals("ADD"))
            {
                if (textBox_permission.Text.Equals("") || textBox_name.Text.Equals(""))
                {
                    MessageBox.Show("Please do not leave any empty fields");
                    return;
                }

                if (controller.GetPermissionId(Int32.Parse(textBox_permission.Text)) == 0)
                {
                    controller.AddPermission(Int32.Parse(textBox_permission.Text));
                }

                currentFacility = new Facility(Int32.Parse(textBox_permission.Text), textBox_name.Text);

                controller.AddFacility(currentFacility);

                MessageBox.Show("Facility " + currentFacility.Name + " added");

                FacilityAdded();
            }
            else
            {
                Facility newFacility = new Facility(Int32.Parse(textBox_permission.Text), textBox_name.Text);

                if (currentFacility.Equals(newFacility))
                {
                    MessageBox.Show("Nothing has changed.");
                }
                else
                {
                    int i = comboBox.SelectedIndex;

                    controller.ChangeFacility(currentFacility, newFacility);

                    MessageBox.Show("Facility " + currentFacility.Name + " has changed");

                    comboBox.Items.Clear();
                    comboBox.Items.Add("New Facility");
                    LinkedList <string> facilities = controller.GetFacilities();
                    foreach (string facility in facilities)
                    {
                        comboBox.Items.Add(facility);
                    }

                    comboBox.SelectedIndex = i;
                }
            }
        }