Seal.Forms.TemplateTextEditorForm.SetSamples C# (CSharp) Méthode

SetSamples() public méthode

public SetSamples ( List samples ) : void
samples List
Résultat void
        public void SetSamples(List<string> samples)
        {
            foreach (string sample in samples)
            {
                ToolStripMenuItem item = new ToolStripMenuItem(sample);
                item.Click += new System.EventHandler(this.item_Click);
                samplesMenuItem.DropDownItems.Add(item);
            }
            if (!mainToolStrip.Items.Contains(samplesMenuItem)) mainToolStrip.Items.Add(samplesMenuItem);
        }

Usage Example

        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);
        }
All Usage Examples Of Seal.Forms.TemplateTextEditorForm::SetSamples