new public void Insert(int index, Index val) { if (this._entity != null) { val.SetEntity(this._entity); } if ( this.Contains(val) ) { this.Remove(val); } this.Insert(index, val); }
new public int Add(Index val) { if (this._entity != null) { val.SetEntity(this._entity); } if ( !this.Contains(val) ) { return base.Add(val); } return -1; }
protected virtual string GetIndexReturnType(Index index) { if (index.PrimaryKey || index.Unique) return index.Entity.Name; else return index.Entity.CollectionName; }
private Index LoadIndexRow(DataRowView row) { string fieldName = (String) row["COLUMN_NAME"]; EntityField field = null; foreach (EntityField f in Fields) { if (f.DBColumn == fieldName) { field = f; break; } } if (field == null) { return null; } string name = (String) row["INDEX_NAME"]; Index index = null; foreach (Index i in Indexes) { if (i.DBName == name) { index = i; break; } } if (index == null) { index = new Index(); Indexes.Add(index); } index.RefreshDBInfo(row, field); return index; }
public void AutoFillLinks(DataSource ds) { // Create Object's Link oLink; DataView dbLinkSchemas; Entity oTargetEntity = null; Index oTargetIndex = null; IndexField oTargetIndexField = null; LinkField oSourceLinkField = null; Boolean bIndexExists = false; Trace.Unindent(); Trace.WriteLine(String.Format("Create Links from Entity \"{0}\"", this.Name)); Trace.Indent(); // Get Schemas dbLinkSchemas = GetDBLinkSchema(ds); // Lopping on Fields foreach (EntityField tmpField in this.Fields) { // Clear Flag bIndexExists = false; if (tmpField.KeyField) // PK { Trace.WriteLine(String.Format("Parsing PK \"{0}\"", tmpField.Name)); // Filter Indexes dbLinkSchemas.RowFilter = String.Format("PK_COLUMN_NAME = '{0}' AND PK_TABLE_NAME = '{1}'", tmpField.DBColumn, this.DBEntityName); // Looping on FK's foreach (DataRowView tmpDataRowView in dbLinkSchemas) { Trace.WriteLine(String.Format("Parsing FK \"{0}\"", tmpDataRowView["FK_NAME"])); // Get Target Entity oTargetEntity = Project.CurrentProject.GetEntity(tmpDataRowView["FK_TABLE_NAME"].ToString()); if (oTargetEntity == null) { Trace.WriteLine(String.Format("Entity for Table \"{0}\" not Found.", tmpDataRowView["FK_TABLE_NAME"])); continue; } // Check if the Link Alread Exists foreach (Link tmpLink in this.Links) { if (tmpLink.Fields.Count.Equals(1) && tmpLink.Fields[0].Name.Equals(tmpDataRowView["FK_COLUMN_NAME"].ToString())) { Trace.WriteLine(String.Format("Link por Field \"{0}\" Alread Exists", tmpField.Name)); bIndexExists = true; break; } } if (bIndexExists) { break; } // Lopping on TargetEntity to Find the Correct Index foreach (Index tmpIndex in oTargetEntity.Indexes) { if (tmpIndex.Fields.Count.Equals(1) && tmpIndex.Fields[0].Name.EndsWith(tmpDataRowView["FK_COLUMN_NAME"].ToString())) { oTargetIndex = tmpIndex; break; } } // Check if Exists if (oTargetIndex == null) { Trace.WriteLine(String.Format("Creating Target Index for FK \"{0}\"", tmpDataRowView["FK_NAME"])); // Create Target Index oTargetIndex = new Index(); oTargetIndex.SelectBy = true; oTargetIndex.DeleteBy = false; oTargetIndex.Name = tmpDataRowView["FK_COLUMN_NAME"].ToString(); oTargetIndex.Unique = false; oTargetIndex.DBName = tmpDataRowView["FK_COLUMN_NAME"].ToString(); oTargetIndex.PrimaryKey = false; // Create Target Index Field oTargetIndexField = new IndexField(); oTargetIndexField.Name = tmpDataRowView["FK_COLUMN_NAME"].ToString(); oTargetIndexField.PartialTextMatch = false; // Add Target Index Field on Target Index oTargetIndex.Fields.Add(oTargetIndexField); // Add Target Index on Target Entity oTargetEntity.Indexes.Add(oTargetIndex); } // Create Link oLink = new Link(); oLink.TargetEntityName = oTargetEntity.Name; oLink.TargetIndexName = oTargetIndex.Name; oLink.IsCollection = true; oLink.IsProperty = true; oLink.ReadOnly = true; // Check if the Target Index is Unique if (oTargetIndex.Unique) // 1-N Relation { oLink.Name = oTargetEntity.Name; // N-M Relation } else { oLink.Name = oTargetEntity.PluralName; } // Check Delete Relation Action if (tmpDataRowView["DELETE_RULE"].ToString().Equals("NO ACTION")) { oLink.CascadeDelete = false; } else { oLink.CascadeUpdate = true; } // Check Update Relation Action if (tmpDataRowView["UPDATE_RULE"].ToString().Equals("NO ACTION")) { oLink.CascadeDelete = false; } else { oLink.CascadeUpdate = true; } // Create Link Field oSourceLinkField = new LinkField(); oSourceLinkField.SourceFieldName = this.Fields.GetFieldFromDBColumn(tmpDataRowView["PK_COLUMN_NAME"].ToString()).Name; oSourceLinkField.TargetFieldName = oTargetEntity.Fields.GetFieldFromDBColumn(tmpDataRowView["FK_COLUMN_NAME"].ToString()).Name; // Add Link Field on Link oLink.Fields.Add(oSourceLinkField); // Add Link on Entity this.Links.Add(oLink); } if (bIndexExists) { continue; } } } }
public IndexNameChangedEventArgs(Index index, string oldName, string newName) { this.Index = index; this.NewName = newName; this.OldName = oldName; }
internal void SetIndex(Index index) { Debug.Assert(index != null, "Index parameter should not be null."); _index = index; }
internal void RemoveIndexFromList(TreeNode rootNode, Index index) { // Looping on Child Nodes foreach (TreeNode tmpNode in rootNode.Nodes) { RemoveIndexFromList(tmpNode, index); } // Verify if (rootNode.Tag.Equals(index)) { // Try to Select Previous Item if (rootNode.PrevVisibleNode != null && rootNode.NextVisibleNode.Tag is Index) { rootNode.TreeView.SelectedNode = rootNode.NextVisibleNode; } else { rootNode.TreeView.SelectedNode = rootNode.PrevVisibleNode; } // Remove rootNode.Parent.Nodes.Remove(rootNode); } }
private bool SchemaContainsField(DataView schema, IndexField field, Index index) { string dbColumn = string.Empty; foreach (EntityField f in index.Entity.Fields) { if (f.Name == field.Name) { dbColumn = f.DBColumn; break; } } if (dbColumn == string.Empty) { dbColumn = field.Name; } foreach (DataRowView row in schema) { if ((string)row["TABLE_NAME"] == index.Entity.DBEntityName && (string)row["INDEX_NAME"] == index.DBName && (string)row["COLUMN_NAME"] == dbColumn) { return true; } } return false; }
private void RemoveUnusedIndexFields(DataView schema, Index index) { for (int i=index.Fields.Count-1; i>=0; i--) { IndexField field = index.Fields[i]; if (!SchemaContainsField(schema, field, index)) { index.Fields.Remove(field); } } }
private void RefreshIndexDBInfo(DataRowView schema, Index index, EntityField field) { IndexField indexField = null; foreach (IndexField f in index.Fields) { if (f.Name == field.Name) { indexField = f; break; } } if (indexField == null) { indexField = new IndexField(); indexField.Name = field.Name; index.Fields.Add(indexField); } index.DBName = (string)schema["INDEX_NAME"]; index.PrimaryKey = (bool)schema["PRIMARY_KEY"]; index.ForeignKey = (((string)schema["INDEX_NAME"]).Substring(0, 3) == "FK_"); index.Unique = (bool)schema["UNIQUE"]; if (index.Name == string.Empty) { if (index.PrimaryKey) { index.IsExcluded = !this.OrmConfiguration.AutoEnableMappedIndexes && !this.OrmConfiguration.AutoEnablePrimaryIndex; if (this.OrmConfiguration.RenamePrimaryIndex && this.OrmConfiguration.PrimaryIndexName != "") { index.Name = this.OrmConfiguration.PrimaryIndexName; } else { index.Name = index.DBName; } index.DeleteBy = true; } else { index.IsExcluded = !this.OrmConfiguration.AutoEnableMappedIndexes; index.Name = index.DBName; } } }
private Index LoadIndexRow(DataRowView row, Entity entity) { Debug.WriteLine(row["COLUMN_NAME"]); string fieldName = (String) row["COLUMN_NAME"]; EntityField field = null; foreach (EntityField f in entity.Fields) { if (f.DBColumn == fieldName) { field = f; break; } } if (field == null) { return null; } string name = (String) row["INDEX_NAME"]; Index index = null; foreach (Index i in entity.Indexes) { if (i.DBName == name) { index = i; break; } } if (index == null) { index = new Index(); entity.Indexes.Add(index); } this.RefreshIndexDBInfo(row, index, field); return index; }
private void designView_OnInsert(object sender, EventArgs e) { if (this.designView.CurrentSelectedNode != null) { if (this.designView.CurrentSelectedNode.Tag is EntityFieldCollection) { EntityField oEntity = new EntityField(); oEntity.Name = Const_DefaultNewFieldText; ((EntityFieldCollection) this.designView.CurrentSelectedNode.Tag).Add(oEntity); this.designView.RefreshFieldsList(this.designView.CurrentSelectedNode, this.designView.CurrentEntity, true); } else if (this.designView.CurrentSelectedNode.Tag is IndexCollection) { Index oIndex = new Index(); oIndex.Name = Const_DefaultNewIndexText; ((IndexCollection) this.designView.CurrentSelectedNode.Tag).Add(oIndex); this.designView.RefreshIndexesList(this.designView.CurrentSelectedNode, this.designView.CurrentEntity, true); } else if (this.designView.CurrentSelectedNode.Tag is LinkCollection) { Link oLink = new Link(); oLink.Name = Const_DefaultNewLinkText; ((LinkCollection) this.designView.CurrentSelectedNode.Tag).Add(oLink); this.designView.RefreshLinksList(this.designView.CurrentSelectedNode, this.designView.CurrentEntity, true); } } }
private void btnAddIndex_Click(object sender, EventArgs e) { IndexCollection Indexes = (IndexCollection) GetSelectedItemOfType(typeof (IndexCollection)); Index oIndex = new Index(); Indexes.Add(oIndex); IObjectEditor editor = new ORIndexEditor(oIndex); ObjectEditorManager.OpenObjectEditorDialog(editor); this.designView.RefreshIndexesList(this.GetSelectedNodeOfType(typeof(IndexCollection)), this.designView.CurrentEntity, false); }
private void btnFieldAutoIndex_Click(object sender, EventArgs e) { // Create Objects EntityFieldCollection entityFieldCollection = new EntityFieldCollection(); EntityField field; Entity entity; Index tmpNewIndex; IndexField tmpNewIndexField; Boolean bSub; // Get Selected Field field = (EntityField) GetSelectedItemOfType(typeof (EntityField)); // Get Current Entity entity = this.designView.CurrentEntity; // Check if Index exists if (field == null) // Create All Field Index { // Get All Fields entityFieldCollection = entity.Fields; } else { entityFieldCollection.Add(field); } // Looping on entityFieldCollection foreach (EntityField tmpEntityField in entityFieldCollection) { // Clear Found Flag bSub = false; // Check the Index Exists foreach(Index tmpIndex in entity.Indexes) { // Index Alread exists, Set Found Flag if (tmpIndex.Name.Equals(tmpEntityField.Name)) { bSub = true; break; } } if (! bSub) // Check's Found Flag { // Create Index tmpNewIndex = new Index(); tmpNewIndex.Name = tmpEntityField.Name; tmpNewIndex.PrimaryKey = tmpEntityField.KeyField; tmpNewIndex.Unique = tmpEntityField.DBIdentity; tmpNewIndex.SelectBy = true; tmpNewIndex.DeleteBy = tmpEntityField.KeyField; entity.Indexes.Add(tmpNewIndex); // Create Index Fields tmpNewIndexField = new IndexField(); tmpNewIndexField.Name = tmpEntityField.Name; tmpNewIndexField.ParameterName = tmpEntityField.Name; tmpNewIndex.Fields.Add(tmpNewIndexField); } } TreeNode rootNode = GetSelectedNodeOfType(typeof (Entity)); TreeNode indexesNode = rootNode.Nodes[1]; // Refresh List this.designView.RefreshIndexesList(indexesNode, entity, false); }
public ORIndexEditor(Index index) : this() { _index = index; }