예제 #1
0
        private void toolStripMenuItemTreeViewEdit_Click(object sender, EventArgs e)
        {
            TreeListNode treeListNode = treeList.FocusedNode;
            Type type = treeListNode.Tag.GetType();

            if (type == typeof(Slyce.TemplateInfo.Option))
            {
                Slyce.ITemplate.IOption option = (Slyce.ITemplate.IOption)treeListNode.Tag;
                Slyce.ITemplate.IUserOption userOption = null;
                object parentObject = treeListNode.ParentNode.ParentNode.Tag;
                Type parentType = parentObject.GetType();

                if (parentType == typeof(ArchAngel.Providers.Database.Model.Table) ||
                parentType == typeof(ArchAngel.Providers.Database.Model.View) ||
                parentType == typeof(ArchAngel.Providers.Database.Model.StoredProcedure))
                {
                    ArchAngel.Providers.Database.Model.ScriptObject parentScriptObject = (ArchAngel.Providers.Database.Model.ScriptObject)parentObject;

                    for (int i = 0; i < parentScriptObject.UserOptions.Count; i++)
                    {
                        if (parentScriptObject.UserOptions[i].Name == option.VariableName)
                        {
                            userOption = parentScriptObject.UserOptions[i];
                            FormObjectOptionEdit form = new FormObjectOptionEdit(option, userOption, parentScriptObject);

                            if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                            {
                                Controller.MainForm.Cursor = Cursors.WaitCursor;
                                parentScriptObject.UserOptions[i].Value = form.UserOption.Value;
                                treeList.Selection[0].Tag = form.CurrentOption;
                                treeList.Selection[0].SetValue(1, form.UserOption.Value);
                                ProcessTreeValidity(treeList.Nodes);
                                Controller.MainForm.Cursor = Cursors.Default;
                            }

                            //((ArchAngel.Providers.Database.Model.ScriptObject)treeList.Selection[0].ParentNode.ParentNode.Tag).UserOptions[i].Value = Convert.ChangeType(form.CurrentOption.DefaultValue, form.CurrentOption.VarType);
                            //parentScriptObject.UserOptions[i].Value = Convert.ChangeType(form.CurrentOption.DefaultValue, form.CurrentOption.VarType);
                            break;
                        }
                    }
                    return;
                }
                else if (parentType == typeof(ArchAngel.Providers.Database.Model.Column))
                {
                    ArchAngel.Providers.Database.Model.Column parentColumn = (ArchAngel.Providers.Database.Model.Column)parentObject;

                    for (int i = 0; i < parentColumn.UserOptions.Count; i++)
                    {
                        if (parentColumn.UserOptions[i].Name == option.VariableName)
                        {
                            userOption = parentColumn.UserOptions[i];
                            FormObjectOptionEdit form = new FormObjectOptionEdit(option, userOption, parentColumn);

                            if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                            {
                                Controller.MainForm.Cursor = Cursors.WaitCursor;
                                parentColumn.UserOptions[i].Value = form.UserOption.Value;
                                treeList.Selection[0].Tag = form.CurrentOption;
                                treeList.Selection[0].SetValue(1, form.UserOption.Value);
                                ProcessTreeValidity(treeList.Nodes);
                                Controller.MainForm.Cursor = Cursors.Default;
                            }
                            break;
                        }
                    }
                    return;
                }
            }
            ScriptBase scriptBase = (ScriptBase)treeListNode.Tag;

            if (type == typeof(ArchAngel.Providers.Database.Model.Table) ||
                type == typeof(ArchAngel.Providers.Database.Model.View) ||
                type == typeof(ArchAngel.Providers.Database.Model.StoredProcedure))
            {
                FormScriptObject form = new FormScriptObject((ScriptObject)scriptBase, (ScriptObject[])treeListNode.ParentNode.Tag);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    UpdateTreeListNodeText(treeListNode, form.ScriptObject);

                    //TreeListHelper.TreeListNodeValidate(treeListNode);
                    foreach (ArchAngel.Providers.Database.Model.Database database in Controller.Instance.BllDatabase.Databases)
                    {
                        database.SnapshotMode = true;
                    }
                    treeList.BeginUpdate();
                    //ValidateNode(treeListNode);
                    ProcessTreeValidity(treeList.Nodes);
                    treeList.EndUpdate();

                    foreach (ArchAngel.Providers.Database.Model.Database database in Controller.Instance.BllDatabase.Databases)
                    {
                        database.SnapshotMode = false;
                    }
                    Controller.MainForm.Cursor = Cursors.Default;
                    return;
                }
            }
            else if (type == typeof(Column))
            {
                FormColumn form = new FormColumn((Column)scriptBase);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    UpdateTreeListNodeText(treeListNode, form.Column);

                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                    return;
                }
            }
            else if (type == typeof(MapColumn))
            {
                FormMapColumn form = new FormMapColumn((ScriptObject)treeListNode.ParentNode.ParentNode.Tag, (MapColumn)scriptBase);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    MapColumn mapColumn = (MapColumn)scriptBase;

                    UpdateTreeListNodeText(treeListNode, form.MapColumn);

                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                    return;
                }
            }
            else if (type.BaseType == typeof(Relationship))
            {
                ArchAngel.Providers.Database.Model.Database database = (ArchAngel.Providers.Database.Model.Database)treeListNode.ParentNode.ParentNode.ParentNode.ParentNode.ParentNode.Tag;
                FormRelationship form = new FormRelationship((Relationship)scriptBase, Controller.Instance.BllDatabase.ScriptObjects);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    UpdateTreeListNodeText(treeListNode, form.PrimaryRelationship);

                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                    return;
                }
            }
            else if (type == typeof(Filter))
            {
                ArchAngel.Providers.Database.Model.Database database = (ArchAngel.Providers.Database.Model.Database)treeListNode.ParentNode.ParentNode.ParentNode.ParentNode.Tag;
                Filter filter = (Filter)scriptBase;

                FormFilter2 form;
                // Stored Procedure Filters can only be created from other Stored Procedures (Enabled or Disabled)
                if (filter.Parent.GetType() == typeof(ArchAngel.Providers.Database.Model.StoredProcedure))
                {
                    form = new FormFilter2(this.ParentForm, filter, database.StoredProcedures);
                }
                else
                {
                    form = new FormFilter2(this.ParentForm, filter, database.EnabledScriptObjects);
                }
                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    UpdateTreeListNodeText(treeListNode, form.Filter);

                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                    return;
                }
            }
            else if (type == typeof(Index))
            {
                FormIndex form = new FormIndex((Index)scriptBase);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    UpdateTreeListNodeText(treeListNode, form.Index);

                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                    return;
                }
            }
            else if (type == typeof(Key))
            {
                FormKey form = new FormKey((Key)scriptBase);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    UpdateTreeListNodeText(treeListNode, form.Key);

                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                    return;
                }
            }
        }
예제 #2
0
        private void toolStripMenuItemTreeViewEdit_Click(object sender, EventArgs e)
        {
            Refresh();
            Node treeListNode = treeList.SelectedNode;
            Type type = treeListNode.Tag.GetType();

            if (type == typeof(Lookup))
            {
                try
                {
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    this.Refresh();
                    FormLookup form = new FormLookup((Lookup)treeListNode.Tag);

                    if (form.ShowDialog(ParentForm) == DialogResult.OK)
                    {
                        treeList.BeginUpdate();
                        treeListNode.Text = form.Lookup.Alias;
                        treeListNode.Tag = form.Lookup;
                        treeList.EndUpdate();
                        return;
                    }
                }
                finally
                {
                    Interfaces.Events.UnShadeMainForm();
                    Interfaces.Events.RaiseRefreshApplicationEvent();
                    Interfaces.Events.SetCursor(Cursors.Default);
                    this.Refresh();
                }
            }
            else if (type == typeof (Option))
            {
                IOption option = (IOption) treeListNode.Tag;
                IUserOption userOption;
                object parentObject = treeListNode.Parent.Parent.Tag;
                Type parentType = parentObject.GetType();

                Type scriptBaseInterface = typeof (IScriptBaseObject);

                if (scriptBaseInterface.IsInstanceOfType(parentObject))
                {
                    IScriptBaseObject parentScriptObject = (IScriptBaseObject) parentObject;

                    for (int i = 0; i < parentScriptObject.Ex.Count; i++)
                    {
                        if (parentScriptObject.Ex[i].Name == option.VariableName)
                        {
                            userOption = parentScriptObject.Ex[i];
                            FormVirtualPropertyEdit form = new FormVirtualPropertyEdit(userOption,
                                                                                                                               parentScriptObject);

                            if (form.ShowDialog(ParentForm) == DialogResult.OK)
                            {
                                Interfaces.Events.UnShadeMainForm();
                                Interfaces.Events.RaiseRefreshApplicationEvent();
                                Interfaces.Events.SetCursor(Cursors.WaitCursor);
                                treeList.BeginUpdate();
                                ProcessTreeValidity(treeList.Nodes);
                                treeList.EndUpdate();
                                Interfaces.Events.SetCursor(Cursors.Default);
                            }
                            break;
                        }
                    }
                    return;
                }
                if (parentType == typeof (Column))
                {
                    Column parentColumn = (Column) parentObject;

                    for (int i = 0; i < parentColumn.Ex.Count; i++)
                    {
                        if (parentColumn.Ex[i].Name == option.VariableName)
                        {
                            userOption = parentColumn.Ex[i];
                            FormVirtualPropertyEdit form = new FormVirtualPropertyEdit(userOption,
                                                                                                                               parentColumn);

                            if (form.ShowDialog(ParentForm) == DialogResult.OK)
                            {
                                Interfaces.Events.UnShadeMainForm();
                                Interfaces.Events.RaiseRefreshApplicationEvent();
                                Interfaces.Events.SetCursor(Cursors.WaitCursor);
                                treeList.BeginUpdate();
                                parentColumn.Ex[i].Value = form.VirtualProperty.Value;
                                treeList.SelectedNode.Cells[1].Text = form.VirtualProperty.Value.ToString();
                                ProcessTreeValidity(treeList.Nodes);
                                treeList.EndUpdate();
                                Interfaces.Events.SetCursor(Cursors.Default);
                            }
                            break;
                        }
                    }
                    return;
                }
            }
            if (type == typeof (Association))
            {
                frmAssociationWizard.Association = (Association) treeListNode.Tag;
                frmAssociationWizard form = new frmAssociationWizard();

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.UnShadeMainForm();
                    Interfaces.Events.RaiseRefreshApplicationEvent();
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    treeList.BeginUpdate();
                    treeListNode.Cells[1].Text = frmAssociationWizard.Association.Name;
                    treeListNode.Tag = frmAssociationWizard.Association;
                    SetNodeImage(treeListNode, Images.GreenBullet);

                    foreach (Model.Database database in ProviderInfo.TheBllDatabase.Databases)
                    {
                        database.SnapshotMode = true;
                    }
                    ProcessTreeValidity(treeList.Nodes);
                    treeList.EndUpdate();

                    foreach (Model.Database database in ProviderInfo.TheBllDatabase.Databases)
                    {
                        database.SnapshotMode = false;
                    }
                    Interfaces.Events.RaiseIsDirtyEvent();
                    Interfaces.Events.SetCursor(Cursors.Default);
                    return;
                }
                return;
            }
            ScriptBase scriptBase = (ScriptBase) treeListNode.Tag;

            if (type == typeof (Table) ||
                type == typeof (View) ||
                type == typeof (StoredProcedure))
            {
                FormScriptObject form = new FormScriptObject((ScriptObject) scriptBase, (ScriptObject[]) treeListNode.Parent.Tag);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.UnShadeMainForm();
                    Interfaces.Events.RaiseRefreshApplicationEvent();
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    treeList.BeginUpdate();
                    UpdateTreeListNodeText(treeListNode, form.ScriptObject);

                    foreach (Model.Database database in ProviderInfo.TheBllDatabase.Databases)
                    {
                        database.SnapshotMode = true;
                    }
                    ProcessTreeValidity(treeList.Nodes);
                    treeList.EndUpdate();

                    foreach (Model.Database database in ProviderInfo.TheBllDatabase.Databases)
                    {
                        database.SnapshotMode = false;
                    }
                    Interfaces.Events.SetCursor(Cursors.Default);
                    return;
                }
            }
            else if (type == typeof (Column))
            {
                FormColumn form = new FormColumn((Column) scriptBase);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.UnShadeMainForm();
                    Interfaces.Events.RaiseRefreshApplicationEvent();
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    treeList.BeginUpdate();
                    UpdateTreeListNodeText(treeListNode, form.Column);
                    ProcessTreeValidity(treeList.Nodes);
                    treeList.EndUpdate();
                    Interfaces.Events.SetCursor(Cursors.Default);
                    return;
                }
            }
            else if (ModelTypes.MapColumn == type)
            {
                FormMapColumn form = new FormMapColumn((ScriptObject) treeListNode.Parent.Parent.Tag, (MapColumn) scriptBase);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.UnShadeMainForm();
                    Interfaces.Events.RaiseRefreshApplicationEvent();
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    treeList.BeginUpdate();

                    UpdateTreeListNodeText(treeListNode, form.MapColumn);
                    ProcessTreeValidity(treeList.Nodes);
                    treeList.EndUpdate();
                    Interfaces.Events.SetCursor(Cursors.Default);
                    return;
                }
            }
            else if (type.BaseType == typeof (Relationship))
            {
                FormRelationship form = new FormRelationship((Relationship) scriptBase, ProviderInfo.TheBllDatabase.AllScriptObjects);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.UnShadeMainForm();
                    Interfaces.Events.RaiseRefreshApplicationEvent();
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    treeList.BeginUpdate();
                    UpdateTreeListNodeText(treeListNode, form.PrimaryRelationship);
                    ProcessTreeValidity(treeList.Nodes);
                    treeList.EndUpdate();
                    Interfaces.Events.SetCursor(Cursors.Default);
                    return;
                }
            }
            else if (type == typeof (Filter))
            {
                Model.Database database = (Model.Database) treeListNode.Parent.Parent.Parent.Parent.Tag;
                Filter filter = (Filter) scriptBase;

                FormFilter2 form;
                // Stored Procedure Filters can only be created from other Stored Procedures (Enabled or Disabled)
                if (filter.Parent.GetType() == typeof (StoredProcedure))
                {
                    form = new FormFilter2(ParentForm, filter);
                }
                else
                {
                    form = new FormFilter2(ParentForm, filter);
                }
                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.UnShadeMainForm();
                    Interfaces.Events.RaiseRefreshApplicationEvent();
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    treeList.BeginUpdate();
                    UpdateTreeListNodeText(treeListNode, form.TheFilter);
                    ProcessTreeValidity(treeList.Nodes);
                    treeList.EndUpdate();
                    Interfaces.Events.SetCursor(Cursors.Default);
                    return;
                }
            }
            else if (type == typeof (Index))
            {
                FormIndex form = new FormIndex((Index) scriptBase);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.UnShadeMainForm();
                    Interfaces.Events.RaiseRefreshApplicationEvent();
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    treeList.BeginUpdate();
                    UpdateTreeListNodeText(treeListNode, form.Index);
                    ProcessTreeValidity(treeList.Nodes);
                    treeList.EndUpdate();
                    Interfaces.Events.SetCursor(Cursors.Default);
                    return;
                }
            }
            else if (type == typeof (Key))
            {
                FormKey form = new FormKey((Key) scriptBase);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.UnShadeMainForm();
                    Interfaces.Events.RaiseRefreshApplicationEvent();
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    treeList.BeginUpdate();
                    UpdateTreeListNodeText(treeListNode, form.Key);
                    ProcessTreeValidity(treeList.Nodes);
                    treeList.EndUpdate();
                    Interfaces.Events.SetCursor(Cursors.Default);
                    return;
                }
            }
        }
예제 #3
0
        private void toolStripMenuItemTreeViewAdd_Click(object sender, EventArgs e)
        {
            treeList.InvalidateNodes();

            treeList.BeginUpdate();

            TreeListNode treeListNode = treeList.FocusedNode;

            Type type = treeListNode.Tag.GetType();

            if (type == typeof(ArchAngel.Providers.Database.Model.Table[]) ||
                type == typeof(ArchAngel.Providers.Database.Model.View[]) ||
                type == typeof(ArchAngel.Providers.Database.Model.StoredProcedure[]))
            {
                ArchAngel.Providers.Database.Model.Database parent = (ArchAngel.Providers.Database.Model.Database)treeListNode.ParentNode.Tag;
                FormScriptObject form = new FormScriptObject((ScriptObject[])treeListNode.Tag, parent);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    parent.AddScriptObject(form.ScriptObject);

                    TreeListNode newTreeListNode = treeList.AppendNode(GetTreeListNodeText(form.ScriptObject), treeListNode);
                    newTreeListNode.Tag = form.ScriptObject;
                    newTreeListNode.ImageIndex = newTreeListNode.SelectImageIndex = (int)Images.GreenBullet;

                    SetupNewTreeListNode(newTreeListNode, form.ScriptObject);

                    if (type == typeof(ArchAngel.Providers.Database.Model.Table[]))
                    {
                        treeListNode.Tag = parent.Tables;
                    }

                    if (type == typeof(ArchAngel.Providers.Database.Model.View[]))
                    {
                        treeListNode.Tag = parent.Views;
                    }

                    if (type == typeof(ArchAngel.Providers.Database.Model.StoredProcedure[]))
                    {
                        treeListNode.Tag = parent.StoredProcedures;
                    }
                    //TreeListHelper.TreeListNodeValidate(newTreeListNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                }
            }
            else if (type == typeof(Column[]))
            {
                ScriptObject parent = (ScriptObject)treeListNode.ParentNode.Tag;
                FormColumn form = new FormColumn(parent);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    parent.AddColumn(form.Column);

                    TreeListNode newTreeListNode = treeList.AppendNode(GetTreeListNodeText(form.Column), treeListNode);
                    newTreeListNode.Tag = form.Column;
                    newTreeListNode.ImageIndex = newTreeListNode.SelectImageIndex = (int)Images.GreenBullet;

                    treeListNode.Tag = parent.Columns;

                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                }
            }
            else if (type == typeof(OneToOneRelationship[]) ||
                type == typeof(OneToManyRelationship[]) ||
                type == typeof(ManyToOneRelationship[]) ||
                type == typeof(ManyToManyRelationship[]))
            {
                ScriptObject parent = (ScriptObject)treeListNode.ParentNode.ParentNode.Tag;

                Type relationshipType = null;
                if (type == typeof(OneToOneRelationship[]))
                {
                    relationshipType = typeof(OneToOneRelationship);
                }

                if (type == typeof(ManyToOneRelationship[]))
                {
                    relationshipType = typeof(ManyToOneRelationship);
                }

                if (type == typeof(OneToManyRelationship[]))
                {
                    relationshipType = typeof(OneToManyRelationship);
                }

                if (type == typeof(ManyToManyRelationship[]))
                {
                    relationshipType = typeof(ManyToManyRelationship);
                }

                ArchAngel.Providers.Database.Model.Database database = (ArchAngel.Providers.Database.Model.Database)treeListNode.ParentNode.ParentNode.ParentNode.ParentNode.Tag;

                FormRelationship form = new FormRelationship(relationshipType, (ScriptObject)treeListNode.ParentNode.ParentNode.Tag, Controller.Instance.BllDatabase.EnabledScriptObjects);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    ScriptObject primaryScriptObject = form.PrimaryRelationship.Parent;
                    primaryScriptObject.AddRelationship(form.PrimaryRelationship);

                    ScriptObject foreignScriptObject = form.ForeignRelationship.Parent;
                    foreignScriptObject.AddRelationship(form.ForeignRelationship);

                    TreeListNode newTreeListNode = treeList.AppendNode(GetTreeListNodeText(form.PrimaryRelationship), treeListNode);
                    newTreeListNode.Tag = form.PrimaryRelationship;
                    newTreeListNode.ImageIndex = newTreeListNode.SelectImageIndex = (int)Images.GreenBullet;

                    if (type == typeof(OneToOneRelationship[]))
                    {
                        treeListNode.Tag = parent.OneToOneRelationships;
                    }

                    if (type == typeof(ManyToOneRelationship[]))
                    {
                        treeListNode.Tag = parent.ManyToOneRelationships;
                    }

                    if (type == typeof(OneToManyRelationship[]))
                    {
                        treeListNode.Tag = parent.OneToManyRelationships;
                    }

                    if (type == typeof(ManyToManyRelationship[]))
                    {
                        treeListNode.Tag = parent.ManyToManyRelationships;
                    }

                    LoadTreeListNode(foreignScriptObject);
                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                }
            }
            else if (type == typeof(Filter[]))
            {
                ArchAngel.Providers.Database.Model.Database database = (ArchAngel.Providers.Database.Model.Database)treeListNode.ParentNode.ParentNode.ParentNode.Tag;
                ScriptObject parent = (ScriptObject)treeListNode.ParentNode.Tag;

                FormFilter2 form;
                // Stored Procedure Filters can only be created from other Stored Procedures (Enabled or Disabled)
                if (parent.GetType() == typeof(ArchAngel.Providers.Database.Model.StoredProcedure))
                {
                    form = new FormFilter2(this.ParentForm, parent, database.StoredProcedures);
                }
                else
                {
                    form = new FormFilter2(this.ParentForm, parent, database.EnabledScriptObjects);
                }
                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    parent.AddFilter(form.Filter);

                    TreeListNode newTreeListNode = treeList.AppendNode(GetTreeListNodeText(form.Filter), treeListNode);
                    newTreeListNode.Tag = form.Filter;
                    newTreeListNode.ImageIndex = newTreeListNode.SelectImageIndex = (int)Images.GreenBullet;

                    treeListNode.Tag = parent.Filters;

                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                }
            }
            else if (type == typeof(Index[]))
            {
                ArchAngel.Providers.Database.Model.Table parent = (ArchAngel.Providers.Database.Model.Table)treeListNode.ParentNode.Tag;
                FormIndex form = new FormIndex((ArchAngel.Providers.Database.Model.Table)treeListNode.ParentNode.Tag);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    parent.AddIndex(form.Index);

                    TreeListNode newTreeListNode = treeList.AppendNode(GetTreeListNodeText(form.Index), treeListNode);
                    newTreeListNode.Tag = form.Index;
                    newTreeListNode.ImageIndex = newTreeListNode.SelectImageIndex = (int)Images.GreenBullet;

                    treeListNode.Tag = parent.Indexes;

                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                }
            }
            else if (type == typeof(Key[]))
            {
                ArchAngel.Providers.Database.Model.Table parent = (ArchAngel.Providers.Database.Model.Table)treeListNode.ParentNode.Tag;
                FormKey form = new FormKey((ArchAngel.Providers.Database.Model.Table)treeListNode.ParentNode.Tag);

                if (form.ShowDialog(this.ParentForm) == DialogResult.OK)
                {
                    Controller.MainForm.Cursor = Cursors.WaitCursor;
                    parent.AddKey(form.Key);

                    TreeListNode newTreeListNode = treeList.AppendNode(GetTreeListNodeText(form.Key), treeListNode);
                    newTreeListNode.Tag = form.Key;
                    newTreeListNode.ImageIndex = newTreeListNode.SelectImageIndex = (int)Images.GreenBullet;

                    treeListNode.Tag = parent.Keys;

                    //TreeListHelper.TreeListNodeValidate(treeListNode.ParentNode);
                    ProcessTreeValidity(treeList.Nodes);
                    Controller.MainForm.Cursor = Cursors.Default;
                }
            }
            treeList.EndUpdate();
        }
예제 #4
0
        private void toolStripMenuItemTreeViewAdd_Click(object sender, EventArgs e)
        {
            Refresh();
            treeList.BeginUpdate();

            Node treeListNode = treeList.SelectedNode;

            Type type = treeListNode.Tag.GetType();

            if (type == typeof (Table[]) ||
                type == typeof (View[]) ||
                type == typeof (StoredProcedure[]))
            {
                Model.Database parent = (Model.Database) treeListNode.Parent.Tag;
                FormScriptObject form = new FormScriptObject((ScriptObject[]) treeListNode.Tag, parent);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    parent.AddScriptObject(form.ScriptObject);

                    Node newTreeListNode = AddNode(treeListNode, "", form.ScriptObject, Images.GreenBullet, true,
                                                                         form.ScriptObject.Enabled);
                    GetTreeListNodeText(form.ScriptObject, newTreeListNode);
                    SetupNewTreeListNode(newTreeListNode, form.ScriptObject);

                    if (type == typeof (Table[]))
                    {
                        treeListNode.Tag = parent.Tables;
                    }
                    if (type == typeof (View[]))
                    {
                        treeListNode.Tag = parent.Views;
                    }
                    if (type == typeof (StoredProcedure[]))
                    {
                        treeListNode.Tag = parent.StoredProcedures;
                    }
                    ProcessTreeValidity(treeList.Nodes);
                    Interfaces.Events.SetCursor(Cursors.Default);
                }
            }
            else if (type == typeof (Column[]))
            {
                ScriptObject parent = (ScriptObject) treeListNode.Parent.Tag;
                FormColumn form = new FormColumn(parent);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    parent.AddColumn(form.Column);

                    Node newTreeListNode = AddNode(treeListNode, "", form.Column, Images.GreenBullet, true,
                                                                         form.Column.Enabled);
                    GetTreeListNodeText(form.Column, newTreeListNode);

                    treeListNode.Tag = parent.Columns;
                    ProcessTreeValidity(treeList.Nodes);
                    Interfaces.Events.SetCursor(Cursors.Default);
                }
            }
            else if (type == typeof(Lookup[]))
            {
                Model.Database database = (Model.Database)treeListNode.Parent.Tag;
                FormLookup form = new FormLookup(database);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    Node newTreeListNode = AddLookupNode(treeListNode, form.Lookup, Images.GreenBullet);
                    treeListNode.Tag = database.Lookups;
                    Interfaces.Events.SetCursor(Cursors.Default);
                    treeList.SelectNode(newTreeListNode, eTreeAction.Code);
                }
            }
            else if (type == typeof (OneToOneRelationship[]) ||
                     type == typeof (OneToManyRelationship[]) ||
                     type == typeof (ManyToOneRelationship[]) ||
                     type == typeof (ManyToManyRelationship[]))
            {
                ScriptObject parent = (ScriptObject) treeListNode.Parent.Parent.Tag;

                Type relationshipType = null;
                if (type == typeof (OneToOneRelationship[]))
                {
                    relationshipType = typeof (OneToOneRelationship);
                }

                if (type == typeof (ManyToOneRelationship[]))
                {
                    relationshipType = typeof (ManyToOneRelationship);
                }

                if (type == typeof (OneToManyRelationship[]))
                {
                    relationshipType = typeof (OneToManyRelationship);
                }

                if (type == typeof (ManyToManyRelationship[]))
                {
                    relationshipType = typeof (ManyToManyRelationship);
                }
                FormRelationship form = new FormRelationship(relationshipType, (ScriptObject) treeListNode.Parent.Parent.Tag,
                                                             ProviderInfo.TheBllDatabase.EnabledScriptObjects);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    ScriptObject primaryScriptObject = form.PrimaryRelationship.Parent;
                    primaryScriptObject.AddRelationship(form.PrimaryRelationship);

                    ScriptObject foreignScriptObject = form.ForeignRelationship.Parent;
                    foreignScriptObject.AddRelationship(form.ForeignRelationship);

                    Node newTreeListNode = AddNode(treeListNode, "", form.PrimaryRelationship, Images.GreenBullet,
                                                                         true, form.PrimaryRelationship.Enabled);
                    GetTreeListNodeText(form.PrimaryRelationship, newTreeListNode);

                    if (type == typeof (OneToOneRelationship[]))
                    {
                        treeListNode.Tag = parent.OneToOneRelationships;
                    }

                    if (type == typeof (ManyToOneRelationship[]))
                    {
                        treeListNode.Tag = parent.ManyToOneRelationships;
                    }

                    if (type == typeof (OneToManyRelationship[]))
                    {
                        treeListNode.Tag = parent.OneToManyRelationships;
                    }

                    if (type == typeof (ManyToManyRelationship[]))
                    {
                        treeListNode.Tag = parent.ManyToManyRelationships;
                    }

                    LoadTreeListNode(foreignScriptObject);
                    ProcessTreeValidity(treeList.Nodes);
                    Interfaces.Events.SetCursor(Cursors.Default);
                }
                if (form.FilterWasCreated)
                {
                    LoadTreeView();
                }
            }
            else if (type == typeof (Filter[]))
            {
                Model.Database database = (Model.Database) treeListNode.Parent.Parent.Parent.Tag;
                ScriptObject parent = (ScriptObject) treeListNode.Parent.Tag;

                FormFilter2 form;

                // Stored Procedure Filters can only be created from other Stored Procedures (Enabled or Disabled)
                if (parent.GetType() == typeof (StoredProcedure))
                {
                    form = new FormFilter2(ParentForm, parent);
                }
                else
                {
                    form = new FormFilter2(ParentForm, parent);
                }
                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    parent.AddFilter(form.TheFilter);

                    Node newTreeListNode = AddNode(treeListNode, "", form.TheFilter, Images.GreenBullet, true,
                                                                         form.TheFilter.Enabled);
                    GetTreeListNodeText(form.TheFilter, newTreeListNode);

                    treeListNode.Tag = parent.Filters;

                    ProcessTreeValidity(treeList.Nodes);
                    Interfaces.Events.SetCursor(Cursors.Default);
                }
            }
            else if (type == typeof (Index[]))
            {
                Table parent = (Table) treeListNode.Parent.Tag;
                FormIndex form = new FormIndex((Table) treeListNode.Parent.Tag);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    parent.AddIndex(form.Index);

                    Node newTreeListNode = AddNode(treeListNode, "", form.Index, Images.GreenBullet, true,
                                                                         form.Index.Enabled);
                    GetTreeListNodeText(form.Index, newTreeListNode);

                    treeListNode.Tag = parent.Indexes;

                    ProcessTreeValidity(treeList.Nodes);
                    Interfaces.Events.SetCursor(Cursors.Default);
                }
            }
            else if (type == typeof (Key[]))
            {
                Table parent = (Table) treeListNode.Parent.Tag;
                FormKey form = new FormKey((Table) treeListNode.Parent.Tag);

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    parent.AddKey(form.Key);

                    Node newTreeListNode = AddNode(treeListNode, "", form.Key, Images.GreenBullet, true,
                                                                         form.Key.Enabled);
                    GetTreeListNodeText(form.Key, newTreeListNode);

                    treeListNode.Tag = parent.Keys;

                    ProcessTreeValidity(treeList.Nodes);
                    Interfaces.Events.SetCursor(Cursors.Default);
                }
            }
            else if (type == typeof (List<Association>))
            {
                ScriptObject parent = (ScriptObject) treeListNode.Parent.Tag;

                frmAssociationWizard.Association = new Association((ScriptObject) treeListNode.Parent.Tag);
                frmAssociationWizard.Association.Enabled = true;
                frmAssociationWizard form = new frmAssociationWizard();

                if (form.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    Interfaces.Events.SetCursor(Cursors.WaitCursor);
                    parent.AddAssociation(frmAssociationWizard.Association);

                    Node newTreeListNode = AddNode(treeListNode,
                                                                         frmAssociationWizard.Association.Name,
                                                                         frmAssociationWizard.Association,
                                                                         Images.GreenBullet, true,
                                                                         frmAssociationWizard.Association.Enabled);
                    treeListNode.Tag = parent.Associations;

                    ProcessTreeValidity(treeList.Nodes);
                    Interfaces.Events.SetCursor(Cursors.Default);
                    treeListNode.Expanded = true;
                    treeList.SelectedNode = newTreeListNode;
                }
            }
            treeList.EndUpdate();
        }