blogjava's web log

blogjava's web log
...

水晶报表相关[导入]

pull模式

         protected   void  Page_Load( object  sender, System.EventArgs e)
        
{
            
//  在此处放置用户代码以初始化页面
            ReportDoc   =   new   ReportDocument();
            ReportDoc.Load(Server.MapPath(
" myReport.rpt " ));
            
解决登录错误问题
            CrystalReportViewer1.ReportSource 
=  ReportDoc;;

        }




push模式

打印

protected   void  btnPrint_Click( object  sender, System.EventArgs e)
        
{
            
//  指定打印机名称,这里是网络工作站Gigi上的打印机Hp Jet 6     
             string  strPrinterName; 
            strPrinterName 
=   @" Canon Bubble-Jet BJC-210SP " ;
            
//  设置打印页边距 
            PageMargins margins; 
            margins 
=  ReportDoc.PrintOptions.PageMargins; 
            margins.bottomMargin 
=   250
            margins.leftMargin 
=   350
            margins.rightMargin 
=   350
            margins.topMargin 
=   450 ;     
            ReportDoc.PrintOptions.ApplyPageMargins(margins);     
            
// 应用打印机名称 
            ReportDoc.PrintOptions.PrinterName  =  strPrinterName;     
            
//  打印     //  打印报表。将 startPageN 和 endPageN 
            
//  参数设置为 0 表示打印所有页。
            ReportDoc.PrintToPrinter( 1 false , 0 , 0 );     
        
        }



导出


        
protected   void  btnExport_Click( object  sender, System.EventArgs e)
        
{
            CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts 
=   new          CrystalDecisions.Shared.DiskFileDestinationOptions();
            ReportDoc.ExportOptions.ExportDestinationType 
=  CrystalDecisions.Shared.ExportDestinationType.DiskFile;
            
switch  (ddlFormat.SelectedItem.Text)
            
{
                
case   " Rich Text (RTF) " :
                         ReportDoc.ExportOptions.ExportFormatType 
=    CrystalDecisions.Shared.ExportFormatType.RichText; //
                         DiskOpts.DiskFileName  =   " c:\\Output.rtf " ; //
                     break ;
                
case   " Portable Document (PDF) " :
                         ReportDoc.ExportOptions.ExportFormatType 
=    CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; //
                         DiskOpts.DiskFileName  =   " c:\\Output.pdf " ; //
                     break ;
                
case   " MS Word (DOC) " :
                         ReportDoc.ExportOptions.ExportFormatType 
=    CrystalDecisions.Shared.ExportFormatType.WordForWindows; //
                         DiskOpts.DiskFileName  =   " c:\\Output.doc " ; //
                     break ;
                
case   " MS Excel (XLS) " :
                         ReportDoc.ExportOptions.ExportFormatType 
=    CrystalDecisions.Shared.ExportFormatType.Excel; //
                         DiskOpts.DiskFileName  =   " c:\\Output.xls " ; //
                     break ;
                
default :
                    
break ;
            }

            ReportDoc.ExportOptions.DestinationOptions 
=  DiskOpts;
             ReportDoc.Export();
        }

子报表
myReport ReportDoc = new myReport(); 
        
protected void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面
            string strProvider = "Server=(local);DataBase=Northwind;UID=sa;PWD=111";
            SqlConnection MyConn 
= new SqlConnection(strProvider);
            MyConn.Open();
            
string strSelOrders = "Select * from orders";
            
string strSelOrdersDetails = "Select * from [Order Details]";
            SqlDataAdapter daOrder 
= new SqlDataAdapter(strSelOrders,MyConn);
            SqlDataAdapter daOrderDetails 
= new SqlDataAdapter(strSelOrdersDetails,MyConn);
            DataSet ds 
= new DataSet();
            daOrder.Fill(ds,
"orders");
            daOrderDetails.Fill(ds,
"Order Details");
            
            ReportDoc.SetDataSource(ds);
            cRV.ReportSource 
= ReportDoc;
        }


        
Web Form Designer generated code
//改变报表文本
        protected void btnChangeText_Click(object sender, System.EventArgs e)
        
{
            TextObject tb 
= (TextObject )ReportDoc.ReportDefinition.ReportObjects["Text2"];
           
            tb.Text 
= "订单号";
        }

//选择一个报表查看

protected void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面
            if(Session["filename"]!=null)
                CrystalReportViewer1.ReportSource 
= Session["filename"].ToString();

        }

protected void btnLoad_Click(object sender, System.EventArgs e)
        
{
            
string strName = File1.PostedFile.FileName;
            
if(strName.Trim()!="")
            
{
                CrystalReportViewer1.ReportSource 
= strName;
                Session[
"filename"= strName;
            }


        }

 

winform  使用

    //customers1是ReportDocument控件
            PrintForm printForm = new PrintForm();
            
this.customers1.Load();
            
this.customers1.SetDataSource(this.myDataSet);
             
//打印人传给报表
            this.customers1.SetParameterValue("printczy",this.tbPrintCzy.Text);
            
this.customers1.Section1.ReportObjects["testField"].Name="city";
            printForm.crystalReportViewer1.ReportSource 
= this.customers1;
            printForm.WindowState 
= FormWindowState.Maximized;
            printForm.ShowDialog();

posted on 2006-05-28 14:12 record java and net 阅读(480) 评论(0)  编辑  收藏 所属分类: dot net相关


只有注册用户登录后才能发表评论。


网站导航:
 

导航

常用链接

留言簿(44)

新闻档案

2.动态语言

3.工具箱

9.文档教程

友情链接

搜索

最新评论