Exemplo n.º 1
0
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            if ((listBox1.SelectedItems.Count > 1) || (listBox1.SelectedItems.Count < 1))
            {
                MessageBox.Show("Select one item for editing");
            }
            else
            {
                object[] list = GetCurrentList();
                if ((list != null) && (listBox1.SelectedIndex >= 0))
                {
                    object item = listBox1.SelectedItem;

                    BaseEditForm frm = null;
                    switch (selectComboBox.SelectedIndex)
                    {
                        case 0:
                            frm = new TrainCategoryForm(item as trainCategory, Timetable, false);
                            break;

                        case 1:
                            frm = new EditScheduleForm(item as schedule, Timetable, Locations, false);
                            break;

                        case 2:
                            frm = new EditRuleForm(item as rule, Timetable);
                            break;
                    }

                    if ((frm != null) && (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK))
                    {
                        listBox1.Items.Remove(item);
                        listBox1.SelectedIndex = listBox1.Items.Add(item);
                        Changed = true;
                    }
                    filterLabel.Text = string.Empty;
                    filterLabel.Visible = false;
                }
            }
        }
Exemplo n.º 2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            object item = null;
            BaseEditForm frm = null;
            switch (selectComboBox.SelectedIndex)
            {
                case 0:
                    item = new trainCategory();
                    (item as trainCategory).categoryID = Timetable.GetNewID();
                    frm = new TrainCategoryForm((trainCategory)item, Timetable, true);
                    break;

                case 1:
                    item = new schedule();
                    (item as schedule).scheduleID = Timetable.GetNewID();
                    frm = new EditScheduleForm(item as schedule, Timetable, Locations, true);
                    item = frm.Item;
                    break;

                case 2:
                    frm = new EditRuleForm(new rule(), Timetable);
                    item = frm.Item;
                    break;
            }

            if ((frm != null) && (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK))
            {
                item.ToString();
                listBox1.Items.Add(item);
                Timetable.AddItem(item);
                Changed = true;
            }
        }
Exemplo n.º 3
0
        private void duplicateButton_Click(object sender, EventArgs e)
        {
            if ((listBox1.SelectedItems.Count > 1) || (listBox1.SelectedItems.Count < 1))
            {
                MessageBox.Show("Select one item for duplicating");
            }
            else
            {
                object[] list = GetCurrentList();
                if ((list != null) && (listBox1.SelectedIndex >= 0))
                {
                    object originalItem = listBox1.SelectedItem;
                    object newItem = null;
                    if (originalItem is schedule)
                    {
                        newItem = (originalItem as schedule).Duplicate();
                        (newItem as schedule).scheduleID = Timetable.GetNewID();
                    }
                    else if (originalItem is rule)
                    {
                        newItem = (originalItem as rule).Duplicate();
                    }
                    else if (originalItem is trainCategory)
                    {
                        newItem = (originalItem as trainCategory).Duplicate();
                        (newItem as trainCategory).categoryID = Timetable.GetNewID();
                    }
                    if (newItem != null)
                    {
                        BaseEditForm frm = null;
                        switch (selectComboBox.SelectedIndex)
                        {
                            case 0:
                                frm = new TrainCategoryForm(newItem as trainCategory, Timetable, true);
                                break;

                            case 1:
                                frm = new EditScheduleForm(newItem as schedule, Timetable, Locations, true);
                                break;

                            case 2:
                                frm = new EditRuleForm(newItem as rule, Timetable);
                                break;
                        }

                        if ((frm != null) && (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK))
                        {
                            Timetable.AddItem(newItem);
                            listBox1.SelectedIndex = listBox1.Items.Add(newItem);
                            Changed = true;
                        }

                        filterLabel.Text = string.Empty;
                        filterLabel.Visible = false;
                    }
                }
            }
        }