WebReportDialogs.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. using System;
  2. using System.Drawing;
  3. using System.Text;
  4. using System.Web;
  5. using FastReport.Dialog;
  6. using System.Windows.Forms;
  7. namespace FastReport.Web
  8. {
  9. public partial class WebReport
  10. {
  11. private void ProcessDialogs(StringBuilder sb, HttpContext context)
  12. {
  13. if (Prop.Dialogs)
  14. {
  15. Report report = this.Report;
  16. while (Prop.CurrentForm < report.Pages.Count && !(report.Pages[Prop.CurrentForm] is DialogPage && report.Pages[Prop.CurrentForm].Visible == true))
  17. Prop.CurrentForm++;
  18. if (Prop.CurrentForm < report.Pages.Count)
  19. {
  20. Prop.State = ReportState.Forms;
  21. DialogPage dialog = report.Pages[Prop.CurrentForm] as DialogPage;
  22. if (!dialog.ActiveInWeb)
  23. {
  24. dialog.ActiveInWeb = true;
  25. dialog.OnLoad(EventArgs.Empty);
  26. dialog.OnShown(EventArgs.Empty);
  27. }
  28. GetDialogHtml(sb, dialog, context);
  29. }
  30. else
  31. Prop.State = ReportState.Report;
  32. }
  33. else
  34. Prop.State = ReportState.Report;
  35. }
  36. internal void SetUpDialogs(HttpContext context)
  37. {
  38. string dialogN = context.Request.Params["dialog"];
  39. string controlName = context.Request.Params["control"];
  40. string eventName = context.Request.Params["event"];
  41. string data = context.Request.Params["data"];
  42. if (!string.IsNullOrEmpty(dialogN))
  43. {
  44. int dialogIndex = Convert.ToInt16(dialogN);
  45. if (dialogIndex >= 0 && dialogIndex < Report.Pages.Count)
  46. {
  47. DialogPage dialog = Report.Pages[dialogIndex] as DialogPage;
  48. DialogControl control = dialog.FindObject(controlName) as DialogControl;
  49. if (control != null)
  50. {
  51. if (eventName == "onchange")
  52. {
  53. if (!string.IsNullOrEmpty(data))
  54. {
  55. if (control is TextBoxControl)
  56. TextBoxChange(control as TextBoxControl, data);
  57. else if (control is ComboBoxControl)
  58. ComboBoxChange(control as ComboBoxControl, Convert.ToInt16(data));
  59. else if (control is ListBoxControl)
  60. ListBoxChange(control as ListBoxControl, Convert.ToInt16(data));
  61. else if (control is CheckedListBoxControl)
  62. CheckedListBoxChange(control as CheckedListBoxControl, data);
  63. else if (control is DateTimePickerControl)
  64. DateTimePickerChange(control as DateTimePickerControl, data);
  65. else if (control is MonthCalendarControl)
  66. MonthCalendarChange(control as MonthCalendarControl, data);
  67. }
  68. }
  69. else if (eventName == "onclick")
  70. {
  71. if (control is ButtonControl)
  72. ButtonClick(control as ButtonControl);
  73. else if (control is CheckBoxControl)
  74. CheckBoxClick(control as CheckBoxControl, data);
  75. else if (control is RadioButtonControl)
  76. RadioButtonClick(control as RadioButtonControl, data);
  77. }
  78. }
  79. }
  80. }
  81. }
  82. private void ControlFilterRefresh(DataFilterBaseControl control)
  83. {
  84. control.FilterData();
  85. if (control.DetailControl != null)
  86. {
  87. control.DetailControl.ResetFilter();
  88. control.DetailControl.FillData(control);
  89. }
  90. }
  91. private string GetDialogID()
  92. {
  93. return String.Concat(Prop.ControlID, "Dialog");
  94. }
  95. private void GetDialogHtml(StringBuilder sb, DialogPage dialog, HttpContext context)
  96. {
  97. string s = "<div style=\"{2} min-width:{0}px! important;min-height:{1}px !important\">";
  98. sb.AppendFormat(s,
  99. dialog.Width.ToString(),
  100. dialog.Height.ToString(),
  101. GetColor(dialog.BackColor));
  102. sb.AppendFormat("<div id=\"{0}\" style=\"position:relative;\" title=\"{1}\">",
  103. GetDialogID(),
  104. dialog.Text);
  105. GetComponentHtml(sb, dialog.Controls);
  106. sb.Append("</div></div>");
  107. }
  108. private void GetComponentHtml(StringBuilder sb, DialogComponentCollection collection)
  109. {
  110. foreach (DialogControl control in collection)
  111. {
  112. if (control.Visible)
  113. {
  114. // button
  115. if (control is ButtonControl)
  116. sb.Append(GetButtonHtml(control as ButtonControl));
  117. // label
  118. else if (control is LabelControl)
  119. sb.Append(GetLabelHtml(control as LabelControl));
  120. // textbox
  121. else if (control is TextBoxControl)
  122. sb.Append(GetTextBoxHtml(control as TextBoxControl));
  123. // checkbox
  124. else if (control is CheckBoxControl)
  125. sb.Append(GetCheckBoxHtml(control as CheckBoxControl));
  126. // radio button
  127. else if (control is RadioButtonControl)
  128. sb.Append(GetRadioButtonHtml(control as RadioButtonControl));
  129. // combo box
  130. else if (control is ComboBoxControl)
  131. sb.Append(GetComboBoxHtml(control as ComboBoxControl));
  132. // list box
  133. else if (control is ListBoxControl)
  134. sb.Append(GetListBoxHtml(control as ListBoxControl));
  135. // checked list box
  136. else if (control is CheckedListBoxControl)
  137. sb.Append(GetCheckedListBoxHtml(control as CheckedListBoxControl));
  138. // datetime
  139. else if (control is DateTimePickerControl)
  140. sb.Append(GetDateTimePickerHtml(control as DateTimePickerControl));
  141. // monthcalendar
  142. else if (control is MonthCalendarControl)
  143. sb.Append(GetMonthCalendarHtml(control as MonthCalendarControl));
  144. // GroupBox
  145. else if (control is GroupBoxControl)
  146. sb.Append(GetGroupBoxHtml(control as GroupBoxControl));
  147. }
  148. }
  149. }
  150. private void GetDialogWindow(StringBuilder sb, DialogPage dialog, WebReport webReport)
  151. {
  152. sb.Append("<script>").
  153. Append("$(function() {").
  154. Append("$(\"#").Append(GetDialogID()).Append("\").dialog({").
  155. Append("width:").Append((int)dialog.Width + 5).Append(", ").
  156. Append("height:").Append((int)dialog.Height + 20).
  157. Append(" }); });").
  158. Append("</script>");
  159. }
  160. private string GetStandardStyle(DialogControl control)
  161. {
  162. return string.Format("{0} {1} {2}",
  163. GetControlPosition(control),
  164. GetControlFont(control.Font),
  165. GetColor(control.BackColor));
  166. }
  167. protected string GetColor(Color color)
  168. {
  169. if (!color.IsEmpty)
  170. return string.Format("background-color: {0};", ColorTranslator.ToHtml(color));
  171. return string.Empty;
  172. }
  173. private string GetEvent(string eventName, DialogControl control, string data)
  174. {
  175. return string.Format("{0}frRequestServer('{1}?object={2}&dialog={3}&control={4}&event={5}&data=' + {6}){7}",
  176. "setTimeout(function(){",
  177. Prop.HandlerURL,
  178. Prop.ControlID,
  179. Prop.CurrentForm.ToString(),
  180. control.Name,
  181. eventName,
  182. string.IsNullOrEmpty(data) ? "''" : string.Format("{0}", data),
  183. "},250)"
  184. );
  185. }
  186. private string GetControlFont(Font font)
  187. {
  188. return string.Format("font-size:{0}pt;font-weight:normal;display:inline-block;", font.Size);
  189. }
  190. private string GetControlPosition(DialogControl control)
  191. {
  192. return string.Format("position:absolute;left:{0}px;top:{1}px;width:{2}px;height:{3}px;padding:0px;margin:0px;",
  193. control.Left,
  194. control.Top,
  195. control.Width,
  196. control.Height);
  197. }
  198. private string GetControlAlign(DialogControl control)
  199. {
  200. if (control is LabelControl)
  201. return GetAlign((control as LabelControl).TextAlign);
  202. else if (control is ButtonControl)
  203. return GetAlign((control as ButtonControl).TextAlign);
  204. else if (control is TextBoxControl)
  205. return GetEditAlign((control as TextBoxControl).TextAlign);
  206. else
  207. return "";
  208. }
  209. private string GetEditAlign(HorizontalAlignment align)
  210. {
  211. if (align == HorizontalAlignment.Left)
  212. return "text-align:left;";
  213. else if (align == HorizontalAlignment.Center)
  214. return "text-align:center;";
  215. else if (align == HorizontalAlignment.Right)
  216. return "text-align:right;";
  217. else
  218. return "";
  219. }
  220. private string GetAlign(ContentAlignment align)
  221. {
  222. if (align == ContentAlignment.TopLeft)
  223. return "text-align:left;vertical-align:top;";
  224. else if (align == ContentAlignment.TopCenter)
  225. return "text-align:center;vertical-align:top;";
  226. else if (align == ContentAlignment.TopRight)
  227. return "text-align:right;vertical-align:top;";
  228. else if (align == ContentAlignment.BottomLeft)
  229. return "text-align:left;vertical-align:bottom;";
  230. else if (align == ContentAlignment.BottomCenter)
  231. return "text-align:center;vertical-align:bottom;";
  232. else if (align == ContentAlignment.TopRight)
  233. return "text-align:right;vertical-align:bottom;";
  234. else if (align == ContentAlignment.MiddleLeft)
  235. return "text-align:left;vertical-align:middle;";
  236. else if (align == ContentAlignment.MiddleCenter)
  237. return "text-align:center;vertical-align:middle;";
  238. else if (align == ContentAlignment.MiddleRight)
  239. return "text-align:right;vertical-align:middle;";
  240. else
  241. return "";
  242. }
  243. }
  244. }