JS获取页面数据并打印

  • Post author:
  • Post category:其他


<%@ Page Language=”C#” %>

<script runat=”server”>

private struct ImageItem {


public string 图片路径;

public string 款号;

public string 系列号;

}

protected void Page_Load(object sender, EventArgs e)

{


string ptype = “”;

if (Request.QueryString[“ptype”]!=null) {


ptype = Request.QueryString[“ptype”];

}

if (Request.Form[“ptype”]!= null)

{


ptype = Request.Form[“ptype”];

}

switch (ptype) {

case “”:    //生成打印脚本

Response.Write(code1.Value);

break;

case “1”:   //生成打印页

Response.Write(“<html>”);

Response.Write(code2.Value);

Response.Write(“</html>”);

break;

case “2”:   //返回空页面

Response.Write(“<html>”);

Response.Write(“</html>”);

break;

case “3”:  //获取成品图片

GetImageList(“1”);

break;

case “4”:  //获取物料图片

GetImageList(“2”);

break;

}

Response.End();

}

private ImageItem GetImageUrl(string idstr, string ylcls)

{


ImageItem imgitm ;

imgitm.款号 = “”;

imgitm.图片路径 = “”;

imgitm.系列号 = “”;

string sql = “”;

if (idstr.Trim().Length == 0) {


return imgitm;

}

if (ylcls == “1”) {// 1为成品

sql = “SELECT jb_bag.kp_images,jb_bag.kp_item_no, jb_bag.kp_item_code, jb_series.kp_series_name”+

“FROM jb_bag INNER JOIN jb_series ON jb_bag.kp_series=jb_series.kp_series_id and kp_item_no=”+idstr;

}

else{


sql=”select kp_url from jb_bagyl where kp_item_no=”+idstr;

}

//return ”

http://t2.baidu.com/it/u=2107939524,1661719057&fm=3&gp=1.jpg

“;

System.Data.DataTable db = GenericDataAccess.selectcommand(GenericDataAccess.createcommand(sql));

if (db.Rows.Count > 0)

{


imgitm.图片路径 = “../ProImage/” + db.Rows[0].ItemArray[0].ToString();

if (db.Rows[0].ItemArray.Length > 1) {


imgitm.款号 = db.Rows[0].ItemArray[2].ToString();

imgitm.系列号 = db.Rows[0].ItemArray[3].ToString();

}

}

return imgitm;

}

private void GetImageList(String ylcls)

{


string ids = “”;

string htm = “”;

ImageItem im;

int ii = 0;//换行标记

int iii = 0; //换页标记

if (this.Request[“ids”] != null) {


ids = this.Request[“ids”];

}

string[] idarray = ids.Split(“`”.ToCharArray());

if (ylcls == “1”)

{


for (int i = 0; i < idarray.Length – 1; i++)

{


if (ii == 0)

{


if (iii == 0)

{ //换页

htm = htm + “<table>/n”;

}

iii = iii + 1;

htm = htm + ”   <tr>/n”;

}

ii = ii + 1;

im = GetImageUrl(idarray[i], ylcls);

htm = htm + ”       <td><img class=’hb’ src='” + im.图片路径  + “‘ class=’pic’><br><span>” + im.系列号  + “/” + im.款号  + “</span></td>/n”;

if (ii == 5)

{


ii = 0;

htm = htm + ”   </tr>/n”;

if (iii == 5)

{


htm = htm + “</table>`/n”;

iii = 0;

}

}

}

if (ii != 0)

{


htm = htm + ”   </tr>/n”;

}

if (iii != 0)

{


htm = htm + ”   </table>`/n”;

}

}

else

{


for (int i = 0; i < idarray.Length – 1; i++)

{


htm = htm + GetImageUrl(idarray[i], ylcls).图片路径 + “`”;

}

}

Response.Write(htm);

}

</script>

<html xmlns=”

http://www.w3.org/1999/xhtml

” >

<head runat=”server”>

<title>无标题页</title>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

<textarea id=”code1″ cols=”20″ rows=”2″ runat=’server’>

String.prototype.Trim = function(){ return Trim(this);}

String.prototype.LTrim = function(){return LTrim(this);}

String.prototype.RTrim = function(){return RTrim(this);}

//此处为独立函数

function LTrim(str)

{


var i;

for(i=0;i<str.length;i++)

{


if(str.charAt(i)!=” “&&str.charAt(i)!=” “)break;

}

str=str.substring(i,str.length);

return str;

}

function RTrim(str)

{


var i;

for(i=str.length-1;i>=0;i–)

{


if(str.charAt(i)!=” “&&str.charAt(i)!=” “)break;

}

str=str.substring(0,i+1);

return str;

}

function Trim(str)

{


return LTrim(RTrim(str));

}

//==============================以上为字符串处理函数==============================================

function initXMLHTTP(){ //初始化xmlhttp对象

if (window.ActiveXObject && !window.XMLHttpRequest)

{


window.XMLHttpRequest = function()

{


var MSXML = [‘Msxml2.XMLHTTP.5.0′,’Msxml2.XMLHTTP.4.0′,’Msxml2.XMLHTTP.3.0′,’Msxml2.XMLHTTP’,’Microsoft.XMLHTTP’];

for (var i = 0; i < MSXML.length; i++)

{


try {

return new ActiveXObject(MSXML[i]);

}

catch (e){}

}

return null;

};

}

}

initXMLHTTP();

function GetTextByNet(sender){


var s = “”;

var xhttp = new XMLHttpRequest()

sender=sender.replace(/`/g,”%60″).replace(//|/,”%7C”)

try {


xhttp.open(“Post”,”../JScript/printer.aspx”,false)

xhttp.setRequestHeader(“Content-Type”,   “text/xml;charset=utf-8”);

xhttp.setRequestHeader(“Content-Length”,sender.length);

xhttp.send(sender);

var s = xhttp.responseText;

xhttp = null;

}

catch(e){


xhttp.open(“get”,”../JScript/printer.aspx?” + sender,false)

xhttp.send(null);

var s = xhttp.responseText;

xhttp = null;

}

xhttp = null;

return s;

}

//================================以上为初始化xmlhttp对象================================================

var  win = null;        //对话框的window对象

var  testdiv = null     //用于获取数据后存放的容器,以便检测数据表格的高度和宽度等,便于分页

document.οnclick=function()

{


var tmpobj = event.srcElement

if(tmpobj.tagName== “INPUT”)

{


if(tmpobj.value.replace(//s/g,””)==”打印”)

{

printbutton=tmpobj;

cviewpage();

printbutton.οncοntextmenu=function (){return false;}

return false;

}

}

function cviewpage(){


var t = new Date

window.blur();

win= window.open(“../JScript/printer.aspx?ptype=1&t=” + t.getTime(),”_blank”,”toolbar=no,menubar=no,status=1,resizable=1,scroll=0,Left=0,Top=0,Width=” + (screen.width – 10)+”,Height=” + (screen.Height-65))

}

}

var myTitle = “”

var myAddress = “”

var myPhone = “”;

var myFax= “”;

function getheaddata() {


var tab= document.all[“editt”];

var i=0,ii=0;iii=0;

var tit = getdocumenttitle().replace(“查询”,””).replace(“管理”,””);

try{


report_load()

if(myTitle.length>0){


tit=myTitle;

}

}

catch(e){

}

var addrbar = “”

var tbstr = “<table style=’width:100%’ ><tr><td colspan=6 style=’text-align:center;font-size:18px;font-weight:bold’>” + tit + “</td></tr></table>”;

if(myAddress.length >0) {


addrbar = addrbar + “&nbsp;&nbsp;地址:” + myAddress + “&nbsp;&nbsp;&nbsp;&nbsp;”

}

if(myPhone.length >0) {


addrbar = addrbar + “&nbsp;&nbsp;电话:” + myPhone + “&nbsp;&nbsp;&nbsp;&nbsp;”

}

if(myFax.length >0) {


addrbar = addrbar + “&nbsp;&nbsp;传真:” + myFax + “&nbsp;&nbsp;&nbsp;&nbsp;”

}

tbstr = tbstr + “<table style=’width:100%’ ><tr><td colspan=6 style=’font-size:14px;padding-left:30px’>” + addrbar + “</td></tr></table>”;

tbstr = tbstr + “<table id&#



版权声明:本文为tao19840705原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。