Visual Studio c# Telerik Reporting

本文关键字:Reporting Telerik Studio Visual | 更新日期: 2023-09-27 18:30:04

我刚刚下载了Telerik,在互联网上找不到太多帮助。我希望能够生成一份华而不实的报告,而Telerik似乎是我的选择。话虽如此,我不想使用所有的向导和垃圾来构建我的报告。加载报告时,我是否可以使用某种"report_load"函数。我需要能够配置连接字符串,并且让用户输入一些值来生成报告。

以下是生成报告的代码:

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();
    }

有没有办法在报告中做到这一点?当然,我实际上会把这些值放在报告中定义的地方。

Visual Studio c# Telerik Reporting

我要做的是为报表类创建一个或多个属性,并在NeedDataSource(您正在询问的"report_load")事件处理程序中设置值,如表、图表和其他绑定到的元素(或为其设置值)。在那里,您可以简单地使用这些内部属性值绑定或设置报表上的值。通过这种方式,连接字符串与报表类无关,您只需设置属性(例如DataSource),并让报表类负责在内部设置其控制值。

注意:有2个类与Telerik报告相关。设计器分部类,它包含所有报表控件等,以及报表类(您的自定义子类)本身。后者是NeedDataSource的用武之地。