2013-05-19 2 views
1

Crystal 보고서를 사용하지 않았습니다. 하지만 프로젝트의 경우 인쇄 문제로 인해 빠른 보고서 대신 사용해야합니다. 몇 시간 동안 문제를 해결하려고했지만 아직 해결 방법을 찾지 못했습니다.Crystal 보고서에서 사용자 정의 개체를 사용하는 방법

글쎄, 크리스탈 리포트에 사용할 클래스. 청구서를 작성하고 싶습니다.

데이터베이스에서 일부 데이터를 구성하여 이러한 클래스에 저장했습니다.

public class ReportInfo 
{ 
    public DateTime Date { get; set; } 
    public string BillNumber { get; set; } 
    public string Address { get; set; } 
    public string BillAddress { get; set; } 
    public string BillOwner { get; set; } 
    public string TaxNumberIDNumber { get; set; } 
    public List<ReportProduct> Products { get; set; } 
    public string PaymentType { get; set; } 
    public string MoneyWithText { get; set; } 

} 

public class ReportProduct 
{       
    public string ProductInfo { get; set; } 
    public double Amount { get; set; } 
    public string ProductCode { get; set; } 
    public double Tax { get; set; } 
    public double Price { get; set; } 

} 

보시다시피, 나는 어떤 값이 될 것이다 보고서를 (만들려면 하나 개의 법안 클래스 (보고서 정보) 및 reportinfo 클래스의 제품 (보고서의 producs)에 대한 목록 ...

있다 청구서 번호, 날짜 ...) 및 세부 정보 영역의 일부 값 (제품 정보)이 포함됩니다. 여기

내가 한 법안 (또한 내가 보고서 viewert에 청구서를 넣어하는 방법을 잘 모릅니다) 내가 그 코드를 실행하면

var serialID = Convert.ToInt32(dgBillSerials.SelectedRows[0].Cells[0].Value); 
var bills= BillsFromDatabase.Bills.Where(b => b.BillSerialID == serialID && (b.BillNumber>=txtFirstBillNumber.Value && b.BillNumber<=txtLastBillNumber.Value)).ToList(); 

var products = BillsFromDatabase.Products.Where(p => p.BillID == bills[0].ID).ToList(); 
ReportInfo ri = new ReportInfo(); 
ri.Address = bills[0].Address; 
ri.BillAddress = bills[0].BillAddress; 
ri.BillNumber =bills[0].SerialNumber + bills[0].BillNumber.ToString(); 
ri.BillOwner = bills[0].OwnerType == "sirket" ? bills[0].PersonTitle : bills[0].Name; 
ri.Date = bills[0].BillDate; 
ri.MoneyWithText = "deneme"; 
ri.PaymentType = bills[0].PaymentType; 
ri.TaxNumberIDNumber=bills[0].OwnerType=="sirket"?bills[0].TaxDepartment + " " + bills[0].TaxNumber:bills[0].NationalID; 
ri.Products = new List<ReportProduct>(); 
double sum=0; 

foreach (var product in products) 
{ 
sum += product.Price; 
ri.Products.Add(new ReportProduct() 
{ 
    Price = product.Price, 
    ProductCode = product.ProductCode, 
    ProductInfo = product.ProductInfo, 
    Amount = Math.Round((product.Price/118)*100,2), 
    Tax =Math.Round(product.Price -((product.Price/118) * 100),2) 
}); 

} 

ri.MoneyWithText = Utils.MoneyToText(sum); 

ReportDocument crystalReport = new ReportDocument(); 

crystalReport.Load(@"..my path....\BillCrystalReport.rpt"); 

crystalReport.SetDataSource(ri); 

crystalReportViewer1.ReportSource = crystalReport; 

예외 즉 던져 그것을 한의 "소스 개체가 잘못되었습니다" crystalReport.SetDataSource (ri);

나는 그것이 불공평 해 보인다는 것을 알고 있지만 내 수정 보고서에 두 개의 테이블을 구현하는 방법을 모른다. 내가 결정 repot 내 두 클래스를 추가 할 때 내가 한 클래스와 그 확인을 위해이 일을 만들어 그

crystal report

것 같습니다. 하지만이 튜토리얼에서는 여러 데이터 객체에 대해 이야기하지 않습니다.

http://msdn.microsoft.com/en-us/library/ms227595(v=vs.80).aspx

추신 : 2012 FW 4.0 설치 SAP 크리스탈 리포트 대 사용.

답변

1

나는 내 문제를 해결했다. 첫째로 나는 법안과 제품 사이의 관계에 관한 int 값을 추가하고 public List Products {get; 세트; } 여기

public class ReportInfo 
{ 
    public DateTime Date { get; set; } 
    public string BillNumber { get; set; } 
    public string Address { get; set; } 
    public string BillAddress { get; set; } 
    public string BillOwner { get; set; } 
    public string TaxNumberIDNumber { get; set; } 
    public string PaymentType { get; set; } 
    public string MoneyWithText { get; set; } 
    public int OrderId { get; set; } 
} 

public class ReportProduct 
{       
    public string ProductInfo { get; set; } 
    public double Amount { get; set; } 
    public string ProductCode { get; set; } 
    public double Tax { get; set; } 
    public double Price { get; set; } 
    public int OrderId { get; set; } 

} 

및 ReportInfo

에서 해당 속성이 새로운 형태의

var serialID = Convert.ToInt32(dgBillSerials.SelectedRows[0].Cells[0].Value); 
       var bills= BillsFromDatabase.Bills.Where(b => b.BillSerialID == serialID && (b.BillNumber>=txtFirstBillNumber.Value && b.BillNumber<=txtLastBillNumber.Value)).ToList(); 


       var reportInfoList = new List<ReportInfo>(); 
       var reportProductList = new List<ReportProduct>(); 
       var tmp1 =new ReportInfo(); 
       var tmp2 = new ReportProduct(); 
       foreach (var bill in bills) 
       { 

        tmp1= new ReportInfo() 
         { 
          Address = bill.Address, 
          BillAddress = bill.BillAddress, 
          BillNumber =bill.SerialNumber + bill.BillNumber.ToString(), 
          BillOwner = bill.OwnerType == "sirket" ? bill.PersonTitle : bill.Name, 
         // Date = bill.BillDate, 
          MoneyWithText = "deneme", 
          PaymentType = bill.PaymentType, 
          TaxNumberIDNumber=bill.OwnerType=="sirket"?bill.TaxDepartment + " " + bill.TaxNumber:bill.NationalID, 
          OrderId = bill.ID, 
          Date = bill.BillDate 
         }; 

        var products = BillsFromDatabase.Products.Where(p => p.BillID == bill.ID).ToList(); 
        double sum = 0; 
        foreach (var product in products) 
        { 
         sum += product.Price; 
         reportProductList.Add(new ReportProduct() 
              { 
               Price = product.Price, 
               ProductCode = product.ProductCode, 
               ProductInfo = product.ProductInfo, 
               Amount = Math.Round((product.Price/118)*100,2), 
               Tax =Math.Round(product.Price -((product.Price/118) * 100),2), 
               OrderId = product.BillID 

              }); 
        } 

        tmp1.MoneyWithText = Utils.MoneyToText(sum); 
        reportInfoList.Add(tmp1); 
       } 

       FrmReportPreview preview = new FrmReportPreview(reportInfoList,reportProductList); 
       preview.Show(); 

새로운 양식을 지폐와 제품을 얻을하고 열려있는 내 여기 크리스탈 리포트 뷰어를

private List<ReportInfo> _reportInfoList; 
    private List<ReportProduct> _reportProductList; 

    public FrmReportPreview(List<ReportInfo> reportInfoList, List<ReportProduct> reportProductList) 
    { 
     InitializeComponent(); 
     _reportInfoList = reportInfoList; 
     _reportProductList = reportProductList; 

    } 

    private void FrmReportPreview_Load(object sender, EventArgs e) 
    { 
     LoadReport(); 
    } 

    private void LoadReport() 
    { 

     ReportDocument crystalReport = new ReportDocument();      

     crystalReport.Load(@"...mypath\BillCrystalReport.rpt"); 


     crystalReport.Database.Tables[0].SetDataSource(_reportInfoList); 
     crystalReport.Database.Tables[1].SetDataSource(_reportProductList); 


     crystalReportViewer1.ReportSource = crystalReport; 

     crystalReportViewer1.RefreshReport(); 

    } 

을 보여줍니다 크리스탈 보고서 디자인

crystal report design

,

이것은 결과

the result

이다
관련 문제