26 May 2010

Open asp.net crystal report from Silverlight 4 - Report with List T and List S subreport


1.- The sources: (To do not have CR errors)

Let's suppose (I like when it works) create a Crystal Report with a Subreport and the source are two List and List.

How can I set the sources.
A.- Create a new report in the project.
B.- Set the following as sources (Both the main and the child one):




 C.- Now you add the subreport to the main report:

D.-And add only the child class.
E.- Now in the main Report from database expert remove the child class because we needed it only to be able to add the child report.



In this moment we have defined the design of the report. Now by code we will fill it in the aspx:
 
E.- We add the viewer and a source

F.- In the .cs we add the following: (Create the templates, depending on the version you will need it)



#region Create XML Templates
XEvento xe = new XEvento();
xe.Cliente = "";
xe.Comercial = "";
xe.Fecha = new DateTime(2010, 10, 10);
xe.SerializeObj(XEvento.ItemsFile);

XHistorico xh = new XHistorico();
xh.Nombre = "Prueba";
xh.Fecha = new DateTime(2010, 10, 10);
xh.Detalle = "Esto es otra prueba";
xh.SerializeObj(XHistorico.ItemsFile);
#endregion

G.- Fill the two lists with your data.
H.- On Page_Load:
this.CrystalReportSource1.ReportDocument.Subreports[0].SetDataSource(xhs);
            this.CrystalReportSource1.ReportDocument.SetDataSource(xes);


And that's all the first part in the asp.net


2.- In a method in the silverlight:


private void BPrint_Click(object sender, RoutedEventArgs e)
        {
            HtmlPopupWindowOptions options = new HtmlPopupWindowOptions()
            {
                Directories = false,
                Location = false,
                Menubar = false,
                Status = false,
                Toolbar = false,
            };

            HtmlPage.PopupWindow(new Uri("http://localhost:51694/Reporting.aspx?Fecha=" + DP.SelectedDate.Value.Date.ToShortDateString().Replace('/','.') ), "_blank", options);
        }


3.- In the Page_Load in the asp.net capture the parameter:


this.TextBox1.Text = HttpContext.Current.Request.Params["Fecha"];

Now you have to set it as a parameter of the crystal report and that's all.

No comments: