Page 1 of 1

Change Back Colour Sales order Form

PostPosted: Thu May 28, 2015 12:14 pm
by Sunny
There is a requirement that the Sales Order Form colour should turn red if a Credit is being raised.
The following code gives a "Object reference not set to an instance of an object. Module:SalesOrder_Created"
Could you help please?
Thanks !
Code: Select all
Public Class FormPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaFormPlugin   
   Private salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm
   
    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
      Dim salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
      
      AddHandler salesOrderForm.SalesOrder.Created, AddressOf SalesOrder_Created
    End Sub
   Public Sub SalesOrder_Created(sender As Object, e As System.EventArgs, ByVal NewSalesOrderType As JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes, ByRef SourceQuoteObject As JiwaSales.SalesQuote.SalesQuote)
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)   
      If salesOrder.CreditNote Then
         msgbox ("Cr Note")
         salesOrderForm.BackColor= System.Drawing.Color.Red               
      Else
         msgbox ("NOT Cr Note")
      End If   
   End Sub
'   
End Class

Re: Change Back Colour Sales order Form

PostPosted: Thu May 28, 2015 12:17 pm
by Scott.Pearce
The error would be being caused by the line:

Code: Select all
salesOrderForm.BackColor= System.Drawing.Color.Red   


In the SalesOrder_Created function, where is the variable salesOrderForm coming from?

Re: Change Back Colour Sales order Form

PostPosted: Thu May 28, 2015 12:34 pm
by Sunny
You are right Scott. That's the "crucial" :), statement I'm struggling with.
As can be seen in the code, I have declared "Private salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm"
I have also tried declaring within the
SalesOrder_Created function as below with the same error:
Code: Select all
   Public Sub SalesOrder_Created(sender As Object, e As System.EventArgs, ByVal NewSalesOrderType As JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes, ByRef SourceQuoteObject As JiwaSales.SalesQuote.SalesQuote)
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
      Dim salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm
      If salesOrder.CreditNote Then
         msgbox ("Cr Note")
         salesOrderForm.BackColor= System.Drawing.Color.Red               
      Else
         msgbox ("NOT Cr Note")
      End If   
   End Sub

Re: Change Back Colour Sales order Form

PostPosted: Thu May 28, 2015 12:37 pm
by Scott.Pearce
Declaring it isn't going to do anything. You need to set it.

Code: Select all
 Public Sub SalesOrder_Created(sender As Object, e As System.EventArgs, ByVal NewSalesOrderType As JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes, ByRef SourceQuoteObject As JiwaSales.SalesQuote.SalesQuote)
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
      Dim salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = salesOrder.Client
      If salesOrder.CreditNote Then
         msgbox ("Cr Note")
         salesOrderForm.BackColor= System.Drawing.Color.Red               
      Else
         msgbox ("NOT Cr Note")
      End If   
   End Sub


We slip the form object into a property of the business logic (.client). Comes in handy at times like this.

Re: Change Back Colour Sales order Form

PostPosted: Thu May 28, 2015 4:19 pm
by Sunny
Thanks for that Scott- that worked, though not exactly as I wanted it to. The
Code: Select all
salesOrderForm.BackColor= System.Drawing.Color.Red

does not seem to anything. The form is not visible because of the controls on it?
When I put in .ForeColor, it makes all the labels, red, though not the form itself (at least we got somewhere!)
The code
Code: Select all
salesOrderForm.Panel2.BackColor= System.Drawing.Color.Red
salesOrderForm.Panel2.ForeColor= System.Drawing.Color.Red

does not seem to do anything either.
Any pointers will be appreciated.

Re: Change Back Colour Sales order Form  Topic is solved

PostPosted: Thu May 28, 2015 5:57 pm
by Scott.Pearce
It's because of the "Application Styling" that gets applied to everything. Every-time a form is loaded in Jiwa, an "Application Style" is applied - this affects the appearance of most of the controls used throughout Jiwa. I guess you could think of it as a style-sheet (css).

Anyway, I suspect that your settings are having no effect because the application style would override them. On each control you want to manipulate, have a look for a property called "UseAppStyling". Set this property to false, then apply your settings. Also note that *most* of the controls in Jiwa are Infragistics controls. These controls have an .Appearance property through which you can set colours, etc.

I've created a post at http://forums.jiwa.com.au/viewtopic.php?f=27&t=340 that should help.

Re: Change Back Colour Sales order Form

PostPosted: Fri May 29, 2015 10:58 am
by Sunny
Thanks for that Scott! :) Appreciate your time.

Re: Change Back Colour Sales order Form

PostPosted: Tue Oct 03, 2017 5:39 pm
by DannyC
Does the code in
viewtopic.php?f=27&t=340
still apply to version 7.1?

I ask because I have something similar working in version 7.0.175 (and prior) which sets the inventory colour based on the status
it uses the code
Code: Select all
inventoryForm.TableLayoutPanel1.BackColor = System.Drawing.Color.Red

but TableLayoutPanel1 doesn't exist in 7.1.

Re: Change Back Colour Sales order Form

PostPosted: Sun Oct 08, 2017 2:30 pm
by Mike.Sheen
DannyC wrote:Does the code in
viewtopic.php?f=27&t=340
still apply to version 7.1?

I ask because I have something similar working in version 7.0.175 (and prior) which sets the inventory colour based on the status
it uses the code
Code: Select all
inventoryForm.TableLayoutPanel1.BackColor = System.Drawing.Color.Red

but TableLayoutPanel1 doesn't exist in 7.1.


Hi Danny,

Yes, it does work - have tested it in 7.1 and the only issue is when importing that plugin it references a JiwaSendMail assembly which no longer exists (emailing is now handled by plugins, so that assembly was retired a year or two ago) - after importing the plugin, just delete the bad reference from the Assembly references tab, save and away you go. Credit notes will display the header section in red.

Mike