| @@ -0,0 +1,64 @@ | ||
| using FastReport.Dialog; | ||
| using System.Text; | ||
| using static FastReport.Web.Constants; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| public partial class Dialog | ||
| { | ||
| private void ComboBoxChange(ComboBoxControl cb, int index) | ||
| { | ||
| cb.SelectedIndex = index; | ||
| ControlFilterRefresh(cb); | ||
| cb.OnSelectedIndexChanged(null); | ||
| } | ||
|
|
||
| private string GetComboBoxHtml(ComboBoxControl control) | ||
| { | ||
| if (control.Items.Count == 0) | ||
| { | ||
| control.FillData(); | ||
| ControlFilterRefresh(control); | ||
| } | ||
| else | ||
| { | ||
| control.SelectedItem = control.Items[control.SelectedIndex]; | ||
| control.Text = control.SelectedItem.ToString(); | ||
| } | ||
|
|
||
| string id = GetControlID(control); | ||
| string html = string.Format("<select style=\"{0}\" name=\"{1}\" onchange=\"{2}\" id=\"{3}\">{4}</select>", | ||
| // style | ||
| GetComboBoxStyle(control), | ||
| // name | ||
| control.Name, | ||
| // onclick | ||
| GetEvent(ONCHANGE, control, SILENT_RELOAD, $"document.getElementById('{id}').selectedIndex"), | ||
| // title | ||
| id, | ||
| GetComboBoxItems(control)//control.Text | ||
| ); | ||
| control.FilterData(); | ||
| return html; | ||
| } | ||
|
|
||
| private string GetComboBoxItems(ComboBoxControl control) | ||
| { | ||
| StringBuilder sb = new StringBuilder(); | ||
| for (int i = 0; i < control.Items.Count; i++) | ||
| { | ||
| sb.Append(string.Format("<option {0} value=\"{1}\">{2}</option>", | ||
| i == control.SelectedIndex ? "selected" : "", | ||
| control.Items[i], | ||
| control.Items[i])); | ||
| } | ||
| return sb.ToString(); | ||
| } | ||
|
|
||
| private string GetComboBoxStyle(ComboBoxControl control) | ||
| { | ||
| return $"{GetControlPosition(control)} {GetControlFont(control.Font)}"; | ||
| } | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,51 @@ | ||
| using System; | ||
| using FastReport.Dialog; | ||
| using static FastReport.Web.Constants; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| public partial class Dialog | ||
| { | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets date time format in javascript type="date" | ||
| /// </summary> | ||
| public string DateTimePickerFormat { | ||
| get; | ||
| set; | ||
| } = DEFAULT_DATE_TIME_PICKER_FORMAT; | ||
|
|
||
|
|
||
| private void DateTimePickerChange(DateTimePickerControl dp, string value) | ||
| { | ||
| dp.Value = DateTime.Parse(value); | ||
| dp.OnValueChanged(null); | ||
| } | ||
|
|
||
| private string GetDateTimePickerHtml(DateTimePickerControl control) | ||
| { | ||
| control.FillData(); | ||
| ControlFilterRefresh(control); | ||
| string id = GetControlID(control); | ||
|
|
||
| return string.Format("<input style=\"{0}\" type=\"date\" name=\"{1}\" value=\"{2}\" onchange=\"{3}\" id=\"{4}\"/>", | ||
| // style | ||
| GetDateTimePickerStyle(control), | ||
| // name | ||
| control.Name, | ||
| // value | ||
| control.Value.ToString(DateTimePickerFormat), | ||
| // onclick | ||
| GetEvent(ONCHANGE, control, SILENT_RELOAD, $"document.getElementById('{id}').value"), | ||
| // title | ||
| id | ||
| ); | ||
| } | ||
|
|
||
| private string GetDateTimePickerStyle(DateTimePickerControl control) | ||
| { | ||
| return $"{GetControlPosition(control)} {GetControlFont(control.Font)}"; | ||
| } | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,23 @@ | ||
| using FastReport.Dialog; | ||
| using System.Text; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| public partial class Dialog | ||
| { | ||
| private string GetGroupBoxHtml(GroupBoxControl groupBox) | ||
| { | ||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| string s = $"<div style=\"{GetControlPosition(groupBox)}\">"; | ||
| sb.Append(s); | ||
|
|
||
| sb.Append($"<div id=\"{groupBox.Name}\" style=\"position:relative;\">"); | ||
|
|
||
| GetComponentHtml(sb, groupBox.Controls); | ||
| sb.Append("</div></div>"); | ||
| return sb.ToString(); | ||
| } | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,18 @@ | ||
| using FastReport.Dialog; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| public partial class Dialog | ||
| { | ||
| private string GetLabelHtml(LabelControl control) | ||
| { | ||
| return $"<div style=\"{GetLabelStyle(control)}\">{control.Text}</div>"; | ||
| } | ||
|
|
||
| private string GetLabelStyle(LabelControl control) | ||
| { | ||
| return $"{GetControlPosition(control)} {GetControlFont(control.Font)} {GetControlAlign(control)}"; | ||
| } | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,59 @@ | ||
| using FastReport.Dialog; | ||
| using System.Text; | ||
| using static FastReport.Web.Constants; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| public partial class Dialog | ||
| { | ||
| private void ListBoxChange(ListBoxControl cb, int index) | ||
| { | ||
| cb.SelectedIndex = index; | ||
| ControlFilterRefresh(cb); | ||
| cb.OnSelectedIndexChanged(null); | ||
| } | ||
|
|
||
| private string GetListBoxHtml(ListBoxControl control) | ||
| { | ||
| if (control.Items.Count == 0) | ||
| { | ||
| control.FillData(); | ||
| ControlFilterRefresh(control); | ||
| } | ||
| string id = GetControlID(control); | ||
| string html = string.Format("<select style=\"{0}\" name=\"{1}\" size=\"{2}\" onchange=\"{3}\" id=\"{4}\">{5}</select>", | ||
| // style | ||
| GetListBoxStyle(control), | ||
| // name | ||
| control.Name, | ||
| // size | ||
| control.Items.Count.ToString(), | ||
| // onclick | ||
| GetEvent(ONCHANGE, control, DIALOG, $"document.getElementById('{id}').selectedIndex"), | ||
| // title | ||
| id, | ||
| GetListBoxItems(control)//control.Text | ||
| ); | ||
| control.FilterData(); | ||
| return html; | ||
| } | ||
|
|
||
| private string GetListBoxItems(ListBoxControl control) | ||
| { | ||
| StringBuilder sb = new StringBuilder(); | ||
| for (int i = 0; i < control.Items.Count; i++) | ||
| { | ||
| sb.Append(string.Format("<option {0}>{1}</option>", | ||
| i == control.SelectedIndex ? "selected" : "", | ||
| control.Items[i])); | ||
| } | ||
| return sb.ToString(); | ||
| } | ||
|
|
||
| private string GetListBoxStyle(ListBoxControl control) | ||
| { | ||
| return $"{GetControlPosition(control)} {GetControlFont(control.Font)}"; | ||
| } | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,49 @@ | ||
| using FastReport.Dialog; | ||
| using System; | ||
| using System.Globalization; | ||
| using System.Text; | ||
| using static FastReport.Web.Constants; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| public partial class Dialog | ||
| { | ||
|
|
||
| private void MonthCalendarChange(MonthCalendarControl dp, string value) | ||
| { | ||
| dp.SelectionStart = DateTime.ParseExact(value, "d", CultureInfo.InvariantCulture); | ||
| } | ||
|
|
||
| private string GetMonthCalendarHtml(MonthCalendarControl control) | ||
| { | ||
| control.FillData(); | ||
| ControlFilterRefresh(control); | ||
| string id = GetControlID(control); | ||
| StringBuilder html = new StringBuilder(); | ||
| string selectedDate = control.SelectionStart.Month.ToString() + "/" + control.SelectionStart.Day.ToString() + "/" + control.SelectionStart.Year.ToString(); | ||
| string ev = GetEvent(ONCHANGE, control, DIALOG, $"document.getElementById('{id}').value"); | ||
| html.Append(String.Format("<div class=\"{0}\" style=\"{1}\" onchange=\"{2}\" id=\"{3}\"></div>", | ||
| "", | ||
| GetMonthCalendarStyle(control), | ||
| ev, | ||
| id | ||
| )); | ||
| html.Append("<script>$(function() {$( \"#").Append(id).AppendLine("\" ).datepicker();"); | ||
| html.Append("$( \"#").Append(id).Append("\" ).datepicker( \"option\", \"dateFormat\", \""). | ||
| Append(DEFAULT_DATE_TIME_PICKER_FORMAT).AppendLine("\" );"); | ||
| html.Append("$( \"#").Append(id).Append(String.Format("\" ).datepicker( \"setDate\", \"{0}\", \"", selectedDate)). | ||
| Append(DEFAULT_DATE_TIME_PICKER_FORMAT).AppendLine("\" );"); | ||
|
|
||
| html.Append("});</script>"); | ||
|
|
||
| //control.FilterData(); | ||
| return html.ToString(); | ||
| } | ||
|
|
||
| private string GetMonthCalendarStyle(MonthCalendarControl control) | ||
| { | ||
| return $"{GetControlPosition(control)} {GetControlFont(control.Font)}"; | ||
| } | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,34 @@ | ||
| using FastReport.Dialog; | ||
| using System.Drawing; | ||
| using System.IO; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| public partial class Dialog | ||
| { | ||
|
|
||
| private string GetPictureBoxHtml(PictureBoxControl control) | ||
| { | ||
| return $"<div style=\"{GetPictureBoxStyle(control)}\"></div>"; | ||
| } | ||
|
|
||
| private string GetPictureBoxStyle(PictureBoxControl control) | ||
| { | ||
| return $"{GetControlPosition(control)} {GetControlAlign(control)} {GetPictureBoxURL(control.Image)} padding:0;margin:0;"; | ||
| } | ||
|
|
||
| private string GetPictureBoxURL(Image image) | ||
| { | ||
| int hash = image.GetHashCode(); | ||
| MemoryStream picStream = new MemoryStream(); | ||
| image.Save(picStream, image.RawFormat); | ||
| byte[] imageArray = new byte[picStream.Length]; | ||
| picStream.Position = 0; | ||
| picStream.Read(imageArray, 0, (int)picStream.Length); | ||
| WebReport.PictureCache.Add(hash.ToString(), imageArray); | ||
|
|
||
| string url = WebUtils.ToUrl(FastReportGlobal.FastReportOptions.RouteBasePath, $"preview.getPicture?"); | ||
| return $" background: url('{url}reportId={WebReport.ID}&pictureId={hash}') no-repeat !important;-webkit-print-color-adjust:exact;"; | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,45 @@ | ||
| using FastReport.Dialog; | ||
| using static FastReport.Web.Constants; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| public partial class Dialog | ||
| { | ||
|
|
||
| private void RadioButtonClick(RadioButtonControl rb, string data) | ||
| { | ||
| rb.Checked = data == "true"; | ||
| rb.FilterData(); | ||
| rb.OnClick(null); | ||
| } | ||
|
|
||
| private string GetRadioButtonHtml(RadioButtonControl control) | ||
| { | ||
| string id = GetControlID(control); | ||
| return string.Format("<span style=\"{0}\"><input style=\"vertical-align:middle;width:{1}px;border:none;padding:0;margin:0 5px 0 0;\" type=\"radio\" name=\"{2}\" value=\"{3}\" onclick=\"{4}\" id=\"{5}\" {6}/><label style=\"{9}\" for=\"{7}\">{8}</label></span>", | ||
| // style | ||
| GetRadioButtonStyle(control), | ||
| // width | ||
| Zoom(10), | ||
| // name | ||
| control.Name, | ||
| // value | ||
| control.Text, | ||
| // onclick | ||
| GetEvent(ONCLICK, control, SILENT_RELOAD, $"document.getElementById('{id}').checked"), | ||
| // title | ||
| id, | ||
| control.Checked ? "checked" : "", | ||
| id, | ||
| control.Text, | ||
| GetControlFont(control.Font) | ||
| ); | ||
| } | ||
|
|
||
| private string GetRadioButtonStyle(RadioButtonControl control) | ||
| { | ||
| return $"{GetControlPosition(control)} {GetControlFont(control.Font)}"; | ||
| } | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,282 @@ | ||
| using System; | ||
| using System.Drawing; | ||
| using System.Text; | ||
| using FastReport.Dialog; | ||
| using System.Windows.Forms; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| public partial class Dialog | ||
| { | ||
| private WebReport WebReport { | ||
| get; | ||
| } | ||
|
|
||
| private int CurrentForm { | ||
| get; | ||
| set; | ||
| } | ||
|
|
||
|
|
||
| public Dialog(WebReport webReport) | ||
| { | ||
| WebReport = webReport; | ||
| } | ||
|
|
||
|
|
||
| private void CheckDialogs() | ||
| { | ||
| Report report = this.WebReport.Report; | ||
| while (CurrentForm < report.Pages.Count && !(report.Pages[CurrentForm] is DialogPage && report.Pages[CurrentForm].Visible == true)) | ||
| CurrentForm++; | ||
|
|
||
| if (CurrentForm < report.Pages.Count) | ||
| { | ||
| WebReport.Mode = WebReportMode.Dialog; | ||
| } | ||
| else | ||
| { | ||
| if(WebReport.Mode == WebReportMode.Dialog) // | ||
| { | ||
| report.PreparePhase2(); | ||
| WebReport.ReportPrepared = true; | ||
| } | ||
| WebReport.Mode = WebReportMode.Preview; | ||
| } | ||
| } | ||
|
|
||
| internal void ProcessDialogs(StringBuilder sb) | ||
| { | ||
| Report report = this.WebReport.Report; | ||
|
|
||
| if (CurrentForm < report.Pages.Count) | ||
| { | ||
| DialogPage dialog = report.Pages[CurrentForm] as DialogPage; | ||
| if (!dialog.ActiveInWeb) | ||
| { | ||
| dialog.ActiveInWeb = true; | ||
| dialog.OnLoad(EventArgs.Empty); | ||
| dialog.OnShown(EventArgs.Empty); | ||
| } | ||
| GetDialogHtml(sb, dialog); | ||
| } | ||
| } | ||
|
|
||
| internal void SetDialogs(string dialogN, string controlName, string eventName, string data) | ||
| { | ||
| SetUpDialogs(dialogN, controlName, eventName, data); | ||
|
|
||
| CheckDialogs(); | ||
| } | ||
|
|
||
|
|
||
| internal void SetUpDialogs(string dialogN, string controlName, string eventName, string data) | ||
| { | ||
| if (!string.IsNullOrEmpty(dialogN)) | ||
| { | ||
| int dialogIndex = Convert.ToInt16(dialogN); | ||
| if (dialogIndex >= 0 && dialogIndex < WebReport.Report.Pages.Count) | ||
| { | ||
| DialogPage dialog = WebReport.Report.Pages[dialogIndex] as DialogPage; | ||
|
|
||
| DialogControl control = dialog.FindObject(controlName) as DialogControl; | ||
| if (control != null) | ||
| { | ||
| if (eventName == ONCHANGE) | ||
| { | ||
| if (!string.IsNullOrEmpty(data)) | ||
| { | ||
| if (control is TextBoxControl) | ||
| TextBoxChange(control as TextBoxControl, data); | ||
| else if (control is ComboBoxControl) | ||
| ComboBoxChange(control as ComboBoxControl, Convert.ToInt16(data)); | ||
| else if (control is ListBoxControl) | ||
| ListBoxChange(control as ListBoxControl, Convert.ToInt16(data)); | ||
| else if (control is CheckedListBoxControl) | ||
| CheckedListBoxChange(control as CheckedListBoxControl, data); | ||
| else if (control is DateTimePickerControl) | ||
| DateTimePickerChange(control as DateTimePickerControl, data); | ||
| else if (control is MonthCalendarControl) | ||
| MonthCalendarChange(control as MonthCalendarControl, data); | ||
| } | ||
| } | ||
| else if (eventName == ONCLICK) | ||
| { | ||
| if (control is ButtonControl) | ||
| ButtonClick(control as ButtonControl); | ||
| else if (control is CheckBoxControl) | ||
| CheckBoxClick(control as CheckBoxControl, data); | ||
| else if (control is RadioButtonControl) | ||
| RadioButtonClick(control as RadioButtonControl, data); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void ControlFilterRefresh(DataFilterBaseControl control) | ||
| { | ||
| control.FilterData(); | ||
| if (control.DetailControl != null) | ||
| { | ||
| control.DetailControl.ResetFilter(); | ||
| control.DetailControl.FillData(control); | ||
| } | ||
| } | ||
|
|
||
| private string GetDialogID() | ||
| { | ||
| return String.Concat(WebReport.ID, "Dialog"); | ||
| } | ||
|
|
||
| private string GetControlID(DialogControl control) | ||
| { | ||
| return WebReport.ID + control.Name; | ||
| } | ||
|
|
||
|
|
||
| private void GetComponentHtml(StringBuilder sb, DialogComponentCollection collection) | ||
| { | ||
| foreach (DialogControl control in collection) | ||
| { | ||
| if (control.Visible) | ||
| { | ||
| // button | ||
| if (control is ButtonControl) | ||
| sb.Append(GetButtonHtml(control as ButtonControl)); | ||
| // label | ||
| else if (control is LabelControl) | ||
| sb.Append(GetLabelHtml(control as LabelControl)); | ||
| // textbox | ||
| else if (control is TextBoxControl) | ||
| sb.Append(GetTextBoxHtml(control as TextBoxControl)); | ||
| // checkbox | ||
| else if (control is CheckBoxControl) | ||
| sb.Append(GetCheckBoxHtml(control as CheckBoxControl)); | ||
| // radio button | ||
| else if (control is RadioButtonControl) | ||
| sb.Append(GetRadioButtonHtml(control as RadioButtonControl)); | ||
| // combo box | ||
| else if (control is ComboBoxControl) | ||
| sb.Append(GetComboBoxHtml(control as ComboBoxControl)); | ||
| // list box | ||
| else if (control is ListBoxControl) | ||
| sb.Append(GetListBoxHtml(control as ListBoxControl)); | ||
| // checked list box | ||
| else if (control is CheckedListBoxControl) | ||
| sb.Append(GetCheckedListBoxHtml(control as CheckedListBoxControl)); | ||
| // datetime | ||
| else if (control is DateTimePickerControl) | ||
| sb.Append(GetDateTimePickerHtml(control as DateTimePickerControl)); | ||
| // monthcalendar | ||
| else if (control is MonthCalendarControl) | ||
| sb.Append(GetMonthCalendarHtml(control as MonthCalendarControl)); | ||
| else if (control is GroupBoxControl) | ||
| sb.Append(GetGroupBoxHtml(control as GroupBoxControl)); | ||
| else if (control is PictureBoxControl) | ||
| sb.Append(GetPictureBoxHtml(control as PictureBoxControl)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private string Zoom(float value) | ||
| { | ||
| return $"{value*WebReport.Zoom:0.##}"; | ||
| } | ||
|
|
||
| private void GetDialogHtml(StringBuilder sb, DialogPage dialog) | ||
| { | ||
| string s = String.Format("<div style=\"min-width:{0}px! important;min-height:{1}px !important\">", | ||
| Zoom(dialog.Width), | ||
| Zoom(dialog.Height) | ||
| ); | ||
| sb.Append(s); | ||
|
|
||
| sb.Append($"<div id=\"{GetDialogID()}\" style=\"position:relative;\" title=\"{dialog.Text}\">"); | ||
|
|
||
| GetComponentHtml(sb, dialog.Controls); | ||
| sb.Append("</div></div>"); | ||
| } | ||
|
|
||
|
|
||
| private string GetEvent(string eventName, DialogControl control, string func, string data = null) | ||
| { | ||
| data = string.IsNullOrEmpty(data) ? "'" : $"&data=' + {data}"; | ||
|
|
||
| string HandlerURL = $"'&dialog={CurrentForm}&control={control.Name}&event={eventName}{data}"; | ||
|
|
||
| return $"fr{WebReport.ID}.{func}({HandlerURL})"; | ||
| } | ||
|
|
||
| private string GetControlFont(Font font) | ||
| { | ||
| string fontStyle = (((font.Style & FontStyle.Bold) > 0) ? "font-weight:bold;" : String.Empty) + | ||
| (((font.Style & FontStyle.Italic) > 0) ? "font-style:italic;" : "font-style:normal;"); | ||
| if ((font.Style & FontStyle.Underline) > 0 && (font.Style & FontStyle.Strikeout) > 0) | ||
| fontStyle += "text-decoration:underline|line-through;"; | ||
| else if ((font.Style & FontStyle.Underline) > 0) | ||
| fontStyle += "text-decoration:underline;"; | ||
| else if ((font.Style & FontStyle.Strikeout) > 0) | ||
| fontStyle += "text-decoration:line-through;"; | ||
|
|
||
| return $"font-size:{Zoom(font.Size)}pt;font-family:{font.FontFamily.Name};{fontStyle};display:inline-block;"; | ||
| } | ||
|
|
||
| private string GetControlPosition(DialogControl control) | ||
| { | ||
| return string.Format("position:absolute;left:{0}px;top:{1}px;width:{2}px;height:{3}px;padding:0px;margin:0px;", | ||
| Zoom(control.Left), | ||
| Zoom(control.Top), | ||
| Zoom(control.Width), | ||
| Zoom(control.Height)); | ||
| } | ||
|
|
||
| private string GetControlAlign(DialogControl control) | ||
| { | ||
| if (control is LabelControl) | ||
| return GetAlign((control as LabelControl).TextAlign); | ||
| else if (control is ButtonControl) | ||
| return GetAlign((control as ButtonControl).TextAlign); | ||
| else if (control is TextBoxControl) | ||
| return GetEditAlign((control as TextBoxControl).TextAlign); | ||
| else | ||
| return ""; | ||
| } | ||
|
|
||
| private string GetEditAlign(HorizontalAlignment align) | ||
| { | ||
| if (align == HorizontalAlignment.Left) | ||
| return "text-align:left;"; | ||
| else if (align == HorizontalAlignment.Center) | ||
| return "text-align:center;"; | ||
| else if (align == HorizontalAlignment.Right) | ||
| return "text-align:right;"; | ||
| else | ||
| return ""; | ||
| } | ||
|
|
||
| private string GetAlign(ContentAlignment align) | ||
| { | ||
| if (align == ContentAlignment.TopLeft) | ||
| return "text-align:left;vertical-align:top;"; | ||
| else if (align == ContentAlignment.TopCenter) | ||
| return "text-align:center;vertical-align:top;"; | ||
| else if (align == ContentAlignment.TopRight) | ||
| return "text-align:right;vertical-align:top;"; | ||
| else if (align == ContentAlignment.BottomLeft) | ||
| return "text-align:left;vertical-align:bottom;"; | ||
| else if (align == ContentAlignment.BottomCenter) | ||
| return "text-align:center;vertical-align:bottom;"; | ||
| else if (align == ContentAlignment.TopRight) | ||
| return "text-align:right;vertical-align:bottom;"; | ||
| else if (align == ContentAlignment.MiddleLeft) | ||
| return "text-align:left;vertical-align:middle;"; | ||
| else if (align == ContentAlignment.MiddleCenter) | ||
| return "text-align:center;vertical-align:middle;"; | ||
| else if (align == ContentAlignment.MiddleRight) | ||
| return "text-align:right;vertical-align:middle;"; | ||
| else | ||
| return ""; | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,66 @@ | ||
| using FastReport.Dialog; | ||
| using static FastReport.Web.Constants; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| public partial class Dialog | ||
| { | ||
| private void TextBoxChange(TextBoxControl tb, string data) | ||
| { | ||
| tb.Text = data; | ||
| tb.FilterData(); | ||
| tb.OnTextChanged(null); | ||
| } | ||
|
|
||
| private string GetValHook() | ||
| { | ||
| return | ||
| "<script>$.valHooks.textarea = {" + | ||
| "get: function(elem) {" + | ||
| "return elem.value.replace(/\\r?\\n/g, \'\\r\\n\');" + | ||
| "}};</script>"; | ||
| } | ||
|
|
||
| private string GetTextBoxHtml(TextBoxControl control) | ||
| { | ||
| string id = GetControlID(control); | ||
| if (control.Multiline) | ||
| { | ||
| return | ||
| //GetValHook() + | ||
| string.Format("<textarea style=\"{0}\" type=\"text\" name=\"{1}\" onchange=\"{3}\" id=\"{4}\">{2}</textarea>", | ||
| // style | ||
| GetTextBoxStyle(control), //0 | ||
| // name | ||
| control.Name, //1 | ||
| // value | ||
| control.Text, //2 | ||
| // onclick | ||
| GetEvent(ONCHANGE, control, DIALOG, $"document.getElementById('{id}').value.replace(/\\r?\\n/g, \'\\r\\n\')"), //3 | ||
| // title | ||
| id //4 | ||
| ); | ||
| } | ||
| else | ||
| { | ||
| return string.Format("<input style=\"{0}\" type=\"text\" name=\"{1}\" value=\"{2}\" onchange=\"{3}\" id=\"{4}\"/>", | ||
| // style | ||
| GetTextBoxStyle(control), | ||
| // name | ||
| control.Name, | ||
| // value | ||
| control.Text, | ||
| // onclick | ||
| GetEvent(ONCHANGE, control, DIALOG, $"document.getElementById('{id}').value"), | ||
| // title | ||
| id | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| private string GetTextBoxStyle(TextBoxControl control) | ||
| { | ||
| return $"{GetControlPosition(control)} {GetControlFont(control.Font)} {GetControlAlign(control)}"; | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,93 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using FastReport.Utils; | ||
| using System.Text.RegularExpressions; | ||
|
|
||
| namespace FastReport.Web | ||
| { | ||
| partial class WebReport | ||
| { | ||
| /// <summary> | ||
| /// Sets custom class for checking the report script. | ||
| /// </summary> | ||
| /// <param name="scriptChecker"></param> | ||
| public static void SetScriptSecurity(IScriptChecker scriptChecker) | ||
| { | ||
| ScriptSecurity.Dispose(); | ||
| ScriptSecurity = new ScriptSecurity(scriptChecker); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| internal class ScriptSecurity : IDisposable | ||
| { | ||
| private IScriptChecker ScriptChecker; | ||
|
|
||
| internal ScriptSecurity(IScriptChecker checker) | ||
| { | ||
| ScriptChecker = checker; | ||
| Config.ScriptCompile += Config_ScriptCompile; | ||
| } | ||
|
|
||
| internal void Config_ScriptCompile(object sender, ScriptSecurityEventArgs e) | ||
| { | ||
| if(Config.EnableScriptSecurity) | ||
| e.IsValid = ScriptChecker.IsValid(e.ReportLanguage, e.ReportScript, e.References, e.Report); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| Config.ScriptCompile -= Config_ScriptCompile; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Interface for overriding the standard check of the report script | ||
| /// <see cref="IsValid(Language, string, string[], Report)"/> | ||
| /// </summary> | ||
| public interface IScriptChecker | ||
| { | ||
| /// <summary> | ||
| /// Method for checking the report script | ||
| /// </summary> | ||
| /// <param name="lang">Report script language</param> | ||
| /// <param name="reportScript">Report script</param> | ||
| /// <param name="references">Referenced assemblies</param> | ||
| /// <param name="report">Report</param> | ||
| /// <returns>Returns true if the report passed the validation check</returns> | ||
| bool IsValid(Language lang, string reportScript, string[] references, Report report); | ||
| } | ||
|
|
||
| internal class ScriptChecker : IScriptChecker | ||
| { | ||
| public bool IsValid(Language lang, string reportScript, string[] references, Report report) | ||
| { | ||
| // LOGIC | ||
| foreach(string reference in references) | ||
| { | ||
| // in .Net Core need to add reference | ||
| if (reference.IndexOf("System.IO.FileSystem") != -1) | ||
| return false; | ||
|
|
||
| if (reference.IndexOf("Microsoft.AspNetCore") != -1) | ||
| return false; | ||
|
|
||
| if(reference.IndexOf("System.Net") != -1) | ||
| return false; | ||
| } | ||
|
|
||
| foreach (string pattern in Config.ScriptSecurityProps.StopList) | ||
| { | ||
| if (reportScript.IndexOf(pattern) != -1) | ||
| return false; | ||
|
|
||
| //regex = new Regex(pattern); | ||
| //if (regex.IsMatch(reportScript)) | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } |
| @@ -1,11 +1,25 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <!-- This file sets version used packages in FastReport.Core, FastReport.OpenSource & FastReport.Core3 --> | ||
| <!-- This group sets version used packages in FastReport.Core, FastReport.OpenSource & FastReport.Core3 --> | ||
| <PropertyGroup> | ||
|
|
||
| <FRCompatVersion>2020.3.2</FRCompatVersion> | ||
| <FRCompatVersion>2020.3.8</FRCompatVersion> | ||
|
|
||
| <FRDataVisualizationVersion>2020.3.1</FRDataVisualizationVersion> | ||
| <FRDataVisualizationVersion>2020.3.8</FRDataVisualizationVersion> | ||
|
|
||
| </PropertyGroup> | ||
|
|
||
| <!-- This group sets version used packages in Demos --> | ||
| <PropertyGroup> | ||
|
|
||
| <FRCoreVersion>2020.3.17</FRCoreVersion> | ||
|
|
||
| <FRCoreWebVersion>2020.3.17</FRCoreWebVersion> | ||
|
|
||
| <FROSVersion>2020.3.17</FROSVersion> | ||
|
|
||
| <FROSWebVersion>2020.3.17</FROSWebVersion> | ||
|
|
||
| </PropertyGroup> | ||
|
|
||
| </Project> |
| @@ -1,3 +1,3 @@ | ||
| theme: jekyll-theme-cayman | ||
| title: FastReport Open Source | ||
| description: FastReport provides open source report generator for .NET Core 2.x/.Net Framework 4.x. | ||
| description: FastReport provides open source report generator for .NET Core/.NET Framework. |