سؤال

I designed a form and used the Bar Chart on my form to display the number of students having a particular problem (e.g family problems) in a particular Program (Nursing) in a particular year (say 2009). I designed everything else to get the total from the Database and display it on a Bar Chart. I am able to achieved this on a Form, but I have to generate a report and display the same Bar Chart on a Report. My question is can I achieve this without connecting to the Database? If yes, then Awesome, but How?? Thanks in Advance.

The code below is the code for a Bar Chart for total number of Students with problems (Family problems, drug addict, etc) in a particular program for 3 years.

    public void calculateStatsFor3Years(int year1, int year2, int year3)
    {
         //count the number of students in with intervention in particular program in a year

        intervention.Classes.Programs objPrograms = new intervention.Classes.Programs();

        List<int> programCodeList = objPrograms.GetProgramCode();

        List<int> numStudentsYear1 = new List<int>();
        List<int> numStudentsYear2 = new List<int>();
        List<int> numStudentsYear3 = new List<int>();

        int temp1 = 0;
        int temp2 = 0;
        int temp3 = 0;

        for (int counter = 0; counter < programCodeList.Count; counter++)
        {

            temp1 = Convert.ToInt32(objControllerClass.get_students_intervention_particular_year_program(year1, programCodeList.ElementAt(counter)));

            numStudentsYear1.Add(temp1);

            temp2 = Convert.ToInt32(objControllerClass.get_students_intervention_particular_year_program(year2, programCodeList.ElementAt(counter)));

            numStudentsYear2.Add(temp2);

            temp3 = Convert.ToInt32(objControllerClass.get_students_intervention_particular_year_program(year3, programCodeList.ElementAt(counter)));

            numStudentsYear3.Add(temp3);

        }//for 

        int[] yValues0 = numStudentsYear1.ToArray();//2011-2012
        int[] yValues1 = numStudentsYear2.ToArray();//2010-2011
        int[] yValues2 = numStudentsYear3.ToArray();//2009-2010 


        string[] xNameSeries0 = { "Agent immobilier", "Mécanique du bâtiment", "Gestion des eaus ", "Soins infirmiers ", "Anglais ", "Comtabilité et gestion ", "Bureautique ", "Architecture et gestion de réseau ", "Programmeur web ", "Assurance de dommages ", "O'Bois ", "Éducation à l'enface ", "Francisation " };

        myBarChart.Series[0].Points.DataBindXY(xNameSeries0, yValues0);
        myBarChart.Series[1].Points.DataBindXY(xNameSeries0, yValues1);
        myBarChart.Series[2].Points.DataBindXY(xNameSeries0, yValues2);


        //legend text
        myBarChart.Series[0].LegendText = year1.ToString();
        myBarChart.Series[1].LegendText = year2.ToString();
        myBarChart.Series[2].LegendText = year3.ToString();

    }//calculateStatsFor3Years()

Here's a screenshot of the horizontal graph that I need to display in Crystal Reports.

http://i1342.photobucket.com/albums/o765/CSharpJunior/C%20Sharp%20project/horizontalGraph.jpg

هل كانت مفيدة؟

المحلول

This is possible. The best way is probably to use a dataset. I often refer people to: http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-without-database.htm

using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataSet1 ds = new DataSet1();
            DataTable t = ds.Tables.Add("Items");
            t.Columns.Add("id", Type.GetType("System.Int32"));
            t.Columns.Add("Item", Type.GetType("System.String"));

            DataRow r ;
            int i = 0;
            for (i = 0; i <= 9; i++)
            {
                r = t.NewRow();
                r["id"] = i;
                r["Item"] = "Item" + i;
                t.Rows.Add(r);
            }

            CrystalReport1 objRpt = new CrystalReport1();
            objRpt.SetDataSource(ds.Tables[1]);
            crystalReportViewer1.ReportSource = objRpt;
            crystalReportViewer1.Refresh(); 
        }
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top