August 2006 - Posts

水晶报表资料

1。新建工程,添加oledbdataadapter,配制数据库,生成数据集  
  2。添加水晶报表,使用项目数据,ADO。NET数据集生成报表  
  3。添加reportdocument控件,选择工程名.报表名做为名称  
  4。添加CrystalReportViewer控件,什么属性都别改  
  以上4步完成后,在希望显示报表的地方添加一下代码  
                  OleDbDataAdapter1.Fill(DataSet11,   "用户登录表")  
                  crystalReport11.SetDataSource(DataSet11)  
                  CrystalReportViewer1.ReportSource   =   crystalReport11  
  就不会弹出登录提示框了,不过原因我还是不清楚,我在这里连用户名,密码都没设置过,更不要说数据源了,所以我想这一定是通过DATASET来连接的

 

从服务器打印基于   Web   的报表  
  如果用户无权访问打印导出的报表所需的应用程序,您可能希望使他们能够从服务器打印报表。对于服务器端打印,报表在   Web   服务器上生成,并被打印到安装在   Web   服务器上的打印机。用户可以选择距离他们最近的打印机,并让服务器处理打印。    
   
  服务器端打印的要求是:    
   
  打印机必须安装在   Web   服务器上    
  本地   SYSTEM   帐户有权访问打印机    
  对包含   .NET   Framework   的配置设置的   Machine.config   文件进行了编辑,以赋予   ASPNET   辅助进程对服务器上系统设置的访问权限。    
  注意       实现服务器端打印涉及到更改服务器上的默认权限,对于对   Internet   公开的应用程序建议不要这么做。  
   
  如果想使用户能够打印在   Web   上访问的整个多页报表,您有下列选项:    
   
  使用Web   窗体   Viewer   工具栏上的“打印”按钮将报表导出为   PDF。    
  注意       报表部件   Viewer   没有此选项。  
  导出报表为可以由客户端的现有应用程序打印的格式。    
  使用PrintToPrinter   方法从服务器打印报表。    
  将报表作为一个连续的页提供以通过   Internet   Explorer   浏览器在客户端启用打印。    
   
  使用   PrintOptions.PrinterName   属性将报表的指定页输出到选定的打印机上。如果未选择打印机,则将使用报表中指定的默认打印机。   
   

[C#]    
  public   virtual   void   PrintToPrinter   (int   nCopies   ,   bool   collated   ,   int   startPageN   ,   int   endPageN   );  

 参数  
  nCopies    
  指明要打印的份数。    
  collated    
  指明是否逐份打印。    
  startPageN    
  指明要打印的第一页。    
  endPageN    
  指明要打印的最后一页。    
  备注  
  若要打印所有页,请将   startPageN   参数和   endPageN   参数设置为零。

 

 [C#]    
  private   void   PrintReport(string   printerName)  
  {  
        PageMargins   margins;  
   
        //   获取   PageMargins   结构并设置  
        //   报表的边距。  
        margins   =   Report.PrintOptions.PageMargins;  
        margins.bottomMargin   =   350;  
        margins.leftMargin   =   350;  
        margins.rightMargin   =   350;  
        margins.topMargin   =   350;  
        //   应用页边距。  
        Report.PrintOptions.ApplyPageMargins(margins);  
   
        //   选择打印机。  
        Report.PrintOptions.PrinterName   =   printerName;  
   
        //   打印报表。将   startPageN   和   endPageN  
        //   参数设置为   0   表示打印所有页。  
        Report.PrintToPrinter(1,   false,0,0);  
  }  
要求  
  命名空间:CrystalDecisions.CrystalReports.Engine  
   
  如果用户无权访问打印导出的报表所需的应用程序,并且服务器端打印存在安全性或访问权限问题,您可能需要使用户能够从他们的浏览器打印报表。此方法将整个报表作为一个连续的页显示在   Web   窗体   Viewer   控件中,因而能够使用浏览器的打印功能。    
   
  在应用程序中,可以在现有   Web   窗体   Viewer   旁边添加一个按钮,该按钮可以将客户端重定向到新的、在浏览器中将整个报表显示为一个连续页的   Web   窗体   Viewer。可以对第二个窗体上的查看器进行格式化,以便禁用组树和工具栏,并将查看器的   SeparatePages   属性设置为   False。    
   
  注意       这种打印方法有一个局限,即无法控制页眉、页脚和分页符的定位。  
  crReportDocument   =   New   Income_Statement()  
  CrystalReportViewer1.ReportSource   =   crReportDocument  
  CrystalReportViewer1.SeparatePages   =   False  
  CrystalReportViewer1.DisplayGroupTree   =   False  
  CrystalReportViewer1.DisplayToolbar   =   False  

Crystal Report的资料
   之前在论坛中经常有人问起在VS2005中使用水晶报表(Crystal Report 10)如何用DataSet实现动态的数据源绑定?关于这个问题我研究了一下,找到了新的解决方案。
    在以前VS2003中可以采用PUSH模式推报表,可以用如下的代码实现:       
   

         con = new SqlConnection(Session["SQLCONNECTION"].ToString());
         strSql 
= "SELECT * FROM htOrder";
         scm 
= new SqlCommand(strSql, con);
         sda 
= new SqlDataAdapter(scm);
         ds 
= new DataSet();
         sda.Fill(ds, 
" order ");
         rptOrder.SetDataSource(ds.Tables[
"order"]);
         crOrder.ReportSource 
= rptOrder;    

         
        VS2005中不再支持“embedded report”嵌入式报表,只能采用非嵌入式报表的方法拉数据,下面是典型的代码:
        

    //绑定报表数据
            private void BindCrystalReports()
        
{
                
string path1 = Server.MapPath("~\\Report\\");
                
string path2 = path1 + "repOrder.rpt";
                ReportDocument repDoc 
= new ReportDocument();
                repDoc.Load(path2);
                SetDBLogonForReport(repDoc);          
//设置数据登录信息
                crOrder.ReportSource = repDoc; 
                
string selectionFormula = "{htOrder.htID} =" + txtHtID.Text.Trim();//设置报表数据筛选公式
                repDoc.DataDefinition.RecordSelectionFormula = selectFormula;
                crOrder. DataBind ();     
        }

        
//设置登录信息
        private void SetDBLogonForReport(ReportDocument reportDocument)
    
{
        
try
        
{
                ConnectionInfo connectionInfo 
= new ConnectionInfo();
                connectionInfo.ServerName 
= ConfigurationManager.AppSettings["ServerName"];
                connectionInfo.DatabaseName 
= ConfigurationManager.AppSettings["DatabaseName"];
                connectionInfo.UserID 
= ConfigurationManager.AppSettings["UserID"];
                connectionInfo.Password 
= ConfigurationManager.AppSettings["Password"];
                Tables tables 
= reportDocument.Database.Tables;
               
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
           
{
                    TableLogOnInfo tableLogonInfo 
= table.LogOnInfo;
                    tableLogonInfo.ConnectionInfo 
= connectionInfo;
                    table.ApplyLogOnInfo(tableLogonInfo);
                }

        }

           
catch
      
{
                lblNote.Text 
= "<script>alert('数据库登录信息不正确!');</script>";
           }

}

                  
        这种方式是不是太频繁琐了,在数据结构更改或者查询条件发生变化时必须要再次更改报表设置,那么在VS2005中水晶报表有没有更简洁的方法呢?最好不用写代码就能搞定呢?有,那就是新的数据绑定控件CrystalReportSource,这个控件与SqlDataSource数据源绑定控件一起连用就可以用SQL表达式作数据源推数据了。下面是实现的步骤:

        1. 建立水晶报表,注意报表要用OLE DB ADO方式连接数据源,这样可以省去报表登录窗口的弹出。
        2. 在设计视图中拖拉报表控件CrystalReportViewer,点击右上角智能标签设置报表数据源,选择报表文件,自动生成CrystalReportSource,这时在设计视图中将显示出报表界面,水晶报表将自动用初始数据填充报表字段。注意这里有个小Bug,如果报表在子目录中,选择报表文件将自动用相对路径表示,这时报表显示会出错,应改成绝对路径才可以。
            <Report FileName="report\rptOrder.rpt">这里应改成:<Report FileName="..\report\rptOrder.rpt">
        3.拖拉一个数据源控件SqlDataSource(也可以用ObjectDataSource),按向导生成数据源,这里可以筛选数据,根据情况选择各类数据源。            
        4.
如何将CrystalReportSourceSqlDataSource两个控件连接在一起呢?可以这样:选择CrystalReportSource控件点击右侧属性中数据栏,再点击Report选择DataSource,在这个数据源集合编辑器选择数据源指定报表名称即可。(下面的Parameters是用来选择报表参数用的)

        经过这几个步骤,就可以运行程序显示报表啦,怎么样不用写一句代码吧?

具体代码可参考如下:

<CR:CrystalReportViewer ID="crOrder" runat="server" AutoDataBind="True"  ReportSourceID="ReportSourceOrder"  BestFitPage="False" DisplayToolbar="False" DisplayGroupTree="False" Height="1042px" Width="775px" EnableParameterPrompt="False" />        
        
<CR:CrystalReportSource ID="ReportSourceOrder" runat="server">
            
<Report FileName="..\report\rptOrder.rpt">                           
                    
<DataSources>
                            
<CR:DataSourceRef DataSourceID="SqlDataSourceOrder" TableName="htOrder" />
                    
</DataSources>
              
</Report>
        
</CR:CrystalReportSource>
        
<asp:SqlDataSource ID="SqlDataSourceOrder" runat="server" ConnectionString="<%$ ConnectionStrings:cc_2005 %>"
            SelectCommand
="SELECT * FROM [htOrder] "></asp:SqlDataSource>
http://blog.csdn.net/haibodotnet/category/13322.aspx?Show=All
Web打印控件,免费的ScriptX

<html>
<head>
<script defer> 
       function SetPrintSettings() { 
              // -- advanced features  ,未曾使用过,有待确认。
              /* /
              factory.printing.SetMarginMeasure(2)    // measure margins in inches 
              factory.SetPageRange(false, 1, 3)          // need pages from 1 to 3 
              factory.printing.printer = "HP DeskJet 870C" 
              factory.printing.copies = 2 
              factory.printing.collate = true 
              factory.printing.paperSize = "A4" debugger;
              factory.printing.paperSource = "Manual feed" */

              // -- basic features  使用过
              factory.printing.paperSize = 4
              factory.printing.header = "This is MeadCo" ;
              factory.printing.footer = "Advanced Printing by ScriptX" ;
              factory.printing.portrait = false ;    //方向,true
              factory.printing.leftMargin = 1.0 ;
              factory.printing.topMargin = 1.0 ;
              factory.printing.rightMargin = 1.0  ;
              factory.printing.bottomMargin = 1.0 ;
               
             factory.printing.Print(true)      //直接打印,true ,好像不起作用,总是弹出选择打印机窗口
            // factory.printing.PageSetup()   //打印设置
           //  factory.printing.Preview()  ;       //打印预览
          
           factory.printing.SetMarginMeasure(2) // set inches


       } 
</script>
</head>
<body>
 <object id="factory" viewastext  style="display:none"
  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
  codebase="file:///C:/Documents%20and%20Settings/FOUNDER/桌面/smsx.cab#Version=6,2,433,70">
</object>
 Hello World!!
 <input type="button" name="button1" onclick="SetPrintSettings();" value="Button"/>
 </body>
</html>

Time的判断

<script language='javascript'>
function keypress(obj)
{
 var kindex = window.event.keyCode;
 if(kindex < 48 || kindex >57)
 {
  window.event.keyCode = 0;
  return;
 }
 debugger;
 var ovalue = obj.value;
 var re = document.selection.createRange();
 re.text = String.fromCharCode(kindex);
 var nvalue = obj.value; 
 re.text = "";
 
 switch(nvalue.length)
 {
  case 1:if(kindex > 51)
   obj.value = ovalue;   
   break;
  case 2:if(parseInt(nvalue,10)>36)
   obj.value = ovalue;
   else
   obj.value = nvalue + ":";
   break;
  case 3:check3value(obj,ovalue,nvalue);
   break;
  case 4:check4value(obj,ovalue,nvalue);
   break;
  case 5:check5value(obj,ovalue,nvalue);
   break;
  default:break;
 }
 obj.focus();
 //window.event.keyCode = 0;
}
function check5value(obj,ovalue,nvalue)
{
 var i = nvalue.indexOf(":");
 nvalue = nvalue.replace(":","");
 switch(i)
 {
  case 2:if(parseInt(nvalue,10) >3600)
   obj.value = ovalue;   
   break;
  default:obj.value = ovalue;
  break;
 }
}
function check4value(obj,ovalue,nvalue)
{
 var i = nvalue.indexOf(":");
 switch(i)
 {  
  case 1:if(parseInt(nvalue.substring(2),10) >59)
   obj.value = ovalue;
   break;
  case 2:nvalue = nvalue.replace(":","");
   if(parseInt(nvalue,10) >360)
   obj.value = ovalue;
   break;
  default:obj.value = ovalue;
  break;
 }
}

function check3value(obj,ovalue,nvalue)
{
 var i = nvalue.indexOf(":");
 switch(i)
 {  
  case 1:break;
  case 2:if(parseInt(nvalue,10) >36)
   obj.value = ovalue;
   break;
  default:obj.value = ovalue;
  break;
 }
}</script>

JavaScript调试小工具

调试javascript的好方法
1、从微软网站下载MS Script Debugger并安装,这是下载地址:
http://download.microsoft.com/download/winscript56/install/1.0a/NT45XP/EN-US/scd10en.exe

2、修改IE的设置:
IE的选项-->高级,有两个选项默认是钩选的:
Disable Script Debugging(Internet Explorer)
Disable Script Debugging(Other)
中文可能是“禁用脚本调试”,去掉这两项的钩选。

3、在需要调试的地方加上debugger;例如: <script language=javascript>
..
debugger;
..
</script>
这就是一个断点,当运行到这里的时候就会中断进入调试模式: