Esempio n. 1
0
 void setContext(ITypeDescriptorContext context)
 {
     _metaConnection = context.Instance as MetaConnection;
     _metaEnum       = context.Instance as MetaEnum;
     _metaTable      = context.Instance as MetaTable;
     _metaColumn     = context.Instance as MetaColumn;
     _metaJoin       = context.Instance as MetaJoin;
     _reportView     = context.Instance as ReportView;
     _reportOutput   = context.Instance as ReportOutput;
     _reportSchedule = context.Instance as ReportSchedule;
     _parameter      = context.Instance as Parameter;
     _security       = context.Instance as SealSecurity;
     _emailDevice    = context.Instance as OutputEmailDevice;
 }
Esempio n. 2
0
 void setContext(ITypeDescriptorContext context)
 {
     _metaConnection   = context.Instance as MetaConnection;
     _metaEnum         = context.Instance as MetaEnum;
     _metaTable        = context.Instance as MetaTable;
     _metaColumn       = context.Instance as MetaColumn;
     _metaJoin         = context.Instance as MetaJoin;
     _reportView       = context.Instance as ReportView;
     _reportOutput     = context.Instance as ReportOutput;
     _reportSchedule   = context.Instance as ReportSchedule;
     _parameter        = context.Instance as Parameter;
     _security         = context.Instance as SealSecurity;
     _emailDevice      = context.Instance as OutputEmailDevice;
     _fileServerDevice = context.Instance as OutputFileServerDevice;
     _model            = context.Instance as ReportModel;
     _configuration    = context.Instance as SealServerConfiguration;
     _widget           = context.Instance as DashboardWidget;
 }
        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;
            }
        }
Esempio n. 4
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var  svc    = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            bool isLINQ = false;

            if (svc != null)
            {
                var frm = new SQLEditorForm();
                frm.Instance     = context.Instance;
                frm.PropertyName = context.PropertyDescriptor.Name;
                string        valueToEdit      = (value == null ? "" : value.ToString());
                bool          forceValueToEdit = false;
                List <string> samples          = new List <string>();
                var           description      = "";

                if (context.Instance is ReportModel)
                {
                    ReportModel model = context.Instance as ReportModel;
                    model.BuildQuery();
                    if (!string.IsNullOrEmpty(model.ExecutionError))
                    {
                        throw new Exception("Error building the SQL Statement...\r\nPlease fix these errors first.\r\n" + model.ExecutionError);
                    }

                    if (context.PropertyDescriptor.Name == "PreSQL" || context.PropertyDescriptor.Name == "PostSQL")
                    {
                        samples.Add(razorModelTemplate);
                        samples.Add("update Employees set LastName=LastName");
                        samples.Add("update Employees set LastName=LastName where {CommonRestriction_LastName}");
                        samples.Add("update Employees set LastName={CommonValue_NewName} where {CommonRestriction_OldName}");
                        frm.clearToolStripButton.Visible = false;
                        description = descriptionTemplate2;
                    }
                    else
                    {
                        frm.checkSQLToolStripButton.Visible = false;
                        forceValueToEdit = true;
                        var value2 = value;
                        if (value2 == null)
                        {
                            value2 = "";
                        }
                        if (context.PropertyDescriptor.Name == "SqlSelect" && string.IsNullOrEmpty(value2.ToString()))
                        {
                            valueToEdit = model.execSelect;
                        }
                        if (context.PropertyDescriptor.Name == "SqlFrom" && string.IsNullOrEmpty(value2.ToString()))
                        {
                            valueToEdit = "FROM " + model.execFromClause.ToString();
                        }
                        if (context.PropertyDescriptor.Name == "SqlGroupBy" && string.IsNullOrEmpty(value2.ToString()))
                        {
                            valueToEdit = "GROUP BY " + model.execGroupByClause.ToString();
                        }
                        if (context.PropertyDescriptor.Name == "SqlOrderBy" && string.IsNullOrEmpty(value2.ToString()))
                        {
                            valueToEdit = "ORDER BY " + model.execOrderByClause.ToString();
                        }
                        if (context.PropertyDescriptor.Name == "SqlCTE" && string.IsNullOrEmpty(value2.ToString()))
                        {
                            valueToEdit = model.execCTEClause.ToString();
                        }
                    }
                }
                else if (context.Instance is MetaJoin)
                {
                    MetaJoin join = context.Instance as MetaJoin;
                    frm.clearToolStripButton.Visible = false;
                    frm.checkSQLToolStripButton.Text = join.Source.IsNoSQL ? "Check Script" : "Check SQL";
                    isLINQ = join.Source.IsNoSQL;

                    if (join.LeftTable != null && join.RightTable != null && join.LeftTable.Columns.Count > 0 && join.RightTable.Columns.Count > 0)
                    {
                        for (int i = 0; i < join.LeftTable.Columns.Count && i < join.RightTable.Columns.Count; i++)
                        {
                            if (join.LeftTable.Columns[i].Type == join.RightTable.Columns[i].Type)
                            {
                                if (join.Source.IsSQL)
                                {
                                    samples.Add(string.Format("{0}={1}", join.LeftTable.Columns[i].Name, join.RightTable.Columns[i].Name));
                                }
                                else
                                {
                                    samples.Add(string.Format("{0} equals {1}", join.LeftTable.Columns[i].RawLINQColumnName, join.RightTable.Columns[i].RawLINQColumnName));
                                }
                            }
                        }
                    }


                    if ((value == null || string.IsNullOrEmpty(value.ToString())) && join.LeftTable != null && join.RightTable != null)
                    {
                        forceValueToEdit = true;
                        if (join.Source.IsSQL)
                        {
                            valueToEdit = string.Format("{0}.<ColumnName> = {1}.<ColumnName>", join.LeftTable.AliasName, join.RightTable.AliasName);
                        }
                        else
                        {
                            valueToEdit = string.Format("Helper.ToString({0}[\"<ColumnName>\"]) equals Helper.ToString({1}[\"<ColumnName>\"])", join.LeftTable.LINQResultName, join.RightTable.LINQResultName);
                        }
                    }
                }
                else if (context.Instance is MetaEnum)
                {
                    if (context.PropertyDescriptor.Name == "SqlDisplay")
                    {
                        samples.Add("SELECT DISTINCT CategoryID, CategoryName\r\nFROM Categories\r\nWHERE CategoryName LIKE '%{EnumFilter}%'\r\nORDER BY 2");
                        samples.Add("SELECT DISTINCT City\r\nFROM Customers\r\nWHERE Country in ({EnumValues_Country})\r\nORDER BY 1");
                        description = descriptionTemplate1 + "The SQL may contain the filter tag by using the keyword '{EnumFilter}' to build the enum with filters got from the user.\r\nThe SQL may contain dependencies with other enum values got from the user by using the keyword {EnumValues_<Name>} where <Name> is the name of the other enumerated list.\r\n";
                    }
                    else
                    {
                        samples.Add(razorEnumTemplate);
                        samples.Add("SELECT DISTINCT CategoryID, CategoryName\r\nFROM Categories\r\nORDER BY 2");
                        samples.Add("SELECT DISTINCT CategoryID, CategoryName, CategoryName, 'font-style:italic', 'info'\r\nFROM Categories\r\nORDER BY 2");
                        description = descriptionTemplate1;
                    }
                    frm.clearToolStripButton.Visible = false;
                    MetaEnum anEnum = context.Instance as MetaEnum;
                    if (value == null || string.IsNullOrEmpty(value.ToString()))
                    {
                        forceValueToEdit = true;
                        valueToEdit      = "SELECT col1,col2 FROM table ORDER BY col2";
                    }
                }
                else if (context.Instance is ReportSource || context.Instance is MetaSource)
                {
                    samples.Add(razorSourceTemplate);
                    frm.clearToolStripButton.Visible = false;
                    description = descriptionTemplate1;
                }
                else if (context.Instance is MetaTable)
                {
                    if (context.PropertyDescriptor.Name == "PreSQL" || context.PropertyDescriptor.Name == "PostSQL")
                    {
                        samples.Add(razorTableTemplate);
                        samples.Add("UPDATE Employees SET LastName=LastName");
                        samples.Add("UPDATE Employees SET LastName=LastName WHERE {CommonRestriction_LastName}");
                        description = descriptionTemplate2;
                    }
                    else if (context.PropertyDescriptor.Name == "WhereSQL")
                    {
                        samples.Add(razorTableWhereTemplate);
                        samples.Add("{CommonRestriction_LastName}");
                        samples.Add("Orders.EmployeeID in (SELECT EmployeeID FROM Employees WHERE LastName={CommonValue_LastNameValue})");
                        description = descriptionTemplate2;
                    }
                    else if (context.PropertyDescriptor.Name == "Sql")
                    {
                        samples.Add("SELECT * FROM Employees WHERE {CommonRestriction_LastName}");
                        samples.Add("SELECT * FROM Employees WHERE EmployeeID > {CommonValue_ID}");
                        description = descriptionTemplate3;
                    }
                    frm.clearToolStripButton.Visible = false;
                }
                else if (context.Instance is ReportTask)
                {
                    samples.Add(razorTaskTemplate);
                    samples.Add("UPDATE Employees SET LastName=LastName");
                    description = descriptionTemplate1;
                    frm.clearToolStripButton.Visible = false;
                }

                if (value != null || forceValueToEdit)
                {
                    frm.sqlTextBox.Text = valueToEdit.ToString();
                }

                if (context.PropertyDescriptor.IsReadOnly)
                {
                    frm.SetReadOnly();
                }
                else
                {
                    frm.SetSamples(samples);
                    if (!string.IsNullOrEmpty(description))
                    {
                        frm.errorTextBox.Text = description;
                    }
                }

                frm.Text = isLINQ ? "LINQ Editor" : "SQL Editor";
                frm.InitLexer(isLINQ ? Lexer.Cpp : Lexer.Sql);

                if (svc.ShowDialog(frm) == DialogResult.OK)
                {
                    value = frm.sqlTextBox.Text;
                }
            }
            return(value);
        }
Esempio n. 5
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;
            }
        }