Use Case Issue - Different Field Required for Sort

Use Case Issue - Different Field Required for Sort

Old forum URL: forums.lhotka.net/forums/t/1542.aspx


jkellywilkerson posted on Thursday, October 19, 2006

Hello All,

I have a use case that requires an Agent.  The agent can be a person or a company.  The issue that I have is that I need to order/sort an NVL BO by name or number.  I have solved that issue; however, if the agent is a company, the CompanyName field is used and, if the agent is a person, the LastName and FirstName fields are used.  Therefore, when the order/sort by name occurs, the "Company Agents" appear in the list first because the LastName and FirstName fields are "String.Empty".

I am using two different stored procedures to return the data for the BO: one that orders by AgentNumber and one that orders by LastName, FirstName, CompanyName.  When I use the BO in the UI, I call AgentNVL.GetAgentList(False) to sort by "Number" and AgentNVL.GetAgentList(True) to sort by "Name".

How do I force the CompanyName field to sort with the LastName.  For instance, I have the following data:

   AgentNumber            LastName            FirstName            CompanyName

   0001                           Williams               John                    

   0002                           Williams               Amy

   0003                                                                                 Winton Corporation

That is how it looks using the order/sort by AgentNumber, but whenever the NVL is ordered/sorted by "Name", I get "0003" listed first, "0002" second, and then "0001".  It should be listed with "0002" first,"0001" second, and "0003" last.

Any help is greatly appriciated.

Kelly.

ajj3085 replied on Thursday, October 19, 2006

Perhaps you could implement IComparable? 

jkellywilkerson replied on Thursday, October 19, 2006

Hey Andy,

I don't think I'm quite ready to tackle that one yet (at least "level-of-knowledge-wise" anyway).  I would not even know where to start.  Thanks for the idea though; I may have to use that as a last resort.

Kelly.

malloc1024 replied on Thursday, October 19, 2006

You could create a name field that returns a company name for a company and the last name + first name for a person.  You would sort by name.  I not sure it this is what you exactly want, but it is an alternative to what you are doing.

jkellywilkerson replied on Thursday, October 19, 2006

That is basically what I'm doing.  I put a check in for the string.length of the fields and if the company name is > 0 then I use the CompanyName and if the last name is > 0 I use LastName, FirstName.  But how do I tell the NVL to sort after the data has been returned from the stored proc?  Do I sort the list from the UI or sort in BO after the list is populated?  Not sure I know how to do that in the BO.  I'm sure that would be the best place to do it because there could be eight or ten thousand agents.  I would think that it would take at least a few seconds to sort it in the UI, don't you think?

Kelly.

ajj3085 replied on Thursday, October 19, 2006

probably the best bet is to toss the resulting list into a SortedBindingList.  Note that the sorting is then done client side and in the UI layer... which is fine, because sorting is a display thing anyway, rarely does the sort really matter to the business layer.

The sort should go pretty quickly.

Finally, Implementing IComparable is pretty easy.  Its just one method.  Basically you woudl figure out what kind of agent the current instance is and what kind the passes instance is, throw the approprate values into two strings, then hand off to string.Compare.

Andy

jkellywilkerson replied on Thursday, October 19, 2006

Thanks Andy,

I'll try the SortedBindingList first.  Then, I'll try the IComparable route just to see which is better.

Thanks for the advice.

Kelly.

ajj3085 replied on Thursday, October 19, 2006

Kelly,

Either way you'll be using sortedbindinglist I would think.  The IComparable method would be instead of creating a third property which picks what to display (fname + lname or company name).

Andy

Copyright (c) Marimer LLC