Example #1
0
        private bool AddToGenerator(string target, BaseGenerator child, BaseGenerator parent = null)
        {
            BaseGenerator _parent;

            if (parent == null)
            {
                _parent = root;
            }
            else
            {
                _parent = parent;
            }

            for (int i = 0; i < _parent.Generators.Count; i++)
            {
                BaseGenerator generator = (BaseGenerator)_parent.Generators[i];

                if (generator.Name == target)
                {
                    generator.Add(child);
                    return(true);
                }

                if (AddToGenerator(target, child, generator))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        private void add_Click(object sender, EventArgs e)
        {
            BaseGenerator generator;

            using (var form = new Add())
            {
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                if (SearchGenerator(form.GeneratorName) != null)
                {
                    MessageBox.Show("Генератор с таким названием уже существует!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                switch (form.Type)
                {
                case Generators.Types.GeneratorType.BASE:
                    generator = new BaseGenerator(form.GeneratorName, form.Count);
                    break;

                case Generators.Types.GeneratorType.RAND:
                    generator = new RandomGenerator(form.GeneratorName, form.Count);
                    break;

                case Generators.Types.GeneratorType.STEP:
                    generator = new GeneratorWithStep(form.GeneratorName, form.Count, form.FirstNumber, form.Step);
                    break;

                default:
                    return;
                }
            }

            if (this.treeView.SelectedNode == null)
            {
                this.root.Add(generator);
                AddToTree(generator);

                return;
            }

            BaseGenerator parent = SearchGenerator(this.treeView.SelectedNode.Text);

            parent.Add(generator);

            this.treeView.BeginUpdate();
            AddToTree(generator, this.treeView.SelectedNode);
            this.treeView.EndUpdate();
        }