/// <summary>
        /// An event handler called when the query for the table schema completed succesfully.
        /// </summary>
        /// <param name="result">The database result.</param>
        /// <param name="recordsAffected">The number of records affected.</param>
        private void OnQuerySuccessTableSchema(DbDataObject result, int recordsAffected)
        {
            // Check the query result has at least one record.
            if (result.RowCount == 0)
            {
                MessageBox.Show(this,
                    "A query for the schema of table \'{0}\' did not return any database schema.".FormatWith(this.textBoxNameDatabase.Text),
                    "Table Schema Not Found",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return;
            }
            // Get the results.
            this.resultSchemas = result;
            this.resultSchema = null;
            // If the query result has at most one record, let the user select one schema.
            if (result.RowCount > 1)
            {
                try
                {
                    // Create a new query to obtain the schema of the selected table.
                    DbQuerySql query = DbQuerySql.CreateSelectAllOn(this.server.TableSchema, this.server.TableTables, "Name", this.resultTable.Name, this.server.Database, this.delegateQueryTableSchema);

                    query.MessageStart = "Updating the database schema for the table \'{0}\'.".FormatWith(this.resultTable.Name);
                    query.MessageFinishSuccess = "Updating the database schema for the table \'{0}\' completed successfully.".FormatWith(this.resultTable.Name);
                    query.MessageFinishFail = "Updating the database schema for the table \'{0}\' failed".FormatWith(this.resultTable.Name);

                    // Repeat until the user selects a schema.
                    do
                    {
                        // Open a new database select window that selects all database tables for the given server.
                        if (this.formDatabaseSelect.ShowDialog(this, this.server, query, this.resultSchemas) == DialogResult.OK)
                        {
                            // Get the results.
                            this.resultSchemas = this.formDatabaseSelect.AllResults;
                            this.resultSchema = this.formDatabaseSelect.SelectedResult as DbObjectSchema;
                        }
                        if (this.resultSchema == null)
                        {
                            MessageBox.Show(this,
                                "A query for the schema of table \'{0}\' returned multiple database schemas. You must select a schema before continuing.".FormatWith(this.textBoxNameDatabase.Text),
                                "Multiple Table Schemas Found",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                        }
                    }
                    while (this.resultSchema == null);
                }
                catch (Exception exception)
                {
                    // If an error occurs, show an error message.
                    MessageBox.Show(this,
                        "Changing the table schema failed. {0}".FormatWith(exception.Message),
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                // Otherwise, select the returned schema.
                this.resultSchema = this.resultSchemas[0] as DbObjectSchema;
            }
            // Set the schema name.
            this.textBoxSchema.Text = this.resultSchema.Name;
            // Raise a configuration changed event.
            if (this.ConfigurationChanged != null) this.ConfigurationChanged(this, EventArgs.Empty);
            // Set the changes to true.
            this.changes = true;
        }
예제 #2
0
 /// <summary>
 /// Compares two database objects.
 /// </summary>
 /// <param name="obj">The object to compare.</param>
 /// <returns><b>True</b> if the two objects are equal, <b>false</b> otherwise.</returns>
 public bool Equals(DbObjectSchema obj)
 {
     return (this.Name == obj.Name);
 }
        // Public methods.
        /// <summary>
        /// Selects a table at the given database server for display.
        /// </summary>
        /// <param name="server">The database server.</param>
        /// <param name="table">The table.</param>
        public void Select(DbServerSql server, ITable table)
        {
            // Set the parameters.
            this.server = server;
            this.table = table;

            // Reset the results.
            this.resultTables = null;
            this.resultDatabases = null;
            this.resultSchemas = null;
            this.resultColumns = null;
            this.resultTable = null;
            this.resultDatabase = null;
            this.resultSchema = null;

            // Initialize the control.
            this.labelTitle.Text = table.LocalName;
            this.textBoxId.Text = table.Id.ToString();
            this.textBoxNameLocal.Text = table.LocalName;
            this.textBoxNameDatabase.Text = table.DatabaseName;
            this.textBoxSchema.Text = table.Schema;
            this.textBoxDatabase.Text = table.DefaultDatabase ? "(default)" : table.Database;
            this.checkBoxDefaultDatabase.Checked = table.DefaultDatabase;
            this.checkBoxReadOnly.Checked = table.IsReadOnly;
            this.pictureBox.Image = table.IsConfigured ? Resources.TableSuccess_32 : Resources.TableWarning_32;
            // The table fields.
            this.listViewFields.Items.Clear();
            foreach (DbField field in table.Fields)
            {
                // If the property type is nullable, replace it with the boxed type.
                ListViewItem item = new ListViewItem(new string[] {
                            field.Property.Name,
                            field.HasName ? field.GetDatabaseName() : string.Empty,
                            field.LocalType,
                            field.DatabaseType,
                            field.IsNullable ? "Yes" : "No"
                        });
                item.ImageKey = field.HasName ? "Field" : "FieldWarning";
                item.Tag = field;
                this.listViewFields.Items.Add(item);
            }
            // The table relationships.
            this.listViewRelationships.Items.Clear();
            foreach (IRelationship relationship in table.Relationships)
            {
                ListViewItem item = new ListViewItem(new string[] {
                    relationship.RightTable.LocalName,
                    relationship.LeftField,
                    relationship.RightField });
                item.ImageKey = "Relationship";
                item.Tag = relationship;
                this.listViewRelationships.Items.Add(item);
            }

            // Set the enabled state.
            this.buttonSelectTable.Enabled = !table.IsReadOnly;
            this.buttonSelectDatabase.Enabled = !table.IsReadOnly;
            this.buttonSelectField.Enabled = false;
            this.checkBoxDefaultDatabase.Enabled = !table.IsReadOnly && !table.DefaultDatabase;

            // Set the focus.
            this.tabControl.SelectedTab = this.tabPageGeneral;
            this.textBoxNameLocal.Select();
            this.textBoxNameLocal.SelectionStart = 0;
            this.textBoxNameLocal.SelectionLength = 0;
        }