Binding Collection of Custom Entity

Stimulsoft Reports.NET discussion
Post Reply
Claudio Maccari
Posts: 12
Joined: Fri Jun 09, 2006 11:53 am
Location: Italy

Binding Collection of Custom Entity

Post by Claudio Maccari »

Hello,

I'm working with a custom entity User which a have a Logs collection.
If I bind an instance of User to the report I see Logs a property but I don't know how bind the entries of the Logs collection to the report.
Thank you in advance for your help.



Here follow you will find my class that create the custom entities.

Code: Select all

namespace Demo
{
    public class User
    {
        public User()
        {
            logs = new Collection();
        }
        private int id;
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        
        public string Name
        {
            get { return string.Format("User {0}", Id); }            
        }

        private Group group;
        public Group Group
        {
            get { return group; }
            set { group = value; }
        }

        private Collection logs;
        public Collection Logs
        {
            get { return logs; }
            set { logs = value; }
        }	
    }

    public class Group
    {
        private int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
    }

    public class Log
    {
        private DateTime date;

        public DateTime Date
        {
            get { return date; }
            set { date = value; }
        }

        private string action;

        public string Action
        {
            get { return action; }
            set { action = value; }
        }
    }

    public sealed class DatabaseFacade
    {
        public static User GetUser()
        {
            Group group = new Group();
            group.Name = "Admin";
            User user = new  User();
            user.Id = DateTime.Now.Millisecond;
            user.Group = group;
            for (int i = 0; i < 100; i++)
            {
                user.Logs.Add(CreateLogEntry());
            }
            return user;
        }

        private static Log CreateLogEntry() 
        {
            Log l = new Log();
            l.Date = DateTime.Now;
            l.Action = "Access denied";
            return l;
        }
    }
}
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Binding Collection of Custom Entity

Post by Edward »

Try to use this code:

Code: Select all

report.RegData("Logs",user.Logs)
Claudio Maccari
Posts: 12
Joined: Fri Jun 09, 2006 11:53 am
Location: Italy

Binding Collection of Custom Entity

Post by Claudio Maccari »

Thank you for your prompt reply

I use Collection and I get error in designer cause the Report class contains this line of code:

Code: Select all

new Stimulsoft.Report.Dictionary.StiDataColumn("Logs", typeof(System.Collections.ObjectModel.Collection`1))});
If I change the collection type with a custom collection like this

Code: Select all

    public class LogCollection : CollectionBase
    {
        public void Add(Log phone)
        {
            List.Add(phone);
        }

        public void AddRange(Log[] phone)
        {
            base.InnerList.AddRange(phone);
        }

        public bool Contains(Log phone)
        {
            return List.Contains(phone);
        }

        public int IndexOf(Log phone)
        {
            return List.IndexOf(phone);
        }

        public void Insert(int index, Log phone)
        {
            List.Insert(index, phone);
        }

        public void Remove(Log phone)
        {
            List.Remove(phone);
        }
    }
it works but I can get reference between Logs collection and the User.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Binding Collection of Custom Entity

Post by Edward »

1. You need use version 1.60 for generic collection.
2. Please write to Image. We will send you link to patch.
Thanks.
Claudio Maccari
Posts: 12
Joined: Fri Jun 09, 2006 11:53 am
Location: Italy

Binding Collection of Custom Entity

Post by Claudio Maccari »

I'm not yet a Stimulsoft customer I'm just evaluating your reporting product.
Could I get the patch or is available only for customers?
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Binding Collection of Custom Entity

Post by Vital »

You can contact to Image to receive patch.
Thanks.
Post Reply