示例#1
0
        public override void OnLeaveView()
        {
            if (cbRelatedTable.SelectedIndex == -1)
            {
                return;
            }
            model.RelationNode.RelatedTableNode = (TableNode)model.TableNodes[cbRelatedTable.SelectedIndex];
            FkRelation fkRelation = (FkRelation)model.RelationNode.Relation;

            fkRelation.RelatedTable = model.RelationNode.RelatedTableNode.Table.Name;
            fkRelation.RelatedType  = model.RelationNode.RelatedTableNode.Table.ClassName;
            RelationDirection dir;

            if (radioToMe.Checked)
            {
                dir = RelationDirection.DirectedToMe;
            }
            else if (radioFromMe.Checked)
            {
                dir = RelationDirection.DirectedFromMe;
            }
            else
            {
                dir = RelationDirection.Bidirectional;
            }
            ((FkRelation)model.RelationNode.Relation).RelationDirection = dir;
        }
示例#2
0
 public void UnmapIntermediateClass(TableNode tn)
 {
     foreach (NDOTreeNode trn in tn.Nodes)
     {
         RelationNode rn = trn as RelationNode;
         if (rn == null)
         {
             continue;
         }
         rn.Remove();
         FkRelation fkRelation = rn.Relation as FkRelation;
         if (fkRelation != null)
         {
             if (fkRelation.RelationDirection != RelationDirection.DirectedFromMe)
             {
                 TableNode    relTn        = databaseNode.FindTableNode(fkRelation.RelatedTable, true);
                 RelationNode nodeToRemove = relTn.FindRelationNode(rn.Text, tn.Text);
                 if (nodeToRemove != null)
                 {
                     nodeToRemove.Remove();
                 }
             }
         }
     }
 }
示例#3
0
        private void ForeignKeyWiz4_Load(object sender, System.EventArgs e)
        {
            FkRelation relation = (FkRelation)model.RelationNode.Relation;

            this.txtRelationName.DataBindings.Add("Text", relation, "RelationName");
            Frame.Description = "The relation name is used to distinguish between different relations to the same target type. If there aren't more than one relation to the same target type, leave this field empty.";
        }
示例#4
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);
        }
示例#5
0
 public ForeignFkRelation(FkRelation master)
 {
     this.master      = master;
     this.isComposite = master.ForeignIsComposite;
     this.codingStyle = master.ForeignCodingStyle;
     this.fieldName   = master.ForeignFieldName;
     base.IsForeign   = true;
 }
示例#6
0
        private void ForeignKeyWiz3_Load(object sender, System.EventArgs e)
        {
            FkRelation relation = (FkRelation)model.RelationNode.Relation;

            this.lblClass.Text = relation.RelatedType;

            if (relation.ForeignFieldName == string.Empty)
            {
                string name = relation.OwningTable;
                name = name.Substring(0, 1).ToLower() + name.Substring(1);
                relation.ForeignFieldName = name;
            }

            this.txtFieldName.DataBindings.Add("Text", relation, "ForeignFieldName");

            if (relation.ForeignCodingStyle == CodingStyle.IList)
            {
                this.radioIList.Checked = true;
            }
            else if (relation.ForeignCodingStyle == CodingStyle.ArrayList)
            {
                this.radioArrayList.Checked = true;
            }
            else if (relation.ForeignCodingStyle == CodingStyle.NDOArrayList)
            {
                this.radioNDOArrayList.Checked = true;
            }
#if !NDO11
            radioArrayList.Text       = "List<T>";
            radioIList.Text           = "IList<T>";
            radioNDOArrayList.Visible = false;
#endif

            this.gbCodingStyle.Enabled = (relation.RelationDirection == RelationDirection.DirectedToMe || relation.RelationDirection == RelationDirection.Bidirectional);
            if (relation.RelationDirection != RelationDirection.DirectedToMe && relation.IsComposite)
            {
                this.gbRelationType.Enabled   = false;
                this.radioAssoziation.Checked = true;
            }
            else
            {
                this.gbRelationType.Enabled = true;
                if (relation.ForeignIsComposite)
                {
                    this.radioComposite.Checked = true;
                }
                else
                {
                    this.radioAssoziation.Checked = true;
                }
            }

            Frame.Description = "Enter the name of the field, which will contain the relation.\n\nEnter the relation type and the list coding style.";
        }
示例#7
0
        public override void FromXml(XmlElement element)
        {
            base.FromXml(element);
            this.CodingStyle       = (CodingStyle)CodingStyle.Parse(typeof(CodingStyle), element.Attributes["CodingStyle"].Value);
            this.fieldName         = element.Attributes["FieldName"].Value;
            this.isComposite       = bool.Parse(element.Attributes["IsComposite"].Value);
            this.relationDirection = (RelationDirection)RelationDirection.Parse(typeof(RelationDirection), element.Attributes["RelationDirection"].Value);
            XmlElement masterElement = (XmlElement)element.SelectSingleNode("Master");

            master = new FkRelation();
            master.FromXml(masterElement);
        }
示例#8
0
        private void ForeignKeyWiz2_Load(object sender, System.EventArgs e)
        {
            FkRelation relation = (FkRelation)model.RelationNode.Relation;

            this.lblClass.Text = relation.OwningType;
            if (relation.FieldName == string.Empty)
            {
                string name = relation.RelatedType;
                name = name.Substring(0, 1).ToLower() + name.Substring(1);
                relation.FieldName = name;
            }
            this.txtFieldName.DataBindings.Add("Text", relation, "FieldName");
            if (relation.IsComposite)
            {
                this.radioComposite.Checked = true;
            }
            else
            {
                this.radioAssoziation.Checked = true;
            }

            if (relation.CodingStyle == CodingStyle.IList)
            {
                this.radioIList.Checked = true;
            }
            else if (relation.CodingStyle == CodingStyle.ArrayList)
            {
                this.radioArrayList.Checked = true;
            }
            else if (relation.CodingStyle == CodingStyle.NDOArrayList)
            {
                this.radioNDOArrayList.Checked = true;
            }

#if !NDO11
            radioArrayList.Text       = "List<T>";
            radioIList.Text           = "IList<T>";
            radioNDOArrayList.Visible = false;
#endif


            this.gbCodingStyle.Visible = false;              // we own the foreign key, so cardinality is always 1

            Frame.Description = "Enter the name of the field, which will contain the relation.\n\nEnter the relation type.";
        }
示例#9
0
        public void DeleteRelation(RelationNode relationNode)
        {
            FkRelation fkRelation = relationNode.Relation as FkRelation;
            TableNode  parentNode = null;

            if (fkRelation == null)
            {
                ForeignFkRelation ffkrel = relationNode.Relation as ForeignFkRelation;
                if (ffkrel == null)
                {
                    return;
                }
                parentNode   = (TableNode)this.databaseNode.FindNode(ffkrel.RelatedTable, typeof(TableNode));
                relationNode = parentNode.FindRelationNode(relationNode.Text, relationNode.Parent.Text);                //(RelationNode) parentNode.FindNode(relationNode.Text, typeof(RelationNode));
                fkRelation   = (FkRelation)relationNode.Relation;
                if (parentNode.Table.MappingType == TableMappingType.MappedAsIntermediateClass)
                {
                    parentNode.UnmapIntermediateClass(null, EventArgs.Empty);
                    return;
                }
            }
            else
            {
                parentNode = (TableNode)relationNode.Parent;
            }

            //parentNode.Nodes. Remove(relationNode);
            relationNode.Remove();
            parentNode.Nodes.Add(relationNode.OriginalColumnNode);

            Debug.Assert(fkRelation != null);
            if (fkRelation != null)
            {
                if (fkRelation.RelationDirection != RelationDirection.DirectedFromMe)
                {
                    TableNode    tn           = databaseNode.FindTableNode(fkRelation.RelatedTable, true);
                    RelationNode nodeToRemove = tn.FindRelationNode(relationNode.Text, parentNode.Text);
                    if (nodeToRemove != null)
                    {
                        nodeToRemove.Remove();
                    }
                }
            }
        }
示例#10
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);
            }
        }
示例#11
0
        public override void OnLeaveView()
        {
            FkRelation relation = (FkRelation)model.RelationNode.Relation;

            if (this.radioIList.Checked)
            {
                relation.CodingStyle = CodingStyle.IList;
            }
            else if (this.radioArrayList.Checked)
            {
                relation.CodingStyle = CodingStyle.ArrayList;
            }
            else if (this.radioNDOArrayList.Checked)
            {
                relation.CodingStyle = CodingStyle.NDOArrayList;
            }

            relation.IsComposite = this.radioComposite.Checked;
        }
示例#12
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);
            }
        }
示例#13
0
            public override DialogResult Run(IModel model)
            {
                ClassGenerator.ForeignKeyWizard.ForeignKeyWizModel fkWizModel = (ClassGenerator.ForeignKeyWizard.ForeignKeyWizModel)model;
                TableNode relTableNode = null;

                foreach (TableNode tn in fkWizModel.TableNodes)
                {
                    if (tn.Text == "Employees")
                    {
                        relTableNode = tn;
                    }
                }

                fkWizModel.RelationNode.RelatedTableNode = relTableNode;
                FkRelation fkRelation = (FkRelation)fkWizModel.RelationNode.Relation;

                fkRelation.RelationDirection  = RelationDirection.Bidirectional;
                fkRelation.FieldName          = "employee";
                fkRelation.ForeignCodingStyle = CodingStyle.IList;
                fkRelation.ForeignFieldName   = "orders";
                return(DialogResult.OK);
            }
示例#14
0
        public override void OnLeaveView()
        {
            FkRelation relation = (FkRelation)model.RelationNode.Relation;

            if (relation.RelationDirection == RelationDirection.DirectedFromMe)
            {
                return;
            }

            if (this.radioIList.Checked)
            {
                relation.ForeignCodingStyle = CodingStyle.IList;
            }
            else if (this.radioArrayList.Checked)
            {
                relation.ForeignCodingStyle = CodingStyle.ArrayList;
            }
            else if (this.radioNDOArrayList.Checked)
            {
                relation.ForeignCodingStyle = CodingStyle.NDOArrayList;
            }

            relation.ForeignIsComposite = this.radioComposite.Checked;
        }
示例#15
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;
        }
示例#16
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);
        }