Beispiel #1
0
 public void ExecuteUseDatabase(string database, string connectionString)
 {
     SqlQueryDataAccess.ExecuteUseDatabase(database, connectionString);
     // TODO: add assertions to method SqlQueryDataAccessTest.ExecuteUseDatabase(String, String)
 }
        /// <summary>
        /// Gets the database view.
        /// </summary>
        /// <param name="autoSizeRows">if set to <c>true</c> [auto size rows].</param>
        private void GetDatabasePerformance(bool autoSizeRows = false)
        {
            if (this.formLoaded)
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    this.DataGridViewPerformance.Cursor = Cursors.WaitCursor;
                    this.panelNoData.SendToBack();
                    this.toolStripStatusExecuting.Visible         = true;
                    this.ToolStripButtonAutoSizeRows.Visible      = false;
                    this.DataGridViewPerformance.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
                    this.DataGridViewPerformance.DataSource       = null;
                    Application.DoEvents();

                    this.ConnectionString = this.GetConnectionString();
                    SqlQueryDataAccess.ExecuteUseDatabase(this.DatabaseName, this.ConnectionString);
                    string sqlStatement = string.Empty;

                    foreach (SqlQuery sql in this.SqlPerformanceQueries.QueryItems)
                    {
                        if (sql.SqlName == this.CurrentQuery)
                        {
                            this.DataGridViewPerformance.DataSource = SqlQueryDataAccess.GetPerformanceQueryResults(sql.SqlCode, this.ConnectionString);
                            break;
                        }
                    }

                    if (this.DataGridViewPerformance.Rows.Count > 0)
                    {
                        int maxColumnWidth = Properties.Settings.Default.MaxColumnWidth;

                        foreach (DataGridViewColumn column in this.DataGridViewPerformance.Columns)
                        {
                            if (column.Width > maxColumnWidth)
                            {
                                column.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                                column.Width        = maxColumnWidth;
                                if (autoSizeRows)
                                {
                                    column.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                                    this.DataGridViewPerformance.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
                                }

                                this.ToolStripButtonAutoSizeRows.Visible = true;
                            }

                            if (column.IsNumericColumn())
                            {
                                column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;

                                if (column.IsDecimalColumn())
                                {
                                    column.DefaultCellStyle.Format = "N2";
                                }
                                else
                                {
                                    column.DefaultCellStyle.Format = "N0";
                                }
                            }
                        }
                    }
                    else
                    {
                        this.ShowNoDataPanel();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.toolStripStatusRowCount.Text     = string.Format("{0} rows  ", this.DataGridViewPerformance.Rows.Count);
                this.toolStripStatusExecuting.Visible = false;
                this.DataGridViewPerformance.Cursor   = Cursors.Default;
                this.Cursor = Cursors.Default;
                this.DataGridViewPerformance.Focus();
            }
        }