2012-04-04 103 views
1

我剛剛下載了Telerik,無法在互聯網上找到很多幫助。我希望能夠生成華麗的報告,並且Telerik看起來像是要走的路。話雖如此,我不想用所有的巫師和垃圾來建立我的報告。報告加載時是否沒有某種「report_load」函數可用?我需要能夠配置連接字符串,並且我有用戶輸入一些生成報告的值。Visual Studio c#Telerik Reporting

這裏是生成報表的代碼:

private void GenerateReport() 
    { 
     DBaseConn.Open(); 
     SqlCommand = new SqlCommand("SELECT Gate, Weight, Date_Created FROM Backrib_Manifest " + 
            "WHERE Date_Created >= '" + fromddate + "'" + 
            "AND Date_Created <= '" + todate + "'", DBaseConn); 
     DataReader = SqlCommand.ExecuteReader(); 

     while (DataReader.Read()) 
     { 
      switch (Convert.ToInt32(DataReader["Gate"])) 
      { 
       case 1: 
        gatecount[0]++; 
        gate1weight += double.Parse(DataReader["Weight"].ToString()); 
        break; 
       case 2: 
        gatecount[1]++; 
        gate2weight += double.Parse(DataReader["Weight"].ToString()); 
        break; 
       case 3: 
        gatecount[2]++; 
        gate3weight += double.Parse(DataReader["Weight"].ToString()); 
        break; 
       case 4: 
        gatecount[3]++; 
        gate4weight += double.Parse(DataReader["Weight"].ToString()); 
        break; 
       case 5: 
        gatecount[4]++; 
        gate5weight += double.Parse(DataReader["Weight"].ToString()); 
        break; 
       case 6: 
        gatecount[5]++; 
        gate6weight += double.Parse(DataReader["Weight"].ToString()); 
        break; 
       case 7: 
        gatecount[6]++; 
        gate7weight += double.Parse(DataReader["Weight"].ToString()); 
        break; 
       case 8: 
        gatecount[7]++; 
        gate8weight += double.Parse(DataReader["Weight"].ToString()); 
        break; 
       case 0: 
        gatecount[8]++; 
        gate0weight += double.Parse(DataReader["Weight"].ToString()); 
        break; 
       default: 
        break; 
      } 
     } 
     DBaseConn.Close(); 

     int totalcount = gatecount[0] + gatecount[1] + gatecount[2] + gatecount[3] + gatecount[4] + 
         gatecount[5] + gatecount[6] + gatecount[7] + gatecount[8]; 

     lblCount1.Text = gatecount[0].ToString(); 
     lblCount2.Text = gatecount[1].ToString(); 
     lblCount3.Text = gatecount[2].ToString(); 
     lblCount4.Text = gatecount[3].ToString(); 
     lblCount5.Text = gatecount[4].ToString(); 
     lblCount6.Text = gatecount[5].ToString(); 
     lblCount7.Text = gatecount[6].ToString(); 
     lblCount8.Text = gatecount[7].ToString(); 
     //lblCount0.Text = gatecount[8].ToString(); 
     if (totalcount != 0) 
     { 
      lblPct1.Text = (gatecount[0]/totalcount).ToString("P2"); 
      lblPct2.Text = (gatecount[1]/totalcount).ToString("P2"); 
      lblPct3.Text = (gatecount[2]/totalcount).ToString("P2"); 
      lblPct4.Text = (gatecount[3]/totalcount).ToString("P2"); 
      lblPct5.Text = (gatecount[4]/totalcount).ToString("P2"); 
      lblPct6.Text = (gatecount[5]/totalcount).ToString("P2"); 
      lblPct7.Text = (gatecount[6]/totalcount).ToString("P2"); 
      lblPct8.Text = (gatecount[7]/totalcount).ToString("P2"); 
      //lblPct0.Text = (gatecount[8]/totalcount).ToString("P2"); 
     } 

     lblWeight1.Text = (gate1weight/gatecount[0]).ToString(); 
     lblWeight2.Text = (gate2weight/gatecount[1]).ToString(); 
     lblWeight3.Text = (gate3weight/gatecount[2]).ToString(); 
     lblWeight4.Text = (gate4weight/gatecount[3]).ToString(); 
     lblWeight5.Text = (gate5weight/gatecount[4]).ToString(); 
     lblWeight6.Text = (gate6weight/gatecount[5]).ToString(); 
     lblWeight7.Text = (gate7weight/gatecount[6]).ToString(); 
     lblWeight8.Text = (gate8weight/gatecount[7]).ToString(); 
     //lblWeight0.Text = (gate0weight/gatecount[8]).ToString(); 
    } 

是否有辦法在報告本身要做到這一點?當然,我實際上會將這些值放在報告中的指定位置。

+0

你在說什麼Telerik產品? WinForms,WPF,Silverlight,ASP.Net? – 2012-04-04 15:16:45

+0

我有Telerik Winforms,但我正在談論使用Telerik報告 – CSharpDev 2012-04-04 15:31:12

回答

0

我會做的是爲您的報表類創建一個屬性(或屬性),並在NeedDataSource中設置值(例如表格,圖表和其他要綁定到的元素)你正在詢問的「report_load」)事件處理程序。在那裏,您可以使用這些內部屬性值簡單地綁定或設置報表上的值。通過這種方式,連接字符串對您的報表類來說是無用的,您只需設置屬性(例如,考慮DataSource)並讓報表類負責在內部設置其控制值。

注意:有2類與Telerik報告相關聯。具有所有報表控件等的設計器部分類以及報表類(您的自定義子類)本身。後者是NeedDataSource將去的地方。