Need help with dynamic tables/data in Silverlight Control

Stimulsoft Reports.Silverlight discussion
DavidWatt
Posts: 13
Joined: Mon Jan 16, 2017 4:28 pm

Need help with dynamic tables/data in Silverlight Control

Post by DavidWatt »

I am trying to do the following using Silverlight 5 and Visual Studio 2015 Update 3

Goals:
1. Insert the StiSLViewerControl into an Xaml screen, and display the Stimulsoft Designer, and provide the capability to preview data
2. Dynamically create a subset of tables available to the end users (I.e. we have hundreds of Database tables and we only want to provide the end users with a few when they are designing a report)

Current attempts:
1. Created a dynamic DataSet and registered as a business object
a. This works well and shows all the tables and fields
b. For Preview mode I cannot see the data to the dataset (in Preview mode or in Visual Studio Debugger - I see the dataset rows in the Debugger but not the field values). How can I get the data into the dataset (Reminder: Silverlight client side)?
2. Created Objects (& Child objects), added data
a. This displays the fields and Data nicely
b. How can I do this, and dynamically hide various tables / objects?
3. I tried to deserialize a JSON string into a "dynamic" c# type and register it as a business object
a. In this case I am seeing a significant number of tables and fields in the designer, which I do not want to show the end user

Can you help me with one of these approaches, or possibly another?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Need help with dynamic tables/data in Silverlight Contro

Post by Alex K. »

Hello,

Can you please send us a simple project which reproduces the issue for analysis.

Thank you.
DavidWatt
Posts: 13
Joined: Mon Jan 16, 2017 4:28 pm

Re: Need help with dynamic tables/data in Silverlight Contro

Post by DavidWatt »

Below are 2 files for the System.Data.DataSet option:

MainPage.xaml:

<UserControl x:Class="Demo_DataSet.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006 ... esentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/marku ... ility/2006"
xmlns:SLDesign="clr-namespace:Stimulsoft.Report.SLDesign;assembly=Stimulsoft.Report.SLDesign"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
Loaded="UserControl_Loaded"
>

<Grid x:Name="LayoutRoot" Background="White">

<SLDesign:StiSLDesignerControl Grid.Row="1" x:Name="StiWebDesignerSL1" HorizontalAlignment="Left" Margin="5" VerticalAlignment="Top"/>

</Grid>
</UserControl>




MainPage.xaml.cs:
using Stimulsoft.Report;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Controls;

namespace Demo_DataSet
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
StiReport report = new StiReport();

DataSet dataSet = CreateTestDataSet();
report.RegBusinessObject("DataSet", "DataSet", dataSet);

report.Dictionary.SynchronizeBusinessObjects(3);

report.Design();
}


private DataSet CreateTestDataSet()
{
Random random = new Random();

DataSet dataSet = new DataSet();

DataTable dataTableTimeZone = new DataTable("TimeZone");
dataSet.Tables.Add(dataTableTimeZone);
DataColumn dataColumn = new DataColumn("TimeZoneID", typeof(int));
dataSet.Tables[dataTableTimeZone.TableName].Columns.Add(dataColumn);
dataColumn = new DataColumn("Description", typeof(string));
dataSet.Tables[dataTableTimeZone.TableName].Columns.Add(dataColumn);



DataTable dataTableFacility = new DataTable("Facility");
dataSet.Tables.Add(dataTableFacility);
dataColumn = new DataColumn("FacilityID", typeof(int));
dataSet.Tables[dataTableFacility.TableName].Columns.Add(dataColumn);
dataColumn = new DataColumn("FacilityName", typeof(string));
dataSet.Tables[dataTableFacility.TableName].Columns.Add(dataColumn);
dataColumn = new DataColumn("TimeZone", typeof(int));
dataSet.Tables[dataTableFacility.TableName].Columns.Add(dataColumn);


DataRelation dataRelation = new DataRelation("FacilityTimeZone", dataTableFacility, dataTableTimeZone);
dataSet.Relations.Add(dataRelation);



var timezones = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "Atlantic Time"),
new KeyValuePair<int, string>(2, "Eastern Time"),
new KeyValuePair<int, string>(3, "Central Time"),
new KeyValuePair<int, string>(4, "Mountain Time"),
new KeyValuePair<int, string>(5, "Pacific Time"),
new KeyValuePair<int, string>(7, "Alaska Time"),
new KeyValuePair<int, string>(8, "Hawaiian Time"),
new KeyValuePair<int, string>(9, "Alaska (Aleutian Islands) Time"),
new KeyValuePair<int, string>(10, "Arizona Time"),
new KeyValuePair<int, string>(11, "Arizona (Navajo) Time"),
new KeyValuePair<int, string>(12, "Somoa Time"),
new KeyValuePair<int, string>(13, "Chomarro Time"),
new KeyValuePair<int, string>(14, "Signapore Time"),
};

var facilities = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "Facility A"),
new KeyValuePair<int, string>(2, "Facility B"),
new KeyValuePair<int, string>(3, "Facility C"),
new KeyValuePair<int, string>(4, "Facility D"),
new KeyValuePair<int, string>(5, "Facility E"),
new KeyValuePair<int, string>(7, "Facility F"),
new KeyValuePair<int, string>(8, "Facility G"),
new KeyValuePair<int, string>(9, "Facility H"),
new KeyValuePair<int, string>(10, "Facility I"),
};


foreach (KeyValuePair<int, string> timezone in timezones)
{
System.Data.DataRow dataRow;
dataTableTimeZone = dataSet.Tables["TimeZone"];
dataRow = dataTableTimeZone.NewRow();

dataRow["TimeZoneID"] = timezone.Key;
dataRow["Description"] = timezone.Value;

dataTableTimeZone.Rows.Add(dataRow);
}


foreach (KeyValuePair<int, string> facility in facilities)
{
System.Data.DataRow dataRow;
dataRow = dataSet.Tables["Facility"].NewRow();

dataRow["FacilityID"] = facility.Key;
dataRow["FacilityName"] = facility.Value;
dataRow["TimeZone"] = random.Next(1, 14);

dataSet.Tables["Facility"].Rows.Add(dataRow);
}

return dataSet;
}

}
}
DavidWatt
Posts: 13
Joined: Mon Jan 16, 2017 4:28 pm

Re: Need help with dynamic tables/data in Silverlight Contro

Post by DavidWatt »

For the Object version How can I hide objects (dynamically)? This one works fine, but I need to hide data.

Note: I use your Data.cs object from your Samples and did not include it here.

MainPage.xaml

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006 ... esentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/marku ... ility/2006"
xmlns:SLDesign="clr-namespace:Stimulsoft.Report.SLDesign;assembly=Stimulsoft.Report.SLDesign" x:Class="Demo_Objects.MainPage"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
Loaded="UserControl_Loaded">

<Grid x:Name="LayoutRoot" Background="White">

<SLDesign:StiSLDesignerControl Grid.Row="1" x:Name="StiWebDesignerSL1" HorizontalAlignment="Left" Margin="5" VerticalAlignment="Top" />

</Grid>
</UserControl>



MainPage.xaml.cs


using Stimulsoft.Report;
using System.Windows;
using System.Windows.Controls;

namespace Demo_Objects
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
//var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("UsingBusinessObjects.SimpleList.mrt");

StiReport report = new StiReport();
//report.Load(stream);

//stream.Close();
//stream.Dispose();
//stream = null;
report.CalculationMode = StiCalculationMode.Interpretation;
report.RegBusinessObject("Data", "Data", new Data());

report.Dictionary.SynchronizeBusinessObjects(3);

report.Design();
}
}
}
DavidWatt
Posts: 13
Joined: Mon Jan 16, 2017 4:28 pm

Re: Need help with dynamic tables/data in Silverlight Contro

Post by DavidWatt »

I did not create the JSON method yet. I was hoping I could deserialize a Json object and feed it to your RegBusinessObject method some how giving me the ability to dynamically set the tables, fields, and some data for the preview.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Need help with dynamic tables/data in Silverlight Contro

Post by Alex K. »

Hello,

Dynamic changes and preview data are not available on the client side in the SL version.
All data retrieved before render report on the server and then send to the client in the viewer.

Thank you.
DavidWatt
Posts: 13
Joined: Mon Jan 16, 2017 4:28 pm

Re: Need help with dynamic tables/data in Silverlight Contro

Post by DavidWatt »

How do you create the DemoNet.data files in your demo? Was this built by using the dataSet.WriteXml (C#) command? Can you supply example code to build these data files?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Need help with dynamic tables/data in Silverlight Contro

Post by HighAley »

Hello, David.

Yes, we use standard .Net Framework methods DataSet.WriteXml() and DataSet.WriteXmlSchema().
You could use them to create the XML file with data.

Thank you.
DavidWatt
Posts: 13
Joined: Mon Jan 16, 2017 4:28 pm

Re: Need help with dynamic tables/data in Silverlight Contro

Post by DavidWatt »

Can you give me an example of this code? I would like to see the details used in these calls so I can match them. My output does not look like the output in DemoNet.data.
DavidWatt
Posts: 13
Joined: Mon Jan 16, 2017 4:28 pm

Re: Need help with dynamic tables/data in Silverlight Contro

Post by DavidWatt »

What .net version are you using? Is there a Sti structure you populate and use to create the data file in your samples? I believe a good example of how you create your sample *.data files would answer most of my questions.
Last edited by DavidWatt on Mon Jan 23, 2017 5:39 pm, edited 1 time in total.
Locked