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

Discussions relating to plugin development, and the Jiwa API.

duplicating line if there is a message box in LineAdded

Postby perry » Tue Oct 10, 2017 2:20 pm

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,
Attachments
Plugin LineAddedBugTest.zip
(4.63 KiB) Downloaded 70 times
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15

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

Postby Mike.Sheen » Tue Oct 10, 2017 8:27 pm

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
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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

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

Postby Mike.Sheen » Tue Oct 10, 2017 8:43 pm

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
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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

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

Postby perry » Thu Oct 12, 2017 9:33 am

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,
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 16 guests