Ejemplo n.º 1
0
        protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
        {
            NumberedDataGrid oGrid = this.DataGridTableStyle.DataGrid as NumberedDataGrid;

            if (oGrid != null)
            {
                oGrid.SetRowPaintIndex(rowNum);
            }
            base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
        }
Ejemplo n.º 2
0
        protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
        {
            DataGrid         oGrid    = this.DataGridTableStyle.DataGrid;
            NumberedDataGrid oNumGrid = oGrid as NumberedDataGrid;
            int  iCol       = -1;
            bool fHilighted = false;

            if (oNumGrid != null)
            {
                oNumGrid.SetRowPaintIndex(rowNum);
                DataTable oTable = oNumGrid.GetDataTableFromDataSource();
                if (oTable != null)
                {
                    DataColumn oCol = oTable.Columns[this.MappingName];
                    if (oCol != null)
                    {
                        iCol = oCol.Ordinal;
                    }
                }
                if (oNumGrid.AreColumnsSelected())
                {
                    fHilighted = oNumGrid.IsColumnSelected(iCol);
                }
                else
                {
                    fHilighted = oGrid.IsSelected(rowNum) ||
                                 (source.Position == rowNum && oGrid.CurrentCell.ColumnNumber == iCol);
                }
            }
            else
            {
                fHilighted = oGrid.IsSelected(rowNum) ||
                             (source.Position == rowNum && oGrid.CurrentCell.ColumnNumber == iCol);
            }

            if (fHilighted)
            {
                foreBrush = SystemBrushes.HighlightText;
                backBrush = SystemBrushes.Highlight;
            }
            else
            {
                foreBrush = SystemBrushes.WindowText;
                backBrush = SystemBrushes.Window;
            }
            base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
        }
Ejemplo n.º 3
0
        public void DoExecute()
        {
            if (stbMain.Text.Length == 0)
                return;

            if (!panelBottom.Visible)
            {
                stbMain.Dock = DockStyle.Top;
                sptMain.Visible = true;
                panelBottom.Visible = true;
            }

            rtxtResults.Clear();
            rtxtResults.BringToFront();

            for (int iControl = panelGrids.Controls.Count; --iControl >= 0; )
                panelGrids.Controls.RemoveAt(iControl);

            m_oDataSet = null;
            m_fExecuteError = false;
            m_sLastError = "";
            sbpStatus.Text = "Executing query batch...";
            sbpTime.Text = GetTimeText(0);
            sbpRows.Text = "0 rows";

            try
            {
                if (m_oConn.State != ConnectionState.Open)
                {
                    m_oConn.Open();
                    m_oConn.ChangeDatabase(sbpDatabase.Text);
                }

                m_fCancelExecute = false;

                long cTickStart = DateTime.Now.Ticks;

                System.Threading.Thread oThread = new System.Threading.Thread(new System.Threading.ThreadStart(ExecuteQuery));
                oThread.Start();

                int cRows = 0;

                string sLastTime = "";
                while (oThread.IsAlive)
                {
                    string sTime = GetTimeText(DateTime.Now.Ticks - cTickStart);
                    if (sTime != sLastTime)
                    {
                        Globals.MainForm.UpdateExecuteState(this);
                        sbpTime.Text = sTime;

                        cRows = 0;
                        if (m_oDataSet != null)
                        {
                            foreach (DataTable oTable in m_oDataSet.Tables)
                                cRows += oTable.Rows.Count;
                            if (cRows == 1)
                                sbpRows.Text = "1 row";
                            else
                                sbpRows.Text = cRows.ToString("#,##0") + " rows";
                        }

                        sLastTime = sTime;
                    }

                    if (m_fCancelExecute)
                    {
                        try
                        {
                            oThread.Abort();
                        }
                        catch (Exception oEx)
                        {
                            string s = oEx.ToString();
                            s = "";
                        }
                        m_fIsExecuting = false;
                        Globals.MainForm.UpdateExecuteState(this);
                    }
                    else
                    {
                        Application.DoEvents();
                        System.Threading.Thread.Sleep(200);
                    }
                }

                int cTables = m_oDataSet.Tables.Count;
                int dypGrid = (cTables == 0) ? 0 : panelGrids.Height / cTables;
                if (dypGrid < kdypMinResults)
                    dypGrid = kdypMinResults;
                panelGrids.AutoScrollMinSize = new Size(0, dypGrid * cTables);

                //for (int iTable = cTables; --iTable >= 0; )
                for (int iTable = 0; iTable < cTables; iTable++)
                {
                    DataTable oTable = m_oDataSet.Tables[iTable];

                    NumberedDataGrid oGrid = new NumberedDataGrid();
                    oGrid.AllowSorting = false;
                    oGrid.Size = new System.Drawing.Size(panelGrids.Width, dypGrid);
                    oGrid.BackgroundColor = System.Drawing.SystemColors.Window;
                    oGrid.CaptionVisible = false;
                    oGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
                    oGrid.ReadOnly = true;
                    oGrid.RowHeadersVisible = false;
                    //oGrid.Resize += new EventHandler(Grid_Resize);
                    panelGrids.Resize += new EventHandler(Grid_Resize);

                    panelGrids.Controls.Add(oGrid);
                    oGrid.Location = new Point(0, iTable * (dypGrid + kdypSpacing));

                    oTable.DefaultView.AllowNew = false;
                    oTable.DefaultView.AllowEdit = false;
                    oTable.DefaultView.AllowDelete = false;

                    DataGridTableStyle oTableStyle = new DataGridTableStyle();
                    oTableStyle.RowHeadersVisible = true;
                    oTableStyle.ReadOnly = true;
                    oTableStyle.MappingName = oTable.TableName;
                    oTableStyle.AllowSorting = false;

                    foreach (DataColumn oColumn in oTable.Columns)
                    {
                        DataGridColumnStyle oColStyle = GetColStyle(oColumn);
                        oTableStyle.GridColumnStyles.Add(oColStyle);
                    }

                    oGrid.TableStyles.Add(oTableStyle);
                    oGrid.DataSource = oTable;
                }

                if (cTables == 0)
                {
                    if (m_sbMessages.Length == 0)
                    {
                        SqlCommand oCommand = m_oConn.CreateCommand();
                        oCommand.CommandText = "select @@rowcount";
                        int cRecords = (int)oCommand.ExecuteScalar();
                        if (cRecords == 1)
                            m_sbMessages.AppendLine("(1 row affected)");
                        else
                            m_sbMessages.AppendLine("(" + cRecords.ToString("#,##0") + " rows affected)");
                    }
                    rtxtResults.Text = m_sbMessages.ToString();
                    rtxtResults.BringToFront();
                }
                else
                {
                    panelGrids.BringToFront();
                }

                sbpTime.Text = GetTimeText(DateTime.Now.Ticks - cTickStart);

                cRows = 0;
                foreach (DataTable oTable in m_oDataSet.Tables)
                    cRows += oTable.Rows.Count;
                if (cRows == 1)
                    sbpRows.Text = "1 row";
                else
                    sbpRows.Text = cRows.ToString("#,##0") + " rows";

                // Since the database might have changed, update it.
                if (m_oConn.State == ConnectionState.Open)
                    sbpDatabase.Text = m_oConn.Database;

                if (m_fCancelExecute)
                    sbpStatus.Text = "Query batch was cancelled";
                else
                    sbpStatus.Text = "Query batch completed";
            }
            catch (Exception oEx)
            {
                m_sLastError = oEx.Message;
            }

            if (m_fExecuteError && !m_fCancelExecute)
            {
                sbpStatus.Text = "Query batch completed with errors";
                rtxtResults.Clear();
                rtxtResults.SelectionColor = System.Drawing.Color.Red;
                rtxtResults.SelectedText = m_sLastError;
                rtxtResults.BringToFront();
            }

            m_fIsExecuting = false;
        }
Ejemplo n.º 4
0
        public void DoExecute()
        {
            if (stbMain.Text.Length == 0)
            {
                return;
            }

            if (!panelBottom.Visible)
            {
                stbMain.Dock        = DockStyle.Top;
                sptMain.Visible     = true;
                panelBottom.Visible = true;
            }

            rtxtResults.Clear();
            rtxtResults.BringToFront();

            for (int iControl = panelGrids.Controls.Count; --iControl >= 0;)
            {
                panelGrids.Controls.RemoveAt(iControl);
            }

            m_oDataSet      = null;
            m_fExecuteError = false;
            m_sLastError    = "";
            sbpStatus.Text  = "Executing query batch...";
            sbpTime.Text    = GetTimeText(0);
            sbpRows.Text    = "0 rows";

            try
            {
                if (m_oConn.State != ConnectionState.Open)
                {
                    m_oConn.Open();
                    m_oConn.ChangeDatabase(sbpDatabase.Text);
                }

                m_fCancelExecute = false;

                long cTickStart = DateTime.Now.Ticks;

                System.Threading.Thread oThread = new System.Threading.Thread(new System.Threading.ThreadStart(ExecuteQuery));
                oThread.Start();

                int cRows = 0;

                string sLastTime = "";
                while (oThread.IsAlive)
                {
                    string sTime = GetTimeText(DateTime.Now.Ticks - cTickStart);
                    if (sTime != sLastTime)
                    {
                        Globals.MainForm.UpdateExecuteState(this);
                        sbpTime.Text = sTime;

                        cRows = 0;
                        if (m_oDataSet != null)
                        {
                            foreach (DataTable oTable in m_oDataSet.Tables)
                            {
                                cRows += oTable.Rows.Count;
                            }
                            if (cRows == 1)
                            {
                                sbpRows.Text = "1 row";
                            }
                            else
                            {
                                sbpRows.Text = cRows.ToString("#,##0") + " rows";
                            }
                        }

                        sLastTime = sTime;
                    }

                    if (m_fCancelExecute)
                    {
                        try
                        {
                            oThread.Abort();
                        }
                        catch (Exception oEx)
                        {
                            string s = oEx.ToString();
                            s = "";
                        }
                        m_fIsExecuting = false;
                        Globals.MainForm.UpdateExecuteState(this);
                    }
                    else
                    {
                        Application.DoEvents();
                        System.Threading.Thread.Sleep(200);
                    }
                }

                int cTables = m_oDataSet.Tables.Count;
                int dypGrid = (cTables == 0) ? 0 : panelGrids.Height / cTables;
                if (dypGrid < kdypMinResults)
                {
                    dypGrid = kdypMinResults;
                }
                panelGrids.AutoScrollMinSize = new Size(0, dypGrid * cTables);

                //for (int iTable = cTables; --iTable >= 0; )
                for (int iTable = 0; iTable < cTables; iTable++)
                {
                    DataTable oTable = m_oDataSet.Tables[iTable];

                    NumberedDataGrid oGrid = new NumberedDataGrid();
                    oGrid.AllowSorting      = false;
                    oGrid.Size              = new System.Drawing.Size(panelGrids.Width, dypGrid);
                    oGrid.BackgroundColor   = System.Drawing.SystemColors.Window;
                    oGrid.CaptionVisible    = false;
                    oGrid.HeaderForeColor   = System.Drawing.SystemColors.ControlText;
                    oGrid.ReadOnly          = true;
                    oGrid.RowHeadersVisible = false;
                    //oGrid.Resize += new EventHandler(Grid_Resize);
                    panelGrids.Resize += new EventHandler(Grid_Resize);

                    panelGrids.Controls.Add(oGrid);
                    oGrid.Location = new Point(0, iTable * (dypGrid + kdypSpacing));

                    oTable.DefaultView.AllowNew    = false;
                    oTable.DefaultView.AllowEdit   = false;
                    oTable.DefaultView.AllowDelete = false;

                    DataGridTableStyle oTableStyle = new DataGridTableStyle();
                    oTableStyle.RowHeadersVisible = true;
                    oTableStyle.ReadOnly          = true;
                    oTableStyle.MappingName       = oTable.TableName;
                    oTableStyle.AllowSorting      = false;

                    foreach (DataColumn oColumn in oTable.Columns)
                    {
                        DataGridColumnStyle oColStyle = GetColStyle(oColumn);
                        oTableStyle.GridColumnStyles.Add(oColStyle);
                    }

                    oGrid.TableStyles.Add(oTableStyle);
                    oGrid.DataSource = oTable;
                }

                if (cTables == 0)
                {
                    if (m_sbMessages.Length == 0)
                    {
                        SqlCommand oCommand = m_oConn.CreateCommand();
                        oCommand.CommandText = "select @@rowcount";
                        int cRecords = (int)oCommand.ExecuteScalar();
                        if (cRecords == 1)
                        {
                            m_sbMessages.AppendLine("(1 row affected)");
                        }
                        else
                        {
                            m_sbMessages.AppendLine("(" + cRecords.ToString("#,##0") + " rows affected)");
                        }
                    }
                    rtxtResults.Text = m_sbMessages.ToString();
                    rtxtResults.BringToFront();
                }
                else
                {
                    panelGrids.BringToFront();
                }

                sbpTime.Text = GetTimeText(DateTime.Now.Ticks - cTickStart);

                cRows = 0;
                foreach (DataTable oTable in m_oDataSet.Tables)
                {
                    cRows += oTable.Rows.Count;
                }
                if (cRows == 1)
                {
                    sbpRows.Text = "1 row";
                }
                else
                {
                    sbpRows.Text = cRows.ToString("#,##0") + " rows";
                }

                // Since the database might have changed, update it.
                if (m_oConn.State == ConnectionState.Open)
                {
                    sbpDatabase.Text = m_oConn.Database;
                }

                if (m_fCancelExecute)
                {
                    sbpStatus.Text = "Query batch was cancelled";
                }
                else
                {
                    sbpStatus.Text = "Query batch completed";
                }
            }
            catch (Exception oEx)
            {
                m_sLastError = oEx.Message;
            }

            if (m_fExecuteError && !m_fCancelExecute)
            {
                sbpStatus.Text = "Query batch completed with errors";
                rtxtResults.Clear();
                rtxtResults.SelectionColor = System.Drawing.Color.Red;
                rtxtResults.SelectedText   = m_sLastError;
                rtxtResults.BringToFront();
            }

            m_fIsExecuting = false;
        }