public override void OnLeaveView() { IntermediateTable intTable = model.IntermediateTableNode.IntermediateTable; intTable[0].Table = cbRelatedTable1.Text; intTable[1].Table = cbRelatedTable2.Text; intTable[0].ForeignKeyColumnName = cbForeignKey1.Text; intTable[1].ForeignKeyColumnName = cbForeignKey2.Text; intTable[0].ChildForeignKeyColumnName = intTable[1].ForeignKeyColumnName; intTable[1].ChildForeignKeyColumnName = intTable[0].ForeignKeyColumnName; TableNode tn = (TableNode)cbRelatedTable1.SelectedItem; intTable[0].Type = tn.Table.ClassName; tn = (TableNode)cbRelatedTable2.SelectedItem; intTable[1].Type = tn.Table.ClassName; }
public override DialogResult Run(IModel model) { IntermediateTableWizardModel intTWizModel = (IntermediateTableWizardModel)model; TableNode empTableNode = null; TableNode terrTableNode = null; foreach (TableNode tn in intTWizModel.TableNodes) { if (tn.Text == "Employees") { empTableNode = tn; } if (tn.Text == "Territories") { terrTableNode = tn; } } Assertion.AssertNotNull(empTableNode); Assertion.AssertNotNull(terrTableNode); IntermediateTable intTable = intTWizModel.IntermediateTableNode.IntermediateTable; intTable[0].CodingStyle = CodingStyle.IList; intTable[0].RelationDirection = RelationDirection.Bidirectional; // intTable[0].RelationDirection = RelationDirection.DirectedToMe; intTable[0].IsComposite = false; intTable[0].IsElement = false; intTable[0].RelationName = "Hi"; intTable[0].Table = empTableNode.Table.Name; intTable[0].Type = empTableNode.Table.ClassName; intTable[0].FieldName = "territories"; intTable[0].ForeignKeyColumnName = "EmployeeID"; intTable[0].ChildForeignKeyColumnName = "TerritoryID"; intTable[1].CodingStyle = CodingStyle.IList; intTable[1].RelationDirection = RelationDirection.Bidirectional; // intTable[1].RelationDirection = RelationDirection.DirectedFromMe; intTable[1].IsComposite = false; intTable[1].IsElement = false; intTable[1].RelationName = "Hi"; intTable[1].Table = terrTableNode.Table.Name; intTable[1].Type = terrTableNode.Table.ClassName; intTable[1].FieldName = "employees"; intTable[1].ForeignKeyColumnName = "TerritoryID"; intTable[1].ChildForeignKeyColumnName = "EmployeeID"; return(DialogResult.OK); }
public IntermediateTableNode(IntermediateTable intTable, TableNode originalTableNode) : base(originalTableNode.Text, originalTableNode.Parent) { this.originalTableNode = originalTableNode; this.myObject = intTable; CalculateIndex(); }
public void MapIntermediateTable(TableNode tn) { IntermediateTable it = new IntermediateTable(tn.Text); IntermediateTableNode itn = new IntermediateTableNode(it, tn); IList tableNodes = databaseNode.TableNodes; tableNodes.Remove(tn); IntermediateTableWizardModel model = new IntermediateTableWizardModel(itn, tableNodes); IWizardController controller = ApplicationController.wizardControllerFactory.Create ("IntermediateTableWizController", "IntTblWiz", "Intermediate Table Wizard"); //controller.FrameSize = new Size(544, 416); DialogResult r = controller.Run(model); if (r == DialogResult.OK) { DatabaseNode parent = (DatabaseNode)tn.Parent; //tn.Parent.Nodes. Remove(tn); int index = parent.Nodes.IndexOf(tn); tn.Remove(); tn.Parent.Nodes.Insert(index, itn); itn.TreeView.SelectedNode = itn; itn.Nodes.Add(tn); // This ensures persisting the column nodes with file/save. RelatedTableInfo rti0 = it[0]; RelatedTableInfo rti1 = it[1]; TableNode relTn0 = null; TableNode relTn1 = null; RelationNode relNode0 = null; RelationNode relNode1 = null; foreach (TableNode loopTn in tableNodes) { if (loopTn.Text == rti0.Table) { relTn0 = loopTn; if (rti0.RelationDirection != RelationDirection.DirectedToMe) { ForeignIntermediateTableRelation fitr = new ForeignIntermediateTableRelation(rti0, tn.Text); relNode0 = new RelationNode(fitr, relTn0); relTn0.Nodes.Add(relNode0); } } if (loopTn.Text == rti1.Table) { relTn1 = loopTn; if (rti1.RelationDirection != RelationDirection.DirectedToMe) { ForeignIntermediateTableRelation fitr = new ForeignIntermediateTableRelation(rti1, tn.Text); relNode1 = new RelationNode(fitr, relTn1); relTn1.Nodes.Add(relNode1); } } } if (relNode0 != null) { relNode0.RelatedTableNode = relTn1; } if (relNode1 != null) { relNode1.RelatedTableNode = relTn0; } } }
private void SetStartIndex() { TreeNodeCollection fkNodes = model.IntermediateTableNode.OriginalTableNode.Nodes; IntermediateTable intermediateTable = model.IntermediateTableNode.IntermediateTable; string fkColumnName = intermediateTable[0].ForeignKeyColumnName; if (fkColumnName == string.Empty) { cbForeignKey1.SelectedIndex = 0; } else { for (int i = 0; i < fkNodes.Count; i++) { if (fkNodes[i].Text == fkColumnName) { cbForeignKey1.SelectedIndex = i; break; } } } fkColumnName = intermediateTable[1].ForeignKeyColumnName; if (fkColumnName == string.Empty) { cbForeignKey2.SelectedIndex = 1; } else { for (int i = 0; i < fkNodes.Count; i++) { if (fkNodes[i].Text == fkColumnName) { cbForeignKey2.SelectedIndex = i; break; } } } string tableName = intermediateTable[0].Table; if (tableName == string.Empty) { cbRelatedTable1.SelectedIndex = 0; } else { for (int i = 0; i < model.TableNodes.Count; i++) { if (((TableNode)model.TableNodes[i]).Text == tableName) { cbRelatedTable1.SelectedIndex = i; break; } } } tableName = intermediateTable[1].Table; if (tableName == string.Empty) { cbRelatedTable2.SelectedIndex = 1; } else { for (int i = 0; i < model.TableNodes.Count; i++) { if (((TableNode)model.TableNodes[i]).Text == tableName) { cbRelatedTable2.SelectedIndex = i; break; } } } }