public TemplateTextEditorForm() { InitializeComponent(); ScintillaHelper.Init(textBox, Lexer.Html); toolStripStatusLabel.Image = null; ShowIcon = true; Icon = Repository.ProductIcon; this.Load += TemplateTextEditorForm_Load; this.FormClosed += TemplateTextEditorForm_FormClosed; this.textBox.KeyDown += TextBox_KeyDown; this.KeyDown += TextBox_KeyDown; }
public SQLEditorForm() { InitializeComponent(); ScintillaHelper.Init(sqlTextBox, Lexer.Sql); toolStripStatusLabel.Image = null; ShowIcon = true; Icon = Repository.ProductIcon; this.Load += SQLEditorForm_Load; this.FormClosed += SQLEditorForm_FormClosed; this.FormClosing += SQLEditorForm_FormClosing; this.sqlTextBox.KeyDown += TextBox_KeyDown; this.KeyDown += TextBox_KeyDown; }
public void InitLexer(Lexer lex) { ScintillaHelper.Init(sqlTextBox, lex); }
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); }
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 RestrictionsPanel() { InitializeComponent(); ScintillaHelper.Init(restrictionsTextBox, Lexer.Container, false); }