Get IOrder of current context in Snap Section

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

JDavis
Posts: 97
Joined: Mon Sep 22, 2008 5:10 pm

Get IOrder of current context in Snap Section

Post by JDavis »

In 2.1 we could get the current Order in the context with the following code:

Code: Select all

Private _order As IOrder
Private _session As Session

_session = New Session(SecurityCache.Instance)
_order = Gateway.Create(_session, CType(_context, Order))
In 2.2, the SDK shows how to retrieve an order with the OrderQuerySpec object if we were in an exteral application and knew the order number. What can we use to pass in the current context/session from within a Snap Section to retrieve the current order?
JDavis
Posts: 97
Joined: Mon Sep 22, 2008 5:10 pm

Re: Get IOrder of current context in Snap Section

Post by JDavis »

I am able to use the following to retrieve the current order in my immediate window:

Code: Select all

CType(_context, SoftPro.BusinessObjects.Core.Order)
However, I can't assign this to an IOrder object as it says that in this context SoftPro.BusinessObjects.Core.Order is marked as "Friend".
JDavis
Posts: 97
Joined: Mon Sep 22, 2008 5:10 pm

Re: Get IOrder of current context in Snap Section

Post by JDavis »

Anyone?
Mark McKenna

Re: Get IOrder of current context in Snap Section

Post by Mark McKenna »

The SoftPro.BusinessObjects.Core.Order type has internal accessibility, so your projects will not be able to reference it directly. Further, its important to recognize that Order does not implement SoftPro.OrderTracking.Client.IOrder, rather, the latter provides a public interface to an order proxy class through which order information may be obtained.

Now, within a snapsection, _context is type SoftPro.BusinessObjects.Base.IBusinessObject, which has a RootContext property of type SoftPro.BusinessObjects.Base.ContextRoot. For any business object that "lives" under the root Order object, this handy little property provides direct access back to the Order object itself. You can then work with the OrderQuerySpec as follows:

Code: Select all

// for clarity, error handling has been omitted
ContextRoot root = _context.RootContext;
string orderNumber = root.GetDataItem( "Number" ) as string;
SoftPro.Select.Client.SelectServer server = new SelectServer( new Uri(@"<url>") ); // provide network credentials, etc, as appropriate
SoftPro.OrderTracking.Client.OrderTracking trackingService = server.GetService<SoftPro.OrderTracking.Client.OrderTracking>();
using ( IOrder order = trackingService.GetOrder( new OrderQuerySpec() { BaseOrderNumber = orderNumber }, true) )
{
    try
    {
        // Do stuff with order
    }
    finally
    {
         trackingService.CloseOrder( order );
    }
}
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: Get IOrder of current context in Snap Section

Post by roteague »

Thanks Mark, that helps a lot.
Robert
JDavis
Posts: 97
Joined: Mon Sep 22, 2008 5:10 pm

Re: Get IOrder of current context in Snap Section

Post by JDavis »

When in the context of a snap section, it does not make sense for us to pass in our own value for the URI of the Select Server:

Code: Select all

Dim server As New SoftPro.Select.Client.SelectServer("http://localhost/SelectServer")
How do we get the current URI for the Select Server that the user is connected to?
Phil Barton
Posts: 54
Joined: Wed Sep 24, 2008 2:37 pm
Location: Raleigh, NC
Contact:

Re: Get IOrder of current context in Snap Section

Post by Phil Barton »

Another possible way for you to retrieve the IOrder in the snap section is:

Code: Select all

IWindowFrame frame = base.GetService<IWindowFrame>();
IOrder order = frame.GetProperty("Order") as IOrder;
Don't make this call in the costructor, though, in that it may fail and cause the snap section not to instantiate.
Phil Barton
Software Architect
SoftPro
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: Get IOrder of current context in Snap Section

Post by roteague »

Phil Barton wrote:Another possible way for you to retrieve the IOrder in the snap section is:

Code: Select all

IWindowFrame frame = base.GetService<IWindowFrame>();
IOrder order = frame.GetProperty("Order") as IOrder;
Don't make this call in the costructor, though, in that it may fail and cause the snap section not to instantiate.
We are using the OnContextNonNull event to load the order data from.
Robert
Phil Barton
Posts: 54
Joined: Wed Sep 24, 2008 2:37 pm
Location: Raleigh, NC
Contact:

Re: Get IOrder of current context in Snap Section

Post by Phil Barton »

I think you should be fine to use it in that event handler.
Phil Barton
Software Architect
SoftPro
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: Get IOrder of current context in Snap Section

Post by roteague »

Phil Barton wrote:Another possible way for you to retrieve the IOrder in the snap section is:

Code: Select all

IWindowFrame frame = base.GetService<IWindowFrame>();
IOrder order = frame.GetProperty("Order") as IOrder;
Don't make this call in the costructor, though, in that it may fail and cause the snap section not to instantiate.
Can you tell us what other properties are available using the GetProperty method?
Robert
Post Reply