OnTime Extension SDK Documentation
In This Topic
    Data Access
    In This Topic

    The Data property of an OnTime extension contains all of the functions that are used to create, read, and update objects in an OnTime account.

    Create, Read, and Update Functions

    An OnTime extension will always inherit the IndependentView, BillingView, or TrackingView classes. These classes are all equipped with a Data property that is an instance of the DataAccess class. All of the create, read, and update operations are called through the Data property of an OnTime extension. Consider the following VB.NET code snippet that creates a new location in an OnTime account.

    Create Example
    Copy Code
    Dim location As New Location
    location.AddressLine1 = "123 Business Park Dr"
    location.City = "Medford"
    location.State = "OR"
    location.PostalCode = "97504"
    location.Phone = "555-123-9876"
    location.CompanyName = "Ben's Auto Parts"
    location.ContactName = "Ben"
    location.Email = "ben@example.com"
    Dim returnedLocation As Location = Data.SaveLocation(location)

    Notice that the function SaveLocation is called. This function will add or update the location that is passed to it, and return the created or updated location. The next example demonstrates how to get an order with a specific tracking number, update the order's weight and dimensions, and persisting the changes to the database.

    Update Example
    Copy Code
    Dim order As Order = Extension.Data.GetOrderList.Where(OrderColumn.TrackingNumber, "4478").FirstOrDefault()
    If order IsNot Nothing Then
         order.Weight = 100.0
         order.Width = 10
         order.Length = 7.5
         order.Height = 2.3
         Dim returnedOrder As Order = Data.SaveOrder(order)
    End If

    The previous example uses the GetOrderList object to find an order by tracking number. An order can also be retrieved if the Guid that identifies the order in the database is known. For example, an order can be retrieved with the following VB.NET code.

    Read Example
    Copy Code
    Dim order As Order = Data.GetOrder(New Guid("dacb41f8-6e11-441f-89f3-9b357bdb74f4"))

    Extra Functions

    Aside from the standard create, read, and update functions illustrated in the previous section, there are extra functions that provide specialized functionality. These functions have the following signatures.

    Specialized Functions
    Copy Code
    Public Overloads Function SaveOrderStatusChange(ByVal orderID As Guid, ByVal description As String, ByVal timestamp As DateTime) As Boolean
    Public Overloads Function SaveOrderStatusChange(ByVal orderID As Guid, ByVal description As String, level As Status.OrderStatusBase, ByVal timestamp As DateTime)
    Public Function UpdateUserPosition(ByVal userID As Guid, latitude As Decimal, longitude As Decimal, timestamp As Date) As Boolean
    Public Function GetUserPositions(ByVal userID As Guid, ByVal startDate As Date, ByVal endDate As Date) As List(Of User.UserPosition)
    Public Function GetUserAvailability(ByVal userID As Guid) As User.UserAvailability
    Public Function GetUserDefinedField(orderID As Guid, fieldName As String) As UserDefinedField
    Public Function MarkInvoiceTransferred(ByVal invoiceID As Guid, ByVal transferred As Boolean) As Boolean
    Public Function MarkPaymentTransferred(ByVal paymentID As Guid, ByVal transferred As Boolean) As Boolean
    Public Function UpdateOrderPrices(ByVal orderID As Guid) As Boolean

    You may find more information about these specialized function by vieweing the documentation for the DataAccess class.

    Automatic Number Generation

    The OnTime SDK allows for the automatic generation of order tracking numbers and customer account numbers. In order for the OnTime SDK to generate these numbers automatically, the proper settings must be configured in the OnTime Management Suite. If the proper settings have been configured, then tracking numbers and customer account numbers will be automatically generated if the TrackingNumber property on the order being created is null or an empty string.