示例#1
0
        protected override void SwitchToState(int newState, out ViewBase newView, out WizardState wizardState)
        {
            int oldState                  = this.State;
            ForeignKeyWizModel model      = (ForeignKeyWizModel)this.Model;
            FkRelation         fkRelation = (FkRelation)model.RelationNode.Relation;

            if (fkRelation.RelationDirection == RelationDirection.DirectedToMe && newState == 1)
            {
                // skip state 1
                if (State == 0)
                {
                    newState = 2;
                }
                if (State == 2)
                {
                    newState = 0;
                }
            }
            if (fkRelation.RelationDirection == RelationDirection.DirectedFromMe && newState == 2)
            {
                // skip state 2
                if (State == 1)
                {
                    newState = 3;
                }
                if (State == 3)
                {
                    newState = 1;
                }
            }
            base.SwitchToState(newState, out newView, out wizardState);
        }
示例#2
0
        public void MakeForeignKey(ColumnNode columnNode, ForeignKeyWizModel model)
        {
            FkRelation   fkRelation   = null;
            RelationNode relationNode = null;

            if (model == null)
            {
                fkRelation   = new FkRelation(columnNode.Name);
                relationNode = new RelationNode(fkRelation, columnNode.Parent);
            }
            else
            {
                fkRelation   = (FkRelation)model.RelationNode.Relation;
                relationNode = model.RelationNode;
            }
            fkRelation.OwningTable = ((TableNode)relationNode.Parent).Table.Name;
            fkRelation.OwningType  = ((TableNode)relationNode.Parent).Table.ClassName;
            IList tableNodes = new ArrayList();

            if (model == null)
            {
                foreach (TableNode tnode in ((DatabaseNode)columnNode.Parent.Parent).TableNodes)
                {
                    if (tnode.Table.MappingType == TableMappingType.MappedAsClass)
                    {
                        tableNodes.Add(tnode);
                    }
                }
                model = new ForeignKeyWizModel(relationNode, tableNodes);
                IWizardController controller = ApplicationController.wizardControllerFactory.Create
                                                   ("ForeignKeyWizController", "ForeignKeyWiz", "Foreign Key Wizard");
                //controller.FrameSize = new Size( 544, 408 );
                DialogResult r = controller.Run(model);
                if (r == DialogResult.OK)
                {
                    MakeForeignKeyRelation(relationNode, columnNode, model);
                }
            }
            else
            {
                MakeForeignKeyRelation(relationNode, columnNode, model);
            }
        }
示例#3
0
 public ForeignKeyWiz1(IModel model)
 {
     InitializeComponent();
     this.model = (ForeignKeyWizModel)model;
 }
示例#4
0
        public void MakeForeignKey(DataRelation dataRelation)
        {
            // The FkRelation is owned by the child table, because it holds
            // the foreign key.
            // Therefore the XPath has to be stored in the ForeignFkRelation.
            string xpath = (string)dataRelation.ExtendedProperties["xpath"];

            TableNode          ownTableNode     = this.databaseNode[dataRelation.ChildTable.TableName];
            TableNode          foreignTableNode = this.databaseNode[dataRelation.ParentTable.TableName];
            ColumnNode         cn           = ownTableNode[dataRelation.ChildColumns[0].ColumnName];
            FkRelation         fkRelation   = new FkRelation(cn.Text);
            RelationNode       relationNode = new RelationNode(fkRelation, cn.Parent);
            ForeignKeyWizModel model        = new ForeignKeyWizModel(relationNode, null);

            fkRelation.CodingStyle        = CodingStyle.ArrayList;
            fkRelation.FieldName          = MakeCamelCase(foreignTableNode.Text);
            fkRelation.RelationDirection  = RelationDirection.DirectedToMe;// Bidirectional;
            relationNode.RelatedTableNode = foreignTableNode;
            fkRelation.RelatedTable       = dataRelation.ParentTable.TableName;
            fkRelation.RelatedType        = relationNode.RelatedTableNode.Table.ClassName;
            fkRelation.IsComposite        = false;

            string singularFieldName = null;

            if (xpath != null)
            {
                singularFieldName = MakePascalCase(xpath.Substring(xpath.LastIndexOf('/') + 1));
            }
            else
            {
                singularFieldName = MakePascalCase(ownTableNode.Text);
            }

            singularFieldName = singularFieldName.Substring(singularFieldName.IndexOf(':') + 1);

            string foreignFieldName = MakeCamelCase(singularFieldName);

            if (foreignFieldName.EndsWith("y"))
            {
                char c = char.ToLower(foreignFieldName[foreignFieldName.Length - 2]);
                if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
                {
                    foreignFieldName += "s";
                }
                else
                {
                    foreignFieldName = foreignFieldName.Substring(0, foreignFieldName.Length - 1) + "ies";
                }
            }
            else if (foreignFieldName.EndsWith("s"))
            {
                foreignFieldName += "es";
            }
            else if (foreignFieldName.EndsWith("f"))
            {
                foreignFieldName = foreignFieldName.Substring(0, foreignFieldName.Length - 1) + "ves";
            }
            else
            {
                foreignFieldName += "s";
            }
            fkRelation.ForeignFieldName = foreignFieldName;

            fkRelation.ForeignIsComposite = true;
            fkRelation.ForeignCodingStyle = CodingStyle.ArrayList;
            fkRelation.RelationName       = string.Empty;
            MakeForeignKey(cn, model);
            fkRelation.ForeignRelation.SingularFieldName = MakePascalCase(singularFieldName);
            fkRelation.ForeignRelation.XPath             = xpath;
        }
示例#5
0
        public bool MapIntermediateClass(TableNode tn)
        {
//			IntermediateClass ic = new IntermediateClass();
//			IntermediateClassNode icn = new IntermediateClassNode(ic, tn);

            IList tableNodes = new ArrayList();

            foreach (TableNode tnode in databaseNode.TableNodes)
            {
                if (tn.Text == tnode.Text)
                {
                    continue;
                }
                if (tnode.Table.MappingType == TableMappingType.MappedAsClass)
                {
                    tableNodes.Add(tnode);
                }
            }

            IntermediateClassWizardModel model = new IntermediateClassWizardModel(tn, tableNodes);

            IWizardController controller = ApplicationController.wizardControllerFactory.Create
                                               ("IntermediateClassWizController", "IntClassWiz", "Intermediate Class Wizard");

            //controller.FrameSize = new Size(544, 500);
            model[0].RelationDirection = RelationDirection.Bidirectional;
            model[1].RelationDirection = RelationDirection.Bidirectional;
            DialogResult r = controller.Run(model);

            if (r == DialogResult.OK)
            {
                DatabaseNode parent = (DatabaseNode)tn.Parent;
                // Nothing to remove, because we use the original table node
                //				tn.Remove();
                //				tn.Parent.Nodes.Add(icn);
                for (int i = 0; i < 2; i++)
                {
                    ColumnNode            columnNode   = (ColumnNode)tn.FindNode(model[i].ForeignKeyColumnName, typeof(ColumnNode));
                    FkRelation            fkr          = new FkRelation(columnNode.Text);
                    IntermediateClassInfo intermClInfo = model[i];
                    fkr.FieldName          = intermClInfo.OwnFieldName;
                    fkr.ForeignCodingStyle = intermClInfo.CodingStyle;
                    fkr.ForeignFieldName   = intermClInfo.ForeignFieldName;
                    fkr.ForeignIsComposite = false;
                    fkr.IsComposite        = false;
                    fkr.OwningTable        = tn.Text;
                    fkr.OwningType         = tn.Table.ClassName;
                    fkr.RelatedTable       = intermClInfo.Table;
                    fkr.RelatedType        = intermClInfo.Type;
                    fkr.RelationDirection  = intermClInfo.RelationDirection;
                    fkr.RelationName       = string.Empty;
                    //ForeignFkRelation ffkr = fkr.ForeignRelation;
                    RelationNode relationNode = new RelationNode(fkr, tn);
                    relationNode.RelatedTableNode = (TableNode)databaseNode.FindNode(intermClInfo.Table);
                    ForeignKeyWizModel fkwizModel = new ForeignKeyWizModel(relationNode, new ArrayList());

                    tn.DualKeyRelations[i] = intermClInfo.OwnFieldName;

                    MakeForeignKeyRelation(relationNode, columnNode, fkwizModel);
                }
                return(true);
            }
            return(false);
        }
示例#6
0
        private void MakeForeignKeyRelation(RelationNode relationNode, ColumnNode columnNode, ForeignKeyWizModel model)
        {
            FkRelation fkRelation = (FkRelation)relationNode.Relation;

            fkRelation.RelatedTable = relationNode.RelatedTableNode.Table.Name;
            fkRelation.RelatedType  = relationNode.RelatedTableNode.Table.ClassName;
            TableNode tn = (TableNode)columnNode.Parent;

            //tn.Nodes. Remove(columnNode);
            columnNode.Remove();
            tn.Nodes.Add(relationNode);
            relationNode.OriginalColumnNode = columnNode;
            this.assemblyNode.Refresh();
            if (fkRelation.RelationDirection == RelationDirection.DirectedToMe ||
                fkRelation.RelationDirection == RelationDirection.Bidirectional)
            {
                tn = databaseNode.FindTableNode(fkRelation.RelatedTable, true);
                RelationNode rn = new RelationNode(fkRelation.ForeignRelation, tn);
                rn.RelatedTableNode = (TableNode)columnNode.Parent;
                tn.Nodes.Add(rn);
            }
        }