Design advice needed: Retrieve data and dynamic data

4 posts, 0 answers
  1. Fredrik
    Fredrik avatar
    42 posts
    Member since:
    Oct 2007

    Posted 16 Aug 2009 Link to this post

    Hi!

    I need some design advice on the implementation of Silverlight controls.

    I have the requirement to build a grid where "all" the properties and behaviour is dynamic, and based on data which is received from a web-service.
    I already have in place (from a previous ASP.NET project) a stored procedure which returns two result-sets:
    * The actual data, which could be any set of columns as well as number of rows
    * The metadata which describes the looks and behaviour for the actual data.

    Examples of metadata:
    - "Hidden". Decides if a certain column should be shown in the grid.
    - "Paging". Decides if paging should be used, pagesize, etc
    - "SelectedItem". Decides which items in the grid which should be selected when the grid initially is loaded.
    - "StyleColumn". Specifies, for a certain column, which other column contains style information, such as font, color, etc

    In other words, the first resultset contains the information which should be shown in the grid, the other resultset decides what it should look like.

    In the current ASP.NET implementation, I have written code to apply the metadata on the ASP.NET grid. I didn't use the "Dynamic data framework", since it wasn't available when I wrote the code. (I never looked much into Dynamic Data, so I'm not sure it would be appropriate to use)

    So, my question is now: How would I go about to implement this in Silverlight? I see two major design decisions:

    How do I pass the data?

    I understand that DataSet, DataTable, etc is not available in Silverlight. So, what would be the best way to pass, through the webservice, the resultsets retrieved from Sql Server?

    How do I use metadata to control the looks/behaviour of the grid in Silverlight?
    I know I can write similar code which I did in the ASP.NET version, but I would prefer to harness anything which is already in place in Silverlight. As I understand it, Dynamic Data is not available. But are there other techniques, which would be useful in my case?

    Thanks!
    /Fredrik

     

  2. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 16 Aug 2009 Link to this post

    As far as passing the data is concerned, you can use the IList class, which is serializable so you can use it in a Web service.

    But you'll need to cast it to have the correct data structure.

    In your svc file, you set your method to return a IList as well, and in Silverlight, in the completed Event methode, you retreive it with a

    IList<youclass> result = e.result;

    In yourclass.cs, you should find the attributes that matches your metadata database structure (hidden, paging, selecteditem...), a constructor, and a method to convert a datatable from your SQL method  into a IList.

    This method works for me.

    To use those metadata, I guess you should create several style like headerstyle, cellstyle which would be set according to your data, but I think the telerik team will be much more helpful than me with this issue.
  3. DevCraft banner
  4. Fredrik
    Fredrik avatar
    42 posts
    Member since:
    Oct 2007

    Posted 16 Aug 2009 Link to this post

    Thanks for your response, Subileae, I appreciate your help!

    I'm not sure I understand fully, though. Can you elaborate?

    For instance, should yourClass resemble the actual data (This wouldn't work since the data is not known at compile time. The stored procedure could return any set of columns, with any datatypes) or the metadata (which is known at compile time)?

    And "a method to convert a datatable from your SQL method  into a IList" - Should this method be invoked on the server-side? And should it be invoked by the serialization framework, or by the svc-code?

    It would be great with some pseudo-code for both server and client-side... :-)

    Thanks again,
    /Fredrik
  5. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 16 Aug 2009 Link to this post

    Sure, I can elaborate.

    For example, I have a radgrid in my application that can take any kind of data,any number of columns of any type.

    In my database, I have one table with 20 attributes, all of them being named txt1 to txt20, which of course limits the total number of columns to 20.
    This table is filled by a trigger procedure that takes several parameters. Given these parameters, it provides me with the data I want to display.

    In my Webservice method

        [OperationContract] 
        public IList<donnees_grilleBO> ExecuteSelectRequestClient(int id_societe,int id_contact,int id_categorie) 
        { 
            return MET_Grille_information.ExecuteSelectRequest(id_societe,id_contact,id_categorie); 
        } 

    and this is donnees_grilleBO.cs

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Runtime.Serialization; 
    using System.Data; 
     
    namespace T2J.Model 
        [DataContract(Name = "donnees_grilleBO"Namespace = "http://schemas.datacontract.org/2004/07/T2J.Model")] 
        public class donnees_grilleBO 
        { 
            [DataMember] 
            public String id_tmp_liste { get; set; } 
     
            [DataMember] 
            public String id_contact { get; set; } 
     
            [DataMember] 
            public String id_categorie_partenaire { get; set; } 
     
            [DataMember] 
            public String id_societe { get; set; } 
     
            [DataMember] 
            public String txta { get; set; } 
     
            [DataMember] 
            public String txtb { get; set; } 
     
            [DataMember] 
            public String txtc { get; set; } 
            [DataMember] 
            public String txtd { get; set; } 
            [DataMember] 
            public String txte { get; set; } 
            [DataMember] 
            public String txtf { get; set; } 
            [DataMember] 
            public String txtg { get; set; } 
            [DataMember] 
            public String txth { get; set; } 
            [DataMember] 
            public String txti { get; set; } 
            [DataMember] 
            public String txtj { get; set; } 
            [DataMember] 
            public String txtk { get; set; } 
            [DataMember] 
            public String txtl { get; set; } 
            [DataMember] 
            public String txtm { get; set; } 
            [DataMember] 
            public String txtn { get; set; } 
            [DataMember] 
            public String txto { get; set; } 
            [DataMember] 
            public String txtp { get; set; } 
            [DataMember] 
            public String txtq { get; set; } 
            [DataMember] 
            public String txtr { get; set; } 
            [DataMember] 
            public String txts { get; set; } 
            [DataMember] 
            public String txtt { get; set; } 
            [DataMember] 
            public int id_partenaire { get; set; } 
            [DataMember] 
            public string nom_colonnes { get; set; } 
     
            public static donnees_grilleBO GetFromDataRow(DataRow r) 
            { 
                donnees_grilleBO temp = new donnees_grilleBO(); 
     
                temp.id_tmp_liste = r["id_tmp_liste"].ToString(); 
                temp.id_contact = r["id_contact"].ToString(); 
                temp.id_categorie_partenaire = r["id_categorie_partenaire"].ToString(); 
                temp.id_societe = r["id_societe"].ToString(); 
                temp.txta = r["txt1"].ToString(); 
                temp.txtb = r["txt2"].ToString(); 
                temp.txtc = r["txt3"].ToString(); 
                temp.txtd = r["txt4"].ToString(); 
                temp.txte = r["txt5"].ToString(); 
                temp.txtf = r["txt6"].ToString(); 
                temp.txtg = r["txt7"].ToString(); 
                temp.txth = r["txt8"].ToString(); 
                temp.txti = r["txt9"].ToString(); 
                temp.txtj = r["txt10"].ToString(); 
                temp.txtk = r["txt11"].ToString(); 
                temp.txtl = r["txt12"].ToString(); 
                temp.txtm = r["txt13"].ToString(); 
                temp.txtn = r["txt14"].ToString(); 
                temp.txto = r["txt15"].ToString(); 
                temp.txtp = r["txt16"].ToString(); 
                temp.txtq = r["txt17"].ToString(); 
                temp.txtr = r["txt18"].ToString(); 
                temp.txts = r["txt19"].ToString(); 
                temp.txtt = r["txt20"].ToString(); 
                temp.id_partenaire = (int)r["id_partenaire"]; 
                temp.nom_colonnes = r["nom_colonnes"].ToString(); 
     
                return temp; 
            } 
            public static IList<donnees_grilleBO> GetListFromDataTable(DataTable t) 
            { 
                IList<donnees_grilleBO> l_liste = new List<donnees_grilleBO>(); 
                if (t != null) 
                { 
                    for (int i = 0; i < t.Rows.Count; i++) 
                    { 
                        l_liste.Add(donnees_grilleBO.GetFromDataRow(t.Rows[i])); 
                    } 
                } 
                return l_liste; 
            } 
     
        } 
     
     

    the method I was talking about, to convert a dataTable into an IList is GetListFromDataTable.

    And finally, to use this in Silverlight, you must have :

     _wsSilverclient.ExecuteSelectRequestClientAsync(id_societe, id_categorie, id_contact); 
                _wsSilverclient.ExecuteSelectRequestClientCompleted += new EventHandler<ExecuteSelectRequestClientCompletedEventArgs>(_wsSilverclient_ExecuteSelectRequestClientCompleted); 

    and

    private void _wsSilverclient_ExecuteSelectRequestClientCompleted(object sender, ExecuteSelectRequestClientCompletedEventArgs e) 
            { 
                String[] ComboValeurs; 
                _wsSilverclient.ExecuteSelectRequestClientCompleted -new EventHandler<ExecuteSelectRequestClientCompletedEventArgs>(_wsSilverclient_ExecuteSelectRequestClientCompleted); 
                if (e.Result != null) 
                { 
                    IList<donnees_grilleBO> result = e.Result; 
                   //rest of the code 
                } 

    I hope you can use these portions of code and adapt them for your needs.
    The only tricky thing is to have a table you can map to provide you with all you need.











Back to Top