/// <summary>
 /// An event handler called when the user selects a new table.
 /// </summary>
 /// <param name="sender">The sender object.</param>
 /// <param name="e">The event arguments.</param>
 private void OnSelectTable(object sender, EventArgs e)
 {
     try
     {
         // Open a new database select window that selects all database tables for the given server.
         if (this.formDatabaseSelect.ShowDialog(this, this.server, this.server.TableTables, this.resultTables) == DialogResult.OK)
         {
             // Get the results.
             this.resultTables = this.formDatabaseSelect.AllResults;
             this.resultTable = this.formDatabaseSelect.SelectedResult as DbObjectTable;
             this.resultColumns = null;
             // Set the name.
             this.textBoxNameDatabase.Text = this.resultTable.Name;
             // Raise a configuration changed event.
             if (this.ConfigurationChanged != null) this.ConfigurationChanged(this, EventArgs.Empty);
             // Set the changes to false.
             this.changes = true;
             // 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);
             // Get the table schema.
             this.DatabaseQuery(this.server, query);
         }
     }
     catch (Exception exception)
     {
         // If an error occurs, show an error message.
         MessageBox.Show(this,
             "Changing the table database name failed. {0}".FormatWith(exception.Message),
             "Error",
             MessageBoxButtons.OK,
             MessageBoxIcon.Error);
     }
 }
예제 #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(DbObjectTable 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;
        }