纽威
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.
 
 
 
 
 

283 lines
15 KiB

using grsvr6Lib;
using Newtonsoft.Json.Linq;
using NFine.Application.ProductManage;
using NFine.Code;
using NFine.Data.Extensions;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using System.Xml;
namespace NFine.Web
{
/// <summary>
/// Handler1 的摘要说明
/// </summary>
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//DiscountRateApp discountrateApp = new DiscountRateApp();
string keyValue = context.Request.Params["keyValue"];
//GridppReportServer Report = new GridppReportServer();
//string TypeText = context.Request.QueryString["type"];
//var data = discountrateApp.GetForm(keyValue);
////首先载入报表模板文件
//string ReportPathFile = context.Server.MapPath("/Grf/1a.grf"); //根据WEB服务器根目录寻址
//bool Success = Report.LoadFromFile(ReportPathFile);
////载入报表数据,为约定格式的 XML 或 JSON 文本数据
//string reportDataText = data.ToJson();
//Report.LoadDataFromXML(reportDataText);
////生成报表文档格式数据
//IGRBinaryObject GRDDataObject = Report.GenerateDocumentData();
//bool IsGRP = (TypeText == "grp");
//string FileName = IsGRP ? "YourFileName.grp" : "YourFileName.grd";
////将生成的数据响应给客户端
//ServerUtility.ResponseBinary(context, GRDDataObject, FileName, "application/grd", "attachment");
string FileValue, PrintValue, ParaName, ParaValue;
FileValue = FileToString(context,"/Frp/lot.fr3");
ParaName = "ShopName`~PrintDepositAdd`~PrintPaperNo`~Title"; //`~为各参数的分隔符
ParaValue = "测试酒楼"
+ "`~说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!"
+ "`~身份证:4325011980639512"
+ "`~押金单";
DataTable dt = SqlHelper.GetDataTableBySql("SELECT * FROM dbo.ICSDiscountRate where F_Id='" + keyValue + "'");
PrintValue = TableToXml(dt);
string ScriptStr;
string PictureStr = "";
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; } "
+ " ObjPrintMange.CheckReg('苏州智合诚信息科技有限公司', '1B98963EDF11C830F8918C3E0BE28ED8'); " //注册码
//+ "ObjPrintMange.MasterOptions(1, 'TransNO', 0 );" //主从关系,参数:主数据集序号,关联字段名,字段是否为数值型
// + PictureStr
//+ "ObjPrintMange.AddPicturePrint('PicTitle', 0, 'Title.bmp','1', 1 );" //增加单个图片打印,参数:报表中图片对象名,数据表的字段(为0),图片文件名,数据集序号,是否清除旧数据(第1次调用时为1,其它时候则为0)
//+ "ObjPrintMange.AddPicturePrint('PicMaterial', 0, '2013-01-18-272b936d03-7208-4452-9d01-1197fbb63bc3.jpg','1', 1 );" //增加数据表中的图片打印,参数:报表中图片对象名,数据表的字段(为1),图片文件名所对应的字段名,数据集序号,是否清除旧数据(第1次调用时为1,其它时候则为0)
//+ "ObjPrintMange.AddPicturePrint('Picture1', 1, 'EATTRIBUTE1','1', 1 );"
+ "ObjPrintMange.ShowReport('"
+ FileValue + "' , '"
+ ParaName + "', '"
+ ParaValue + "', '"
//+ PrintValue + "', '"
+ PrintValue + "', '','', '', '', '');"
+ "ObjPrintMange = null; } </script>";
ScriptStr = ScriptStr.Replace(System.Environment.NewLine, string.Empty);
context.Response.Write(ScriptStr);
}
public bool IsReusable
{
get
{
return false;
}
}
private string FileToString(HttpContext context, string FileName)
{
try
{
string[] ByteStr = new string[256];
for (int i = 0; i < 256; i++)
{
if (i == 0)
ByteStr[i] = "00";
else if (i < 16)
ByteStr[i] = "0" + Convert.ToString(i, 16).ToUpper();
else
ByteStr[i] = Convert.ToString(i, 16).ToUpper();
}
if (System.IO.File.Exists(context.Server.MapPath(FileName)) == false)
return "";
byte[] FileValue = System.IO.File.ReadAllBytes(context.Server.MapPath(FileName));
StringBuilder FileStr = new StringBuilder();
for (int FileRecn = 0; FileRecn < FileValue.Length; FileRecn++)
{
FileStr.Append(ByteStr[FileValue[FileRecn]]);
}
FileValue = null;
return FileStr.ToString();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
private string TableToXml(DataTable DtTable)
{
StringBuilder PrintStr = new StringBuilder();
XmlWriterSettings setting = new XmlWriterSettings();
setting.Indent = true;
setting.OmitXmlDeclaration = true;
using (XmlWriter PrintXml = XmlWriter.Create(PrintStr, setting))
{
PrintXml.WriteStartElement("xml");
PrintXml.WriteAttributeString("xmlns", "s", null, "u");
PrintXml.WriteAttributeString("xmlns", "dt", null, "u");
PrintXml.WriteAttributeString("xmlns", "rs", null, "u");
PrintXml.WriteAttributeString("xmlns", "z", null, "#R");
PrintXml.WriteStartElement("s", "Schema", null);
PrintXml.WriteAttributeString("id", "RowsetSchema");
PrintXml.WriteStartElement("s", "ElementType", null);
PrintXml.WriteAttributeString("name", "row");
PrintXml.WriteAttributeString("content", "eltOnly");
PrintXml.WriteAttributeString("rs", "updatable", null, "true");
foreach (DataColumn Column in DtTable.Columns)
{
if (Column.DataType.Name == "Int64" || Column.DataType.Name == "Boolean"
|| Column.DataType.Name == "String" || Column.DataType.Name == "DateTime"
|| Column.DataType.Name == "Decimal" || Column.DataType.Name == "Double"
|| Column.DataType.Name == "Int32" || Column.DataType.Name == "Single"
|| Column.DataType.Name == "Int16" || Column.DataType.Name == "Byte")
{
PrintXml.WriteStartElement("s", "AttributeType", null);
PrintXml.WriteAttributeString("name", Column.ColumnName);
PrintXml.WriteAttributeString("rs", "number", null, (Column.Ordinal + 1).ToString());
PrintXml.WriteAttributeString("rs", "nullable", null, "true");
PrintXml.WriteAttributeString("rs", "maydefer", null, "true");
PrintXml.WriteAttributeString("rs", "writeunknown", null, "true");
PrintXml.WriteAttributeString("rs", "basetable", null, DtTable.TableName);
PrintXml.WriteAttributeString("rs", "basecolumn", null, Column.ColumnName);
if (Column.DataType.Name == "Int64")
{ //bigint
PrintXml.WriteStartElement("s", "datatype", null);
PrintXml.WriteAttributeString("dt", "type", null, "i8");
PrintXml.WriteAttributeString("dt", "maxLength", null, "8");
PrintXml.WriteEndElement();
}
else if (Column.DataType.Name == "Boolean")
{ //bit
PrintXml.WriteStartElement("s", "datatype", null);
PrintXml.WriteAttributeString("dt", "type", null, "boolean");
PrintXml.WriteAttributeString("dt", "maxLength", null, "2");
PrintXml.WriteEndElement();
}
else if (Column.DataType.Name == "String")
{ //char
PrintXml.WriteStartElement("s", "datatype", null);
PrintXml.WriteAttributeString("dt", "type", null, "string");
PrintXml.WriteAttributeString("dt", "maxLength", null, Column.MaxLength.ToString());
PrintXml.WriteEndElement();
}
else if (Column.DataType.Name == "DateTime")
{ //dateTime
PrintXml.WriteStartElement("s", "datatype", null);
PrintXml.WriteAttributeString("dt", "type", null, "dateTime");
PrintXml.WriteAttributeString("dt", "maxLength", null, "16");
PrintXml.WriteEndElement();
}
else if (Column.DataType.Name == "Decimal")
{ //Decimal
PrintXml.WriteStartElement("s", "datatype", null);
PrintXml.WriteAttributeString("dt", "type", null, "number");
PrintXml.WriteAttributeString("dt", "maxLength", null, "19");
PrintXml.WriteEndElement();
}
else if (Column.DataType.Name == "Double")
{ //Float
PrintXml.WriteStartElement("s", "datatype", null);
PrintXml.WriteAttributeString("dt", "type", null, "float");
PrintXml.WriteAttributeString("dt", "maxLength", null, "8");
PrintXml.WriteEndElement();
}
else if (Column.DataType.Name == "Int32")
{ //int
PrintXml.WriteStartElement("s", "datatype", null);
PrintXml.WriteAttributeString("dt", "type", null, "int");
PrintXml.WriteAttributeString("dt", "maxLength", null, "4");
PrintXml.WriteEndElement();
}
else if (Column.DataType.Name == "Single")
{ //Real
PrintXml.WriteStartElement("s", "datatype", null);
PrintXml.WriteAttributeString("dt", "type", null, "r4");
PrintXml.WriteAttributeString("dt", "maxLength", null, "4");
PrintXml.WriteEndElement();
}
else if (Column.DataType.Name == "Int16")
{ //smallint
PrintXml.WriteStartElement("s", "datatype", null);
PrintXml.WriteAttributeString("dt", "type", null, "i2");
PrintXml.WriteAttributeString("dt", "maxLength", null, "2");
PrintXml.WriteEndElement();
}
else if (Column.DataType.Name == "Byte")
{ //tinyint
PrintXml.WriteStartElement("s", "datatype", null);
PrintXml.WriteAttributeString("dt", "type", null, "ui1");
PrintXml.WriteAttributeString("dt", "maxLength", null, "1");
PrintXml.WriteEndElement();
}
PrintXml.WriteEndElement();
}
}
PrintXml.WriteEndElement();
PrintXml.WriteEndElement();
PrintXml.WriteStartElement("rs", "data", null);
foreach (DataRow Row in DtTable.Rows)
{
PrintXml.WriteStartElement("z", "row", null);
foreach (DataColumn Column in DtTable.Columns)
{
if (Row.IsNull(Column) == true)
continue;
if (Column.DataType.Name == "Int64" || Column.DataType.Name == "Boolean"
|| Column.DataType.Name == "String" || Column.DataType.Name == "DateTime"
|| Column.DataType.Name == "Decimal" || Column.DataType.Name == "Double"
|| Column.DataType.Name == "Int32" || Column.DataType.Name == "Single"
|| Column.DataType.Name == "Int16" || Column.DataType.Name == "Byte")
{
if (Column.DataType.Name == "DateTime")
{
DateTime TmpDateTime = System.Convert.ToDateTime(Row[Column]);
string TmpStr = TmpDateTime.ToString("yyyy-MM-dd") + "T" + TmpDateTime.ToString("HH:mm:ss");
PrintXml.WriteAttributeString(Column.ColumnName, TmpStr);
}
else
{
PrintXml.WriteAttributeString(Column.ColumnName, Row[Column].ToString());
}
}
}
PrintXml.WriteEndElement();
}
PrintXml.WriteEndElement();
PrintXml.WriteEndElement();
}
return PrintStr.ToString();
}
}
}