// 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); } } } }
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!"); } } } }