Page 1 of 1

How to check for printed Status during Sales Order Plugin

PostPosted: Thu Dec 04, 2014 3:09 pm
by Ernst
Hi Guys,

Have this plug in to show a message that order no is required. However message also pops up when printing. Is there a way to stop this.
In JIWA6 it was if printing = false.
Thanks for the help.

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 JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm Then
Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
AddHandler salesOrderForm.SalesOrder.SaveStart, AddressOf SalesOrder_SaveStart
End If
End Sub

Private Sub SalesOrder_SaveStart(sender As Object, e As System.EventArgs)
' msgbox ("in Save Start")
Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
If salesOrder.OrderNo.Trim.Length = 0 Then
' Throw New System.Exception("Sales Order - Order no may not be blank")
System.Windows.Forms.MessageBox.Show("Customer Order No Should not be blank ")
End If
' End If
End Sub
End Class

Re: How to check for printed Status during Sales Order Plugi  Topic is solved

PostPosted: Thu Dec 04, 2014 3:31 pm
by Mike.Sheen
Ernst wrote:However message also pops up when printing. Is there a way to stop this.


Hi Ernst,

The easiest way is to remove your save handler when printing is commencing and add it again after printing - that way your save handler is not invoked during printing.

ie:

Code: Select all
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      If TypeOf JiwaForm Is JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm Then
         Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
         AddHandler salesOrderForm.SalesOrder.SaveStart, AddressOf SalesOrder_SaveStart
         AddHandler salesOrderForm.SalesOrder.PrintingMany, AddressOf SalesOrder_PrintingMany
         AddHandler salesOrderForm.SalesOrder.PrintedMany, AddressOf SalesOrder_PrintedMany
      End If
    End Sub
   
   Private Sub SalesOrder_PrintingMany(sender As Object, e As System.EventArgs, ByRef ReportCollection As JiwaApplication.JiwaCollection(Of JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport))
      ' We remove the handler so we don't listen to the save just because we are printing
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
      RemoveHandler salesOrder.SaveStart, AddressOf SalesOrder_SaveStart
   End Sub
   
   Private Sub SalesOrder_PrintedMany(sender As Object, e As System.EventArgs, ReportCollection As JiwaApplication.JiwaCollection(Of JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport))
      ' We add back the handler after printing
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
      AddHandler salesOrder.SaveStart, AddressOf SalesOrder_SaveStart
   End Sub
   
   Private Sub SalesOrder_SaveStart(sender As Object, e As System.EventArgs)
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
      If salesOrder.OrderNo.Trim.Length = 0 Then               
         System.Windows.Forms.MessageBox.Show("Customer Order No Should not be blank ")
      End If      
   End Sub


Attached is a working sample.
Plugin Sales Order Prompt When No Order No..xml
Sample plugin
(33.8 KiB) Downloaded 134 times


Mike

Re: How to check for printed Status during Sales Order Plugi

PostPosted: Mon Dec 08, 2014 7:32 am
by Ernst
Great thanks.