public void checkSQL()
        {
            string initialSQL = "", error = "";

            try
            {
                if (Instance is ReportModel)
                {
                    ReportModel model = Instance as ReportModel;
                    if (PropertyName == "PreSQL" || PropertyName == "PostSQL")
                    {
                        if (sqlTextBox.Text.StartsWith("@"))
                        {
                            FormHelper.CheckRazorSyntax(sqlTextBox, "", model, _compilationErrors);
                        }
                        error = model.Source.CheckSQL(RazorHelper.CompileExecute(sqlTextBox.Text, model), null, model, true);
                    }
                    else
                    {
                        var sql = !string.IsNullOrEmpty(SqlToCheck) ? SqlToCheck : sqlTextBox.Text;
                        if (model.IsLINQ)
                        {
                            error = model.Source.CheckLINQ(sql, model.FromTables, model);
                        }
                        else
                        {
                            error = model.Source.CheckSQL(sql, model.FromTables, model, false);
                        }
                    }
                }
                if (Instance is MetaEnum)
                {
                    MetaEnum anEnum = Instance as MetaEnum;
                    if (sqlTextBox.Text.StartsWith("@"))
                    {
                        FormHelper.CheckRazorSyntax(sqlTextBox, "", anEnum, _compilationErrors);
                    }
                    error = anEnum.Source.CheckSQL(RazorHelper.CompileExecute(sqlTextBox.Text, anEnum), null, null, false);
                }
                else if (Instance is MetaSource)
                {
                    MetaSource source = Instance as MetaSource;
                    if (PropertyName == "PreSQL" || PropertyName == "PostSQL")
                    {
                        if (sqlTextBox.Text.StartsWith("@"))
                        {
                            FormHelper.CheckRazorSyntax(sqlTextBox, "", source, _compilationErrors);
                        }
                        error = source.CheckSQL(RazorHelper.CompileExecute(sqlTextBox.Text, source), null, null, true);
                    }
                }
                else if (Instance is MetaTable)
                {
                    MetaTable table = Instance as MetaTable;
                    if (PropertyName == "PreSQL" || PropertyName == "PostSQL")
                    {
                        if (sqlTextBox.Text.StartsWith("@"))
                        {
                            FormHelper.CheckRazorSyntax(sqlTextBox, "", table, _compilationErrors);
                        }
                        error = table.Source.CheckSQL(RazorHelper.CompileExecute(sqlTextBox.Text, table), null, null, true);
                    }
                    else
                    {
                        if (PropertyName == "WhereSQL")
                        {
                            initialSQL = table.WhereSQL;
                            if (sqlTextBox.Text.StartsWith("@"))
                            {
                                FormHelper.CheckRazorSyntax(sqlTextBox, "", table, _compilationErrors);
                            }
                            table.WhereSQL = RazorHelper.CompileExecute(sqlTextBox.Text, table);
                        }
                        else
                        {
                            initialSQL = table.Sql;
                            table.Sql  = sqlTextBox.Text;
                        }
                        try
                        {
                            table.CheckTable(null);
                            if (sqlTextBox.ReadOnly)
                            {
                                table.SetReadOnly();
                            }
                            error = table.Error;
                        }
                        finally
                        {
                            if (PropertyName == "WhereSQL")
                            {
                                table.WhereSQL = initialSQL;
                            }
                            else
                            {
                                table.Sql = initialSQL;
                            }
                        }
                    }
                }
                else if (Instance is MetaJoin)
                {
                    MetaJoin join = Instance as MetaJoin;
                    initialSQL = join.Clause;
                    try
                    {
                        join.Clause = sqlTextBox.Text;
                        join.CheckJoin();
                        if (sqlTextBox.ReadOnly)
                        {
                            join.SetReadOnly();
                        }
                        error = join.Error;
                    }
                    finally
                    {
                        join.Clause = initialSQL;
                    }
                }
                else if (Instance is ReportTask)
                {
                    ReportTask task = Instance as ReportTask;
                    if (sqlTextBox.Text.StartsWith("@"))
                    {
                        FormHelper.CheckRazorSyntax(sqlTextBox, "", task, _compilationErrors);
                    }
                    error = task.Source.CheckSQL(RazorHelper.CompileExecute(sqlTextBox.Text, task), null, null, false);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            errorTextBox.Text = error;
            if (!string.IsNullOrEmpty(error))
            {
                toolStripStatusLabel.Text  = "Error";
                toolStripStatusLabel.Image = global::Seal.Properties.Resources.error2;
            }
            else
            {
                toolStripStatusLabel.Text  = "Script checked successfully";
                toolStripStatusLabel.Image = global::Seal.Properties.Resources.checkedGreen;
            }
        }
示例#2
0
        public void checkSQLToolStripButton_Click(object sender, EventArgs e)
        {
            string initialSQL = "", error = "";

            try
            {
                if (Instance is ReportModel)
                {
                    ReportModel model = Instance as ReportModel;
                    if (PropertyName == "PreSQL" || PropertyName == "PostSQL")
                    {
                        error = model.Source.CheckSQL(Helper.ParseRazor(sqlTextBox.Text, model), null, model, true);
                    }
                    else
                    {
                        error = model.Source.CheckSQL(sqlTextBox.Text, model.FromTables, model, false);
                    }
                }
                if (Instance is MetaEnum)
                {
                    MetaEnum anEnum = Instance as MetaEnum;
                    error = anEnum.Source.CheckSQL(sqlTextBox.Text, null, null, false);
                }
                else if (Instance is MetaSource)
                {
                    MetaSource source = Instance as MetaSource;
                    if (PropertyName == "PreSQL" || PropertyName == "PostSQL")
                    {
                        error = source.CheckSQL(Helper.ParseRazor(sqlTextBox.Text, source), null, null, true);
                    }
                }
                else if (Instance is MetaTable)
                {
                    MetaTable table = Instance as MetaTable;
                    if (PropertyName == "PreSQL" || PropertyName == "PostSQL")
                    {
                        error = table.Source.CheckSQL(Helper.ParseRazor(sqlTextBox.Text, table), null, null, true);
                    }
                    else
                    {
                        if (PropertyName == "WhereSQL")
                        {
                            initialSQL     = table.WhereSQL;
                            table.WhereSQL = Helper.ParseRazor(sqlTextBox.Text, table);
                        }
                        else
                        {
                            initialSQL = table.Sql;
                            table.Sql  = sqlTextBox.Text;
                        }
                        try
                        {
                            table.CheckTable(null);
                            if (sqlTextBox.IsReadOnly)
                            {
                                table.SetReadOnly();
                            }
                            error = table.Error;
                        }
                        finally
                        {
                            if (PropertyName == "WhereSQL")
                            {
                                table.WhereSQL = initialSQL;
                            }
                            else
                            {
                                table.Sql = initialSQL;
                            }
                        }
                    }
                }
                else if (Instance is MetaJoin)
                {
                    MetaJoin join = Instance as MetaJoin;
                    initialSQL = join.Clause;
                    try
                    {
                        join.Clause = sqlTextBox.Text;
                        join.CheckJoin();
                        if (sqlTextBox.IsReadOnly)
                        {
                            join.SetReadOnly();
                        }
                        error = join.Error;
                    }
                    finally
                    {
                        join.Clause = initialSQL;
                    }
                }
                else if (Instance is ReportTask)
                {
                    ReportTask task = Instance as ReportTask;
                    error = task.Source.CheckSQL(Helper.ParseRazor(sqlTextBox.Text, task), null, null, false);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            errorTextBox.Text = error;
            if (!string.IsNullOrEmpty(error))
            {
                toolStripStatusLabel.Text  = "Error";
                toolStripStatusLabel.Image = global::Seal.Properties.Resources.error2;
            }
            else
            {
                toolStripStatusLabel.Text  = "SQL checked successfully";
                toolStripStatusLabel.Image = global::Seal.Properties.Resources.checkedGreen;
            }
        }