Inheritance: System.Windows.Forms.Form
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (svc != null)
            {
                var frm = new TemplateTextEditorForm();

                string template = "";
                string valueToEdit = (value == null ? "" : value.ToString());
                if (context.Instance is ReportView)
                {
                    frm.View = context.Instance as ReportView;
                    if (context.PropertyDescriptor.Name == "CustomTemplate")
                    {
                        if (string.IsNullOrEmpty(valueToEdit)) valueToEdit = frm.View.ViewTemplateText;
                        template = frm.View.ViewTemplateText.Trim();
                        frm.Text = "Edit custom template";
                        frm.TypeForCheckSyntax = frm.View.Template.ForModel ? typeof(ReportModel) : typeof(Report);
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                    else if (context.PropertyDescriptor.Name == "CustomConfiguration")
                    {
                        if (string.IsNullOrEmpty(valueToEdit)) valueToEdit = frm.View.Template.Configuration;
                        template = frm.View.Template.Configuration.Trim();
                        frm.Text = "Edit template configuration";
                        frm.TypeForCheckSyntax = typeof(ReportViewTemplate);
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                    else if (context.PropertyDescriptor.Name == "NVD3Configuration")
                    {
                        frm.Text = frm.View.NVD3ConfigurationParameter.DisplayName;
                        var param = frm.View.Template.Parameters.FirstOrDefault(i => i.Name == Parameter.NVD3ConfigurationParameter);
                        if (param != null) template = param.TextValue;
                        frm.textBox.ConfigurationManager.Language = (string.IsNullOrEmpty(frm.View.NVD3ConfigurationParameter.EditorLanguage) ? "" : frm.View.NVD3ConfigurationParameter.EditorLanguage);
                    }
                }
                else if (context.Instance is ReportTask)
                {
                    template = razorTaskTemplate;
                    frm.TypeForCheckSyntax = typeof(ReportTask);
                    frm.Text = "Edit task script";
                    frm.textBox.ConfigurationManager.Language = "cs";
                    List<string> samples = new List<string>();
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Refresh Data Sources enumerated lists\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\thelper.RefreshRepositoryEnums();\r\n}");
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Load a table from an Excel file, may need ODBC Office 2007 Drivers\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\thelper.LoadTableFromExcel(@\"c:\\temp\\loadFolder\", @\"c:\\temp\\excelFile.xlsx\", \"ExcelTabName\", \"DestinationTableName\", false /* true to load in all connections */);\r\n}");
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Load a table from a CSV file\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\thelper.LoadTableFromCSV(@\"c:\\temp\\loadFolder\", @\"c:\\temp\\aCSVFile.csv\", \"DestinationTableName\", null /* separator may be specified here */, false /* true to load in all connections */);\r\n}");
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Load a table from a source table located in an external data source\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\thelper.LoadTableFromExternalSource(\"SourceConnectionString\", \"SourceSelectStatement\", \"DestinationTableName\", false /* true to load in all connections */, \"OptionalSourceCheckSelect\", \"OptionalDestinationCheckSelect\");\r\n}");
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Execute a program and display Standard Output and Errors\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\thelper.ExecuteProcess(@\"executablePath\");\r\n}");
                    frm.SetSamples(samples);
                }
                else if (context.Instance is ReportOutput)
                {
                    if (context.PropertyDescriptor.Name == "PreScript") template = razorPreOutputTemplate;
                    else if (context.PropertyDescriptor.Name == "PostScript") template = razorPostOutputTemplate;
                    frm.TypeForCheckSyntax = typeof(ReportOutput);
                    frm.Text = "Edit output script";
                    frm.textBox.ConfigurationManager.Language = "cs";
                }
                else if (context.Instance is Parameter)
                {
                    Parameter parameter = context.Instance as Parameter;
                    frm.Text = parameter.DisplayName;
                    frm.textBox.ConfigurationManager.Language = (string.IsNullOrEmpty(parameter.EditorLanguage) ? "" : parameter.EditorLanguage);
                }
                else if (context.Instance.GetType().ToString() == "SealPdfConverter.PdfConverter")
                {
                    string language = "cs";
                    SealPdfConverter converter = SealPdfConverter.Create("");
                    converter.ConfigureTemplateEditor(frm, context.PropertyDescriptor.Name, ref template, ref language);
                    frm.textBox.ConfigurationManager.Language = language;
                }
                else if (context.Instance.GetType().ToString() == "SealExcelConverter.ExcelConverter")
                {
                    string language = "cs";
                    SealExcelConverter converter = SealExcelConverter.Create("");
                    converter.ConfigureTemplateEditor(frm, context.PropertyDescriptor.Name, ref template, ref language);
                    frm.textBox.ConfigurationManager.Language = language;
                }
                else if (context.Instance is ViewFolder)
                {
                    if (context.PropertyDescriptor.Name == "DisplayName")
                    {
                        template = displayNameTemplate;
                        frm.TypeForCheckSyntax = typeof(Report);
                        frm.Text = "Edit display name script";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                }
                else if (context.Instance is ReportElement)
                {
                    ReportElement element = context.Instance as ReportElement;
                    if (context.PropertyDescriptor.Name == "CellScript")
                    {
                        frm.Text = "Edit custom script for the cell";
                        template = razorCellScriptTemplate;
                        frm.TypeForCheckSyntax = typeof(ResultCell);
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                    else if (context.PropertyDescriptor.Name == "SQL")
                    {
                        frm.Text = "Edit custom SQL";
                        frm.textBox.ConfigurationManager.Language = "sql";
                        template = element.RawSQLColumn;
                        List<string> samples = new List<string>();
                        samples.Add(element.RawSQLColumn);
                        if (!string.IsNullOrEmpty(element.SQL) && !samples.Contains(element.SQL)) samples.Add(element.SQL);
                        frm.SetSamples(samples);
                        frm.textBox.LineWrapping.Mode = ScintillaNET.LineWrappingMode.Word;
                    }
                    else if (context.PropertyDescriptor.Name == "CellCss")
                    {
                        frm.Text = "Edit custom CSS";
                        frm.textBox.ConfigurationManager.Language = "css";
                        List<string> samples = new List<string>();
                        samples.Add("text-align:right;");
                        samples.Add("text-align:center;");
                        samples.Add("text-align:left;");
                        samples.Add("font-style:italic;");
                        samples.Add("font-weight:bold;color:red;background-color:yellow;");
                        samples.Add("color:green;text-align:right;|color:black;|font-weight:bold;color:red;text-align:right;");
                        samples.Add("white-space: nowrap;");
                        frm.SetSamples(samples);
                        frm.textBox.LineWrapping.Mode = ScintillaNET.LineWrappingMode.Word;
                    }
                }
                else if (context.Instance is MetaColumn)
                {
                    if (context.PropertyDescriptor.Name == "Name")
                    {
                        frm.Text = "Edit column name";
                        frm.textBox.ConfigurationManager.Language = "sql";
                        frm.textBox.LineWrapping.Mode = ScintillaNET.LineWrappingMode.Word;
                    }
                }
                else if (context.Instance is SealSecurity)
                {
                    if (context.PropertyDescriptor.Name == "Script" || context.PropertyDescriptor.Name == "ProviderScript")
                    {
                        template = ((SealSecurity)context.Instance).ProviderScript;
                        frm.TypeForCheckSyntax = typeof(SecurityUser);
                        frm.Text = "Edit security script";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                }
                else if (context.Instance is MetaTable)
                {
                    if (context.PropertyDescriptor.Name == "DefinitionScript")
                    {
                        template = razorTableDefinitionScriptTemplate;
                        frm.TypeForCheckSyntax = typeof(MetaTable);
                        frm.Text = "Edit the script to define the table";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                    else if (context.PropertyDescriptor.Name == "LoadScript")
                    {
                        template = razorTableLoadScriptTemplate;
                        frm.TypeForCheckSyntax = typeof(MetaTable);
                        frm.Text = "Edit the default script to load the table";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                }
                else if (context.Instance is ReportModel)
                {
                   if (context.PropertyDescriptor.Name == "PreLoadScript")
                    {
                        template = razorModelPreLoadScriptTemplateNoSQL;
                        frm.TypeForCheckSyntax = typeof(ReportModel);
                        frm.Text = "Edit the script executed before table load";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                   else if (context.PropertyDescriptor.Name == "FinalScript")
                   {
                       template = razorTableFinalScriptTemplate;
                       frm.TypeForCheckSyntax = typeof(ReportModel);
                       frm.Text = "Edit the final script executed for the model";
                       frm.textBox.ConfigurationManager.Language = "cs";
                   }
                   else if (context.PropertyDescriptor.Name == "LoadScript")
                   {
                       if (((ReportModel)context.Instance).Source.IsNoSQL)
                       {
                           frm.Text = "Edit the script executed after table load";
                           template = razorModelLoadScriptTemplateNoSQL;
                       }
                       else
                       {
                           frm.Text = "Edit the script to load the table";
                           template = razorModelLoadScriptTemplate;
                       }
                       frm.TypeForCheckSyntax = typeof(ReportModel);
                       frm.textBox.ConfigurationManager.Language = "cs";
                   }
                }

                if (!string.IsNullOrEmpty(template) && string.IsNullOrWhiteSpace(valueToEdit))
                {
                    valueToEdit = template;
                }

                //Reset button
                if (!string.IsNullOrEmpty(template) && !context.PropertyDescriptor.IsReadOnly) frm.SetResetText(template);

                frm.textBox.Text = valueToEdit.ToString();

                if (context.PropertyDescriptor.IsReadOnly)
                {
                    frm.textBox.IsReadOnly = true;
                    frm.okToolStripButton.Visible = false;
                    frm.cancelToolStripButton.Text = "Close";
                }
                frm.checkSyntaxToolStripButton.Visible = (frm.TypeForCheckSyntax != null);

                if (svc.ShowDialog(frm) == DialogResult.OK)
                {
                    if (frm.textBox.Text.Trim() != template || string.IsNullOrEmpty(template)) value = frm.textBox.Text;
                    else if (frm.textBox.Text.Trim() == template && !string.IsNullOrEmpty(template)) value = "";
                }
            }
            return value;
        }
Exemplo n.º 2
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (svc != null)
            {
                var frm = new TemplateTextEditorForm();

                string template    = "";
                string valueToEdit = (value == null ? "" : value.ToString());
                if (context.Instance is ReportView)
                {
                    frm.View = context.Instance as ReportView;
                    if (context.PropertyDescriptor.Name == "CustomTemplate")
                    {
                        if (string.IsNullOrEmpty(valueToEdit))
                        {
                            valueToEdit = frm.View.ViewTemplateText;
                        }
                        template = frm.View.ViewTemplateText.Trim();
                        frm.Text = "Edit custom template";
                        frm.TypeForCheckSyntax = frm.View.Template.ForModel ? typeof(ReportModel) : typeof(Report);
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                    else if (context.PropertyDescriptor.Name == "CustomConfiguration")
                    {
                        if (string.IsNullOrEmpty(valueToEdit))
                        {
                            valueToEdit = frm.View.Template.Configuration;
                        }
                        template = frm.View.Template.Configuration.Trim();
                        frm.Text = "Edit template configuration";
                        frm.TypeForCheckSyntax = typeof(ReportViewTemplate);
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                }
                else if (context.Instance is ReportTask)
                {
                    template = razorTaskTemplate;
                    frm.TypeForCheckSyntax = typeof(ReportTask);
                    frm.Text = "Edit task script";
                    frm.textBox.ConfigurationManager.Language = "cs";
                    frm.TextToAddForCheck = ((ReportTask)context.Instance).Report.TasksScript + "\r\n" + ((ReportTask)context.Instance).Source.TasksScript;
                    List <string> samples = new List <string>();
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Refresh Data Sources enumerated lists\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\thelper.RefreshRepositoryEnums();\r\n}");
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Load a table from an Excel file, may need ODBC Office 2007 Drivers\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\thelper.LoadTableFromExcel(@\"c:\\temp\\loadFolder\", @\"c:\\temp\\excelFile.xlsx\", \"ExcelTabName\", \"DestinationTableName\", false /* true to load in all connections */);\r\n}");
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Load a table from a CSV file\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\thelper.LoadTableFromCSV(@\"c:\\temp\\loadFolder\", @\"c:\\temp\\aCSVFile.csv\", \"DestinationTableName\", null /* separator may be specified here */, false /* true to load in all connections */);\r\n}");
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Load a table from a source table located in an external data source\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\thelper.LoadTableFromExternalSource(\"SourceConnectionString\", \"SourceSelectStatement\", \"DestinationTableName\", false /* true to load in all connections */, \"OptionalSourceCheckSelect\", \"OptionalDestinationCheckSelect\");\r\n}");
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Query or update the database\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\tstring name = (string) helper.ExecuteScalar(\"select LastName from employees\");\r\n\thelper.LogMessage(\"Name=\" + name);\r\n\thelper.ExecuteNonQuery(\"update employees set LastName = '' where 1=0\", false /* true to execute in all connections */);\r\n}");
                    samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@{\r\n\t//Execute a program and display Standard Output and Errors\r\n\tReportTask task = Model;\r\n\tvar helper = new TaskHelper(task);\r\n\thelper.ExecuteProcess(@\"executablePath\");\r\n}");
                    frm.SetSamples(samples);
                }
                else if (context.Instance is ReportOutput)
                {
                    if (context.PropertyDescriptor.Name == "PreScript")
                    {
                        template = razorPreOutputTemplate;
                    }
                    else if (context.PropertyDescriptor.Name == "PostScript")
                    {
                        template = razorPostOutputTemplate;
                    }
                    frm.TypeForCheckSyntax = typeof(ReportOutput);
                    frm.Text = "Edit output script";
                    frm.textBox.ConfigurationManager.Language = "cs";
                }
                else if (context.Instance is Parameter)
                {
                    Parameter parameter = context.Instance as Parameter;
                    template = parameter.ConfigValue;
                    frm.Text = parameter.DisplayName;
                    frm.textBox.ConfigurationManager.Language = (string.IsNullOrEmpty(parameter.EditorLanguage) ? "" : parameter.EditorLanguage);
                }
                else if (context.Instance.GetType().ToString() == "SealPdfConverter.PdfConverter")
                {
                    string           language  = "cs";
                    SealPdfConverter converter = SealPdfConverter.Create("");
                    converter.ConfigureTemplateEditor(frm, context.PropertyDescriptor.Name, ref template, ref language);
                    frm.textBox.ConfigurationManager.Language = language;
                }
                else if (context.Instance.GetType().ToString() == "SealExcelConverter.ExcelConverter")
                {
                    string             language  = "cs";
                    SealExcelConverter converter = SealExcelConverter.Create("");
                    converter.ConfigureTemplateEditor(frm, context.PropertyDescriptor.Name, ref template, ref language);
                    frm.textBox.ConfigurationManager.Language = language;
                }
                else if (context.Instance is ViewFolder)
                {
                    if (context.PropertyDescriptor.Name == "DisplayName")
                    {
                        template = displayNameTemplate;
                        frm.TypeForCheckSyntax = typeof(Report);
                        frm.Text = "Edit display name script";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                    else if (context.PropertyDescriptor.Name == "InitScript")
                    {
                        template = razorInitScriptTemplate;
                        frm.TypeForCheckSyntax = typeof(Report);
                        frm.Text = "Edit the script executed when the report is initialized";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                }
                else if (context.Instance is ReportElement)
                {
                    ReportElement element = context.Instance as ReportElement;
                    if (context.PropertyDescriptor.Name == "CellScript")
                    {
                        frm.Text = "Edit custom script for the cell";
                        template = razorCellScriptTemplate;
                        frm.TypeForCheckSyntax = typeof(ResultCell);
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                    else if (context.PropertyDescriptor.Name == "SQL")
                    {
                        frm.Text = "Edit custom SQL";
                        frm.textBox.ConfigurationManager.Language = "sql";
                        template = element.RawSQLColumn;
                        List <string> samples = new List <string>();
                        samples.Add(element.RawSQLColumn);
                        if (!string.IsNullOrEmpty(element.SQL) && !samples.Contains(element.SQL))
                        {
                            samples.Add(element.SQL);
                        }
                        frm.SetSamples(samples);
                        frm.textBox.LineWrapping.Mode = ScintillaNET.LineWrappingMode.Word;
                    }
                    else if (context.PropertyDescriptor.Name == "CellCss")
                    {
                        frm.Text = "Edit custom CSS";
                        frm.textBox.ConfigurationManager.Language = "css";
                        List <string> samples = new List <string>();
                        samples.Add("text-align:right;");
                        samples.Add("text-align:center;");
                        samples.Add("text-align:left;");
                        samples.Add("font-style:italic;");
                        samples.Add("font-weight:bold;color:red;background-color:yellow;");
                        samples.Add("color:green;text-align:right;|color:black;|font-weight:bold;color:red;text-align:right;");
                        samples.Add("white-space: nowrap;");
                        frm.SetSamples(samples);
                        frm.textBox.LineWrapping.Mode = ScintillaNET.LineWrappingMode.Word;
                    }
                }
                else if (context.Instance is MetaColumn)
                {
                    if (context.PropertyDescriptor.Name == "Name")
                    {
                        frm.Text = "Edit column name";
                        frm.textBox.ConfigurationManager.Language = "sql";
                        frm.textBox.LineWrapping.Mode             = ScintillaNET.LineWrappingMode.Word;
                    }
                }
                else if (context.Instance is SealSecurity)
                {
                    if (context.PropertyDescriptor.Name == "Script" || context.PropertyDescriptor.Name == "ProviderScript")
                    {
                        template = ((SealSecurity)context.Instance).ProviderScript;
                        frm.TypeForCheckSyntax = typeof(SecurityUser);
                        frm.Text = "Edit security script";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                }
                else if (context.Instance is MetaTable)
                {
                    if (context.PropertyDescriptor.Name == "DefinitionScript")
                    {
                        template = razorTableDefinitionScriptTemplate;
                        frm.TypeForCheckSyntax = typeof(MetaTable);
                        frm.Text = "Edit the script to define the table";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                    else if (context.PropertyDescriptor.Name == "LoadScript")
                    {
                        template = razorTableLoadScriptTemplate;
                        frm.TypeForCheckSyntax = typeof(MetaTable);
                        frm.Text = "Edit the default script to load the table";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                }
                else if (context.Instance is ReportModel)
                {
                    if (context.PropertyDescriptor.Name == "PreLoadScript")
                    {
                        template = razorModelPreLoadScriptTemplateNoSQL;
                        frm.TypeForCheckSyntax = typeof(ReportModel);
                        frm.Text = "Edit the script executed before table load";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                    else if (context.PropertyDescriptor.Name == "FinalScript")
                    {
                        template = razorTableFinalScriptTemplate;
                        frm.TypeForCheckSyntax = typeof(ReportModel);
                        frm.Text = "Edit the final script executed for the model";
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                    else if (context.PropertyDescriptor.Name == "LoadScript")
                    {
                        if (((ReportModel)context.Instance).Source.IsNoSQL)
                        {
                            frm.Text = "Edit the script executed after table load";
                            template = razorModelLoadScriptTemplateNoSQL;
                        }
                        else
                        {
                            frm.Text = "Edit the script to load the table";
                            template = razorModelLoadScriptTemplate;
                        }
                        frm.TypeForCheckSyntax = typeof(ReportModel);
                        frm.textBox.ConfigurationManager.Language = "cs";
                    }
                }
                else if (context.Instance is TasksFolder || context.Instance is MetaSource)
                {
                    template = razorTasksTemplate;
                    frm.TypeForCheckSyntax = typeof(ReportTask);
                    frm.Text = "Edit the script that will be added to all task scripts";
                    frm.textBox.ConfigurationManager.Language = "cs";
                }

                if (!string.IsNullOrEmpty(template) && string.IsNullOrWhiteSpace(valueToEdit) && !context.PropertyDescriptor.IsReadOnly)
                {
                    valueToEdit = template;
                }

                //Reset button
                if (!string.IsNullOrEmpty(template) && !context.PropertyDescriptor.IsReadOnly)
                {
                    frm.SetResetText(template);
                }

                frm.textBox.Text = valueToEdit.ToString();

                if (context.PropertyDescriptor.IsReadOnly)
                {
                    frm.textBox.IsReadOnly         = true;
                    frm.okToolStripButton.Visible  = false;
                    frm.cancelToolStripButton.Text = "Close";
                }
                frm.checkSyntaxToolStripButton.Visible = (frm.TypeForCheckSyntax != null);

                if (svc.ShowDialog(frm) == DialogResult.OK)
                {
                    if (frm.textBox.Text.Trim() != template || string.IsNullOrEmpty(template))
                    {
                        value = frm.textBox.Text;
                    }
                    else if (frm.textBox.Text.Trim() == template && !string.IsNullOrEmpty(template))
                    {
                        value = "";
                    }
                }
            }
            return(value);
        }
        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;
            }
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (svc != null)
            {
                var frm = new TemplateTextEditorForm();

                string template    = "";
                string valueToEdit = (value == null ? "" : value.ToString());
                if (context.Instance is ReportView)
                {
                    var view = context.Instance as ReportView;
                    if (context.PropertyDescriptor.Name == "CustomTemplate")
                    {
                        if (string.IsNullOrEmpty(valueToEdit))
                        {
                            valueToEdit = view.ViewTemplateText;
                        }
                        template = view.Template.Text.Trim();
                        frm.Text = "Edit custom template";
                        frm.ObjectForCheckSyntax = view.Report;
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                    else if (context.PropertyDescriptor.Name == "CustomConfiguration")
                    {
                        if (string.IsNullOrEmpty(valueToEdit))
                        {
                            valueToEdit = view.Template.Configuration;
                        }
                        template = view.Template.Configuration.Trim();
                        frm.Text = "Edit template configuration";
                        frm.ObjectForCheckSyntax = view.Template;
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                }
                else if (context.Instance is ReportViewPartialTemplate)
                {
                    var pt           = context.Instance as ReportViewPartialTemplate;
                    var templateText = pt.View.Template.GetPartialTemplateText(pt.Name);
                    if (string.IsNullOrEmpty(valueToEdit))
                    {
                        valueToEdit = templateText;
                    }
                    template = templateText;
                    frm.Text = "Edit custom partial template";
                    frm.ObjectForCheckSyntax = pt.View.Template.ForReportModel ? (object)pt.View.Model : (object)pt.View;
                    ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                }
                else if (context.Instance is ReportTask)
                {
                    template = razorTaskTemplate;
                    frm.ObjectForCheckSyntax = context.Instance;
                    frm.Text = "Edit task script";
                    ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    List <string> samples = new List <string>();
                    foreach (var sample in tasksSamples)
                    {
                        samples.Add("@using Seal.Model\r\n@using Seal.Helpers\r\n@using System.Data\r\n@{\r\n\t//" + sample.Item1 + "\r\n\t" + sample.Item2 + "}\r\n|" + sample.Item1);
                    }
                    frm.SetSamples(samples);
                }
                else if (context.Instance is ReportOutput)
                {
                    if (context.PropertyDescriptor.Name == "PreScript")
                    {
                        template = razorPreOutputTemplate;
                    }
                    else if (context.PropertyDescriptor.Name == "PostScript")
                    {
                        template = razorPostOutputTemplate;
                    }
                    frm.ObjectForCheckSyntax = context.Instance;
                    frm.Text = "Edit output script";
                    ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                }
                else if (context.Instance is Parameter || context.Instance is ParametersEditor)
                {
                    Parameter parameter = context.Instance is Parameter ? context.Instance as Parameter : ((ParametersEditor)context.Instance).GetParameter(context.PropertyDescriptor.Name);
                    if (parameter != null)
                    {
                        template = parameter.ConfigValue;
                        frm.Text = parameter.DisplayName;
                        ScintillaHelper.Init(frm.textBox, (string.IsNullOrEmpty(parameter.EditorLanguage) ? "" : parameter.EditorLanguage));
                        if (parameter.TextSamples != null)
                        {
                            frm.SetSamples(parameter.TextSamples.ToList());
                        }
                    }
                }
                else if (context.Instance.GetType().ToString() == "SealPdfConverter.PdfConverter")
                {
                    string           language  = "cs";
                    SealPdfConverter converter = (SealPdfConverter)context.Instance;
                    converter.ConfigureTemplateEditor(frm, context.PropertyDescriptor.Name, ref template, ref language);
                    ScintillaHelper.Init(frm.textBox, language);
                }
                else if (context.Instance.GetType().ToString() == "SealExcelConverter.ExcelConverter")
                {
                    string             language  = "cs";
                    SealExcelConverter converter = (SealExcelConverter)context.Instance;
                    converter.ConfigureTemplateEditor(frm, context.PropertyDescriptor.Name, ref template, ref language);
                    ScintillaHelper.Init(frm.textBox, language);
                }
                else if (context.Instance is ViewFolder)
                {
                    if (context.PropertyDescriptor.Name == "DisplayName")
                    {
                        template = displayNameTemplate;
                        frm.ObjectForCheckSyntax = ((ReportComponent)context.Instance).Report;
                        frm.Text = "Edit display name script";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                    else if (context.PropertyDescriptor.Name == "InitScript")
                    {
                        template = razorInitScriptTemplate;
                        frm.ObjectForCheckSyntax = ((ReportComponent)context.Instance).Report;
                        frm.Text = "Edit the script executed when the report is initialized";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                }
                else if (context.Instance is ReportElement)
                {
                    ReportElement element = context.Instance as ReportElement;
                    if (context.PropertyDescriptor.Name == "CellScript")
                    {
                        frm.Text = "Edit custom script for the cell";
                        template = razorCellScriptTemplate;
                        List <string> samples = new List <string>();
                        foreach (var sample in razorCellScriptSamples)
                        {
                            samples.Add("@using Seal.Model\r\n@{\r\n\t//" + sample.Item1 + "\r\n\tResultCell cell=Model;\r\n\tReportElement element = cell.Element;\r\n\tReportModel reportModel = element.Model;\r\n\tReport report = reportModel.Report;\r\n\t" + sample.Item2 + "}\r\n|" + sample.Item1);
                        }
                        frm.SetSamples(samples);

                        frm.ObjectForCheckSyntax = new ResultCell();
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                    else if (context.PropertyDescriptor.Name == "SQL")
                    {
                        frm.Text = "Edit custom SQL";
                        ScintillaHelper.Init(frm.textBox, Lexer.Sql);
                        template = element.RawSQLColumn;
                        List <string> samples = new List <string>();
                        samples.Add(element.RawSQLColumn);
                        if (!string.IsNullOrEmpty(element.SQL) && !samples.Contains(element.SQL))
                        {
                            samples.Add(element.SQL);
                        }
                        frm.SetSamples(samples);
                        frm.textBox.WrapMode = WrapMode.Word;
                    }
                    else if (context.PropertyDescriptor.Name == "CellCss")
                    {
                        frm.Text = "Edit custom CSS";
                        ScintillaHelper.Init(frm.textBox, Lexer.Css);
                        List <string> samples = new List <string>();
                        samples.Add("text-align:right;");
                        samples.Add("text-align:center;");
                        samples.Add("text-align:left;");
                        samples.Add("font-style:italic;");
                        samples.Add("font-weight:bold;color:red;background-color:yellow;");
                        samples.Add("color:green;text-align:right;|color:black;|font-weight:bold;color:red;text-align:right;");
                        samples.Add("white-space: nowrap;");
                        frm.SetSamples(samples);
                        frm.textBox.WrapMode = WrapMode.Word;
                    }
                }
                else if (context.Instance is MetaColumn)
                {
                    if (context.PropertyDescriptor.Name == "Name")
                    {
                        frm.Text = "Edit column name";
                        ScintillaHelper.Init(frm.textBox, Lexer.Sql);
                        frm.textBox.WrapMode = WrapMode.Word;
                    }
                }
                else if (context.Instance is SealSecurity)
                {
                    if (context.PropertyDescriptor.Name == "Script" || context.PropertyDescriptor.Name == "ProviderScript")
                    {
                        template = ((SealSecurity)context.Instance).ProviderScript;
                        frm.ObjectForCheckSyntax = new SecurityUser(null);
                        frm.Text = "Edit security script";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                }
                else if (context.Instance is MetaTable)
                {
                    if (context.PropertyDescriptor.Name == "DefinitionScript")
                    {
                        template = razorTableDefinitionScriptTemplate;
                        frm.ObjectForCheckSyntax = context.Instance;
                        frm.Text = "Edit the script to define the table";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                    else if (context.PropertyDescriptor.Name == "LoadScript")
                    {
                        template = razorTableLoadScriptTemplate;
                        frm.ObjectForCheckSyntax = context.Instance;
                        frm.Text = "Edit the default script to load the table";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                }
                else if (context.Instance is ReportModel)
                {
                    if (context.PropertyDescriptor.Name == "PreLoadScript")
                    {
                        template = razorModelPreLoadScriptTemplateNoSQL;
                        frm.ObjectForCheckSyntax = context.Instance;
                        frm.Text = "Edit the script executed before table load";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                    else if (context.PropertyDescriptor.Name == "FinalScript")
                    {
                        template = razorTableFinalScriptTemplate;
                        frm.ObjectForCheckSyntax = context.Instance;
                        frm.Text = "Edit the final script executed for the model";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                    else if (context.PropertyDescriptor.Name == "LoadScript")
                    {
                        if (((ReportModel)context.Instance).Source.IsNoSQL)
                        {
                            frm.Text = "Edit the script executed after table load";
                            template = razorModelLoadScriptTemplateNoSQL;
                        }
                        else
                        {
                            frm.Text = "Edit the script to load the table";
                            template = razorModelLoadScriptTemplate;
                        }
                        frm.ObjectForCheckSyntax = context.Instance;
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                }
                else if (context.Instance is MetaSource && context.PropertyDescriptor.Name == "InitScript")
                {
                    template = razorSourceInitScriptTemplate;
                    frm.ObjectForCheckSyntax = context.Instance;
                    frm.Text = "Edit the init script of the source";
                    ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                }
                else if (context.Instance is TasksFolder)
                {
                    if (context.PropertyDescriptor.Name == "TasksScript")
                    {
                        template = razorTasksTemplate;
                        frm.ObjectForCheckSyntax = new ReportTask();
                        if (CurrentEntity is Report)
                        {
                            frm.ScriptHeader  = ((Report)CurrentEntity).Repository.Configuration.CommonScriptsHeader;
                            frm.ScriptHeader += ((Report)CurrentEntity).Repository.Configuration.TasksScript;
                            frm.ScriptHeader += ((Report)CurrentEntity).CommonScriptsHeader;
                        }
                        frm.Text = "Edit the script that will be added to all task scripts";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                }
                else if (context.Instance is CommonScript)
                {
                    template = CommonScript.RazorTemplate;
                    frm.Text = "Edit the script that will be added to all scripts executed for the report.";
                    if (CurrentEntity is SealServerConfiguration)
                    {
                        //common script from configuration
                        frm.ScriptHeader = ((SealServerConfiguration)CurrentEntity).GetCommonScriptsHeader((CommonScript)context.Instance);
                    }
                    if (CurrentEntity is Report)
                    {
                        //common script from report
                        frm.ScriptHeader  = ((Report)CurrentEntity).Repository.Configuration.CommonScriptsHeader;
                        frm.ScriptHeader += ((Report)CurrentEntity).GetCommonScriptsHeader((CommonScript)context.Instance);
                    }
                    frm.ObjectForCheckSyntax = CurrentEntity;
                    ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                }
                else if (context.Instance is SealServerConfiguration)
                {
                    //use report tag to store current config
                    var report = new Report();
                    report.Tag = context.Instance;
                    if (context.PropertyDescriptor.Name == "InitScript")
                    {
                        template = razorConfigurationInitScriptTemplate;
                        frm.ObjectForCheckSyntax = report;
                        frm.Text = "Edit the root init script";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                    else if (context.PropertyDescriptor.Name == "TasksScript")
                    {
                        template                 = razorTasksTemplate;
                        frm.ScriptHeader         = ((SealServerConfiguration)context.Instance).CommonScriptsHeader;
                        frm.ObjectForCheckSyntax = new ReportTask();
                        frm.Text                 = "Edit the script that will be added to all task scripts";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                    else if (context.PropertyDescriptor.Name == "ReportCreationScript")
                    {
                        template = razorConfigurationReportCreationScriptTemplate;
                        frm.ObjectForCheckSyntax = report;
                        frm.Text = "Edit the script executed when a new report is created";
                        ScintillaHelper.Init(frm.textBox, Lexer.Cpp);
                    }
                }

                if (!string.IsNullOrEmpty(template) && string.IsNullOrWhiteSpace(valueToEdit) && !context.PropertyDescriptor.IsReadOnly)
                {
                    valueToEdit = template;
                }

                //Reset button
                if (!string.IsNullOrEmpty(template) && !context.PropertyDescriptor.IsReadOnly)
                {
                    frm.SetResetText(template);
                }

                frm.textBox.Text = valueToEdit.ToString();

                if (context.PropertyDescriptor.IsReadOnly)
                {
                    frm.textBox.ReadOnly           = true;
                    frm.okToolStripButton.Visible  = false;
                    frm.cancelToolStripButton.Text = "Close";
                }
                frm.checkSyntaxToolStripButton.Visible = (frm.ObjectForCheckSyntax != null);

                if (svc.ShowDialog(frm) == DialogResult.OK)
                {
                    if (string.IsNullOrEmpty(template))
                    {
                        template = "";
                    }

                    if (frm.textBox.Text.Trim() != template.Trim() || string.IsNullOrEmpty(template))
                    {
                        value = frm.textBox.Text;
                    }
                    else if (frm.textBox.Text.Trim() == template.Trim() && !string.IsNullOrEmpty(template))
                    {
                        value = "";
                    }
                }
            }
            return(value);
        }
Exemplo n.º 5
0
 public virtual void ConfigureTemplateEditor(TemplateTextEditorForm frm, string propertyName, ref string template, ref string language) { }