Exemplo n.º 1
0
 protected void btnAllProcFunc_Click(object sender, EventArgs e)
 {
     SqlExecuteProcedures.ChangeExecuteResultLabel(ref this.lbExecutionResult, true, 0);
     this.grvSelect.TopLeftHeaderCell.Value = "";
     //this.lbTableName.Visible = false;
     this.grvSelect.DataSource = this.mySqlCon.AllProcFunc();
 }
Exemplo n.º 2
0
        //DataGridView resources
        protected void grvSelect_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //if user doubleClicked on a table name from a sp_help TABLE (including btnAllTables)
            if (e.ColumnIndex == 2 && e.RowIndex >= 0 && String.IsNullOrEmpty((string)this.grvSelect.TopLeftHeaderCell.Value) && this.grvSelect.Columns[e.ColumnIndex].HeaderText == "TABLE_NAME")
            {
                try
                {
                    //get table name
                    string tableName = (string)this.grvSelect.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                    string code      = "select * from " + tableName;

                    //execute
                    DataTable dataTable       = null;
                    string    exception       = null;
                    int       qtdLinesChanged = 0;
                    this.mySqlCon.ExecuteOneSQLCmd(code, true, ref dataTable, ref exception, ref qtdLinesChanged);

                    //put in DataGridView
                    SqlExecuteProcedures.ChangeExecuteResultLabel(ref this.lbExecutionResult, true, 0);
                    this.grvSelect.TopLeftHeaderCell.Value = tableName;
                    //this.lbTableName.Text = tableName;
                    //this.lbTableName.Visible = true;
                    this.grvSelect.DataSource = dataTable;
                }
                catch (Exception err)
                { }
            }
        }
Exemplo n.º 3
0
        //btnHelp
        protected void btnHelp_Click(object sender, EventArgs e)
        {
            try
            {
                string    code            = "select * from " + this.tableName;
                DataTable table           = new DataTable();
                string    excep           = null;
                int       qtdLinesChanged = 0;
                this.mySqlConn.ExecuteOneSQLCmd(code, true, ref table, ref excep, ref qtdLinesChanged);

                SqlExecuteProcedures.ChangeExecuteResultLabel(ref this.lbExecutionResult, true, 0);
                this.grvSelectTry.TopLeftHeaderCell.Value = this.tableName;
                this.grvSelectTry.DataSource = table;

                MessageBox.Show("Hi! I created a table so you can practice what I will teach you!\n\r\n\r" +
                                "The table's name is '" + this.tableName + "' and you can see its fields in the selection...");
            }
            catch (Exception err)
            {
                MessageBox.Show("Someone has dropped the table I created('" + this.tableName + "')!");
            }
        }
Exemplo n.º 4
0
        // EXECUTE
        protected void btnExecute_Click(object sender, EventArgs e)
        {
            //get allCodes or lines without even quotation marks
            Queue <int> linesNoEvenQuotMarks = new Queue <int>();
            string      allCodes             = SqlExecuteProcedures.AllCodes(this.sqlRchtxtbx, ref linesNoEvenQuotMarks);

            if (linesNoEvenQuotMarks.Count > 0)
            {
                string msg = SqlExecuteProcedures.MessageFromNoEvenQuotMarks(linesNoEvenQuotMarks);
                MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //1. See if user is practicing the right command
                Queue <int> commandsCod   = this.mySqlConn.GetCodCommandsFromCode(allCodes);
                bool        onlyTryingCmd = true;
                while (commandsCod.Count > 0)
                {
                    if (commandsCod.Dequeue() != this.codCmd)
                    {
                        onlyTryingCmd = false;
                        break;
                    }
                }

                if (!onlyTryingCmd)
                {
                    this.grvSelectTry.DataSource = new DataTable();
                    MessageBox.Show("This area is for you to practice '" + this.command.Trim().ToUpper() + "'command ! Use the main form to make other commands!",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    //2. Execute the command
                    DataTable dataTable       = new DataTable();
                    string    excep           = null;
                    int       qtdLinesChanged = 0;
                    bool      worked          = this.mySqlConn.ExecuteOneSQLCmd(allCodes, this.mySqlConn.CommandIsQuery(this.codCmd), ref dataTable, ref excep, ref qtdLinesChanged);

                    //change label
                    SqlExecuteProcedures.ChangeExecuteResultLabel(ref this.lbExecutionResult, worked, qtdLinesChanged);

                    string tableName;
                    if (worked)
                    {
                        tableName = this.mySqlConn.TableName(allCodes, this.codCmd);
                    }
                    else
                    {
                        tableName = "";
                    }
                    this.grvSelectTry.TopLeftHeaderCell.Value = tableName;

                    this.grvSelectTry.DataSource = dataTable;

                    if (!worked)
                    {
                        MessageBox.Show("SQL Exception:\r\n" + excep,
                                        "SQL Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected void Execute(int executeType) //ExecuteType: 0=Automatic, 1=Non-Query, 2=Query
        {
            //get allCodes or lines without even quotation marks
            Queue <int> linesNoEvenQuotMarks = new Queue <int>();
            string      allCodes             = SqlExecuteProcedures.AllCodes(this.sqlRchtxtbx, ref linesNoEvenQuotMarks);
            int         qtdLinesChanged      = 0;

            if (linesNoEvenQuotMarks.Count > 0)
            {
                string msg = SqlExecuteProcedures.MessageFromNoEvenQuotMarks(linesNoEvenQuotMarks);

                MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            if (executeType == 0)
            {
                Queue <Error> errors    = new Queue <Error>();
                string        tableName = "";

                //DataGridView
                DataTable dataTable = this.mySqlCon.ExecuteAutomaticSqlCommands(allCodes, ref errors,
                                                                                ref qtdLinesChanged, ref tableName);
                this.grvSelect.TopLeftHeaderCell.Value = tableName;
                //this.lbTableName.Text = tableName;
                //this.lbTableName.Visible = true;
                this.grvSelect.DataSource = dataTable;

                bool worked = (errors == null || errors.Count == 0);

                //change label
                SqlExecuteProcedures.ChangeExecuteResultLabel(ref this.lbExecutionResult, worked, qtdLinesChanged);

                //notification
                if (this.allowNotification)
                {
                    if (worked)
                    {
                        MessageBox.Show("Succesfully executed!");
                    }
                    else
                    {
                        this.ShowErrors(errors);
                    }
                }
            }
            else
            {
                //execute one Query or Non-Query (based on the radiobutton checked)
                DataTable dataTable = null;
                bool      worked    = true;
                string    excep     = null;
                worked = this.mySqlCon.ExecuteOneSQLCmd(allCodes, executeType == 2, ref dataTable, ref excep, ref qtdLinesChanged);

                this.grvSelect.TopLeftHeaderCell.Value = "";
                //this.lbTableName.Visible = false;
                this.grvSelect.DataSource = dataTable;

                //change label
                SqlExecuteProcedures.ChangeExecuteResultLabel(ref this.lbExecutionResult, worked, qtdLinesChanged);

                //notification
                if (this.allowNotification)
                {
                    if (!worked)
                    {
                        string message = "Error in code: \n\r" +
                                         allCodes +
                                         "\n\rError:" +
                                         excep;

                        MessageBox.Show(message, "SQL Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Succesfull execution!");
                    }
                }
            }
        }
        public static string AllCodes(SqlRichTextBox sqlRchtxtbx, ref Queue <int> linesNoEvenQuotMarks)
        {
            RichTextBox rchtxtCode = sqlRchtxtbx.SQLRichTextBox;
            //or this.rchtxtCode

            //put txtCode.Items in a String (with spaces between each line)
            string allCodes = "";

            //if there's nothing selected
            if (rchtxtCode.SelectionLength <= 0)
            {
                for (int i = 0; i < rchtxtCode.Lines.Length; i++)
                {
                    string currLine = rchtxtCode.Lines[i];

                    //if there're even
                    if (SqlExecuteProcedures.RealCodeLine(ref currLine))
                    {
                        allCodes += " " + currLine;
                    }
                    else
                    {
                        linesNoEvenQuotMarks.Enqueue(i);
                    }
                }
            }
            else
            //there's something selected
            {
                int qtdOtherChars1 = 0;
                int indexFirstLine = sqlRchtxtbx.IndexOfLine(rchtxtCode.SelectionStart, ref qtdOtherChars1);
                int qtdOtherChars2 = 0;
                int indexLastLine  = sqlRchtxtbx.IndexOfLine(rchtxtCode.SelectionStart + rchtxtCode.SelectionLength,
                                                             ref qtdOtherChars2);

                for (int i = indexFirstLine; i <= indexLastLine; i++)
                {
                    string line;
                    if (i == indexFirstLine)
                    {
                        int final;
                        if (indexFirstLine == indexLastLine)
                        {
                            final = rchtxtCode.SelectionStart + rchtxtCode.SelectionLength - qtdOtherChars1;
                        }
                        else
                        {
                            final = rchtxtCode.Lines[i].Length;
                        }

                        int start = rchtxtCode.SelectionStart - qtdOtherChars1;

                        line = rchtxtCode.Lines[i].Substring(start, final - start);
                    }
                    else
                    if (i == indexLastLine)
                    {
                        line = rchtxtCode.Lines[i].Substring(0, rchtxtCode.SelectionStart + rchtxtCode.SelectionLength - qtdOtherChars2);
                    }
                    else
                    if (i < indexLastLine)
                    {
                        line = rchtxtCode.Lines[i];
                    }
                    else
                    {
                        break;
                    }

                    //if there're even
                    if (SqlExecuteProcedures.RealCodeLine(ref line))
                    {
                        allCodes += " " + line;
                    }
                    else
                    {
                        linesNoEvenQuotMarks.Enqueue(i);
                    }
                }
            }

            return(allCodes);
        }