Set custom field decimals  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Set custom field decimals

Postby DannyC » Wed Dec 16, 2020 11:25 pm

Thought this would be a quick 5 minute job. Famous last words ;)

I just need to set a float custom field from the normal 2 decimals to something else, say 6.
Using this old thread (in VB) as an example I've got the below code in C# but I just can't work out the syntax to set .DecimalPlaces = 6. viewtopic.php?f=26&t=497

Bloody driving me crazy!

Code: Select all
    public void FormatCell(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic BusinessLogicHost, JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid GridObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm FormObject, int Col, int Row, JiwaFinancials.Jiwa.JiwaApplication.IJiwaCustomFieldValues HostObject, JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomField CustomField, JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue CustomFieldValue)
    {
        if (CustomField.PluginCustomField.Name == "MyFloat")
        {
            // Set decimal places to 6
            if (GridObject.ActiveSheet.Cells[Row, Col].CellType == null)
         {
                GridObject.ActiveSheet.Cells[Row, Col].CellType = new FarPoint.Win.Spread.CellType.NumberCellType();
         }   
         need to set decimal places here
        }
   }
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Set custom field decimals

Postby SBarnes » Thu Dec 17, 2020 8:33 am

The following works for add column on the grid by using qtycelltype for the column type so you can probably follow the same thing

Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.JiwaManageGrid.JiwaDecimalPlacesCellType qtycelltype = new JiwaFinancials.Jiwa.JiwaApplication.JiwaManageGrid.JiwaDecimalPlacesCellType(dForm.Manager);
qtycelltype.DecimalPlaces = 2;
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Set custom field decimals

Postby Scott.Pearce » Thu Dec 17, 2020 8:44 am

If you want to set the decimal places of a particular cell, you cast the .CellType property, then that will give you properties that are relevant to that cell type (like .DecimalPlaces). Example:

Code: Select all
((JiwaFinancials.Jiwa.JiwaApplication.JiwaManageGrid.JiwaCurrencyCellType)transactionsJiwaGrid.ActiveSheet.Columns["IncTaxAmount"].CellType).DecimalPlaces = 6;


or:

Code: Select all
((FarPoint.Win.Spread.CellType.NumberCellType)transactionsJiwaGrid.ActiveSheet.Columns["Percentage"].CellType).DecimalPlaces = 6;


If you want to set the decimal places to be the same for the entire column, then you can use:

Code: Select all
myGrid.GridDecimalPlaces("Cost", -1, 6)
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Set custom field decimals  Topic is solved

Postby Scott.Pearce » Thu Dec 17, 2020 8:57 am

So your code should look like this:

Code: Select all
    public void FormatCell(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic BusinessLogicHost, JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid GridObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm FormObject, int Col, int Row, JiwaFinancials.Jiwa.JiwaApplication.IJiwaCustomFieldValues HostObject, JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomField CustomField, JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue CustomFieldValue)
    {
        if (CustomField.PluginCustomField.Name == "MyFloat")
        {
            // Set decimal places to 6
            if (GridObject.ActiveSheet.Cells[Row, Col].CellType == null)
                GridObject.ActiveSheet.Cells[Row, Col].CellType = new FarPoint.Win.Spread.CellType.NumberCellType();

            ((FarPoint.Win.Spread.CellType.NumberCellType)GridObject.ActiveSheet.Cells[Row, Col].CellType).DecimalPlaces = 6;
        }
   }


Note that we check for CellType == null. This is because the grid will use the column cell type for cells that do not have their own cell type defined - they essentially "inherit" the column's cell type. So if we are changing properties that we want to only affect a particular cell in that column and not the entire column, we must first give that cell it's own .CellType - hence the "new FarPoint.Win.Spread.CellType.NumberCellType();" line.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Set custom field decimals

Postby Mike.Sheen » Thu Dec 17, 2020 12:53 pm

What's wrong with using the helper method GridDecimalPlaces?

Code: Select all
GridObject.GridDecimalPlaces("Contents", Row, 6, Row)
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Set custom field decimals

Postby DannyC » Thu Dec 17, 2020 1:05 pm

Thanks guys.
I tried Scott's suggestion first and that worked so I'll just run with that. I like the succinctness of Mike's code though!
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Set custom field decimals

Postby pricerc » Thu Dec 17, 2020 1:37 pm

Mike.Sheen wrote:What's wrong with using the helper method GridDecimalPlaces?

Code: Select all
GridObject.GridDecimalPlaces("Contents", Row, 6, Row)


For people like me who code in an a fairly eclectic array of environments, using a method to set a property is counter-intuitive.

If I could choose, then

Code: Select all
GridObject.Columns("Contents").DecimalPlaces = 6


or for an individual cell:

Code: Select all
GridObject(row, "Contents").DecimalPlaces = 6


would be my preferred way of doing it.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 518
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 21

Re: Set custom field decimals

Postby Mike.Sheen » Thu Dec 17, 2020 2:39 pm

pricerc wrote:
Code: Select all
GridObject(row, "Contents").DecimalPlaces = 6


would be my preferred way of doing it.


Sure - but one thing I've found is C# doesn't like properties with parameters - as a result we get awful hidden wrapper functions - and example is the GridText method - VB.NET happily knows how to use that:

Code: Select all
grid.GridText("MyColumName", Row) = "xxx"


but with C# we have to use:

Code: Select all
grid.set_GridText("MyColumName", Row, "xxx");


And to add insult to injury, the method isn't visible via intellisense - so unless you know about this quirk, it can be a bit of a problem.
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Set custom field decimals

Postby pricerc » Thu Dec 17, 2020 8:50 pm

Mike.Sheen wrote:Sure - but one thing I've found is C# doesn't like properties with parameters - as a result we get awful hidden wrapper functions - and example is the GridText method - VB.NET happily knows how to use that:

Code: Select all
grid.GridText("MyColumName", Row) = "xxx"


but with C# we have to use:

Code: Select all
grid.set_GridText("MyColumName", Row, "xxx");


And to add insult to injury, the method isn't visible via intellisense - so unless you know about this quirk, it can be a bit of a problem.


It comes up in my intellisense ?
JiwaGrid_GridText.png
intellisense
JiwaGrid_GridText.png (38.94 KiB) Viewed 13300 times



But that is one of those dumb arbitrary design decisions that remind me why I'm not a C# fan. I've never fathomed the argument for having [ ] for 'indexers' and ( ) for 'arguments'.

All properties and indexers get compiled down to methods in CIL (like the aforementioned ugly ones you need to use from C#). So requiring C# developers to make a distinction is a completely arbitrary and synthetic limitation.

Especially when it should not matter to the consumer (developer) what goes on in.

And then you see people in chat forums telling people they should be using one or the other, because 'reasons'.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 518
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 21

Re: Set custom field decimals

Postby Mike.Sheen » Thu Dec 17, 2020 9:31 pm

pricerc wrote:It comes up in my intellisense ?


GridDecimalPlaces does - because that's a method. If we changed it to a property like you expressed you'd prefer, then you'd see the problem - I cited the GridText property as an example of where properties with parameters makes C# "invent" a wrapper method for the setter and getter (what might actually happen is the opposite - there are always methods for the getter and setter, but VB.NET magic's that away to make it look like a property).

Visual Studio does intellisense the wrappers - but our code editor built into the Plugin Maintenance form does not. Perhaps the newer version of that addresses this - when we test their newer version (for the newer language support) that might also get fixed.. bonus!
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Next

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 5 guests