private void CloseButton_Click(object sender, EventArgs e)
        {
            changeValidator.Enabled = origLink.TrainNamingScheme is AutoTrainNameGen;
            var validators = new ValidatorCollection(differenceValidator, differenceValidator, changeValidator, offsetValidator);

            if (!validators.IsValid)
            {
                MessageBox.Show(T._("Bitte erst alle Felder korrekt ausfüllen:\n{0}", validators.Message));
                Result = DialogResult.None;
                return;
            }

            var th     = new TrainEditHelper();
            var offset = TimeEntry.Parse(startOffsetTextBox.Text);
            var diff   = TimeEntry.Parse(differenceTextBox.Text);

            var count = int.Parse(countTextBox.Text);

            ITrainNameGen tnc;

            switch (origLink.TrainNamingScheme)
            {
            // Create new link.
            case AutoTrainNameGen _:
                var add = int.Parse(changeTextBox.Text);
                tnc = new AutoTrainNameGen(nameTextBox.Text, add);
                break;

            case SpecialTrainNameGen _:
                var entries = ((SpecialNameEntry[])specialNameGridView.DataStore).Select(en => en.Name).ToArray();
                if (entries.Any(string.IsNullOrEmpty))
                {
                    MessageBox.Show(T._("Es wurden keinen Namen für alle Züge angegeben!"));
                    return;
                }
                tnc = new SpecialTrainNameGen(entries);
                break;

            default:
                throw new NotSupportedException("Not Implemented: Name calculator not supported!");
            }

            tt.RemoveLink(origLink);                               // Remove old link.
            th.LinkTrainMultiple(train, offset, diff, count, tnc); // Create new link.

            Close(DialogResult.Ok);
        }
Esempio n. 2
0
        private void CloseButton_Click(object sender, EventArgs e)
        {
            var copy = modeSelect.SelectedState == CopySelectionMode.Copy || modeSelect.SelectedState == CopySelectionMode.Link;

            if (!diffValidator.Valid || (copy && (!countValidator.Valid || !changeValidator.Valid)))
            {
                var msg = diffValidator.Valid ? "" : diffValidator.ErrorMessage + Environment.NewLine;
                if (copy)
                {
                    msg += countValidator.Valid ? "" : countValidator.ErrorMessage + Environment.NewLine;
                    msg += changeValidator.Valid ? "" : changeValidator.ErrorMessage + Environment.NewLine;
                }
                MessageBox.Show(T._("Bitte erst alle Felder korrekt ausfüllen:\n{0}", msg));
                Result = DialogResult.None;
                return;
            }

            var th   = new TrainEditHelper();
            var diff = int.Parse(diffTextBox.Text);

            if (modeSelect.SelectedState == CopySelectionMode.Copy)
            {
                var count = int.Parse(countTextBox.Text);
                var add   = int.Parse(changeTextBox.Text);

                var trains = th.CopyTrainMultiple(train, diff, nameTextBox.Text, copyAllCheckBox.Checked.Value, count, add);

                foreach (var newTrain in trains)
                {
                    if (tt.Trains.Any(t => t.TName == newTrain.TName))
                    {
                        if (MessageBox.Show(T._("Es ist bereits ein Zug mit der Zugnummer {0} in diesem Fahrplan vorhanden, soll diese Kopie trotzdem angelegt werden?", newTrain.TName),
                                            T._("Züge kopieren"), MessageBoxButtons.YesNo) == DialogResult.No)
                        {
                            continue;
                        }
                    }

                    tt.AddTrain(newTrain);
                }
            }
            else if (modeSelect.SelectedState == CopySelectionMode.Link)
            {
                var           count = int.Parse(countTextBox.Text);
                ITrainNameGen tnc;

                switch (linkSelect.SelectedState)
                {
                case LinkTypeMode.Auto:
                    var add = int.Parse(changeTextBox.Text);
                    tnc = new AutoTrainNameGen(nameTextBox.Text, add);
                    break;

                case LinkTypeMode.Special:
                    var entries = ((SpecialNameEntry[])specialNameGridView.DataStore).Select(en => en.Name).ToArray();
                    if (entries.Any(string.IsNullOrEmpty))
                    {
                        MessageBox.Show(T._("Es wurden keinen Namen für alle Züge angegeben!"));
                        return;
                    }
                    tnc = new SpecialTrainNameGen(entries);
                    break;

                default:
                    throw new NotSupportedException("The selected LinkTypeMode is not defined!");
                }

                th.LinkTrainMultiple(train, TimeEntry.Zero, new TimeEntry(0, diff), count, tnc);
            }
            else
            {
                th.MoveTrain(train, diff);
            }

            Close(DialogResult.Ok);
        }