Page 1 of 1

C# syntax to instantiate sales order history

PostPosted: Mon Aug 27, 2018 3:50 pm
by DannyC
I need to get the first character of the delivery address.
It doesn't seem to be available from the salesorder object, so I figure I need to read the full history object, then get the postcode from that.

My code here is erroring when trying to assign the salesHist object
Code: Select all
    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
      JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm salesOrderForm = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)JiwaForm;
      salesOrderForm.SalesOrder.SalesOrderLineAdding += GetThePostcode;
    }
   
   public void GetThePostcode(object sender, System.EventArgs e, JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine item)
   {
      JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesOrder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder) sender;
      JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderHistory salesHist = salesOrder.SalesOrderHistorys(salesOrder.CurrentHistoryNo);
      string StateCode = salesHist.PostCode.Substring(0,1);
   }

error is "non invocable member JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder.SalesOrderHistorys cannot be used like a method. "

What am I doing wrong?

Re: C# syntax to instantiate sales order history  Topic is solved

PostPosted: Mon Aug 27, 2018 3:52 pm
by Scott.Pearce
c# uses [] instead of () when indexing into something. So change your line:

Code: Select all
JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderHistory salesHist = salesOrder.SalesOrderHistorys(salesOrder.CurrentHistoryNo);


to:

Code: Select all
JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderHistory salesHist = salesOrder.SalesOrderHistorys[salesOrder.CurrentHistoryNo];

Re: C# syntax to instantiate sales order history

PostPosted: Mon Aug 27, 2018 3:58 pm
by DannyC
Oh man, ya kidding right? Something so simple yet cryptically silent when googling!
This C# is doing my head in...

Re: C# syntax to instantiate sales order history

PostPosted: Mon Aug 27, 2018 4:00 pm
by Scott.Pearce
You'll get used to it in no time mate. c# is a lot stricter but it results in better code.

Re: C# syntax to instantiate sales order history

PostPosted: Tue Aug 28, 2018 7:28 am
by SBarnes
Amen to that give me a strict type safe language any day as it means 80% of issues are found by the compiler rather than debugging which always takes longer.

Opening the Jiwa DLLs with Telerik Just Decompile and reading the code as C# is probably one of the quickest ways to become familiar with it.