Warehouse transfer Out, on activate  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Warehouse transfer Out, on activate

Postby DannyC » Mon Jun 30, 2014 11:27 am

Hi,

I am trying to write plugin to write a CSV file on activation of a Warehouse Transfer Out.
I cannot seem to find the correct syntax for the form variable.
Although the plugin compiles successfully, when loading the warehouse transfer form I am getting an error.

For now, I'd be happy just to get a messagebox with an object of the form, say the Transfer number or destination warehouse description.
This is what I have so far:

Code: Select all
Imports JiwaFinancials.Jiwa
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Data

Public Class FormPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaFormPlugin

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.SetupBeforeHandlers
    End Sub

    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      If TypeOf JiwaForm Is JiwaWhouseTransferUI.WarehouseTransferOut Then
         Dim TransferForm As JiwaWhouseTransferUI.WarehouseTransferOut = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)   
         AddHandler TransferForm.Activated , AddressOf WriteCSV
      End If                
   End Sub
      
   Private Sub WriteCSV(sender As Object ,  e As System.EventArgs )
      Dim TransferForm As JiwaFinancials.Jiwa.JiwaWhouseTransfer.clsWarehouseTransfer = DirectCast(sender, JiwaWhouseTransfer.clsWarehouseTransfer)
      Messagebox.show(TransferForm.DestinationWarehouseLogicalDescription)
   End Sub


Thanks
User avatar
DannyC
Senpai
Senpai
 
Posts: 635
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 29

Re: Warehouse transfer Out, on activate  Topic is solved

Postby Mike.Sheen » Mon Jun 30, 2014 7:42 pm

Hi Danny,

You're probably getting your error on this line:

Code: Select all
AddHandler TransferForm.Activated , AddressOf WriteCSV


This is because there is no Activated event for that form, nor is there such an event for the business logic. To write out a CSV when a transfer out is activated, you want to add a handler for the business logic attached to the form, for the TransferSaveFinalBefore event, and examine the Activated and OriginalActivated flags. This business logic isn't quite styled inline with our current preferred style (it was probably converted to .NET before we bedded down our base classes) so it's a little different to our other business logic objects. That kinda sucks and makes it somewhat confusing, but what you're trying to achieve is possible.

I've taken your code and modified it to prove the concept - I've tested this on 07.00.66.00 and it works. The code is as follows:

Code: Select all
Imports JiwaFinancials.Jiwa
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Data

Public Class FormPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaFormPlugin

    Private _warehouseTransferForm As JiwaWhouseTransferUI.WarehouseTransferOut

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.SetupBeforeHandlers
    End Sub

    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      If TypeOf JiwaForm Is JiwaWhouseTransferUI.WarehouseTransferOut Then
         Dim TransferForm As JiwaWhouseTransferUI.WarehouseTransferOut = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)   
         _warehouseTransferForm = TransferForm ' Store a reference to the form in a class field so we can access it in the WriteCSV Sub
         AddHandler TransferForm._WarehouseTransfer.TransferSaveFinalBefore, AddressOf WriteCSV
      End If               
   End Sub
     
   Private Sub WriteCSV(ByVal WriteHandle As Integer, ByRef Cancel As Boolean)
      If _warehouseTransferForm._WarehouseTransfer.Activated = True AndAlso _warehouseTransferForm._WarehouseTransfer.OriginalActivated = False Then
           Messagebox.show(_warehouseTransferForm._WarehouseTransfer.DestinationWarehouseLogicalDescription)
      End If
   End Sub
End Class


Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755


Return to Technical and or Programming

Who is online

Users browsing this forum: Google [Bot] and 3 guests