new public void Insert(int index, DataSource val) { val.SetProject(Project); if ( this.Contains(val) ) { base.Remove(val); } base.Insert(index, val); }
new public int Add(DataSource val) { val.SetProject(Project); if ( !this.Contains(val) ) { return base.Add(val); } return -1; }
public DbEntitySelector(DataSource dataSource) { // // Required for Windows Form Designer support // InitializeComponent(); _dataSource = dataSource; }
public DataSourceEditor(DataSource ds) : this() { _dataSource = ds; }
private DataView GetDBLinkSchema(DataSource ds) { using (OleDbConnection cn = new OleDbConnection(ds.ConnectionString)) { cn.Open(); try { return new DataView(cn.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, null)); } finally { cn.Close(); } } }
public void RefreshDBLinks(DataSource ds) { // DataView schema = GetDBLinkSchema(ds); // string[] toManyIndexes = GetFKIndexes(schema); // foreach (string index in fkIndexes) { // // string[] fields = GetFKIndexFields(schema, index); // foreach ( // } // // string[] pkIndexes = GetPKIndexes(schema); }
private DataView GetDBIndexes(DataSource dataSource) { using (OleDbConnection cn = new OleDbConnection(dataSource.ConnectionString)) { cn.Open(); try { return new DataView(cn.GetOleDbSchemaTable(OleDbSchemaGuid.Indexes, null)); } finally { cn.Close(); } } }
private void FillIndexes(DataSource dataSource) { DataView indexes = GetDBIndexes(dataSource); indexes.RowFilter = "TABLE_NAME = '" + DBEntityName + "'"; indexes.Sort = "INDEX_NAME asc, ORDINAL_POSITION asc"; foreach (DataRowView row in indexes) { Index index = LoadIndexRow(row); if (index != null) { index.RemoveUnusedFields(indexes); } } }
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 void RefreshDBInfo(DataSource dataSource, DatabaseSchema database, TableSchema table) { DataSourceName = dataSource.Name; DBName = database.Name; DBEntityName = table.Name; if (Name == string.Empty) { Name = table.Name.Replace(" ", ""); } FillFields(table); FillIndexes(dataSource); }
public DataSourceNameChangedEventArgs(DataSource ds, string oldName, string newName) { this.DataSource = ds; this.NewName = newName; this.OldName = oldName; }
private void lstDataSources_SelectedIndexChanged(object sender, EventArgs e) { if (lstDataSources.SelectedItem != null) { ds = (DataSource) lstDataSources.SelectedItem; lblProvider.Text = ds.Provider; lblConnectionString.Text = ds.ConnectionString; } }
private void cmdOk_Click(object sender, EventArgs e) { txtNome_Validated(null, null); if (errCount == 0) { string connectionString = txtConnectionString.Text; // string connectionString = string.Format( // SQL_CONNECTIONSTRING, // new string[] { // cmbSqlServer.Text, cmbDatabase.Text, (chkIntegrated.Checked ? "SSPI" : ""), // txtUid.Text, txtPassword.Text}); dataSource = new DataSource(txtNome.Text, connectionString); this.Close(); } else { MessageBox.Show("Há erros que devem ser corrigidos antes de prosseguir.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }