2008-12-16 41 views

Trả lời

7

Sau khi vừa trải qua nỗi đau của bản thân mình, đây là một vài gợi ý mà hy vọng sẽ giúp bạn tiết kiệm thời gian ...

Crystal Reports on MSDN - rất nhiều thứ tốt ở đây

Which Persistence Approach Should I Use with Crystal Reports - cung cấp chi tiết và mã mẫu về cách tốt nhất để kiểm soát lifesycle của một đối tượng báo cáo

This post cũng đưa ra một số lời khuyên tốt xung quanh vòng đời đối tượng báo cáo

triển khai ... Th Các báo cáo mới nhất của Crystal Reports không chạy trong môi trường 64 bit, vì vậy nếu triển khai đến máy chủ 64 bit, bạn sẽ phải cấu hình IIS để chạy chế độ 32 bit hoặc sử dụng phiên bản trước của thời gian chạy. Tôi đã có may mắn nhất với thời gian chạy được phân phối với VS2008, điều này có thể được tìm thấy trong

C: \ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ Bootstrapper \ Packages \ CrystalReports10_5

Tôi lưu ý rằng bạn đang sử dụng ASP.NET 2.0 - tôi chắc chắn có thời gian chạy tương đương VS2005. Hãy thử và có được môi trường triển khai làm việc sớm trong dự án, vì nó sẽ không nghi ngờ gây ra đau đầu nhiều hơn bạn mong đợi.

Cuối cùng, một điểm cuối cùng đã khiến chúng tôi tốn thời gian và đáng nói đến - màn hình thông số chuẩn trong Crystal Reports sẽ chỉ đưa bạn đến thời điểm này. Nếu bạn muốn phức tạp với cách bạn trình bày tham số của mình cho người dùng (ví dụ: bằng cách có tham số phụ thuộc vào việc chọn tham số khác), bạn sẽ cần phải cuộn màn hình tham số của riêng mình. Điều này là khá dễ dàng như mô hình đối tượng cung cấp cho bạn truy cập vào tất cả các thông tin bạn sẽ cần về các tham số. Chúng tôi đã đi xuống con đường của việc tạo ra một màn hình thông số chung mà xây dựng chính nó theo các thông số được tìm thấy trong báo cáo nó được chỉ ra.

0

Đây là mã tôi thường sử dụng:

'Generate the Report 
Dim oRpt As New ReportDocument 
Dim reportPath As String = Server.MapPath("crtTAL.rpt") 
oRpt.Load(reportPath) 

oRpt.SetDataSource(dsTAL) 

If Not IO.Directory.Exists(tempLocation) Then 
    IO.Directory.CreateDirectory(tempLocation) 
End If 

If IO.File.Exists(tempLocation & filename) Then 
    IO.File.Delete(tempLocation & filename) 
End If 

' ******************************** 

' First we must create a new instance of the diskfiledestinationoptions class and 
' set variable called crExportOptions to the exportoptions class of the reportdocument. 
Dim crDiskFileDestinationOptions As New DiskFileDestinationOptions 
Dim crExportOptions As ExportOptions = oRpt.ExportOptions 

'Export to Word 

'append a filename to the export path and set this file as the filename property for 
'the DestinationOptions class 
crDiskFileDestinationOptions.DiskFileName = tempLocation + filename 

'set the required report ExportOptions properties 
With crExportOptions 
    .DestinationOptions = crDiskFileDestinationOptions 
    .ExportDestinationType = ExportDestinationType.DiskFile 
    .ExportFormatType = ExportFormatType.WordForWindows 
End With 

'Once the export options have been set for the report, the report can be exported. The Export command 
'does not take any arguments 
Try 
    ' Export the report 
    oRpt.Export() 
    oRpt.Close() 
    oRpt.Dispose() 
    projectCount = projectCount + 1 
Catch err As Exception 
    Response.Write("<BR>") 
    Response.Write(err.Message.ToString) 
    errorList = errorList & dtrProjects.Item("Title") & "; " 
End Try 
0

Thats những gì tôi sử dụng thông thường, Asp.net/C#

public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

     ///create instance of class first 
     ReportDocument rpDoc = new ReportDocument(); 
     ///load the report 
     rpDoc.Load(@"TicketingBasic.rpt"); 

     ///pass the report to method for dataInfo 
     getDBInfo(rpDoc); 
     /// et the source for report to be displayed 
     CrystalReportViewer1.ReportSource = rpDoc; 
    } 

    protected static void getDBInfo(ReportDocument rpDoc) 
    { 
     ///Connection Onject 
     ConnectionInfo cn = new ConnectionInfo(); 
     ///DataBase,Table, and Table Logon Info 
     Database db; 
     Tables tbl; 
     TableLogOnInfo tblLOI; 

     ///Connection Declaration 
     cn.ServerName = "??????"; 
     cn.DatabaseName = "???????"; 
     cn.UserID = "???????"; 
     cn.Password = "????????"; 

     //table info getting from report 
     db = rpDoc.Database; 
     tbl = db.Tables; 

     ///for each loop for all tables to be applied the connection info to 
     foreach (Table table in tbl) 
     { 
      tblLOI = table.LogOnInfo; 
      tblLOI.ConnectionInfo = cn; 
      table.ApplyLogOnInfo(tblLOI); 
      table.Location = "DBO." + table.Location.Substring(table.Location.LastIndexOf(".") + 1); 

     } 

     db.Dispose(); 
     tbl.Dispose(); 
    } 

và trên ASPX phụ:

<CR:CrystalReportViewer 
    ID="CrystalReportViewer1" 
    runat="server" 
    AutoDataBind="true" 
    EnableDatabaseLogonPrompt="false" 
    /> 
Các vấn đề liên quan