Exemple #1
0
        private void _toolbar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
        {
            // change connection string
            if (e.Button == this._tbConnString)
            {
                string conn = _qb.ConnectionString;
                _qb.ConnectionString = PromptConnectionString(conn, Handle);
                ResetUI();
                return;
            }

            // show properties
            if (e.Button == this._tbProperties)
            {
                using (QueryPropertiesForm f = new QueryPropertiesForm())
                {
                    f.QueryBuilder = _qb;
                    f.ShowDialog();
                    _txtSql.Text = _qb.Sql;
                }
                return;
            }

            // toggle GroupBy switch
            if (e.Button == this._tbGroupBy)
            {
                _qb.GroupBy  = this._tbGroupBy.Pushed;
                _txtSql.Text = _qb.Sql;

                // show/hide GroupBy column
                _flex.Cols["GroupBy"].Visible = this._tbGroupBy.Pushed;
                return;
            }

            // clear query
            if (e.Button == this._tbClearQuery)
            {
                // confirm with user
                if (!ShowMessage("Are you sure you want to clear this query?", MessageBoxIcon.Question))
                {
                    return;
                }

                // clear it
                _qb.QueryFields.Clear();
                return;
            }

            // preview results/check syntax
            if (e.Button == this._tbViewResults || e.Button == this._tbCheckSql)
            {
                // sanity...
                if (_qb.QueryFields.Count == 0)
                {
                    return;
                }

                // prepare to get data/check sql
                string    conn = _qb.ConnectionString;
                string    sql  = _qb.Sql;
                DataTable dt   = new DataTable();

                try
                {
                    // build data adapter
                    OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);

                    // check sql by retrieving schema
                    if (e.Button == this._tbCheckSql)
                    {
                        da.FillSchema(dt, SchemaType.Mapped);
                        ShowMessage("The SQL syntax has been verified against the data source.",
                                    MessageBoxIcon.Information);
                        return;
                    }

                    // get data into table
                    da.Fill(dt);
                }
                catch (Exception x)
                {
                    ShowMessage("Failed to retrieve the data:\r\n" + x.Message,
                                MessageBoxIcon.Warning);
                    return;
                }

                // show data preview form
                PreviewForm f = new PreviewForm();
                f._flex.DataSource = dt;
                f.ShowDialog();
            }
        }
Exemple #2
0
        private void _toolbar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
        {
            // change connection string
            if (e.Button == this._tbConnString)
            {
                string conn = _qb.ConnectionString;
                _qb.ConnectionString = PromptConnectionString(conn, Handle);
                ResetUI();
                return;
            }

            // show properties
            if (e.Button == this._tbProperties)
            {
                using (QueryPropertiesForm f = new QueryPropertiesForm())
                {
                    f.QueryBuilder = _qb;
                    f.ShowDialog();
                    _txtSql.Text = _qb.Sql;
                }
                return;
            }

            // toggle GroupBy switch
            if (e.Button == this._tbGroupBy)
            {
                _qb.GroupBy  = this._tbGroupBy.Pushed;
                _txtSql.Text = _qb.Sql;

                // show/hide GroupBy column
                _flex.Cols["GroupBy"].Visible = this._tbGroupBy.Pushed;
                return;
            }

            // clear query
            if (e.Button == this._tbClearQuery)
            {
                // confirm with user
                DialogResult dr = FlexReportDesignerApp.MessageForm.Ask(FlexReportDesignerApp.Strings.SqlBuilderDialog.ClearQueryQ, MessageBoxButtons.YesNo);
                if (dr != System.Windows.Forms.DialogResult.Yes)
                {
                    return;
                }

                // clear it
                _qb.QueryFields.Clear();
                return;
            }

            // preview results/check syntax
            if (e.Button == this._tbViewResults || e.Button == this._tbCheckSql)
            {
                // sanity...
                if (_qb.QueryFields.Count == 0)
                {
                    return;
                }

                // prepare to get data/check sql
                string    conn = _qb.ConnectionString;
                string    sql  = _qb.Sql;
                DataTable dt   = new DataTable();

                try
                {
                    // build data adapter
                    OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);

                    // check sql by retrieving schema
                    if (e.Button == this._tbCheckSql)
                    {
                        da.FillSchema(dt, SchemaType.Mapped);
                        // ShowMessage(ReportDesignerApp.Strings.SqlBuilderDialog.SqlVerified, MessageBoxIcon.Information);
                        FlexReportDesignerApp.MessageForm.Info(FlexReportDesignerApp.Strings.SqlBuilderDialog.SqlVerified);
                        return;
                    }

                    // get data into table
                    da.Fill(dt);
                }
                catch (Exception x)
                {
                    // ShowMessage(string.Format(ReportDesignerApp.Strings.SqlBuilderDialog.ErrCannotGetDataFmt, x.Message), MessageBoxIcon.Warning);
                    FlexReportDesignerApp.MessageForm.Warn(string.Format(FlexReportDesignerApp.Strings.SqlBuilderDialog.ErrCannotGetDataFmt, x.Message));
                    return;
                }

                // show data preview form
                PreviewForm f = new PreviewForm();
                f._flex.DataSource = dt;
                f.ShowDialog();
            }
        }