HTMLExportTemplates.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using FastReport.Utils;
  5. namespace FastReport.Export.Html
  6. {
  7. /// <summary>
  8. /// Represents the HTML export templates.
  9. /// </summary>
  10. public class HtmlTemplates
  11. {
  12. #region private fields
  13. private string pageTemplateTitle;
  14. private string pageTemplateFooter;
  15. private string navigatorTemplate;
  16. private string outlineTemplate;
  17. private string indexTemplate;
  18. private FastString capacitor;
  19. #endregion
  20. #region private methods
  21. private void NewCapacitor()
  22. {
  23. capacitor = new FastString(512);
  24. }
  25. private void Part(string str)
  26. {
  27. capacitor.AppendLine(str);
  28. }
  29. private string Capacitor()
  30. {
  31. return capacitor.ToString();
  32. }
  33. #endregion
  34. #region public properties
  35. /// <summary>
  36. /// Page Template Title
  37. /// </summary>
  38. public string PageTemplateTitle
  39. {
  40. get { return pageTemplateTitle; }
  41. set { pageTemplateTitle = value; }
  42. }
  43. /// <summary>
  44. /// Page Template Footer
  45. /// </summary>
  46. public string PageTemplateFooter
  47. {
  48. get { return pageTemplateFooter; }
  49. set { pageTemplateFooter = value; }
  50. }
  51. /// <summary>
  52. /// Navigator Template
  53. /// </summary>
  54. public string NavigatorTemplate
  55. {
  56. get { return navigatorTemplate; }
  57. set { navigatorTemplate = value; }
  58. }
  59. /// <summary>
  60. /// OutlineTemplate
  61. /// </summary>
  62. public string OutlineTemplate
  63. {
  64. get { return outlineTemplate; }
  65. set { outlineTemplate = value; }
  66. }
  67. /// <summary>
  68. /// Index Template
  69. /// </summary>
  70. public string IndexTemplate
  71. {
  72. get { return indexTemplate; }
  73. set { indexTemplate = value; }
  74. }
  75. #endregion
  76. /// <summary>
  77. /// Initializes a new instance of the <see cref="HtmlTemplates"/> class.
  78. /// </summary>
  79. public HtmlTemplates()
  80. {
  81. #region fill page template
  82. // {0} - title
  83. NewCapacitor();
  84. Part("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
  85. Part("<html><head>");
  86. Part("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
  87. Part("<meta name=Generator content=\"FastReport http://www.fast-report.com\">");
  88. Part("<title>{0}</title>");
  89. pageTemplateTitle = Capacitor();
  90. NewCapacitor();
  91. Part("</html>");
  92. pageTemplateFooter = Capacitor();
  93. #endregion
  94. #region fill navigator template
  95. // {0} - pages count {1} - name of report {2} multipage document {3} prefix of pages
  96. // {4} first caption {5} previous caption {6} next caption {7} last caption
  97. // {8} total caption
  98. NewCapacitor();
  99. Part("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
  100. Part("<html><head>");
  101. Part("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
  102. Part("<meta name=Generator content=\"FastReport http://www.fast-report.com\">");
  103. Part("<title></title><style type=\"text/css\"><!--");
  104. Part("body,input,select {{ font-family:\"Lucida Grande\",Calibri,Arial,sans-serif; font-size: 8px; font-weight: bold; font-style: normal; text-align: center; vertical-align: middle; }}");
  105. Part("input {{text-align: center}}");
  106. Part(".nav {{ font-size : 9pt; color : #283e66; font-weight : bold; text-decoration : none;}}");
  107. Part("--></style><script language=\"javascript\" type=\"text/javascript\"><!--");
  108. Part(" var frCurPage = 1; var frPgCnt = {0}; var frRepName = \"{1}\"; var frMultipage = {2}; var frPrefix=\"{3}\";");
  109. Part(" function DoPage(PgN) {{");
  110. Part(" if ((PgN > 0) && (PgN <= frPgCnt) && (PgN != frCurPage)) {{");
  111. Part(" if (frMultipage > 0) parent.mainFrame.location = frPrefix + PgN + \".html\";");
  112. Part(" else parent.mainFrame.location = frPrefix + \".main.html#PageN\" + PgN;");
  113. Part(" UpdateNav(PgN); }} else document.PgForm.PgEdit.value = frCurPage; }}");
  114. Part(" function UpdateNav(PgN) {{");
  115. Part(" frCurPage = PgN; document.PgForm.PgEdit.value = PgN;");
  116. Part(" if (PgN == 1) {{ document.PgForm.bFirst.disabled = 1; document.PgForm.bPrev.disabled = 1; }}");
  117. Part(" else {{ document.PgForm.bFirst.disabled = 0; document.PgForm.bPrev.disabled = 0; }}");
  118. Part(" if (PgN == frPgCnt) {{ document.PgForm.bNext.disabled = 1; document.PgForm.bLast.disabled = 1; }}");
  119. Part(" else {{ document.PgForm.bNext.disabled = 0; document.PgForm.bLast.disabled = 0; }} }}");
  120. Part("--></script></head>");
  121. Part("<body bgcolor=\"#DDDDDD\" text=\"#000000\" leftmargin=\"0\" topmargin=\"4\" onload=\"UpdateNav(frCurPage)\">");
  122. Part("<form name=\"PgForm\" onsubmit=\"DoPage(document.forms[0].PgEdit.value); return false;\" action=\"\">");
  123. Part("<table cellspacing=\"0\" align=\"left\" cellpadding=\"0\" border=\"0\" width=\"100%\">");
  124. Part("<tr valign=\"middle\">");
  125. Part("<td width=\"60\" align=\"center\"><button name=\"bFirst\" class=\"nav\" type=\"button\" onclick=\"DoPage(1); return false;\"><b>{4}</b></button></td>");
  126. Part("<td width=\"60\" align=\"center\"><button name=\"bPrev\" class=\"nav\" type=\"button\" onclick=\"DoPage(Math.max(frCurPage - 1, 1)); return false;\"><b>{5}</b></button></td>");
  127. Part("<td width=\"100\" align=\"center\"><input type=\"text\" class=\"nav\" name=\"PgEdit\" value=\"frCurPage\" size=\"4\"></td>");
  128. Part("<td width=\"60\" align=\"center\"><button name=\"bNext\" class=\"nav\" type=\"button\" onclick=\"DoPage(frCurPage + 1); return false;\"><b>{6}</b></button></td>");
  129. Part("<td width=\"60\" align=\"center\"><button name=\"bLast\" class=\"nav\" type=\"button\" onclick=\"DoPage(frPgCnt); return false;\"><b>{7}</b></button></td>");
  130. Part("<td width=\"20\">&nbsp;</td>\r\n");
  131. Part("<td align=\"right\">{8}: <script language=\"javascript\" type=\"text/javascript\"> document.write(frPgCnt);</script></td>");
  132. Part("<td width=\"10\">&nbsp;</td>");
  133. Part("</tr></table></form></body></html>");
  134. navigatorTemplate = Capacitor();
  135. #endregion
  136. #region fill outline template
  137. // under construction
  138. outlineTemplate = String.Empty;
  139. #endregion
  140. #region fill index template
  141. // {0} - title, {1} - navigator frame, {2} - main frame
  142. NewCapacitor();
  143. Part("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\"");
  144. Part("<html><head>");
  145. Part("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
  146. Part("<meta name=Generator content=\"FastReport http://www.fast-report.com\">");
  147. Part("<title>{0}</title>");
  148. Part("<frameset rows=\"36,*\" cols=\"*\">");
  149. Part("<frame name=\"topFrame\" src=\"{1}\" noresize frameborder=\"0\" scrolling=\"no\">");
  150. Part("<frame name=\"mainFrame\" src=\"{2}\" frameborder=\"0\">");
  151. Part("</frameset>");
  152. Part("</html>");
  153. indexTemplate = Capacitor();
  154. #endregion
  155. }
  156. }
  157. }