Page 1 of 1

duplicating line if there is a message box in LineAdded

PostPosted: Tue Oct 10, 2017 2:20 pm
by perry
Hi
7.0.175, sample plugin attached.

If I have a message box in LineAdded event (both SO and QO), line is duplicated (added to SO/QO twice) if copy/paste the part number in grid.
It is fine if I type or use lookup button to add a line, only happens if I paste the part number.

I think I may need to set a "line added" flag during the line added event and implement the msgbox in line change event?

Regards,

Re: duplicating line if there is a message box in LineAdded  Topic is solved

PostPosted: Tue Oct 10, 2017 8:27 pm
by Mike.Sheen
Hi Perry,

Thanks for the plugin - with this I was easily able to reproduce this on 7.00.175.00.

This seems to be an odd behaviour of the grid when pasting - but only when handling the Added event by adding a handler in the SetupBeforeHandlers method.

If I move your code which is in the SetupBeforeHandlers to the Setup method the problem no longer occurs.

It doesn't make a lot of sense to handle the business logic Added event in the SetupBeforeHandlers method - you'd typically want to add handlers in SetupBeforeHandlers only if you're interested in intercepting actions before the form has dealt with them (like potentially cancelling adding a line to the business logic) - is that really what you want to do - or will moving your adding of your handlers to the Setup method satisfy your needs?

Mike

Re: duplicating line if there is a message box in LineAdded

PostPosted: Tue Oct 10, 2017 8:43 pm
by Mike.Sheen
Also, you might want to consider checking a Form type using strong typing instead of the GetType.Name -

So instead of:
Code: Select all
Select Case JiwaForm.GetType.Name
   Case "SalesOrderEntryForm"
      SOUI = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
      AddHandler SOUI.SalesOrder.SalesOrderLineAdded, AddressOf SOLineAdded
   Case "SalesQuoteEntryForm"
      QOUI = DirectCast(JiwaForm, JiwaSalesUI.SalesQuote.SalesQuoteEntryForm)
      AddHandler QOUI.SalesQuote.SalesQuoteLineAdded, AddressOf QOLineAdded
End Select


You could use:
Code: Select all
If TypeOf JiwaForm Is JiwaSalesUI.SalesOrder.SalesOrderEntryForm Then
   Dim SOUI = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
   AddHandler SOUI.SalesOrder.SalesOrderLineAdded, AddressOf SOLineAdded
ElseIf TypeOf JiwaForm Is JiwaSalesUI.SalesQuote.SalesQuoteEntryForm Then
   Dim QOUI = DirectCast(JiwaForm, JiwaSalesUI.SalesQuote.SalesQuoteEntryForm)
   AddHandler QOUI.SalesQuote.SalesQuoteLineAdded, AddressOf QOLineAdded
End If


That way if the name of our class ever changes, it will fail to compile instead of simply not adding your handlers.

It's your choice, and you may have a good reason to use the GetType.Name instead - but my instinct is always to use strong typing when possible.

Mike

Re: duplicating line if there is a message box in LineAdded

PostPosted: Thu Oct 12, 2017 9:33 am
by perry
Hi Mike,

Thanks for your replies and advise,

I chose a long way of solving the problem. I added line changed event inside line added and trigger my msgbox in there...

Regards,