/// <summary>
 /// Shows the form as a dialog with the specified database table.
 /// </summary>
 /// <param name="owner">The owner window.</param>
 /// <param name="server">The database server.</param>
 /// <param name="table">The database relationship.</param>
 /// <returns>The dialog result.</returns>
 public DialogResult ShowDialog(IWin32Window owner, DbServerSql server, IRelationship relationship)
 {
     // If the table is null, do nothing.
     if (null == relationship) return DialogResult.Abort;
     // Set the control relationsip.
     this.control.Relationship = relationship;
     // Set the form title.
     this.Text = "{0} Relationship Properties".FormatWith(this.control.Title);
     // Disable the apply button.
     this.buttonApply.Enabled = false;
     // Open the dialog.
     return base.ShowDialog(owner);
 }
        /// <summary>
        /// Shows the form as a dialog with the specified database table.
        /// </summary>
        /// <param name="owner">The owner window.</param>
        /// <param name="server">The database server.</param>
        /// <param name="table">The database table.</param>
        /// <returns>The dialog result.</returns>
        public DialogResult ShowDialog(IWin32Window owner, DbServerSql server, ITable table)
        {
            // If the table is null, do nothing.
            if (null == table) return DialogResult.Abort;

            // Select the server an table.
            this.control.Select(server, table);
            // Set the title.
            this.Text = "{0} Table Properties".FormatWith(table.LocalName);
            // Disable the apply button.
            this.buttonApply.Enabled = false;
            // Open the dialog.
            return base.ShowDialog(owner);
        }
        /// <summary>
        /// Shows the form as a dialog and the specified database server.
        /// </summary>
        /// <param name="owner">The owner window.</param>
        /// <param name="server">The database server.</param>
        /// <param name="isPrimary">Indicates if the database server is primary.</param>
        /// <returns>The dialog result.</returns>
        public DialogResult ShowDialog(IWin32Window owner, DbServerSql server, bool isPrimary)
        {
            // If the server is null, do nothing.
            if (null == server) return DialogResult.Abort;

            // Set the server.
            this.control.Server = server;
            this.control.IsPrimary = isPrimary;
            // Set the title.
            this.Text = "{0} Server Properties".FormatWith(server.Name);
            // Disable the apply button.
            this.buttonApply.Enabled = false;
            // Set an event handler for the server state.
            server.StateChanged += this.OnServerStateChanged;
            // Open the dialog.
            return base.ShowDialog(owner);
        }
Exemplo n.º 4
0
 /// <summary>
 /// An event handler called when the state of the connection has changed.
 /// </summary>
 /// <param name="state">The new server state.</param>
 /// <param name="e">The event arguments.</param>
 protected void OnStateChange(DbServerSql.ServerState state)
 {
     // Save the old state.
     DbServerSql.ServerState oldState = this.state;
     // Set the new state.
     this.state = state;
     // Call the event.
     if (this.StateChanged != null) this.StateChanged(this, new DbServerStateEventArgs(this, oldState, this.state));
 }
 // Public methods.
 /// <summary>
 /// Opens the modal dialog to select database objects from the specified database server and table.
 /// </summary>
 /// <typeparam name="T">The database object type.</typeparam>
 /// <param name="owner">The window owner.</param>
 /// <param name="server">The database server.</param>
 /// <param name="table">The database table.</param>
 /// <param name="result">The result to display when the dialog opens.</param>
 /// <returns>The dialog result.</returns>
 public DialogResult ShowDialog(IWin32Window owner, DbServerSql server, ITable table, DbDataObject result)
 {
     // Reset the result.
     this.SelectedResult = null;
     this.AllResults = result;
     // Initialize the control.
     this.control.Select(server, table, result);
     // Show the dialog.
     return base.ShowDialog(owner);
 }
Exemplo n.º 6
0
 /// <summary>
 /// An event handler called when the refresh operation failed.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="exception">The exception.</param>
 private void DatabaseQueryFail(DbServerSql server, DbQuerySql query, Exception exception)
 {
     // Execute the code on the UI thread.
     this.Invoke(() =>
     {
         this.OnQueryFailed(server, query, exception);
     });
 }
Exemplo n.º 7
0
 // Protected methods.
 /// <summary>
 /// A method called when the execution of the database query starts.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="command">The database command.</param>
 protected virtual void OnQueryStarted(DbServerSql server, DbQuerySql query, DbCommand command)
 {
 }
        // Private methods.
        /// <summary>
        /// Adds a new server to the servers control.
        /// </summary>
        /// <param name="server">The server.</param>
        private void AddServer(DbServerSql server)
        {
            // Create a new server item.
            ListViewItem item = new ListViewItem(new string[] {
                    server.Name,
                    this.crawler.Database.Sql.IsPrimary(server) ? "Primary" : "Backup",
                    server.State.ToString(),
                    server.Version,
                    server.Id.ToString()
                });
            item.ImageKey = ControlServersSql.imageKeys[(int)server.State];
            item.Tag = server.Id;
            this.listView.Items.Add(item);
            // Create a new tree node for the server.
            TreeNode nodeServer = new TreeNode(this.GetServerTreeName(server));
            nodeServer.ImageKey = ControlServersSql.imageKeys[(int)server.State];
            nodeServer.SelectedImageKey = ControlServersSql.imageKeys[(int)server.State];
            this.treeNode.Nodes.Add(nodeServer);
            // Create a new tree node for the server query.
            TreeNode nodeQuery = new TreeNode("Query");
            nodeQuery.ImageKey = "QueryDatabase";
            nodeQuery.SelectedImageKey = "QueryDatabase";
            // Create a new tree node for the server log.
            TreeNode nodeLog = new TreeNode("Server log");
            nodeLog.ImageKey = "Log";
            nodeLog.SelectedImageKey = "Log";
            // Add the children nodes to the server node.
            nodeServer.Nodes.AddRange(new TreeNode[] {
                    nodeQuery,
                    nodeLog
                });
            this.treeNode.ExpandAll();

            // Create a new controls item.
            ServerControls controls = new ServerControls(item, nodeServer);

            // Initialize the server controls.
            controls.ControlServer.Initialize(this.crawler, server, nodeServer);
            controls.ControlLog.Initialize(this.crawler.Config, server.Log);
            controls.ControlQuery.Initialize(this.crawler, server);

            // Add the controls to the panel.
            this.controls.Add(controls.ControlServer);
            this.controls.Add(controls.ControlQuery);
            this.controls.Add(controls.ControlLog);

            // Set the tree nodes tag.
            nodeServer.Tag = controls.ControlServer;
            nodeQuery.Tag = controls.ControlQuery;
            nodeLog.Tag = controls.ControlLog;

            // Add the servers controls to the dictionary.
            this.items.Add(server.Id, controls);
        }
 /// <summary>
 /// A method called when the executiopn of the database query has failed.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="exception">The exception.</param>
 protected override void OnQueryFailed(DbServerSql server, DbQuerySql query, Exception exception)
 {
     // Enable the refresh button.
     this.buttonDatabaseRefresh.Enabled = true;
 }
        /// <summary>
        /// A method called when the executiopn of the database query has failed.
        /// </summary>
        /// <param name="server">The database server.</param>
        /// <param name="query">The database query.</param>
        /// <param name="exception">The exception.</param>
        protected override void OnQueryFailed(DbServerSql server, DbQuerySql query, Exception exception)
        {
            // Enable the buttons.
            this.buttonRefresh.Enabled = true;
            this.buttonCancel.Enabled = false;
            this.buttonClose.Enabled = true;

            // Set the current command to null.
            this.command = null;

            // Update the status box.
            this.labelStatus.Text = "Query failed. {0}".FormatWith(exception.Message);

            // Raise the database operation finished event.
            if (this.DatabaseOperationFinished != null) this.DatabaseOperationFinished(this, EventArgs.Empty);
        }
        /// <summary>
        /// Selects records from the specified database server given a custom query.
        /// </summary>
        /// <param name="server">The database server.</param>
        /// <param name="query">The database table.</param>
        /// <param name="result">The database results, if any.</param>
        public void Select(DbServerSql server, DbQuerySql query, DbDataObject result)
        {
            // Check the database table is configured.
            if (!query.Table.IsConfigured) throw new DbException("Cannot select the list of database objects for table \'{0}\', because the table is not configured.".FormatWith(query.Table.LocalName));
            // Check the results, if different from null, are for the current table and if not, ignore them.
            if (result != null)
            {
                if (result.Table != query.Table) result = null;
            }

            // Set the current server.
            this.server = server;
            // Set the current query.
            this.query = query;
            // Set the current results.
            this.result = result;

            // Clear the data grid.
            this.dataGrid.Rows.Clear();
            this.dataGrid.Columns.Clear();
            // Initialize the data grid columns.
            foreach (DbField field in this.query.Table.Fields)
            {
                this.dataGrid.Columns.Add(field.Property.Name, field.DisplayName);
            }
            // If a current result exists, intialize the data grid rows.
            if (this.result != null)
            {
                for (int row = 0; row < this.result.RowCount; row++)
                {
                    // Add the new row, and get the row index.
                    int index = this.dataGrid.Rows.Add(this.query.Table.GetValues(this.result[row]));
                    // Set the row tag with the table object.
                    this.dataGrid.Rows[index].Tag = result[row];
                }
            }

            // Intialize the buttons.
            this.buttonRefresh.Enabled = true;
            this.buttonCancel.Enabled = false;
            this.buttonSelect.Enabled = false;
            this.buttonClose.Enabled = true;
        }
        // Public methods.
        /// <summary>
        /// Selects all records for the specified databse server and table.
        /// </summary>
        /// <param name="server">The database server.</param>
        /// <param name="table">The database table.</param>
        /// <param name="result">The database results, if any.</param>
        public void Select(DbServerSql server, ITable table, DbDataObject result)
        {
            // Create a select all query for all field in the current table.
            DbQuerySql query = DbQuerySql.CreateSelectAll(table, server.Database);

            query.MessageStart = "Refreshing the data for table \'{0}\' on the database server \'{1}\'...".FormatWith(table.LocalName, server.Name);
            query.MessageFinishSuccess = "Refreshing the data for table \'{0}\' on the database server \'{1}\' completed successfully.".FormatWith(table.LocalName, server.Name);
            query.MessageFinishFail = "Refreshing the data for table \'{0}\' on the database server \'{1}\' failed.".FormatWith(table.LocalName, server.Name);

            // Use the generic select methods.
            this.Select(server, query, result);
        }
        /// <summary>
        /// Initializes the control.
        /// </summary>
        /// <param name="crawler">The crawler instance.</param>
        /// <param name="server">The database server.</param>
        public void Initialize(Crawler crawler, DbServerSql server)
        {
            // Set the crawler.
            this.crawler = crawler;
            // Set the server.
            this.server = server;

            // Add the event handlers for the database server.
            this.server.StateChanged += this.OnServerStateChanged;

            // Initialize the contols.
            this.OnServerStateChanged(this.server, null);
        }
 /// <summary>
 /// Creates a new event arguments instance.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="relationship">The database relationship.</param>
 public DbServerRelationshipEventArgs(DbServerSql server, IRelationship relationship)
     : base(server)
 {
     this.Relationship = relationship;
 }
 /// <summary>
 /// Creates a new event arguments instance.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="table">The database table.</param>
 public DbServerTableEventArgs(DbServerSql server, ITable table)
     : base(server)
 {
     this.Table = table;
 }
 /// <summary>
 /// A method called when the execution of the database query starts.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="command">The database command.</param>
 protected override void OnQueryStarted(DbServerSql server, DbQuerySql query, DbCommand command)
 {
     // Save the current command.
     this.command = command;
     // Enable the cancel button.
     this.buttonRefresh.Enabled = false;
     this.buttonClose.Enabled = false;
     this.buttonCancel.Enabled = true;
     // Raise the database operation started event.
     if (this.DatabaseOperationStarted != null) this.DatabaseOperationStarted(this, EventArgs.Empty);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        /// <param name="crawler">The crawler instance.</param>
        /// <param name="server">The database server.</param>
        /// <param name="treeNode">The tree node corresponding to this server.</param>
        public void Initialize(Crawler crawler, DbServerSql server, TreeNode treeNode)
        {
            // Set the crawler.
            this.crawler = crawler;
            // Set the server.
            this.server = server;
            // Set the tree node and the tree node tag.
            this.treeNode = treeNode;

            // Set the title.
            this.panelServer.Title = "Database Server ({0})".FormatWith(server.Name);

            // Add the event handlers for the database server.
            this.server.ServerChanged += this.OnServerChanged;
            this.server.StateChanged += this.OnServerStateChanged;
            this.server.DatabaseChanged += this.OnDatabaseChanged;
            this.server.TableAdded += this.OnTableAdded;
            this.server.TableRemoved += this.OnTableRemoved;
            this.server.TableChanged += this.OnTableChanged;
            this.server.RelationshipAdded += this.OnRelationshipAdded;
            this.server.RelationshipRemoved += this.OnRelationshipRemoved;
            this.server.EventLogged += this.OnEventLogged;
            this.crawler.Database.Sql.PrimaryServerChanged += this.OnPrimaryServerChanged;

            // Initialize the contols.
            this.OnServerChanged(this, new DbServerEventArgs(this.server));
            this.OnServerStateChanged(this.server, null);

            // Initialize the server database.
            this.OnDatabaseChanged(this, new DbServerDatabaseChangedEventArgs(this.server, null, this.server.Database));

            // Initialize the server database tables.
            this.OnTablesChanged();

            // Initialize the server database relationships.
            this.OnRelationshipsChanged();
        }
 /// <summary>
 /// An event handler called when the refresh operation completed successfully and the resulting data is object
 /// data.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="result">The database result.</param>
 /// <param name="recordsAffected">The number of records affected.</param>
 protected override void OnQuerySucceeded(DbServerSql server, DbQuerySql query, DbDataObject result, int recordsAffected)
 {
     // Set the current result.
     this.result = result;
     try
     {
         // Add the table rows.
         for (int row = 0; row < this.result.RowCount; row++)
         {
             // Add the new row, and get the row index.
             int index = this.dataGrid.Rows.Add(this.query.Table.GetValues(this.result[row]));
             // Set the row tag with the table object.
             this.dataGrid.Rows[index].Tag = result[row];
         }
     }
     catch (Exception exception)
     {
         // If an exception occurs, call the refresh fail method.
         this.OnQueryFailed(server, query, exception);
         return;
     }
     // Set the current command to null.
     this.command = null;
     // Enable the buttons.
     this.buttonRefresh.Enabled = true;
     this.buttonCancel.Enabled = false;
     this.buttonClose.Enabled = true;
     // Update the status box.
     this.labelStatus.Text = "{0} object{1} fetched.".FormatWith(result.RowCount, result.RowCount.PluralSuffix());
     // Raise the database operation finished event.
     if (this.DatabaseOperationFinished != null) this.DatabaseOperationFinished(this, EventArgs.Empty);
 }
Exemplo n.º 19
0
 /// <summary>
 /// A method called when the execution of the database query succeeded and the data is object.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="result">The result data.</param>
 /// <param name="recordsAffected">The number of records affected.</param>
 protected override void OnQuerySucceeded(DbServerSql server, DbQuerySql query, DbDataObject result, int recordsAffected)
 {
     // Add the databases to the list.
     for (int row = 0; row < result.RowCount; row++)
     {
         // Get the database object.
         DbObjectDatabase database = result[row] as DbObjectDatabase;
         // Add a new list view item.
         ListViewItem item = new ListViewItem(new string[] {
             database.Name,
             database.DatabaseId.ToString(),
             database.CreateDate.ToString()
         });
         item.Tag = database;
         item.ImageIndex = database.Equals(this.server.Database) ? 1 : 0;
         this.listViewDatabases.Items.Add(item);
     }
     // Enable the refresh button.
     this.buttonDatabaseRefresh.Enabled = true;
 }
        // 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;
        }
Exemplo n.º 21
0
 /// <summary>
 /// A method called when the executiopn of the database query has failed.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="exception">The exception.</param>
 protected virtual void OnQueryFailed(DbServerSql server, DbQuerySql query, Exception exception)
 {
 }
 /// <summary>
 /// A method called when a query failed.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="exception">The exception.</param>
 protected override void OnQueryFailed(DbServerSql server, DbQuerySql query, Exception exception)
 {
     // Enable the control.
     this.tabControl.Enabled = true;
     // Raise the database operation finished event.
     if (this.DatabaseOperationFinished != null) this.DatabaseOperationFinished(this, EventArgs.Empty);
 }
Exemplo n.º 23
0
 /// <summary>
 /// A method called when the execution of the database query succeeded and the data is object.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="result">The result data.</param>
 /// <param name="recordsAffected">The number of records affected.</param>
 protected virtual void OnQuerySucceeded(DbServerSql server, DbQuerySql query, DbDataObject result, int recordsAffected)
 {
 }
 /// <summary>
 /// A method called when staring a query.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="command">The database command.</param>
 protected override void OnQueryStarted(DbServerSql server, DbQuerySql query, DbCommand command)
 {
     // Disable the control.
     this.tabControl.Enabled = false;
     // Raise the database operation started event.
     if (this.DatabaseOperationStarted != null) this.DatabaseOperationStarted(this, EventArgs.Empty);
 }
Exemplo n.º 25
0
 /// <summary>
 /// An event handler called when the database query completed successfully and the resulting data is object
 /// data.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="result">The database result.</param>
 /// <param name="recordsAffected">The number of records affected.</param>
 private void DatabaseQuerySuccess(DbServerSql server, DbQuerySql query, DbDataObject result, int recordsAffected)
 {
     // Execute the code on the UI thread.
     this.Invoke(() =>
     {
         this.OnQuerySucceeded(server, query, result, recordsAffected);
     });
 }
 /// <summary>
 /// A method called when a query completed successfully.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="query">The database query.</param>
 /// <param name="result">The database result.</param>
 /// <param name="recordsAffected">The number of records affected.</param>
 protected override void OnQuerySucceeded(DbServerSql server, DbQuerySql query, DbDataObject result, int recordsAffected)
 {
     // Enable the control.
     this.tabControl.Enabled = true;
     // Raise the database operation finished event.
     if (this.DatabaseOperationFinished != null) this.DatabaseOperationFinished(this, EventArgs.Empty);
     // If the query state is not null.
     if (query.State != null)
     {
         // If the query state is a delegate.
         if (query.State is QuerySuccessAction)
         {
             // Get the call the delegate.
             QuerySuccessAction handler = query.State as QuerySuccessAction;
             handler(result, recordsAffected);
         }
     }
 }
 /// <summary>
 /// Creates a new event arguments instance.
 /// </summary>
 /// <param name="oldDatabase">The old database.</param>
 /// <param name="newDatabase">The new database.</param>
 public DbServerDatabaseChangedEventArgs(DbServerSql server, DbObjectDatabase oldDatabase, DbObjectDatabase newDatabase)
     : base(server)
 {
     this.OldDatabase = oldDatabase;
     this.NewDatabase = newDatabase;
 }
 /// <summary>
 /// Creates a new instance of the asynchronous state.
 /// </summary>
 /// <param name="server">The database server.</param>
 /// <param name="state">The user state.</param>
 public DbServerAsyncState(DbServerSql server, object state)
     : base(state)
 {
     // Save the database server.
     this.server = server;
 }