Beispiel #1
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;
                }
            }
        }
Beispiel #2
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();
        }