/// <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(DbObjectColumn obj)
 {
     return (this.Name == obj.Name) && (this.ColumnId == obj.ColumnId) && (this.SystemTypeId == obj.SystemTypeId) && (this.UserTypeId == obj.UserTypeId);
 }
        /// <summary>
        /// An event handler called when the user selects a new field.
        /// </summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSelectField(object sender, EventArgs e)
        {
            // If there are pending changes, ask the user to save before continuing.
            if (this.changes)
            {
                if (DialogResult.Yes == MessageBox.Show(this,
                    "There are pending changes for this table and you cannot modify the table until all changes have been saved. Do you want to save the changes now?",
                    "Pending Table Changes",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question))
                {
                    // Save the changes.
                    this.SaveConfiguration();
                }
                else return;
            }
            // Check the table has a database name.
            if ((this.table.DatabaseName == null) || (this.table.DatabaseName == string.Empty))
            {
                MessageBox.Show(
                    this,
                    "Cannot change the field for the current table, because the table does not have a database name yet.",
                    "Cannot Change Table Field",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }
            // Check the table has a database (either the default database or a custom one.
            if ((!this.table.DefaultDatabase) && ((this.table.Database == null) || (this.table.Database == string.Empty)))
            {
                MessageBox.Show(
                    this,
                    "Cannot change the field for the current table, because the table does not have a database yet.",
                    "Cannot Change Table Field",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            try
            {
                // Create a new query to obtain the columns of the selected table.
                DbQuerySql queryColumn = DbQuerySql.CreateSelectAllOn(this.server.TableColumns, this.server.TableTables, "Name", this.table.DatabaseName, this.server.Database);
                queryColumn.MessageStart = "Updating the fields list for the table \'{0}\'.".FormatWith(this.table.DatabaseName);
                queryColumn.MessageFinishSuccess = "Updating the fields list for the table \'{0}\' completed successfully.".FormatWith(this.table.DatabaseName);
                queryColumn.MessageFinishFail = "Updating the fields list for the table \'{0}\' failed".FormatWith(this.table.DatabaseName);

                // Open a new database select window that selects all database columns for the given server and table.
                if (this.formDatabaseSelect.ShowDialog(this, this.server, queryColumn, this.resultColumns) == DialogResult.OK)
                {
                    // Get the result.
                    this.resultColumn = this.formDatabaseSelect.SelectedResult as DbObjectColumn;
                    this.resultColumns = this.formDatabaseSelect.AllResults;

                    // Create a new query to obtain the type of the selected column.
                    DbQuerySql queryType = DbQuerySql.CreateSelectAllOn(this.server.TableTypes, this.server.TableColumns, new string[] {"ObjectId", "ColumnId"}, new object[] {this.resultColumn.ObjectId, this.resultColumn.ColumnId}, this.server.Database, this.delegateQueryColumnType);
                    queryType.MessageStart = "Updating the type for the table field \'{0}\'.".FormatWith(this.resultColumn.Name);
                    queryType.MessageFinishSuccess = "Updating the type for the table field \'{0}\' completed successfully.".FormatWith(this.resultColumn.Name);
                    queryType.MessageFinishFail = "Updating the type for the table field \'{0}\' failed".FormatWith(this.resultColumn.Name);
                    // Get the column type.
                    this.DatabaseQuery(this.server, queryType);
                }
            }
            catch (Exception exception)
            {
                // If an error occurs, show an error message.
                MessageBox.Show(this,
                    "Changing the table field failed. {0}".FormatWith(exception.Message),
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }