This is a migrated thread and some comments may be shown as answers.

Help populating rad controls from repository pattern methods

4 Answers 80 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
WebTeam
Top achievements
Rank 1
WebTeam asked on 05 Nov 2012, 10:52 AM
Hi,

I am very new to using Telerik tools, I have just about got a grasp on EF, UnitOfWork and repository pattern which was further complicated by the fact I using Devart's dotConnect for Oracle.

What I would like to know is, based on the fact I am working with Oracle and have abstracted this issue in to a repository pattern, how can I work with my repository pattern methods and RadControls.

Perhaps we could start with a very basic populate a listbox?

I have a method that returns an Enumerable List:

public IEnumerable GetNodesByParent(string Jid)
{
    UnitOfWork unitofwork = new UnitOfWork();
    return (from r in unitofwork.PsldwRepository.Get()
            where r.RELRELAT01A == Jid
            select r.PDTCODEA).ToList();
}

I then have a standard telerik web form and have dropped a listbox object on to it. Please can you tell me how I go about using the method above, which is in my Project.BL namespace, to populate the list box?

Many thanks,

Andy

4 Answers, 1 is accepted

Sort by
0
WebTeam
Top achievements
Rank 1
answered on 06 Nov 2012, 04:25 PM
Hi,

I have played around a little more and have managed to work out how data is bound to the objects.

I am now specifically working with the OrgChart, I have a new query the creates and IEnumerable<OrgChartDataItem> which I use to bind data to the OrgChart Object.

This contains a full set of data for ALL staff or in the case of my OrgChart all jobs.

So what I do is use the position table to get a current list of jobs for all staff and then crate the org chart data collection based on jobs.

So....

Each Job Code = a Node ID
Each Job Title = the Node Text
And the managerd Job Code is returned from the relationship table which is a join to the position table on Job Code and supplies the Mangers Job Code which = the PartentID

This is my model for OrgChartData

public class OrgChartDataItem
    {
        private string _id;
        private string _text;
        private string _parentId;
 
        [Key]
        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }
 
        public string Text
        {
            get { return _text; }
            set { _text = value; }
        }
 
        public string ParentID
        {
            get { return _parentId; }
            set { _parentId = value; }
        }
 
        public OrgChartDataItem(string id, string text, string parentId)
        {
            _id = id;
            _text = text;
            _parentId = parentId;
        }
    }

This is my business layer which creates the data source for the OrgChart:

public IEnumerable<OrgChartDataItem> GetAllNodeData()
        {
            UnitOfWork uow = new UnitOfWork();
            IEnumerable<OrgChartDataItem> ocdi = (from r in uow.PsldwRepository.Get()
                                                  join p in CurrentPOS() on r.PDTCODEA equals p.POSNUMBERA
                                                  where r.RELRELAT01A != "999999"
                                                  select new OrgChartDataItem(p.POSNUMBERA, p.POSTITLEA, r.RELRELAT01A));
            OrgChartDataItem man = (from r in uow.PsldwRepository.Get()
                       join p in CurrentPOS() on r.PDTCODEA equals p.POSNUMBERA
                       where r.RELRELAT01A == "999999"
                       select new OrgChartDataItem(p.POSNUMBERA, p.POSTITLEA, null)).Single();
 
            ocdi = ocdi.Add(man);
            return (ocdi);
        }
 
public IEnumerable<EMPOS> CurrentPOS()
        {
            UnitOfWork unitofwork = new UnitOfWork();
            return (from n in unitofwork.EmposRepository.Get()
                    where n.POSSTARTC <= DateTime.Today &&
                    (n.POSENDD == null || n.POSENDD > DateTime.Today)
                    && n.POSLVEGRPA != "PEN"
                    select n).ToList();
        }

This is my on page load:

Protected void Page_Load(object sender, EventArgs e)
    {
        BusinessLayer BL = new BusinessLayer();
        RadOrgChart1.DataFieldID = "ID";
        RadOrgChart1.DataFieldParentID = "ParentID";
        RadOrgChart1.DataTextField = "Text";
        RadOrgChart1.DataSource = BL.GetAllNodeData();
        RadOrgChart1.MaxDataBindDepth = 3;
        RadOrgChart1.DataBind();
    }

And this is my Mark Up for the page:

<div class="qsf-demo-canvas">
        <telerik:RadAjaxLoadingPanel runat="server" ID="RadLoadingPanel1" Skin="Telerik" />
 
    <div class="qsf-demo-canvas">
        <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="RadLoadingPanel1">
            <telerik:RadOrgChart ID="RadOrgChart1" runat="server" EnableDrillDown="true"
                LoadOnDemand="Nodes" MaxDataBindDepth="3" />
        </telerik:RadAjaxPanel>
    </div>
    </div>

I aim to get the OrgChart to load up from the CEO with 3 levels down initially as the page loads. So I have set the MaxDataBindDepth to 3, I also want to be able to move from the top and drill down to bottom so I have enabled drill down.

As the org chart is running off jobs rather than people I want to be able to show vacant positions, but I think this may be creating the issue I am getting to some extent...

As you can imagine in a large organisation, there are some empty positions that people report in to until they are repopulated. This means there may be nodes that aren't on the position selection and I think that may be half the problem as the manager ID or ParentID will exist in the Relationship table for a node, but that manager node won't exist in the Position table.

Can you advise what the best way of dealing with this situation would be?

Also a later function I need help with, is that for each node I want to list the employees who are in that job (as a node is a job code), how could I go about doing this so within each node, it still displays the node text as the Job title, but below this lists all the employee names who are in that job or says vacant if there aren't any?

I hope some one can help,

Andy
0
Peter Filipov
Telerik team
answered on 08 Nov 2012, 09:36 AM
Hello Andrew,

My suggestion is to use GroupEnabled binding and you could have empty groups which will indicates vacant jobs positions. Also you could review the drag and drop demo to review how an empty group look like when the groupitems are reordered. To add extra information in the groupitems you could use templates or rendered fields.

Regards,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
WebTeam
Top achievements
Rank 1
answered on 13 Nov 2012, 11:58 AM
Hi,

Thanks, I am getting there slowly. I will have a go with the group enabled binding, however the idea was to narrow the tree.

So this being said I aimed to have nodes based on job codes and list the staff in a rendered field within the node.

So my Node structure is Node ID = Job Code, Text = Job Title, Parent ID = Manager Job Code

What I had tried to do for the rendered field I called "Staff" was create another model called NodeContents which holds the staff details.

string Job Code (or Node Id)
string Employee ID
string Forename
string Surname

I then have a function that returns an IEnuerable<NodeContents> and this is held within the NodeDataItem, i.e:

string Node ID
string Text
string Parent ID
IEnumerable<NodeContents> Staff

The issue I found with this was that it produced an Out of Memory exception.

I also just tried stroring staff as a string and within the repository method that gets the org chart data I call the function as before that gets the node contents but this time returns it as a string.

The problem with this is that it is painfully slow as the function is as follows:

public IEnumerable<EMPOS> CurrentPOS()
{
    UnitOfWork unitofwork = new UnitOfWork();
    return (from n in unitofwork.EmposRepository.Get()
            where n.POSSTARTC <= DateTime.Today &&
            (n.POSENDD == null || n.POSENDD > DateTime.Today)
            && n.POSLVEGRPA != "PEN"
            select n).ToList();
}
 
public IEnumerable<OrgChartDataItem> GetAllNodeData()
{
    UnitOfWork uow = new UnitOfWork();
 
 
    IEnumerable<OrgChartDataItem> ocdi = (from p in CurrentPOS()
                                          join r in uow.PsldwRepository.Get() on p.POSNUMBERA equals r.PDTCODEA
                                          where r.RELRELAT01A != "999999" && p.POSNUMBERA != "EFBTMK"
                                          select new OrgChartDataItem(p.POSNUMBERA, p.POSTITLEA, r.RELRELAT01A, true, GetNodeContents(p.POSNUMBERA)));
    OrgChartDataItem man = (from r in uow.PsldwRepository.Get()
                            join p in CurrentPOS() on r.PDTCODEA equals p.POSNUMBERA
                            where r.RELRELAT01A == "999999"
                            select new OrgChartDataItem(p.POSNUMBERA, p.POSTITLEA, null, false,GetNodeContents(p.POSNUMBERA))).Single();
 
    ocdi = ocdi.Add(man);
    return (ocdi);
}
 
public string GetNodeContents(string Nid)
{
    UnitOfWork uow = new UnitOfWork();
    string ndi = "";
    var query = (from p in CurrentPOS()
                 where p.POSNUMBERA == Nid
                 select p.DETNUMBERA);
    if (query.Count() > 0)
    {
        foreach (string emp in query)
        {
            if (ndi.Length > 0)
            {
                ndi = ndi + Environment.NewLine + emp;
            }
            else
            {
                ndi = emp;
            }
        }
    }
    else
    {
        ndi = "Vacant";
    }
    return (ndi);
}


What would you suggest is the best way of working and is there any way I can better use LOD to reduce the amount of data being queried that is not needed?

Also can the rendered fields be rendered as part of a node expand or collapse i.e. the 2 top levels that are initially loaded are populated with node contents ONLY, then as you expand nodes below it uses LOD to get the structure and render the NodeContents or Staff rendered field?

What do you think is the best way of doing this?

Is it possible to render a list as a rendered field and for it to be quick?

Many thanks,

Andy
0
Peter Filipov
Telerik team
answered on 16 Nov 2012, 11:05 AM
Hi Andrew,

I setup a sample project for you. An OrgChart with 5000 groupItems divided in 10 groups. Please test the attachment. In that case the functionalities of the control are working properly.
I added an AjaxLoadingPanel which indicates the drill down process. In order to observe it better uncomment the code in the DrillDown event.
Using DrillDown and MaxBindDepth you could limit the depth of the binding and decrease the amount of the retrieved data. When LOD is used the whole structure of the RadOrgChart is bind on every callback.

Regards,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
General Discussions
Asked by
WebTeam
Top achievements
Rank 1
Answers by
WebTeam
Top achievements
Rank 1
Peter Filipov
Telerik team
Share this question
or