纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
15 KiB

2 years ago
  1. using grsvr6Lib;
  2. using Newtonsoft.Json.Linq;
  3. using NFine.Application.ProductManage;
  4. using NFine.Code;
  5. using NFine.Data.Extensions;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Text;
  13. using System.Web;
  14. using System.Xml;
  15. namespace NFine.Web
  16. {
  17. /// <summary>
  18. /// Handler1 的摘要说明
  19. /// </summary>
  20. public class Handler1 : IHttpHandler
  21. {
  22. public void ProcessRequest(HttpContext context)
  23. {
  24. //DiscountRateApp discountrateApp = new DiscountRateApp();
  25. string keyValue = context.Request.Params["keyValue"];
  26. //GridppReportServer Report = new GridppReportServer();
  27. //string TypeText = context.Request.QueryString["type"];
  28. //var data = discountrateApp.GetForm(keyValue);
  29. ////首先载入报表模板文件
  30. //string ReportPathFile = context.Server.MapPath("/Grf/1a.grf"); //根据WEB服务器根目录寻址
  31. //bool Success = Report.LoadFromFile(ReportPathFile);
  32. ////载入报表数据,为约定格式的 XML 或 JSON 文本数据
  33. //string reportDataText = data.ToJson();
  34. //Report.LoadDataFromXML(reportDataText);
  35. ////生成报表文档格式数据
  36. //IGRBinaryObject GRDDataObject = Report.GenerateDocumentData();
  37. //bool IsGRP = (TypeText == "grp");
  38. //string FileName = IsGRP ? "YourFileName.grp" : "YourFileName.grd";
  39. ////将生成的数据响应给客户端
  40. //ServerUtility.ResponseBinary(context, GRDDataObject, FileName, "application/grd", "attachment");
  41. string FileValue, PrintValue, ParaName, ParaValue;
  42. FileValue = FileToString(context,"/Frp/lot.fr3");
  43. ParaName = "ShopName`~PrintDepositAdd`~PrintPaperNo`~Title"; //`~为各参数的分隔符
  44. ParaValue = "测试酒楼"
  45. + "`~说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!"
  46. + "`~身份证:4325011980639512"
  47. + "`~押金单";
  48. DataTable dt = SqlHelper.GetDataTableBySql("SELECT * FROM dbo.ICSDiscountRate where F_Id='" + keyValue + "'");
  49. PrintValue = TableToXml(dt);
  50. string ScriptStr;
  51. string PictureStr = "";
  52. ScriptStr = "<script language='javascript'>window.onload = function() { try { var ObjPrintMange = new ActiveXObject('WebPrint.WebPrintUnit'); } catch(e) { if( confirm('打印控件未安装,现在下载吗?') ) { window.location='../Frp/PrintActivex.exe'; } return; } var OldVersion=ObjPrintMange.Version; NewVerion='5.0(2011-08-01)'; if(OldVersion < NewVerion) { ObjPrintMange = null; alert('打印控件需升级。请先进行下载,下载后关闭IE,然后安装升级版。'); window.location='../Frp/PrintActivex.exe'; return; } "
  53. + " ObjPrintMange.CheckReg('苏州智合诚信息科技有限公司', '1B98963EDF11C830F8918C3E0BE28ED8'); " //注册码
  54. //+ "ObjPrintMange.MasterOptions(1, 'TransNO', 0 );" //主从关系,参数:主数据集序号,关联字段名,字段是否为数值型
  55. // + PictureStr
  56. //+ "ObjPrintMange.AddPicturePrint('PicTitle', 0, 'Title.bmp','1', 1 );" //增加单个图片打印,参数:报表中图片对象名,数据表的字段(为0),图片文件名,数据集序号,是否清除旧数据(第1次调用时为1,其它时候则为0)
  57. //+ "ObjPrintMange.AddPicturePrint('PicMaterial', 0, '2013-01-18-272b936d03-7208-4452-9d01-1197fbb63bc3.jpg','1', 1 );" //增加数据表中的图片打印,参数:报表中图片对象名,数据表的字段(为1),图片文件名所对应的字段名,数据集序号,是否清除旧数据(第1次调用时为1,其它时候则为0)
  58. //+ "ObjPrintMange.AddPicturePrint('Picture1', 1, 'EATTRIBUTE1','1', 1 );"
  59. + "ObjPrintMange.ShowReport('"
  60. + FileValue + "' , '"
  61. + ParaName + "', '"
  62. + ParaValue + "', '"
  63. //+ PrintValue + "', '"
  64. + PrintValue + "', '','', '', '', '');"
  65. + "ObjPrintMange = null; } </script>";
  66. ScriptStr = ScriptStr.Replace(System.Environment.NewLine, string.Empty);
  67. context.Response.Write(ScriptStr);
  68. }
  69. public bool IsReusable
  70. {
  71. get
  72. {
  73. return false;
  74. }
  75. }
  76. private string FileToString(HttpContext context, string FileName)
  77. {
  78. try
  79. {
  80. string[] ByteStr = new string[256];
  81. for (int i = 0; i < 256; i++)
  82. {
  83. if (i == 0)
  84. ByteStr[i] = "00";
  85. else if (i < 16)
  86. ByteStr[i] = "0" + Convert.ToString(i, 16).ToUpper();
  87. else
  88. ByteStr[i] = Convert.ToString(i, 16).ToUpper();
  89. }
  90. if (System.IO.File.Exists(context.Server.MapPath(FileName)) == false)
  91. return "";
  92. byte[] FileValue = System.IO.File.ReadAllBytes(context.Server.MapPath(FileName));
  93. StringBuilder FileStr = new StringBuilder();
  94. for (int FileRecn = 0; FileRecn < FileValue.Length; FileRecn++)
  95. {
  96. FileStr.Append(ByteStr[FileValue[FileRecn]]);
  97. }
  98. FileValue = null;
  99. return FileStr.ToString();
  100. }
  101. catch (Exception ex)
  102. {
  103. throw new Exception(ex.Message);
  104. }
  105. }
  106. private string TableToXml(DataTable DtTable)
  107. {
  108. StringBuilder PrintStr = new StringBuilder();
  109. XmlWriterSettings setting = new XmlWriterSettings();
  110. setting.Indent = true;
  111. setting.OmitXmlDeclaration = true;
  112. using (XmlWriter PrintXml = XmlWriter.Create(PrintStr, setting))
  113. {
  114. PrintXml.WriteStartElement("xml");
  115. PrintXml.WriteAttributeString("xmlns", "s", null, "u");
  116. PrintXml.WriteAttributeString("xmlns", "dt", null, "u");
  117. PrintXml.WriteAttributeString("xmlns", "rs", null, "u");
  118. PrintXml.WriteAttributeString("xmlns", "z", null, "#R");
  119. PrintXml.WriteStartElement("s", "Schema", null);
  120. PrintXml.WriteAttributeString("id", "RowsetSchema");
  121. PrintXml.WriteStartElement("s", "ElementType", null);
  122. PrintXml.WriteAttributeString("name", "row");
  123. PrintXml.WriteAttributeString("content", "eltOnly");
  124. PrintXml.WriteAttributeString("rs", "updatable", null, "true");
  125. foreach (DataColumn Column in DtTable.Columns)
  126. {
  127. if (Column.DataType.Name == "Int64" || Column.DataType.Name == "Boolean"
  128. || Column.DataType.Name == "String" || Column.DataType.Name == "DateTime"
  129. || Column.DataType.Name == "Decimal" || Column.DataType.Name == "Double"
  130. || Column.DataType.Name == "Int32" || Column.DataType.Name == "Single"
  131. || Column.DataType.Name == "Int16" || Column.DataType.Name == "Byte")
  132. {
  133. PrintXml.WriteStartElement("s", "AttributeType", null);
  134. PrintXml.WriteAttributeString("name", Column.ColumnName);
  135. PrintXml.WriteAttributeString("rs", "number", null, (Column.Ordinal + 1).ToString());
  136. PrintXml.WriteAttributeString("rs", "nullable", null, "true");
  137. PrintXml.WriteAttributeString("rs", "maydefer", null, "true");
  138. PrintXml.WriteAttributeString("rs", "writeunknown", null, "true");
  139. PrintXml.WriteAttributeString("rs", "basetable", null, DtTable.TableName);
  140. PrintXml.WriteAttributeString("rs", "basecolumn", null, Column.ColumnName);
  141. if (Column.DataType.Name == "Int64")
  142. { //bigint
  143. PrintXml.WriteStartElement("s", "datatype", null);
  144. PrintXml.WriteAttributeString("dt", "type", null, "i8");
  145. PrintXml.WriteAttributeString("dt", "maxLength", null, "8");
  146. PrintXml.WriteEndElement();
  147. }
  148. else if (Column.DataType.Name == "Boolean")
  149. { //bit
  150. PrintXml.WriteStartElement("s", "datatype", null);
  151. PrintXml.WriteAttributeString("dt", "type", null, "boolean");
  152. PrintXml.WriteAttributeString("dt", "maxLength", null, "2");
  153. PrintXml.WriteEndElement();
  154. }
  155. else if (Column.DataType.Name == "String")
  156. { //char
  157. PrintXml.WriteStartElement("s", "datatype", null);
  158. PrintXml.WriteAttributeString("dt", "type", null, "string");
  159. PrintXml.WriteAttributeString("dt", "maxLength", null, Column.MaxLength.ToString());
  160. PrintXml.WriteEndElement();
  161. }
  162. else if (Column.DataType.Name == "DateTime")
  163. { //dateTime
  164. PrintXml.WriteStartElement("s", "datatype", null);
  165. PrintXml.WriteAttributeString("dt", "type", null, "dateTime");
  166. PrintXml.WriteAttributeString("dt", "maxLength", null, "16");
  167. PrintXml.WriteEndElement();
  168. }
  169. else if (Column.DataType.Name == "Decimal")
  170. { //Decimal
  171. PrintXml.WriteStartElement("s", "datatype", null);
  172. PrintXml.WriteAttributeString("dt", "type", null, "number");
  173. PrintXml.WriteAttributeString("dt", "maxLength", null, "19");
  174. PrintXml.WriteEndElement();
  175. }
  176. else if (Column.DataType.Name == "Double")
  177. { //Float
  178. PrintXml.WriteStartElement("s", "datatype", null);
  179. PrintXml.WriteAttributeString("dt", "type", null, "float");
  180. PrintXml.WriteAttributeString("dt", "maxLength", null, "8");
  181. PrintXml.WriteEndElement();
  182. }
  183. else if (Column.DataType.Name == "Int32")
  184. { //int
  185. PrintXml.WriteStartElement("s", "datatype", null);
  186. PrintXml.WriteAttributeString("dt", "type", null, "int");
  187. PrintXml.WriteAttributeString("dt", "maxLength", null, "4");
  188. PrintXml.WriteEndElement();
  189. }
  190. else if (Column.DataType.Name == "Single")
  191. { //Real
  192. PrintXml.WriteStartElement("s", "datatype", null);
  193. PrintXml.WriteAttributeString("dt", "type", null, "r4");
  194. PrintXml.WriteAttributeString("dt", "maxLength", null, "4");
  195. PrintXml.WriteEndElement();
  196. }
  197. else if (Column.DataType.Name == "Int16")
  198. { //smallint
  199. PrintXml.WriteStartElement("s", "datatype", null);
  200. PrintXml.WriteAttributeString("dt", "type", null, "i2");
  201. PrintXml.WriteAttributeString("dt", "maxLength", null, "2");
  202. PrintXml.WriteEndElement();
  203. }
  204. else if (Column.DataType.Name == "Byte")
  205. { //tinyint
  206. PrintXml.WriteStartElement("s", "datatype", null);
  207. PrintXml.WriteAttributeString("dt", "type", null, "ui1");
  208. PrintXml.WriteAttributeString("dt", "maxLength", null, "1");
  209. PrintXml.WriteEndElement();
  210. }
  211. PrintXml.WriteEndElement();
  212. }
  213. }
  214. PrintXml.WriteEndElement();
  215. PrintXml.WriteEndElement();
  216. PrintXml.WriteStartElement("rs", "data", null);
  217. foreach (DataRow Row in DtTable.Rows)
  218. {
  219. PrintXml.WriteStartElement("z", "row", null);
  220. foreach (DataColumn Column in DtTable.Columns)
  221. {
  222. if (Row.IsNull(Column) == true)
  223. continue;
  224. if (Column.DataType.Name == "Int64" || Column.DataType.Name == "Boolean"
  225. || Column.DataType.Name == "String" || Column.DataType.Name == "DateTime"
  226. || Column.DataType.Name == "Decimal" || Column.DataType.Name == "Double"
  227. || Column.DataType.Name == "Int32" || Column.DataType.Name == "Single"
  228. || Column.DataType.Name == "Int16" || Column.DataType.Name == "Byte")
  229. {
  230. if (Column.DataType.Name == "DateTime")
  231. {
  232. DateTime TmpDateTime = System.Convert.ToDateTime(Row[Column]);
  233. string TmpStr = TmpDateTime.ToString("yyyy-MM-dd") + "T" + TmpDateTime.ToString("HH:mm:ss");
  234. PrintXml.WriteAttributeString(Column.ColumnName, TmpStr);
  235. }
  236. else
  237. {
  238. PrintXml.WriteAttributeString(Column.ColumnName, Row[Column].ToString());
  239. }
  240. }
  241. }
  242. PrintXml.WriteEndElement();
  243. }
  244. PrintXml.WriteEndElement();
  245. PrintXml.WriteEndElement();
  246. }
  247. return PrintStr.ToString();
  248. }
  249. }
  250. }