DocumentWindowViewModel.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Xsl;
  8. using System.Xml;
  9. namespace EdTestEmulator.ViewModels
  10. {
  11. public class DocumentWindowViewModel
  12. {
  13. public string Title { get; set; }
  14. public string XmlString { get; set; }
  15. public string XlstPath { get; set; }
  16. public string Url => "file:///H:/ComparerSrc/Ed/GTDSAMPLE/gtd.html";
  17. public string HtmlResult { get; set; } = @"
  18. <!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
  19. <html xmlns=""http://www.w3.org/1999/xhtml"" xmlns:catESAD_ru=""urn:customs.ru:RUCommonAggregateTypes:5.21.0"" xmlns:RUScat_ru=""urn:customs.ru:RUSCommonAggregateTypes:5.21.0"" xmlns:RUDECLcat=""urn:customs.ru:RUDeclCommonAggregateTypesCust:5.21.0"" xmlns:goom=""urn:customs.ru:Information:CustomsDocuments:GTDoutCustomsMark:5.21.0"" xmlns:nGTDr=""urn:customs.ru:Information:ExchangeDocuments:NotifGTDRegistration:5.21.0"">
  20. <head>
  21. <meta content=""text/html; charset=UTF-8"" http-equiv=""Content-Type"" />
  22. <title>Электронная копия декларации на товары и транзитной декларации. Внешний формат.</title>
  23. <style type=""text/css"">
  24. body {background: #CCCCCC; font-size: 9pt;}
  25. div.page {
  26. width: 210mm;
  27. margin: 10px auto;
  28. padding: 5mm 10mm;
  29. background: white;
  30. border: solid 1px black;
  31. page-break-before: always;
  32. }
  33. div.page_album {
  34. width: 297mm;
  35. margin: 10px auto;
  36. padding: 10mm;
  37. background: white;
  38. border: solid 1px black;
  39. page-break-before: always;
  40. }
  41. div.page.nobreak {
  42. page-break-before: avoid;
  43. }
  44. /*Стиль для удаления чёрной границы вокруг нарисованной ""страницы"" при печати*/
  45. @media print {div.page {border: none; margin: 0; padding: 0;}}
  46. div.goods {background: white;}
  47. .bordered {
  48. border: solid 1px black;
  49. padding-top: 4pt;
  50. padding-bottom: 4pt;
  51. font-family: Arial;
  52. font-size: 9pt;
  53. font-weight: bold;
  54. }
  55. .underlined {border-bottom: solid 0.8pt black;}
  56. p.NumberDate {font-weight: bold;}
  57. .graph {font-family: Arial; font-size: 7pt;}
  58. .graphColumn {font-family: Arial; font-size: 6.5pt;}
  59. .graphTitleIt {font-family: Arial; font-size: 7pt; font-style: italic;}
  60. .graphMain {font-family: Arial; font-size: 9pt; font-weight: bold; }
  61. .graphNum {font-family: Arial; font-size: 7pt; font-weight: bold;}
  62. .graphNo {font-size: 7pt; font-weight: bold;}
  63. h1{font-size: 12pt;}
  64. table.addInfo {border-collapse: collapse; vertical-align: top;}
  65. table.addInfo th {border: 1px solid black; background-color: LightGrey;}
  66. table.addInfo td {border: 1px solid black; vertical-align: top;}
  67. hr {border: 0; border-bottom: 1px solid black; margin: 0;}
  68. .tr {border-right: 1px solid black;}
  69. .tl {border-left: 1px solid black;}
  70. .tb {border-bottom: 1px solid black;}
  71. .tt {border-top: 1px solid black;}
  72. .br {border-right: 2px solid black;}
  73. .bl {border-left: 2px solid black;}
  74. .bb {border-bottom: 2px solid black;}
  75. .bt {border-top: 2px solid black;}
  76. .db {border-bottom: 1px dashed black;}
  77. .dl {border-left: 1px dashed black;}
  78. .number {
  79. text-align: center;
  80. color: black;
  81. font-size: 11pt;
  82. font-weight: bold;
  83. vertical-align: middle;
  84. }
  85. </style>
  86. </head>
  87. <body>
  88. <div class=""page nobreak"">
  89. <p>TECKADSKADHSLKDHADKJSHAKDSDDADSAD</p>
  90. </div>
  91. </body>
  92. </html>
  93. ";
  94. public void ConvertToHtml()
  95. {
  96. XslCompiledTransform transform = new XslCompiledTransform();
  97. using (XmlReader reader = XmlReader.Create(new StringReader(File.ReadAllText(XlstPath))))
  98. {
  99. transform.Load(reader);
  100. }
  101. StringWriter results = new StringWriter();
  102. using (XmlReader reader = XmlReader.Create(new StringReader(XmlString)))
  103. {
  104. transform.Transform(reader, null, results);
  105. }
  106. HtmlResult = results.ToString();
  107. }
  108. }
  109. }