在用户单击“确认”按钮开始打印时,控件向服务端发送一个HTTP 的POST 消息,这样服务端收到此消息后就可以记录在什么时候打印了报表,对于打印了什么报表,是何人打印的,我们可以在POST 消息中加上这两个参数或者用Session 就可以解决这个问题。
下面我详细的讲解一下怎样利用我设计的Web 打印控件实现获取Web 打印的实际打印次数。讲解以ASP.NET 为例,当然其它语言也可以举一反三,很容易实现。因为调用打印控件统一是JavaScirpt ,提交服务器的数据是Http 协议的Post 方式,这些都是通用的。
获取Web 打印的实际打印次数的部分代码如下:
string FileValue, PrintValue, ParaName, ParaValue;
FileValue = FileToString(".\\Frp\\DepositAmt.fr3");
ParaName = "ShopName`~PrintDepositAdd`~PrintPaperNo`~Title"; //`~为各参数的分隔符
ParaValue = "测试酒楼"
+ "`~说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!"
+ "`~身份证:4325011980639512"
+ "`~押金单";
SqlConnection ConPrintTest = new SqlConnection(ConfigurationManager.ConnectionStrings["PrintTestConnectionString"].ToString());
ConPrintTest.Open();
DataSet DsCashLog = new DataSet();
SqlDataAdapter DaCashLog = new SqlDataAdapter("Select top 1 CashNo, CashDate, CashAmt, PayName, GuestName, RoomNo, ItemRemark, CashUserName, Remark From CashLog", ConPrintTest);
DaCashLog.FillSchema(DsCashLog, SchemaType.Source, "CashLog");
DaCashLog.Fill(DsCashLog, "CashLog");
PrintValue = TableToXml(DsCashLog.Tables["CashLog"]);
DsCashLog.Dispose();
ConPrintTest.Close();Ext.grid.EditorGridPanel 中combo的显示异常
string ScriptStr;
ScriptStr = "<script language='javascript'>window.onload = function() { try { var ObjPrintMange = new ActiveXObject('WebPrint.WebPrintUnit'); } catch(e) { if( confirm('打印控件未安装,现在下载吗?') ) { window.location='./PrintActivex.exe'; } return; } var OldVersion=ObjPrintMange.Version; NewVerion='5.0(2011-08-01)'; if(OldVersion < NewVerion) { ObjPrintMange = null; alert('打印控件需升级。请先进行下载,下载后关闭IE,然后安装升级版。'); window.location='./PrintActivex.exe'; return; } "
+ " ObjPrintMange.CheckReg('公司名称', '3B8E5B998A3125EE89983EA940BB2AEE'); " //注册码
+ " ObjPrintMange.PrintURL='http://www.xinyuerj.com/ASPPost/PrintNum.asp?FileName=DepsitAmt.fr3'; "
+ "ObjPrintMange.ShowReport('"
+ FileValue + "' , '"
+ ParaName + "', '"
+ ParaValue + "', '"
+ PrintValue + "', '', '', '', '', '');"
+ "ObjPrintMange = null; } </script>";
ScriptStr = ScriptStr.Replace(System.Environment.NewLine, string.Empty);
Response.Write(ScriptStr);
PrintURL 属性,设置此属性,则在报表打印时,在弹出的选择打印机的窗口后点击“确定”按钮时,通过Http 的Post 方式直接提交到所设置的URL 页面,用户可以在URL 处理用户已打印的份数。Post 的字段名指定为PrintCopy ,此参数为用户打印时所选择的份数,默认为1 。
接收实际打印的消息的代码如下:手与iPad2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
namespace Upload
{
public partial class Show : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string FileName, PrintCopy;
FileName = Request.QueryString["FileName"];
PrintCopy = Request.Form["PrintCopy"];
WriteReportFile(FileName, PrintCopy);
Response.Write("File Name" + FileName);
Response.Write("Print Copy" + PrintCopy);
}
private void WriteReportFile(string FileName, string PrintCopy)
{
if ( FileName == null || FileName == "" || FileValue == null ||FileValue == "")
return;
File.WriteAllText(Server.MapPath(FileName), PrintCopy);
}
}
}