Cameron API New Order

Discussions related to custom development with Select.
john.morton
Posts: 89
Joined: Wed Nov 16, 2011 11:51 am

Re: Cameron API New Order

Post by john.morton »

Please ensure you have the following using statements:

Code: Select all

using SoftPro.Select.Client;
using SoftPro.OrderTracking.Client.Orders;
using SoftPro.ClientModel;
using SoftPro.ClientModel.Linq;
using SoftPro.Select.Client.Profiles;
sanjay.mittal
Posts: 94
Joined: Mon Dec 28, 2009 3:43 pm

Re: Cameron API New Order

Post by sanjay.mittal »

It didn't make any difference.
john.morton
Posts: 89
Joined: Wed Nov 16, 2011 11:51 am

Re: Cameron API New Order

Post by john.morton »

Could you please post your whole code sample for this?
sanjay.mittal
Posts: 94
Joined: Mon Dec 28, 2009 3:43 pm

Re: Cameron API New Order

Post by sanjay.mittal »

Option Strict Off
Imports System
Imports System.IO
Imports System.Xml
Imports System.Data.SqlClient
Imports System.Timers
Imports System.Threading
Imports System.Messaging
Imports System.Reflection
Imports System.Net
Imports System.Runtime.InteropServices
Imports ERprjSmartHostWcfClient
Imports ERprjSmartServiceBusWcfClient

Imports SoftPro.Select.Client
Imports SoftPro.OrderTracking.Client
Imports SoftPro.ClientModel
Imports SoftPro.ClientModel.Security
Imports SoftPro.OrderTracking.Client.Orders
Imports SoftPro.Select.Client.Profiles
Imports SoftPro.ClientModel.Linq
Sub Main(ByVal strArgs As String())

'connect to the server
creds = New NetworkCredential(mstrUserID, mstrPWord, "[SERVER]")
sps = New SelectServer(mstrServer, creds)
sps.EnsureAuthenticated()
'get order tracking service
' ot = sps.GetService(Of OrderTracking)()
Dim Profile As IProfile
Dim OrderStore As IOrderStore = sps.GetService(Of IOrderStore)()

Dim numberManager As IOrderNumberingManager = sps.GetService(Of IOrderNumberingManager)()
Dim profileManager As IProfileManager = sps.GetService(Of IProfileManager)()
Dim group As IOrderNumberingGroup = numberManager.OrderNumberingGroups ' get the order numbering manager associated with the user's active profile

'Profile = group 'profileManager.FindProfile.firs Search(New ClosestAncestorProfileSearch(profileManager.ActiveProfile))
' .FirstOrDefault();

Dim spec As New OrderCreationSpec()



Using order As IOrder = OrderStore.NewOrder(spec)
spec.Number = group.GetFormattedOrderNumber()


Try


Dim newOrder As Object = order
Try
newOrder.Project = "Setting a simple string property."
newOrder.Properties(0).Address.City = "City"

Dim propertyInfo As Object = order.CreateNew("Property")
propertyInfo.Address.Address1 = "test"

Try : newOrder.SettlementDate = System.Convert.ToDateTime(strClosingDate) : Catch : End Try

Catch ex As Exception

End Try

OrderStore.ApplyChanges(order)
Catch ex As Exception
Call LogError(ex, strErr_Source & ":" & CStr(mintMessage_ID))
Finally
OrderStore.CloseOrder(order)
End Try
End Using
End Sub
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: Cameron API New Order

Post by John Morris »

Please also post your build or runtime (w/callstack) errors.
John Morris
Sr. Software Architect
SoftPro
sanjay.mittal
Posts: 94
Joined: Mon Dec 28, 2009 3:43 pm

Re: Cameron API New Order

Post by sanjay.mittal »

Well didn't go that far. VS didn't like the following statements

'Profile =profileManager.FindProfile.firs Search(New ClosestAncestorProfileSearch(profileManager.ActiveProfile))
' .FirstOrDefault()

spec.Number = group.GetFormattedOrderNumber()
sanjay.mittal
Posts: 94
Joined: Mon Dec 28, 2009 3:43 pm

Re: Cameron API New Order

Post by sanjay.mittal »

Any luck?
john.morton
Posts: 89
Joined: Wed Nov 16, 2011 11:51 am

Re: Cameron API New Order

Post by john.morton »

I wrote a little WinForm app using your sample code, and the below works. There were a couple issues...

The OrderCreationSpec is intended to be used to specify how to create an order. So, you need to make sure to setup the ordernumber, prefixes, templates, etc... before you use it to create an order.

For some reason I was unable to get our extension methods to work correctly in visual basic. In order to call our extension method called "Search" on IQueryable<IOrderNumberingGroup>, I had to explicitly call the static method. Obviously, that's not the way extension methods are supposed to work. I'm assuming it's a compiler setting or something else in the VB environment that prevents it from properly recognizing it.

Code: Select all

Public Class Form1
 
    Dim creds As NetworkCredential
    Dim sps As SelectServer
 
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        'connect to the server
        creds = New NetworkCredential("Admin", "Passw0rd", "[SERVER]")
        sps = New SelectServer("http://LOCALHOST:8080", creds)
        sps.EnsureAuthenticated()
 
        Dim OrderStore As IOrderStore = sps.GetService(Of IOrderStore)()
        Dim numberManager As IOrderNumberingManager = sps.GetService(Of IOrderNumberingManager)()
        Dim profileManager As IProfileManager = sps.GetService(Of IProfileManager)()
        Dim groups As IQueryable(Of IOrderNumberingGroup) = numberManager.OrderNumberingGroups
        Dim closestProfile = New ClosestAncestorProfileSearch(profileManager.ActiveProfile)
 
        Dim group As IOrderNumberingGroup
        group = Searchable.Search(Of IOrderNumberingGroup, ClosestAncestorProfileSearch)(groups, closestProfile).FirstOrDefault()
 
        'The creationSpec needs to be setup before using it to create an order
        Dim spec As New OrderCreationSpec() With {
            .Number = group.GetFormattedOrderNumber()}
 
        group.GetNextNumber(Nothing, Nothing) 'If you were providing prefix or suffix, they would go here
 
        'Using order As IOrder = OrderStore.NewOrder(spec)
        Using order As IOrder = OrderStore.NewOrder(spec)
            Try
                Dim DynOrder As Object = order
                DynOrder.Project = "Setting a simple string property."
                DynOrder.Properties(0).Address.City = "City"
 
 
                Dim propertyInfo As Object = order.CreateNew("Property")
                propertyInfo.Address.Address1 = "test"
 
                Try : DynOrder.SettlementDate = DateTime.Now : Catch : End Try
 
                OrderStore.ApplyChanges(order)
                MsgBox(String.Format("Order has been created: {0}", DynOrder.Number))
            Catch ex As Exception
                MsgBox(String.Format("An error occured: {0}", ex.Message))
            Finally
                OrderStore.CloseOrder(order)
            End Try
        End Using
    End Sub
 
End Class
sanjay.mittal
Posts: 94
Joined: Mon Dec 28, 2009 3:43 pm

Re: Cameron API New Order

Post by sanjay.mittal »

The compiler still doesn't like the following statment.

.Number = group.GetFormattedOrderNumber()}

How do I resolve this?
john.morton
Posts: 89
Joined: Wed Nov 16, 2011 11:51 am

Re: Cameron API New Order

Post by john.morton »

What is the version on the libraries you are using?
Post Reply