Пример #1
0
        private void RenderResults(IList <DataSet> dataSets)
        {
            if (dataSets != null && dataSets.Count > 0)
            {
                int queryNo = 0;
                int batchNo = 0;

                foreach (DataSet ds in dataSets)
                {
                    batchNo++;
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables.Count; i++)
                        {
                            queryNo = i + 1;
                            int recordCnt = ds.Tables[i].Rows.Count;

                            if (i == 0)
                            {
                                _sqlMessages.Add(SqlMessage.CreateInfoMessage("Batch #" + batchNo.ToString() + " : " + ds.Tables.Count.ToString() + " resultset(s) were returned."));
                            }

                            _sqlMessages.Add(SqlMessage.CreateInfoMessage("Query " + queryNo.ToString() + ": Returned " + recordCnt.ToString() + " record(s)."));

                            // create tab page
                            tabOutput.TabPages.Add("Query " + queryNo.ToString() + " [" + recordCnt.ToString() + "]");

                            //crate individual grids
                            DataGridView grd = new DataGridView();
                            grd.DataSource            = ds.Tables[i];
                            grd.ReadOnly              = true;
                            grd.Parent                = tabOutput.TabPages[tabOutput.TabPages.Count - 1];
                            grd.Dock                  = DockStyle.Fill;
                            grd.CellPainting         += new DataGridViewCellPaintingEventHandler(OnCellPainting);
                            grd.AllowUserToAddRows    = false;
                            grd.BackgroundColor       = SystemColors.Window;
                            grd.AllowUserToResizeRows = false;
                            grd.BorderStyle           = BorderStyle.None;
                            grd.ShowEditingIcon       = false;

                            _grids.Add(grd);
                        }
                        _sqlMessages.Add(SqlMessage.CreateMessage(""));
                    }
                }
            }
            else
            {
                _grids.Clear();
            }
        }
Пример #2
0
        private IList <DataSet> ExecuteScript(BackgroundWorker bw, string queryText)
        {
            int totalLineCnt   = 0;
            int currentLineCnt = 0;

            _grids.Clear();

            IList <DataSet> dataSets = new List <DataSet>();

            if (workerThread.CancellationPending)
            {
                return(dataSets);
            }

            _conn.InfoMessage += new SqlInfoMessageEventHandler(HandleSqlInfo);
            try
            {
                IList <string> batches = ProgrammabilityHelper.SplitBatches(queryText);
                while (batches.Count > 0)
                {
                    try
                    {
                        DataSet toFill = new DataSet();
                        dataSets.Add(toFill);

                        string batch = batches[0];
                        currentLineCnt = LineCount(batch);
                        totalLineCnt  += currentLineCnt;

                        if (String.IsNullOrEmpty(batch))
                        {
                            batches.RemoveAt(0);
                            continue;
                        }

                        batches.RemoveAt(0);

                        _cmd = new SqlCommand(batch, _conn);
                        _cmd.CommandTimeout = 30;


                        SqlDataAdapter adapter = new SqlDataAdapter();
                        adapter.SelectCommand = _cmd;
                        int recordsAffected = adapter.Fill(toFill);

                        if (batches.Count == 0)
                        {
                            _sqlMessages.Add(SqlMessage.CreateInfoMessage("Command(s) completed sucesfully"));
                            _sqlMessages.Add(SqlMessage.CreateMessage(""));
                        }

                        if (toFill.Tables.Count == 0)
                        {
                            _sqlMessages.Add(SqlMessage.CreateInfoMessage("( " + recordsAffected.ToString() + " row(s) affected ) "));
                        }
                    }
                    catch (SqlException sqlEx)
                    {
                        int lineNo = totalLineCnt - currentLineCnt + sqlEx.LineNumber;
                        _sqlMessages.Add(SqlMessage.CreateErrorMessage(sqlEx.Message, lineNo, sqlEx.Number, sqlEx.State));
                    }
                    catch (Exception ex)
                    {
                        _sqlMessages.Add(SqlMessage.CreateErrorMessage("Exception of type \"" + ex.GetType().ToString() + "\": " + ex.Message, -1, -1, -1));
                    }
                }
            }
            finally
            {
                _conn.InfoMessage -= new SqlInfoMessageEventHandler(HandleSqlInfo);
            }

            return(dataSets);
        }