注:由于自带的水晶报表Web方式下无法打印,所以,需要结合CrystalReportView和Javascript来实现打印的控制,包括记录打印人信息。另外操作中对打印机的参数进行了设置。

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="PrintForm.aspx.vb" Inherits="RC.PrintForm"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    
<HEAD>
        
<title>PrintForm</title>
        
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
        
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
        
<meta content="JavaScript" name="vs_defaultClientScript">
        
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
        
<style>.Display { }
    .NotDisplay 
{ DISPLAY: none }
    .tbSeparateHeaderHeight 
{ HEIGHT: 25px }
    .tbSeparateFooterHeight 
{ HEIGHT: 30px }
        
</style>
        
<script language="javascript">
        
//隐藏某段 HTML 对象
        function HidePnl(objName)
        {
            Form1.all(objName).className
='NotDisplay';
        }
        
        
//显示某段 HTML 对象
        function ShowPnl(objName)
        {
            Form1.all(objName).className
='Display';
        }
        
        
//打印操作执行前需要执行的动作
        function beforePrint()
        {
            Form1.all.TbWait.style.display
='';
            Form1.all.imgPrint.style.display
='none';
            HidePnl('pnlShowPart');
        }
        
        
//打印操作
        function printReport()
        {
         
try
         {
            ShowPnl('pnlPrintPart');
            HidePnl('pnlShowPart');
            
//隐藏 Waitting 
            Form1.all.imgPrint.style.display='none';
            Form1.all.TbWait.style.display 
= 'none';
            
            
//设置打印机属性
            pageSetup_null();
            
            
//打印所有的报表            
            window.print();
            
            
//调用打印完成后的处理函数
            afterPrint();
         }
catch(e){alert(e);}
        }    
        
        
//打印操作执行后需要执行的动作
        function afterPrint()
        {
            ShowPnl('pnlShowPart');
            HidePnl('pnlPrintPart');
            
//开启 [打印] 按钮
            Form1.all.imgPrint.style.display='';
        }    
        
</script>
        
<script language="VBScript">
        
dim hkey_root,hkey_path,hkey_key
        hkey_root
="HKEY_CURRENT_USER"
        hkey_path="\Software\Microsoft\Internet Explorer\PageSetup"
        '//設置網頁打印的頁眉頁腳為空
        function pageSetup_null()
            
on error resume next
            
Set RegWsh = CreateObject("WScript.Shell")
            hkey_key
="\header"    
            RegWsh.RegWrite hkey_root
+hkey_path+hkey_key,""
            hkey_key="\footer"
            RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""
            hkey_key="\margin_bottom"
            RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"0.25000"
            hkey_key="\margin_left"
            RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"0.10000"
            hkey_key="\margin_right"
            RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"0.10000"
            hkey_key="\margin_top"
            RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"0.25000"
        end function
        
function pageSetup_default()
            
on error resume next
            
Set RegWsh = CreateObject("WScript.Shell")
            hkey_key
="\header"    
            RegWsh.RegWrite hkey_root
+hkey_path+hkey_key,"&w&b第&p页 共&P页"
            hkey_key="\footer"
            RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&u&b&d"
        end function
        
</script>
        
<script language="javascript">
        
//禁止右键
        document.oncontextmenu=function()
        {    
return false;    }
        
//禁止复制
        document.onselectstart=function()
        {    
return false;    }
        document.ondragstart
=function()
        {    
return false;    }        
        
//双击鼠标滚动屏幕的代码
        var currentpos,timer;
        
function initialize()
        {
            timer
=setInterval ("scrollwindow ()",30);
        }
        
function sc()
        {
            clearInterval(timer);
        }
        
function scrollwindow()
        {
            currentpos
=document.body.scrollTop;
            window.scrollTo(
0,++currentpos);                        
            
if (currentpos !=document.body.scrollTop)
            sc();
        }
        document.onmousedown
=sc
        document.ondblclick
=initialize
        
//为了防止用户直接进入页面,在Page Load的时候,加入下面的检察
        function onloadCheck()
        {
            
if (window.opener==null)
            {
                alert('Not Permission
! The page will be closed水晶报表打印方案的实现 - 控制打印,记录打印人信息等.');
                window.opener
="deny";
                self.close();
            }
        }
        
</script>
    
</HEAD>
    
<body leftMargin="0" topMargin="0" MS_POSITIONING="GridLayout" onload="onloadCheck();" onunload="pageSetup_default();">
        
<form id="Form1" method="post" runat="server">
            
<asp:panel id="pnlShowPart" runat="server"></asp:panel><asp:panel id="pnlPrintPart" Runat="server"></asp:panel>
            
<!--***********************************************************************************
                    TbWait :点击 [打印] 按钮之后,出现的一个提示信息区域
                ********************************************************************************
-->
            
<TABLE id="TbWait" style="DISPLAY: none" height="80" cellSpacing="1" cellPadding="0" width="300"
                align
="center" bgColor="#999999" border="0">
                
<TR>
                    
<TD>
                        
<TABLE height="100%" cellSpacing="0" cellPadding="0" width="100%" bgColor="#999999" border="0">
                            
<TR bgColor="#ffffff">
                                
<TD align="center" width="20%"><IMG height="32" src="../icon/waiting.gif" width="32" align="middle"></TD>
                                
<TD vAlign="middle" align="left"><FONT color="black" size="2"><B>&nbsp;&nbsp; 
                                            正在验证打印请求,请稍侯水晶报表打印方案的实现 - 控制打印,记录打印人信息等
</B></FONT></TD>
                            
</TR>
                        
</TABLE>
                    
</TD>
                
</TR>
            
</TABLE>
            
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                添加打印按钮
            +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-->
            
<INPUT id="imgPrint" title="打印" onclick="beforePrint();" type="image" height="26" width="30"
                src
="/RC/icon/printer.jpg" runat="server" style="Z-INDEX: 12345; LEFT: 608px; POSITION: absolute; TOP: 8px">
        
</form>
    
</body>
</HTML>

水晶报表打印方案的实现 - 控制打印,记录打印人信息等'*********************************************************************************************************************
水晶报表打印方案的实现 - 控制打印,记录打印人信息等'
Author       : SunnyZhao              
水晶报表打印方案的实现 - 控制打印,记录打印人信息等'
Vendor       : Facet - 全领(上海)信息科技
水晶报表打印方案的实现 - 控制打印,记录打印人信息等'
DateTime     : 2005/08/02
水晶报表打印方案的实现 - 控制打印,记录打印人信息等'
From Page    : PrintReleaseCard.aspx
水晶报表打印方案的实现 - 控制打印,记录打印人信息等'
Page Desc    : 根据从页面 PrintReleaseCard.aspx 传过来的参数查询并显示报表,并提供报表打印之功能
水晶报表打印方案的实现 - 控制打印,记录打印人信息等'
额外说明     : 当用户点击了 [打印] 按钮之后,将执行下列步骤
水晶报表打印方案的实现 - 控制打印,记录打印人信息等'
                1. 判断用户有没有打印的权限,是否可以让用户打印。如果不让,提示信息;
水晶报表打印方案的实现 - 控制打印,记录打印人信息等'
                2. 如果用户可以打印,那么修改数据库,添加用户打印信息; 
水晶报表打印方案的实现 - 控制打印,记录打印人信息等'
*********************************************************************************************************************
水晶报表打印方案的实现 - 控制打印,记录打印人信息等
Imports System.Data.SqlClient
水晶报表打印方案的实现 - 控制打印,记录打印人信息等
Imports CrystalDecisions.Web

相关文章: