상속: System.Windows.Forms.Form
예제 #1
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (svc != null)
            {
                var frm = new SQLEditorForm();
                frm.Instance     = context.Instance;
                frm.PropertyName = context.PropertyDescriptor.Name;
                string template    = "";
                string valueToEdit = (value == null ? "" : value.ToString());
                if (context.Instance is ReportModel)
                {
                    ReportModel model = context.Instance as ReportModel;
                    model.BuildSQL();
                    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 == "SqlEditor")
                    {
                        frm.clearToolStripButton.Visible = false;
                        frm.sqlTextBox.Text       = model.Sql;
                        frm.sqlTextBox.IsReadOnly = true;
                    }
                    else if (context.PropertyDescriptor.Name == "PreSQL" || context.PropertyDescriptor.Name == "PostSQL")
                    {
                        template = razorModelTemplate;
                        frm.clearToolStripButton.Visible = false;
                    }
                    else
                    {
                        frm.checkSQLToolStripButton.Visible = false;
                        if (value == null)
                        {
                            value = "";
                        }
                        if (context.PropertyDescriptor.Name == "SqlSelect" && string.IsNullOrEmpty(value.ToString()))
                        {
                            valueToEdit = model.execSelect;
                        }
                        if (context.PropertyDescriptor.Name == "SqlFrom" && string.IsNullOrEmpty(value.ToString()))
                        {
                            valueToEdit = "FROM " + model.execFromClause.ToString();
                        }
                        if (context.PropertyDescriptor.Name == "SqlGroupBy" && string.IsNullOrEmpty(value.ToString()))
                        {
                            valueToEdit = "GROUP BY " + model.execGroupByClause.ToString();
                        }
                        if (context.PropertyDescriptor.Name == "SqlOrderBy" && string.IsNullOrEmpty(value.ToString()))
                        {
                            valueToEdit = "ORDER BY " + model.execOrderByClause.ToString();
                        }
                    }
                }
                else if (context.Instance is MetaJoin)
                {
                    frm.clearToolStripButton.Visible = false;
                }
                else if (context.Instance is MetaEnum)
                {
                    template = razorEnumTemplate;
                    frm.clearToolStripButton.Visible = false;
                    MetaEnum anEnum = context.Instance as MetaEnum;
                    if (value == null || string.IsNullOrEmpty(value.ToString()))
                    {
                        value       = "";
                        valueToEdit = anEnum.DefaultSQL;
                    }
                }
                else if (context.Instance is ReportSource || context.Instance is MetaSource)
                {
                    template = razorSourceTemplate;
                    frm.clearToolStripButton.Visible = false;
                }
                else if (context.Instance is MetaTable)
                {
                    if (context.PropertyDescriptor.Name == "PreSQL" || context.PropertyDescriptor.Name == "PostSQL")
                    {
                        template = razorTableTemplate;
                    }
                    else if (context.PropertyDescriptor.Name == "WhereSQL")
                    {
                        template = razorTableWhereTemplate;
                    }
                    frm.clearToolStripButton.Visible = false;
                }
                else if (context.Instance is ReportTask)
                {
                    template = razorTaskTemplate;
                    frm.clearToolStripButton.Visible = false;
                }

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

                if (context.PropertyDescriptor.IsReadOnly)
                {
                    frm.SetReadOnly();
                }
                else if (!string.IsNullOrEmpty(template))
                {
                    frm.SetSamples(new List <string>()
                    {
                        template
                    });
                    frm.errorTextBox.Text = "Note that Razor script can be used if the text starts with '@'.\r\n";
                }

                if (svc.ShowDialog(frm) == DialogResult.OK)
                {
                    value = frm.sqlTextBox.Text;
                }
            }
            return(value);
        }
        void helperButton_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (sender is ToolStripItem)
                {
                    Keys key = (Keys)((ToolStripItem)sender).Tag;

                    if (SelectedEntity is MetaSource)
                    {
                        if (key == Keys.F7)
                        {
                            MetaSource source = ((MetaSource)SelectedEntity);
                            source.Connection.CheckConnection();
                            source.Information = source.Connection.Information;
                            source.Error       = source.Connection.Error;
                            source.InitEditor();
                        }
                        if (key == Keys.F12)
                        {
                            MetaTable table = ((MetaSource)SelectedEntity).MetaData.MasterTable;
                            if (table != null)
                            {
                                TreeViewHelper.SelectNode(MainTreeView, MainTreeView.SelectedNode.Nodes, table);
                                EditProperty("Default Load Script");
                            }
                        }
                    }
                    else if (SelectedEntity is MetaConnection)
                    {
                        if (key == Keys.F7)
                        {
                            ((MetaConnection)SelectedEntity).CheckConnection();
                        }
                    }
                    else if (SelectedEntity is MetaTable)
                    {
                        if (key == Keys.F7)
                        {
                            ((MetaTable)SelectedEntity).CheckTable(null);
                        }
                        if (key == Keys.F8)
                        {
                            if (((MetaTable)SelectedEntity).IsSQL)
                            {
                                EditProperty("SQL Select Statement");
                            }
                            else
                            {
                                EditProperty("Definition Script");
                            }
                        }
                        if (key == Keys.F9 && ((MetaTable)SelectedEntity).DynamicColumns)
                        {
                            ((MetaTable)SelectedEntity).Refresh();
                            if (EntityHandler != null)
                            {
                                EntityHandler.SetModified();
                                EntityHandler.InitEntity(SelectedEntity);
                            }
                        }
                        if (key == Keys.F12)
                        {
                            EditProperty("Default Load Script");
                        }
                    }
                    else if (SelectedEntity is MetaColumn)
                    {
                        if (key == Keys.F7)
                        {
                            EditProperty("Check column SQL syntax");
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("Show column values");
                        }
                    }
                    else if (SelectedEntity is MetaEnum)
                    {
                        if (key == Keys.F8)
                        {
                            EditProperty("SQL Select Statement");
                        }
                        if (key == Keys.F9)
                        {
                            if (EntityHandler != null)
                            {
                                EntityHandler.SetModified();
                            }
                            ((MetaEnum)SelectedEntity).RefreshEnum();
                        }
                    }
                    else if (SelectedEntity is MetaJoin)
                    {
                        if (key == Keys.F7)
                        {
                            ((MetaJoin)SelectedEntity).CheckJoin();
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("SQL Clause");
                        }
                    }
                    else if (SelectedEntity is TasksFolder)
                    {
                        if (key == Keys.F7)
                        {
                            EditProperty("Common Scripts");
                        }
                    }
                    else if (SelectedEntity is ReportTask)
                    {
                        if (key == Keys.F7)
                        {
                            EditProperty("Script");
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("SQL Statement");
                        }
                    }
                    else if (SelectedEntity is ReportModel)
                    {
                        if (key == Keys.F7 || key == Keys.F8)
                        {
                            var frm = new SQLEditorForm();
                            frm.Instance     = SelectedEntity;
                            frm.PropertyName = "";

                            ReportModel model = SelectedEntity as ReportModel;
                            if (model.IsSQLModel && key == Keys.F7)
                            {
                                frm.Text = "SQL Editor: Edit the SQL Select Statement";
                                frm.SetSamples(new List <string>()
                                {
                                    "SELECT * FROM Orders", "SELECT *\r\nFROM Employees\r\nWHERE {CommonRestriction_LastName}",
                                    "SELECT * FROM Orders", "SELECT *\r\nFROM Employees\r\nWHERE EmployeeID > {CommonValue_ID}"
                                });
                                frm.WarningOnError  = true;
                                frm.sqlTextBox.Text = model.Table.Sql;
                                if (frm.ShowDialog() == DialogResult.OK)
                                {
                                    try
                                    {
                                        Cursor.Current  = Cursors.WaitCursor;
                                        model.Table.Sql = frm.sqlTextBox.Text;
                                        model.RefreshMetaTable(true);
                                    }
                                    finally
                                    {
                                        Cursor.Current = Cursors.Default;
                                    }

                                    if (EntityHandler != null)
                                    {
                                        EntityHandler.SetModified();
                                        EntityHandler.RefreshModelTreeView();
                                    }

                                    if (!string.IsNullOrEmpty(model.Table.Error))
                                    {
                                        throw new Exception("Error when building columns from the SQL Select Statement:\r\n" + model.Table.Error);
                                    }
                                }
                            }
                            else
                            {
                                model.Report.CheckingExecution = true;
                                try
                                {
                                    model.BuildSQL();
                                    frm.SqlToCheck = model.Sql;
                                    model.Report.CheckingExecution = false;
                                    model.BuildSQL();
                                }
                                finally
                                {
                                    model.Report.CheckingExecution = false;
                                }
                                if (!string.IsNullOrEmpty(model.ExecutionError))
                                {
                                    throw new Exception("Error building the SQL Statement...\r\nPlease fix these errors first.\r\n" + model.ExecutionError);
                                }
                                frm.sqlTextBox.Text = model.Sql;
                                frm.SetReadOnly();
                                if (key == Keys.F8)
                                {
                                    frm.checkSQL();
                                }
                                frm.ShowDialog();
                            }
                        }
                    }
                    else if (SelectedEntity is ReportView)
                    {
                        if (key == Keys.F8)
                        {
                            EditProperty("Custom template");
                        }
                    }
                    else if (SelectedEntity is ViewFolder)
                    {
                        if (key == Keys.F8)
                        {
                            EditProperty("Report Input Values");
                        }
                    }
                    else if (SelectedEntity is ReportSchedule)
                    {
                        if (key == Keys.F8)
                        {
                            EditProperty("Edit schedule properties");
                        }
                        if (key == Keys.F9)
                        {
                            EditProperty("Run Task Scheduler MMC");
                        }
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        void helperButton_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (sender is ToolStripItem)
                {
                    var  toolStrip = (ToolStripItem)sender;
                    Keys?key       = null;
                    if (toolStrip.Tag != null)
                    {
                        key = (Keys)toolStrip.Tag;
                    }

                    if (SelectedEntity is MetaSource)
                    {
                        if (key == Keys.F7)
                        {
                            MetaSource source = ((MetaSource)SelectedEntity);
                            source.Connection.CheckConnection();
                            source.Information = source.Connection.Information;
                            source.Error       = source.Connection.Error;
                            source.InitEditor();
                        }
                    }
                    else if (SelectedEntity is MetaConnection)
                    {
                        if (key == Keys.F7)
                        {
                            ((MetaConnection)SelectedEntity).CheckConnection();
                        }
                    }
                    else if (SelectedEntity is MetaTable)
                    {
                        if (key == Keys.F7)
                        {
                            ((MetaTable)SelectedEntity).CheckTable(null);
                        }
                        if (key == Keys.F8)
                        {
                            if (((MetaTable)SelectedEntity).IsSQL)
                            {
                                EditProperty("SQL Select Statement");
                            }
                            else
                            {
                                EditProperty("Definition Script");
                            }
                        }
                        if (key == Keys.F9 && ((MetaTable)SelectedEntity).DynamicColumns)
                        {
                            ((MetaTable)SelectedEntity).Refresh();
                            if (EntityHandler != null)
                            {
                                EntityHandler.SetModified();
                                EntityHandler.InitEntity(SelectedEntity);
                            }
                        }
                        if (key == Keys.F12)
                        {
                            EditProperty("Default Load Script");
                        }
                    }
                    else if (SelectedEntity is MetaColumn)
                    {
                        if (key == Keys.F7)
                        {
                            EditProperty("Check column SQL syntax");
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("Show column values");
                        }
                    }
                    else if (SelectedEntity is MetaEnum)
                    {
                        if (key == Keys.F7)
                        {
                            EditProperty("SQL Select Statement");
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("Script");
                        }
                        if (key == Keys.F9)
                        {
                            if (EntityHandler != null)
                            {
                                EntityHandler.SetModified();
                            }
                            ((MetaEnum)SelectedEntity).RefreshEnum();
                        }
                    }
                    else if (SelectedEntity is MetaJoin)
                    {
                        if (key == Keys.F7)
                        {
                            ((MetaJoin)SelectedEntity).CheckJoin();
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("Join clause");
                        }
                    }
                    else if (SelectedEntity is ReportTask)
                    {
                        if (key == Keys.F7)
                        {
                            EditProperty("Script");
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("SQL Statement");
                        }
                    }
                    else if (SelectedEntity is ReportModel)
                    {
                        ReportModel model = SelectedEntity as ReportModel;

                        if (key == null && model.IsLINQ)
                        {
                            model.BuildQuery(false, true);
                            EntityHandler.UpdateModelNode();

                            MessageBox.Show(string.Format("The LINQ Model has been refreshed...\r\n\r\nIt contains {0} SQL Sub-Model(s) and {1} NoSQL Sub-Table(s).", model.LINQSubModels.Count, model.LINQSubTables.Count), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (key == Keys.F7 || key == Keys.F8)
                        {
                            if (model.IsLINQ)
                            {
                                var frm = new TemplateTextEditorForm();
                                frm.Text = "LINQ Editor" + (!string.IsNullOrEmpty(model.LoadScript) ? " (WARNING: Script got from the 'Load Script' property of the model)" : "");
                                frm.ObjectForCheckSyntax = model;
                                ScintillaHelper.Init(frm.textBox, Lexer.Cpp);

                                if (string.IsNullOrEmpty(model.LoadScript))
                                {
                                    model.Report.CheckingExecution = true;
                                    try
                                    {
                                        model.BuildQuery();
                                        frm.textBox.Text = model.LINQLoadScript;
                                        model.Report.CheckingExecution = false;
                                        model.BuildQuery();
                                    }
                                    finally
                                    {
                                        model.Report.CheckingExecution = false;
                                    }
                                    if (!string.IsNullOrEmpty(model.ExecutionError))
                                    {
                                        throw new Exception(model.ExecutionError);
                                    }

                                    frm.textBox.Text = model.LINQLoadScript;
                                }
                                else
                                {
                                    frm.textBox.Text = model.LoadScript;
                                }

                                if (key == Keys.F8)
                                {
                                    frm.CheckSyntax();
                                }
                                frm.textBox.ReadOnly           = true;
                                frm.okToolStripButton.Visible  = false;
                                frm.cancelToolStripButton.Text = "Close";
                                frm.ShowDialog();
                            }
                            else
                            {
                                var frm = new SQLEditorForm();
                                frm.Instance     = SelectedEntity;
                                frm.PropertyName = "";
                                frm.InitLexer(Lexer.Sql);

                                if (model.IsSQLModel && key == Keys.F7)
                                {
                                    frm.Text = "SQL Editor: Edit the SQL Select Statement";
                                    frm.SetSamples(new List <string>()
                                    {
                                        "SELECT * FROM Orders", "SELECT *\r\nFROM Employees\r\nWHERE {CommonRestriction_LastName}",
                                        "SELECT * FROM Orders", "SELECT *\r\nFROM Employees\r\nWHERE EmployeeID > {CommonValue_ID}"
                                    });

                                    frm.WarningOnError  = true;
                                    frm.sqlTextBox.Text = model.Table.Sql;
                                    if (frm.ShowDialog() == DialogResult.OK)
                                    {
                                        try
                                        {
                                            Cursor.Current  = Cursors.WaitCursor;
                                            model.Table.Sql = frm.sqlTextBox.Text;
                                            model.RefreshMetaTable(true);
                                        }
                                        finally
                                        {
                                            Cursor.Current = Cursors.Default;
                                        }

                                        if (EntityHandler != null)
                                        {
                                            EntityHandler.SetModified();
                                            EntityHandler.RefreshModelTreeView();
                                        }

                                        if (!string.IsNullOrEmpty(model.Table.Error))
                                        {
                                            throw new Exception("Error when building columns from the SQL Select Statement:\r\n" + model.Table.Error);
                                        }
                                    }
                                }
                                else
                                {
                                    model.Report.CheckingExecution = true;
                                    try
                                    {
                                        model.BuildQuery();
                                        frm.SqlToCheck = model.Sql;
                                        model.Report.CheckingExecution = false;
                                        model.BuildQuery();
                                    }
                                    finally
                                    {
                                        model.Report.CheckingExecution = false;
                                    }
                                    if (!string.IsNullOrEmpty(model.ExecutionError))
                                    {
                                        throw new Exception("Error building the SQL Statement...\r\nPlease fix these errors first.\r\n" + model.ExecutionError);
                                    }
                                    frm.sqlTextBox.Text = model.Sql;
                                    frm.SetReadOnly();
                                    if (key == Keys.F8)
                                    {
                                        frm.checkSQL();
                                    }
                                    frm.ShowDialog();
                                }
                            }
                        }
                    }
                    else if (SelectedEntity is ReportView)
                    {
                        if (key == Keys.F8)
                        {
                            EditProperty("Custom template");
                        }
                    }
                    else if (SelectedEntity is Report)
                    {
                        if (key == Keys.F7)
                        {
                            EditProperty("Common Scripts");
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("Report Input Values");
                        }
                    }
                    else if (SelectedEntity is ReportSchedule)
                    {
                        if (key == Keys.F8)
                        {
                            EditProperty("Edit schedule properties");
                        }
                        if (key == Keys.F9)
                        {
                            EditProperty("Run Task Scheduler MMC");
                        }
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
예제 #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);
        }
예제 #5
0
        void helperButton_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (sender is ToolStripItem)
                {
                    Keys key = (Keys)((ToolStripItem)sender).Tag;

                    if (SelectedEntity is MetaSource)
                    {
                        if (key == Keys.F7)
                        {
                            MetaSource source = ((MetaSource)SelectedEntity);
                            source.Connection.CheckConnection();
                            source.Information = source.Connection.Information;
                            source.Error       = source.Connection.Error;
                            source.InitEditor();
                        }
                        if (key == Keys.F8 || key == Keys.F10)
                        {
                            MetaTable table = ((MetaSource)SelectedEntity).MetaData.MasterTable;
                            if (table != null)
                            {
                                TreeViewHelper.SelectNode(MainTreeView, MainTreeView.SelectedNode.Nodes, table);
                                EditProperty(table.IsSQL ? "SQL Statement" : "Default Load Script");
                            }
                        }
                    }
                    else if (SelectedEntity is MetaConnection)
                    {
                        if (key == Keys.F7)
                        {
                            ((MetaConnection)SelectedEntity).CheckConnection();
                        }
                    }
                    else if (SelectedEntity is MetaTable)
                    {
                        if (key == Keys.F7)
                        {
                            ((MetaTable)SelectedEntity).CheckTable(null);
                        }
                        if (key == Keys.F8)
                        {
                            if (((MetaTable)SelectedEntity).IsSQL)
                            {
                                EditProperty("SQL Statement");
                            }
                            else
                            {
                                EditProperty("Definition Script");
                            }
                        }
                        if (key == Keys.F9 && ((MetaTable)SelectedEntity).DynamicColumns)
                        {
                            ((MetaTable)SelectedEntity).Refresh();
                            if (EntityHandler != null)
                            {
                                EntityHandler.SetModified();
                                EntityHandler.InitEntity(SelectedEntity);
                            }
                        }
                        if (key == Keys.F10)
                        {
                            EditProperty("Default Load Script");
                        }
                    }
                    else if (SelectedEntity is MetaColumn)
                    {
                        if (key == Keys.F7)
                        {
                            EditProperty("Check column SQL syntax");
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("Show column values");
                        }
                    }
                    else if (SelectedEntity is MetaEnum)
                    {
                        if (key == Keys.F8)
                        {
                            EditProperty("Select SQL Statement");
                        }
                        if (key == Keys.F9)
                        {
                            ((MetaEnum)SelectedEntity).RefreshEnum();
                        }
                    }
                    else if (SelectedEntity is MetaJoin)
                    {
                        if (key == Keys.F7)
                        {
                            ((MetaJoin)SelectedEntity).CheckJoin();
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("SQL Clause");
                        }
                    }
                    else if (SelectedEntity is ReportTask)
                    {
                        if (key == Keys.F7)
                        {
                            EditProperty("Script");
                        }
                        if (key == Keys.F8)
                        {
                            EditProperty("SQL Statement");
                        }
                    }
                    else if (SelectedEntity is ReportModel)
                    {
                        if (key == Keys.F7 || key == Keys.F8)
                        {
                            var frm = new SQLEditorForm();
                            frm.Instance     = SelectedEntity;
                            frm.PropertyName = "";

                            ReportModel model = SelectedEntity as ReportModel;
                            model.Report.CheckingExecution = true;
                            try
                            {
                                model.BuildSQL();
                            }
                            finally
                            {
                                model.Report.CheckingExecution = false;
                            }
                            if (!string.IsNullOrEmpty(model.ExecutionError))
                            {
                                throw new Exception("Error building the SQL Statement...\r\nPlease fix these errors first.\r\n" + model.ExecutionError);
                            }
                            frm.sqlTextBox.Text = model.Sql;
                            frm.SetReadOnly();
                            if (key == Keys.F8)
                            {
                                frm.checkSQLToolStripButton_Click(null, null);
                            }
                            frm.ShowDialog();
                        }
                    }
                    else if (SelectedEntity is ReportView)
                    {
                        if (key == Keys.F7)
                        {
                            EditProperty("General Parameters");
                        }
                        else if (key == Keys.F8)
                        {
                            EditProperty("CSS");
                        }
                        else if (key == Keys.F9)
                        {
                            EditProperty("Data Table Configuration");
                        }
                        else if (key == Keys.F10)
                        {
                            EditProperty("NVD3 Chart Configuration");
                        }
                    }
                    else if (SelectedEntity is ReportSchedule)
                    {
                        if (key == Keys.F8)
                        {
                            EditProperty("Edit schedule properties");
                        }
                        if (key == Keys.F9)
                        {
                            EditProperty("Run Task Scheduler MMC");
                        }
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
예제 #6
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            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.BuildSQL();
                    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 {SharedRestriction_LastName}");
                        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();
                        }
                    }
                }
                else if (context.Instance is MetaJoin)
                {
                    frm.clearToolStripButton.Visible = false;
                }
                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");
                        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 {SharedRestriction_LastName}");
                        description = descriptionTemplate2;
                    }
                    else if (context.PropertyDescriptor.Name == "WhereSQL")
                    {
                        samples.Add(razorTableWhereTemplate);
                        samples.Add("{SharedRestriction_LastName}");
                        description = descriptionTemplate2;
                    }
                    else if (context.PropertyDescriptor.Name == "Sql")
                    {
                        samples.Add("SELECT * FROM Employees WHERE {SharedRestriction_LastName}");
                        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;
                    }
                }

                if (svc.ShowDialog(frm) == DialogResult.OK)
                {
                    value = frm.sqlTextBox.Text;
                }
            }
            return(value);
        }
예제 #7
0
        void helperButton_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (sender is ToolStripItem)
                {
                    Keys key = (Keys)((ToolStripItem)sender).Tag;

                    if (SelectedEntity is MetaSource)
                    {
                        if (key == Keys.F7)
                        {
                            MetaSource source = ((MetaSource)SelectedEntity);
                            source.Connection.CheckConnection();
                            source.Information = source.Connection.Information;
                            source.Error = source.Connection.Error;
                            source.InitEditor();
                        }
                        if (key == Keys.F8 || key == Keys.F12)
                        {
                            MetaTable table = ((MetaSource)SelectedEntity).MetaData.MasterTable;
                            if (table != null)
                            {
                                TreeViewHelper.SelectNode(MainTreeView, MainTreeView.SelectedNode.Nodes, table);
                                EditProperty(table.IsSQL ? "SQL Statement" : "Default Load Script");
                            }
                        }
                    }
                    else if (SelectedEntity is MetaConnection)
                    {
                        if (key == Keys.F7) ((MetaConnection)SelectedEntity).CheckConnection();
                    }
                    else if (SelectedEntity is MetaTable)
                    {
                        if (key == Keys.F7) ((MetaTable)SelectedEntity).CheckTable(null);
                        if (key == Keys.F8)
                        {
                            if (((MetaTable)SelectedEntity).IsSQL) EditProperty("SQL Statement");
                            else EditProperty("Definition Script");
                        }
                        if (key == Keys.F9 && ((MetaTable)SelectedEntity).DynamicColumns)
                        {
                            ((MetaTable)SelectedEntity).Refresh();
                            if (EntityHandler != null)
                            {
                                EntityHandler.SetModified();
                                EntityHandler.InitEntity(SelectedEntity);
                            }
                        }
                        if (key == Keys.F12)
                        {
                            EditProperty("Default Load Script");
                        }
                    }
                    else if (SelectedEntity is MetaColumn)
                    {
                        if (key == Keys.F7) EditProperty("Check column SQL syntax");
                        if (key == Keys.F8) EditProperty("Show column values");
                    }
                    else if (SelectedEntity is MetaEnum)
                    {
                        if (key == Keys.F8) EditProperty("Select SQL Statement");
                        if (key == Keys.F9) ((MetaEnum)SelectedEntity).RefreshEnum();
                    }
                    else if (SelectedEntity is MetaJoin)
                    {
                        if (key == Keys.F7) ((MetaJoin)SelectedEntity).CheckJoin();
                        if (key == Keys.F8) EditProperty("SQL Clause");
                    }
                    else if (SelectedEntity is TasksFolder)
                    {
                        if (key == Keys.F7) EditProperty("Tasks Script");
                    }
                    else if (SelectedEntity is ReportTask)
                    {
                        if (key == Keys.F7) EditProperty("Script");
                        if (key == Keys.F8) EditProperty("SQL Statement");
                    }
                    else if (SelectedEntity is ReportModel)
                    {
                        if (key == Keys.F7 || key == Keys.F8)
                        {
                            var frm = new SQLEditorForm();
                            frm.Instance = SelectedEntity;
                            frm.PropertyName = "";

                            ReportModel model = SelectedEntity as ReportModel;
                            model.Report.CheckingExecution = true;
                            try
                            {
                                model.BuildSQL();
                            }
                            finally
                            {
                                model.Report.CheckingExecution = false;
                            }
                            if (!string.IsNullOrEmpty(model.ExecutionError))
                            {
                                throw new Exception("Error building the SQL Statement...\r\nPlease fix these errors first.\r\n" + model.ExecutionError);
                            }
                            frm.sqlTextBox.Text = model.Sql;
                            frm.SetReadOnly();
                            if (key == Keys.F8) frm.checkSQLToolStripButton_Click(null, null);
                            frm.ShowDialog();
                        }
                    }
                    else if (SelectedEntity is ReportView)
                    {
                        if (key == Keys.F7) EditProperty("General Parameters");
                        else if (key == Keys.F8) EditProperty("CSS");
                        else if (key == Keys.F9) EditProperty("Data Table Configuration");
                        else if (key == Keys.F12) EditProperty("NVD3 Chart Configuration");
                    }
                    else if (SelectedEntity is ReportSchedule)
                    {
                        if (key == Keys.F8) EditProperty("Edit schedule properties");
                        if (key == Keys.F9) EditProperty("Run Task Scheduler MMC");
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
예제 #8
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (svc != null)
            {
                var frm = new SQLEditorForm();
                frm.Instance = context.Instance;
                frm.PropertyName = context.PropertyDescriptor.Name;
                string template = "";
                string valueToEdit = (value == null ? "" : value.ToString());
                if (context.Instance is ReportModel)
                {
                    ReportModel model = context.Instance as ReportModel;
                    model.BuildSQL();
                    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 == "SqlEditor")
                    {
                        frm.clearToolStripButton.Visible = false;
                        frm.sqlTextBox.Text = model.Sql;
                        frm.sqlTextBox.IsReadOnly = true;
                    }
                    else if (context.PropertyDescriptor.Name == "PreSQL" || context.PropertyDescriptor.Name == "PostSQL")
                    {
                        template = razorModelTemplate; 
                        frm.clearToolStripButton.Visible = false;
                    }
                    else
                    {
                        frm.checkSQLToolStripButton.Visible = false;
                        if (value == null) value = "";
                        if (context.PropertyDescriptor.Name == "SqlSelect" && string.IsNullOrEmpty(value.ToString())) valueToEdit = model.execSelect;
                        if (context.PropertyDescriptor.Name == "SqlFrom" && string.IsNullOrEmpty(value.ToString())) valueToEdit = "FROM " + model.execFromClause.ToString();
                        if (context.PropertyDescriptor.Name == "SqlGroupBy" && string.IsNullOrEmpty(value.ToString())) valueToEdit = "GROUP BY " + model.execGroupByClause.ToString();
                        if (context.PropertyDescriptor.Name == "SqlOrderBy" && string.IsNullOrEmpty(value.ToString())) valueToEdit = "ORDER BY " + model.execOrderByClause.ToString();
                    }
                }
                else if (context.Instance is MetaJoin)
                {
                    frm.clearToolStripButton.Visible = false;
                }
                else if (context.Instance is MetaEnum)
                {
                    frm.clearToolStripButton.Visible = false;
                    MetaEnum anEnum = context.Instance as MetaEnum;
                    if (value == null || string.IsNullOrEmpty(value.ToString()))
                    {
                        value = "";
                        valueToEdit = anEnum.DefaultSQL;
                    }
                }
                else if (context.Instance is ReportSource)
                {
                    template = razorSourceTemplate;
                    frm.clearToolStripButton.Visible = false;
                }
                else if (context.Instance is MetaTable)
                {
                    if (context.PropertyDescriptor.Name == "PreSQL" || context.PropertyDescriptor.Name == "PostSQL")
                    {
                        template = razorTableTemplate; 
                    }
                    else if (context.PropertyDescriptor.Name == "WhereSQL")
                    {
                        template = razorTableWhereTemplate;
                    }
                    frm.clearToolStripButton.Visible = false;
                }
                else if (context.Instance is ReportTask)
                {
                    template = razorTaskTemplate;
                    frm.clearToolStripButton.Visible = false;
                }

                if (!string.IsNullOrEmpty(template))
                {
                    frm.errorTextBox.Text = "Note that Razor script can be used if the text starts with '@'. Here is a template:\r\n" + template;
                }
                
                if (value != null) frm.sqlTextBox.Text = valueToEdit.ToString();

                if (context.PropertyDescriptor.IsReadOnly) frm.SetReadOnly();

                if (svc.ShowDialog(frm) == DialogResult.OK)
                {
                    value = frm.sqlTextBox.Text;
                }
            }
            return value;
        }