WebToolbar.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. using FastReport.Utils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Text;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. namespace FastReport.Web
  9. {
  10. #region Toolbar enums
  11. /// <summary>
  12. /// Describes sizes of Toolbar enum
  13. /// </summary>
  14. public enum ToolbarStyle
  15. {
  16. /// <summary>
  17. /// Small size toolbar
  18. /// </summary>
  19. Small,
  20. /// <summary>
  21. /// Big size toolbar
  22. /// </summary>
  23. Large
  24. }
  25. /// <summary>
  26. /// Toolbar Icons Styles
  27. /// </summary>
  28. public enum ToolbarIconsStyle
  29. {
  30. /// <summary>
  31. /// Red Icons
  32. /// </summary>
  33. Red,
  34. /// <summary>
  35. /// Green Icons
  36. /// </summary>
  37. Green,
  38. /// <summary>
  39. /// Blue Icons
  40. /// </summary>
  41. Blue,
  42. /// <summary>
  43. /// Black Icons
  44. /// </summary>
  45. Black,
  46. /// <summary>
  47. /// Custom Icons
  48. /// </summary>
  49. Custom
  50. }
  51. /// <summary>
  52. /// Toolbar Background Styles.
  53. /// </summary>
  54. public enum ToolbarBackgroundStyle
  55. {
  56. /// <summary>
  57. /// Transparent background.
  58. /// </summary>
  59. None,
  60. /// <summary>
  61. /// Light background.
  62. /// </summary>
  63. Light,
  64. /// <summary>
  65. /// Medium dark background.
  66. /// </summary>
  67. Medium,
  68. /// <summary>
  69. /// Dark background.
  70. /// </summary>
  71. Dark,
  72. /// <summary>
  73. /// Custom background.
  74. /// </summary>
  75. Custom
  76. }
  77. #endregion
  78. /// <summary>
  79. /// Web Toolbar
  80. /// </summary>
  81. internal class WebToolbar
  82. {
  83. #region Private variables
  84. private Page page;
  85. private bool enableFit = true;
  86. private List<ReportTab> fTabs;
  87. private int currentTab = 0;
  88. private WebRes res;
  89. private string backgroundColor = "white";
  90. #endregion
  91. #region Public properties
  92. /// <summary>
  93. /// Gets or sets the background color.
  94. /// </summary>
  95. public string BackgroundColor
  96. {
  97. get { return backgroundColor; }
  98. set { backgroundColor = value; }
  99. }
  100. /// <summary>
  101. /// Gets or sets current tab index
  102. /// </summary>
  103. public int CurrentTabIndex
  104. {
  105. get
  106. {
  107. return currentTab;
  108. }
  109. set
  110. {
  111. currentTab = value;
  112. }
  113. }
  114. /// <summary>
  115. /// Enable or disable fitting
  116. /// </summary>
  117. public bool EnableFit
  118. {
  119. get { return enableFit; }
  120. set { enableFit = value; }
  121. }
  122. /// <summary>
  123. /// Report properties
  124. /// </summary>
  125. public WebReportProperties ReportProperties
  126. {
  127. get { return fTabs[currentTab].Properties; }
  128. set { fTabs[currentTab].Properties = value; }
  129. }
  130. /// <summary>
  131. /// Current report
  132. /// </summary>
  133. public Report Report
  134. {
  135. get { return fTabs[currentTab].Report; }
  136. set { fTabs[currentTab].Report = value; }
  137. }
  138. #endregion Public properties
  139. #region Private methods
  140. private string GetReportId()
  141. {
  142. return string.Format("<input type=\"hidden\" name=\"object\" value=\"{0}\"/>", ReportProperties.ControlID);
  143. }
  144. private string GetNavigation()
  145. {
  146. StringBuilder sb = new StringBuilder();
  147. if (ReportProperties.TotalPages > 1 && !ReportProperties.SinglePage)
  148. {
  149. res.Root("Web");
  150. sb.Append("<div class=\"td divider\">&nbsp;</div>");
  151. if (ReportProperties.ShowFirstButton)
  152. sb.Append(string.Format("<input class=\"td nav first_button\" type=\"button\" name=\"first\" value=\"\" {0} title=\"{1}\" onclick=\"{2}\"/>",
  153. (ReportProperties.CurrentPage == 0) ? "disabled=\"disabled\"" : "",
  154. res.Get("First"),
  155. GetNavRequest("first", "1")));
  156. if (ReportProperties.ShowPrevButton)
  157. sb.Append(string.Format("<input class=\"td nav prev_button\" type=\"button\" name=\"prev\" value=\"\" {0} title=\"{1}\" onclick=\"{2}\"/>",
  158. (ReportProperties.CurrentPage == 0) ? "disabled=\"disabled\"" : "",
  159. res.Get("Prev"),
  160. GetNavRequest("prev", "1")));
  161. sb.Append(GetPageNumbers());
  162. if (ReportProperties.ShowNextButton)
  163. sb.Append(string.Format("<input class=\"td nav next_button\" type=\"button\" name=\"next\" value=\"\" {0} title=\"{1}\" onclick=\"{2}\"/>",
  164. (ReportProperties.CurrentPage < ReportProperties.TotalPages - 1) ? "" : "disabled=\"disabled\"",
  165. res.Get("Next"),
  166. GetNavRequest("next", "1")));
  167. if (ReportProperties.ShowLastButton)
  168. {
  169. sb.Append(string.Format("<input class=\"td nav last_button\" type=\"button\" name=\"last\" value=\"\" {0} title=\"{1}\" onclick=\"{2}\"/>",
  170. (ReportProperties.CurrentPage < ReportProperties.TotalPages - 1) ? "" : "disabled=\"disabled\"",
  171. res.Get("Last"),
  172. GetNavRequest("last", "1")));
  173. }
  174. }
  175. sb.Append("<div class=\"td divider\">&nbsp;</div>");
  176. return sb.ToString();
  177. }
  178. private string GetPageNumbers()
  179. {
  180. StringBuilder sb = new StringBuilder();
  181. if (ReportProperties.ShowPageNumber)
  182. {
  183. res.Root("Web");
  184. string id = ReportProperties.ControlID + "PageN";
  185. string s = string.Format("<input class=\"td input center\" type=\"text\" name=\"page\" value=\"{0}\" size=\"4\" onchange=\"{1}\" title=\"{3}\" id=\"{2}\"/>",
  186. (ReportProperties.TotalPages > 0 ? ReportProperties.CurrentPage + 1 : 0).ToString(),
  187. GetNavRequest("goto", "' + document.getElementById('" + id + "').value + '"), id, res.Get("EnterPage"));
  188. sb.Append(s);
  189. sb.Append("<div class=\"td delim\">/</div>");
  190. sb.Append(string.Format("<input class=\"td input center\" type=\"text\" value=\"{0}\" size=\"4\" readonly=\"readonly\" title=\"{1}\"/>", ReportProperties.TotalPages.ToString(), res.Get("TotalPages")));
  191. }
  192. return sb.ToString();
  193. }
  194. private string GetRefresh()
  195. {
  196. StringBuilder sb = new StringBuilder();
  197. if (ReportProperties.ShowRefreshButton)
  198. {
  199. res.Root("Web");
  200. sb.Append("<div class=\"td divider\">&nbsp;</div>");
  201. sb.Append(string.Format("<input class=\"td nav refresh_button\" type=\"button\" name=\"refresh\" value=\"\" title=\"{0}\" onclick=\"{1}\"/>",
  202. res.Get("Refresh"), GetNavRequest("refresh", "1")));
  203. }
  204. return sb.ToString();
  205. }
  206. private string GetBackButton()
  207. {
  208. StringBuilder sb = new StringBuilder();
  209. if (ReportProperties.ShowBackButton && currentTab > 0)
  210. {
  211. res.Root("Web");
  212. sb.Append("<div class=\"td divider\">&nbsp;</div>");
  213. sb.Append(string.Format("<input class=\"td nav back_button\" type=\"button\" name=\"back\" value=\"\" title=\"{0}\" onclick=\"{1}\"/>",
  214. res.Get("Back"), GetNavRequest("settab", ReportProperties.PreviousTab.ToString())));
  215. }
  216. return sb.ToString();
  217. }
  218. private string GetZoomMenu()
  219. {
  220. StringBuilder sb = new StringBuilder();
  221. if (ReportProperties.ShowZoomButton)
  222. {
  223. res.Root("Web");
  224. sb.Append("<div class=\"td divider\">&nbsp;</div>");
  225. sb.Append("<ul class=\"td nav\">");
  226. sb.Append("<li><input class=\"nav zoom_button\" type=\"button\" value=\"\"/>");
  227. sb.Append("<ul class=\"round checkboxes\">");
  228. if (enableFit)
  229. {
  230. sb.Append(GetZoomItem("zoom_width", res.Get("FitWidth")));
  231. sb.Append(GetZoomItem("zoom_page", res.Get("FitPage")));
  232. }
  233. sb.Append(GetZoomItem("zoom_300", "300%"));
  234. sb.Append(GetZoomItem("zoom_200", "200%"));
  235. sb.Append(GetZoomItem("zoom_150", "150%"));
  236. sb.Append(GetZoomItem("zoom_100", "100%"));
  237. sb.Append(GetZoomItem("zoom_90", "90%"));
  238. sb.Append(GetZoomItem("zoom_75", "75%"));
  239. sb.Append(GetZoomItem("zoom_50", "50%"));
  240. sb.Append(GetZoomItem("zoom_25", "25%"));
  241. sb.Append("</ul></li></ul>");
  242. }
  243. return sb.ToString();
  244. }
  245. private string GetZoomItem(string actionName, string caption)
  246. {
  247. return string.Format("<li class=\"radioitem\"><input class=\"menutext padleft {0}\" type=\"button\" name=\"{1}\" value=\"{2}\" onclick=\"{3}\"/></li>",
  248. CheckCurrentZoom(actionName) ? "checked" : "", actionName, caption,
  249. GetNavRequest(actionName, "1"));
  250. }
  251. private bool CheckCurrentZoom(string name)
  252. {
  253. string s = name.Substring(5);
  254. if (s == "width" && ReportProperties.ZoomMode == ZoomMode.Width)
  255. return true;
  256. else if (s == "page" && ReportProperties.ZoomMode == ZoomMode.Page)
  257. return true;
  258. else if (ReportProperties.ZoomMode == ZoomMode.Scale && Math.Round(ReportProperties.Zoom * 100).ToString() == s)
  259. return true;
  260. else
  261. return false;
  262. }
  263. private string GetTabs()
  264. {
  265. StringBuilder sb = new StringBuilder();
  266. if (fTabs.Count > 1)
  267. {
  268. for (int i = 0; i < fTabs.Count; i++)
  269. {
  270. sb.Append("<div class=\"tabselector\">");
  271. sb.Append(string.Format("<input class=\"td tab {2}\" type=\"button\" name=\"tab1\" value=\"{0}\" title=\"{3}\" onclick=\"{1}\"/>",
  272. GetTabName(i), GetNavRequest("settab", i.ToString()), i == CurrentTabIndex ? "tabselected":"", fTabs[i].Name));
  273. if (ReportProperties.ShowTabCloseButton)
  274. {
  275. sb.Append(string.Format("<input class=\"td tabclose {2}\" type=\"button\" name=\"tab1c\" value=\"{0}\" title=\"{3}\" onclick=\"{1}\"/>",
  276. "X", GetNavRequest("closetab", i.ToString()), i == CurrentTabIndex ? "tabselected" : "", "X"));
  277. }
  278. sb.Append("</div>");
  279. }
  280. if (ReportProperties.TabPosition == TabPosition.UnderToolbar)
  281. sb.Append("<br /><br />");
  282. }
  283. return sb.ToString();
  284. }
  285. private string GetTabName(int i)
  286. {
  287. if (String.IsNullOrEmpty(fTabs[i].Name))
  288. {
  289. string s = fTabs[i].Report.ReportInfo.Name;
  290. if (String.IsNullOrEmpty(s))
  291. s = Path.GetFileNameWithoutExtension(fTabs[i].Report.FileName);
  292. if (String.IsNullOrEmpty(s))
  293. s = (i + 1).ToString();
  294. return s;
  295. }
  296. else
  297. return fTabs[i].Name;
  298. }
  299. private string GetPrintMenu()
  300. {
  301. StringBuilder sb = new StringBuilder();
  302. if (ReportProperties.ShowPrint)
  303. {
  304. res.Root("Web");
  305. sb.Append("<div class=\"td divider\">&nbsp;</div>");
  306. sb.Append("<ul class=\"td nav\">");
  307. sb.Append(String.Format("<li><input class=\"nav print_button\" type=\"button\" value=\"\" title=\"{0}\" onclick=\"{1}\"/>",
  308. GetPrintRes(),
  309. GetPrintReq()
  310. ));
  311. if (ReportProperties.PrintInPdf && ReportProperties.PrintInBrowser)
  312. {
  313. sb.Append("<ul class=\"round\">");
  314. sb.Append(GetActionButton("print_browser", res.Get("PrintFromBrowser")));
  315. sb.Append(GetActionButton("print_pdf", res.Get("PrintFromAcrobat")));
  316. sb.Append("</ul>");
  317. }
  318. sb.Append("</li></ul>");
  319. }
  320. return sb.ToString();
  321. }
  322. private string GetPrintReq()
  323. {
  324. string result = "";
  325. if (ReportProperties.PrintInPdf && !ReportProperties.PrintInBrowser)
  326. result = GetRequest("print_pdf", "1");
  327. else if (!ReportProperties.PrintInPdf && ReportProperties.PrintInBrowser)
  328. result = GetRequest("print_browser", "1");
  329. return result;
  330. }
  331. private string GetPrintRes()
  332. {
  333. string result = "";
  334. res.Root("Web");
  335. if (ReportProperties.PrintInPdf && !ReportProperties.PrintInBrowser)
  336. result = res.Get("PrintFromAcrobat");
  337. else if (!ReportProperties.PrintInPdf && ReportProperties.PrintInBrowser)
  338. result = res.Get("PrintFromBrowser");
  339. return result;
  340. }
  341. private string GetExportMenu()
  342. {
  343. StringBuilder sb = new StringBuilder();
  344. if (ReportProperties.ShowExports)
  345. {
  346. sb.Append("<div class=\"td divider\">&nbsp;</div>");
  347. sb.Append("<ul class=\"td nav\">");
  348. sb.Append("<li><input class=\"nav export_button\" type=\"button\" value=\"\"/>");
  349. sb.Append("<ul class=\"round\">");
  350. res.Root("Preview");
  351. if (ReportProperties.ShowPreparedReport)
  352. sb.Append(GetActionButton("export_fpx", res.Get("SaveNative")));
  353. res.Root("Export");
  354. if (ReportProperties.ShowPdfExport)
  355. sb.Append(GetActionButton("export_pdf", res.Get("Pdf,File")));
  356. if (ReportProperties.ShowExcel2007Export)
  357. sb.Append(GetActionButton("export_excel2007", res.Get("Xlsx,File")));
  358. if (ReportProperties.ShowWord2007Export)
  359. sb.Append(GetActionButton("export_word2007", res.Get("Docx,File")));
  360. if (ReportProperties.ShowPowerPoint2007Export)
  361. sb.Append(GetActionButton("export_pp2007", res.Get("Pptx,File")));
  362. if (ReportProperties.ShowTextExport)
  363. sb.Append(GetActionButton("export_text", res.Get("Text,File")));
  364. if (ReportProperties.ShowRtfExport)
  365. sb.Append(GetActionButton("export_rtf", res.Get("RichText,File")));
  366. if (ReportProperties.ShowXpsExport)
  367. sb.Append(GetActionButton("export_xps", res.Get("Xps,File")));
  368. if (ReportProperties.ShowOdsExport)
  369. sb.Append(GetActionButton("export_ods", res.Get("Ods,File")));
  370. if (ReportProperties.ShowOdtExport)
  371. sb.Append(GetActionButton("export_odt", res.Get("Odt,File")));
  372. if (ReportProperties.ShowMhtExport)
  373. sb.Append(GetActionButton("export_mht", res.Get("Html,MHTFile")));
  374. if (ReportProperties.ShowXmlExcelExport)
  375. sb.Append(GetActionButton("export_xml", res.Get("Xml,File")));
  376. if (ReportProperties.ShowDbfExport)
  377. sb.Append(GetActionButton("export_dbf", res.Get("Dbf,File")));
  378. if (ReportProperties.ShowCsvExport)
  379. sb.Append(GetActionButton("export_csv", res.Get("Csv,File")));
  380. sb.Append("</ul></li></ul>");
  381. }
  382. return sb.ToString();
  383. }
  384. private string GetActionButton(string actionCode, string actionName)
  385. {
  386. return string.Format("<li class=\"menuitem\"><input class=\"menutext\" type=\"button\" name=\"{0}\" value=\"{1}\" onclick=\"{2}\"/></li>",
  387. actionCode, actionName, GetRequest(actionCode, "1"));
  388. }
  389. private string GetRequest(string requestName, string value)
  390. {
  391. return string.Format("window.open('{0}?previewobject={1}&{2}={3}{4}')",
  392. ReportProperties.HandlerURL, ReportProperties.ControlID,
  393. requestName, value, WebUtils.GetSalt());
  394. }
  395. private string GetNavRequest(string requestName, string value)
  396. {
  397. return string.Format("frRequestServer('{0}?previewobject={1}&{2}={3}{4}')",
  398. ReportProperties.HandlerURL, ReportProperties.ControlID,
  399. requestName, value, WebUtils.GetSalt());
  400. }
  401. private string GetCheckBoxImageURL()
  402. {
  403. if (String.IsNullOrEmpty(ReportProperties.ButtonsPath))
  404. return GetResourceImageUrl("Checkbox.gif");
  405. else
  406. return ReportProperties.ButtonsPath + "Checkbox.gif";
  407. }
  408. private string GetDisabledImagesURL()
  409. {
  410. if (ReportProperties.ToolbarStyle == ToolbarStyle.Large)
  411. return (ReportProperties.ToolbarIconsStyle == ToolbarIconsStyle.Custom) ?
  412. ReportProperties.ButtonsPath + "toolbar_disabled_big.png" :
  413. GetResourceImageUrl("toolbar_disabled_32.png");
  414. else
  415. return (ReportProperties.ToolbarIconsStyle == ToolbarIconsStyle.Custom) ?
  416. ReportProperties.ButtonsPath + "toolbar_disabled.png" :
  417. GetResourceImageUrl("toolbar_disabled.png");
  418. }
  419. private string GetToolBarIconsURL()
  420. {
  421. string backExt = (ReportProperties.ToolbarStyle == ToolbarStyle.Large) ? "_32.png" : ".png";
  422. if (ReportProperties.ToolbarIconsStyle == ToolbarIconsStyle.Red)
  423. return GetResourceImageUrl("toolbar_red" + backExt);
  424. else if (ReportProperties.ToolbarIconsStyle == ToolbarIconsStyle.Green)
  425. return GetResourceImageUrl("toolbar_green" + backExt);
  426. else if (ReportProperties.ToolbarIconsStyle == ToolbarIconsStyle.Blue)
  427. return GetResourceImageUrl("toolbar_blue" + backExt);
  428. else if (ReportProperties.ToolbarIconsStyle == ToolbarIconsStyle.Black)
  429. return GetResourceImageUrl("toolbar_black" + backExt);
  430. else
  431. {
  432. // custom
  433. return (ReportProperties.ToolbarStyle == ToolbarStyle.Large) ?
  434. ReportProperties.ButtonsPath + "toolbar_big.png" :
  435. ReportProperties.ButtonsPath + "toolbar.png";
  436. }
  437. }
  438. private string GetToolBarBackgroundURL()
  439. {
  440. string backExt = (ReportProperties.ToolbarStyle == ToolbarStyle.Large) ? "_32.png" : ".png";
  441. if (ReportProperties.ToolbarBackgroundStyle == ToolbarBackgroundStyle.Light)
  442. return GetResourceImageUrl("toolbar_background_light" + backExt);
  443. else if (ReportProperties.ToolbarBackgroundStyle == ToolbarBackgroundStyle.Medium)
  444. return GetResourceImageUrl("toolbar_background_medium" + backExt);
  445. else if (ReportProperties.ToolbarBackgroundStyle == ToolbarBackgroundStyle.Dark)
  446. return GetResourceImageUrl("toolbar_background_dark" + backExt);
  447. else
  448. {
  449. // custom background
  450. return (ReportProperties.ToolbarStyle == ToolbarStyle.Large) ?
  451. ReportProperties.ButtonsPath + "toolbar_background_big.png" :
  452. ReportProperties.ButtonsPath + "toolbar_background.png";
  453. }
  454. }
  455. private string GetResourceImageUrl(string resName)
  456. {
  457. return page.ClientScript.GetWebResourceUrl(this.GetType(), string.Format("FastReport.Web.Resources.Images.{0}", resName));
  458. }
  459. private string GetResourceTemplateUrl(string resName)
  460. {
  461. return page.ClientScript.GetWebResourceUrl(this.GetType(), string.Format("FastReport.Web.Resources.Templates.{0}", resName));
  462. }
  463. private string GetResourceJqueryUrl(string resName)
  464. {
  465. return page.ClientScript.GetWebResourceUrl(this.GetType(), string.Format("FastReport.Web.Resources.jquery.{0}", resName));
  466. }
  467. private string GetResourceButtonUrl(string resName)
  468. {
  469. return page.ClientScript.GetWebResourceUrl(this.GetType(), string.Format("FastReport.Web.Resources.Buttons.{0}", resName));
  470. }
  471. private string GetResourceTemplate(string name)
  472. {
  473. string result;
  474. using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(string.Format("FastReport.Web.Resources.Templates.{0}", name)))
  475. using (TextReader reader = new StreamReader(stream))
  476. result = reader.ReadToEnd();
  477. return result;
  478. }
  479. #endregion
  480. #region Public methods
  481. /// <summary>
  482. /// Registration of scripts and styles in ClientScript
  483. /// </summary>
  484. /// <param name="ID"></param>
  485. /// <param name="ClientScript"></param>
  486. /// <param name="t"></param>
  487. /// <param name="extJquery"></param>
  488. public void RegisterGlobals(string ID, ClientScriptManager ClientScript, Type t, bool extJquery)
  489. {
  490. ClientScript.RegisterClientScriptBlock(t, ID, GetCss(), false);
  491. ClientScript.RegisterClientScriptInclude(t, "fr_util", GetResourceTemplateUrl("fr_util.js"));
  492. if (!extJquery)
  493. {
  494. ClientScript.RegisterClientScriptInclude(t, "jquery-fr", GetResourceJqueryUrl("jquery.min.js"));
  495. ClientScript.RegisterClientScriptInclude(t, "jquery-ui-fr", GetResourceJqueryUrl("jquery-ui.custom.min.js"));
  496. ClientScript.RegisterClientScriptBlock(t, "jquery-css-fr",
  497. String.Format("<link rel=\"stylesheet\" href=\"{0}\">",
  498. GetResourceJqueryUrl("jquery-ui.min.css")), false);
  499. }
  500. }
  501. /// <summary>
  502. /// Gets Inline Registration as string
  503. /// </summary>
  504. /// <returns></returns>
  505. public string GetInlineRegistration(bool extJquery)
  506. {
  507. StringBuilder reg = new StringBuilder();
  508. reg.AppendLine(GetCss());
  509. if (!extJquery)
  510. {
  511. reg.AppendLine(WebReportGlobals.StylesAsString());
  512. reg.AppendLine(WebReportGlobals.ScriptsAsString());
  513. }
  514. else
  515. {
  516. reg.AppendLine(WebReportGlobals.StylesWOjQueryAsString());
  517. reg.AppendLine(WebReportGlobals.ScriptsWOjQueryAsString());
  518. }
  519. return reg.ToString();
  520. }
  521. /// <summary>
  522. /// Gets CSS of toolbar
  523. /// </summary>
  524. /// <returns></returns>
  525. public string GetCss()
  526. {
  527. StringBuilder sb = new StringBuilder();
  528. string s = GetResourceTemplate(ReportProperties.ToolbarStyle == ToolbarStyle.Large ? "styles_big.css" : "styles.css");
  529. sb.AppendLine("<style type=\"text/css\"><!--");
  530. s = s.Replace("frreport", ReportProperties.ControlID);
  531. WebTemplate template = new WebTemplate(s, WebTemplateMode.CSS, false);
  532. template.SetVariable("main-background-color", backgroundColor);
  533. template.SetVariable("body-height", "calc(100% - " + ReportProperties.ToolbarHeight.ToString() + "px)");
  534. template.SetVariable("toolbar-height", ReportProperties.ToolbarHeight.ToString() + "px");
  535. template.SetVariable("toolbar-background-color", WebUtils.HTMLColor(ReportProperties.ToolbarColor));
  536. template.SetVariable("toolbar-background-url",
  537. ReportProperties.ToolbarBackgroundStyle == ToolbarBackgroundStyle.None ? "none" :
  538. string.Format("url({0})", GetToolBarBackgroundURL()));
  539. template.SetVariable("toolbar-checkbox-url", string.Format("url({0})", GetCheckBoxImageURL()));
  540. template.SetVariable("toolbar-image-url", string.Format("url({0})", GetToolBarIconsURL()));
  541. template.SetVariable("toolbar-image-disabled-url", string.Format("url({0})", GetDisabledImagesURL()));
  542. s = template.Prepare();
  543. sb.AppendLine(s).Append("--></style>");
  544. return sb.ToString();
  545. }
  546. /// <summary>
  547. ///
  548. /// </summary>
  549. /// <returns></returns>
  550. public string GetHtmlBody()
  551. {
  552. WebTemplate template = new WebTemplate(GetResourceTemplate("toolbar.html"), WebTemplateMode.HTML, false);
  553. if (ReportProperties.State == ReportState.Done)
  554. {
  555. template.SetVariable("back-button", GetBackButton());
  556. template.SetVariable("export-menu", GetExportMenu());
  557. template.SetVariable("print-menu", GetPrintMenu());
  558. template.SetVariable("zoom-menu", GetZoomMenu());
  559. template.SetVariable("navigation", GetNavigation());
  560. }
  561. template.SetVariable("refresh-button", GetRefresh());
  562. if (ReportProperties.TabPosition == TabPosition.InsideToolbar)
  563. template.SetVariable("tabsinside", GetTabs());
  564. else if (ReportProperties.TabPosition == TabPosition.UnderToolbar)
  565. template.SetVariable("tabsunder", GetTabs());
  566. template.SetVariable("reportid", GetReportId());
  567. return template.Prepare();
  568. }
  569. /// <summary>
  570. ///
  571. /// </summary>
  572. /// <param name="handlerPath"></param>
  573. /// <param name="ID"></param>
  574. /// <param name="preview"></param>
  575. /// <param name="width"></param>
  576. /// <param name="height"></param>
  577. /// <returns></returns>
  578. public string GetHtmlProgress(string handlerPath, string ID, bool preview, Unit width, Unit height)
  579. {
  580. StringBuilder sb = new StringBuilder();
  581. string progress_path = String.IsNullOrEmpty(ReportProperties.ButtonsPath) ?
  582. GetResourceImageUrl("Progress.gif") :
  583. ReportProperties.ButtonsPath + "Progress.gif";
  584. sb.Append("<div id=\"").Append(ID).Append("\"><noscript><span style='color:red'>ERROR: JavaScript disabled</span></noscript>");
  585. sb.Append("<div style=\"background:url(").Append(progress_path).Append(") no-repeat center center").
  586. Append(";width:100%;height:100%;min-width:110px;min-height:110px;\"></div>").
  587. Append("<script>frRequestServer(").
  588. Append("'").Append(handlerPath).Append("?").Append(preview ? "previewobject=" : "object=").Append(ID).
  589. Append("'").Append(");</script></div>");
  590. return sb.ToString();
  591. }
  592. /// <summary>
  593. ///
  594. /// </summary>
  595. /// <param name="handlerPath"></param>
  596. /// <param name="ID"></param>
  597. /// <param name="refreshTimeOut"></param>
  598. /// <returns></returns>
  599. public string GetAutoRefresh(string handlerPath, string ID, int refreshTimeOut)
  600. {
  601. StringBuilder sb = new StringBuilder();
  602. sb.Append("<script>setTimeout(function(){frRequestServer(").
  603. Append("'").Append(handlerPath).Append("?reload=true&object=").Append(ID).
  604. Append("'").
  605. Append(");},").Append(refreshTimeOut.ToString()).Append(");</script>");
  606. return sb.ToString();
  607. }
  608. #endregion
  609. /// <summary>
  610. /// Constructor of WebToolbar
  611. /// </summary>
  612. /// <param name="guid"></param>
  613. /// <param name="tabs"></param>
  614. /// <param name="fit"></param>
  615. /// <param name="Localization"></param>
  616. public WebToolbar(string guid, List<ReportTab> tabs, bool fit, WebRes Localization)
  617. {
  618. page = new Page();
  619. fTabs = tabs;
  620. res = Localization;
  621. enableFit = fit;
  622. }
  623. }
  624. }