Custom Property Not Updating


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I have seven integer fields from my table represented in a business object.  One custom property adds the values and returns the total (int).  A second custom property determines the percentage (total points / total available) -- called rating.  A third custom property references the percentage and presents a letter grade (A, B, C, or D).  Rather simple.  If I click new on the form, the defaults work fine (all int fields maxed at 10, total points is 70, the rating is 100% and the grade is 'A').  The moment I change a value in any one of the seven integer fields, the total points and the rating are zeroed out.  The grade always reverts to the lowest possible choice.  What are the possible reasons that my custom fields are not updating properly?


[Browsable(false),
BusinessFieldDisplayInEditor(),
Description("Total Points"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int TotalPoints
{
   
get
   
{
       
int mTotalPoints = ontimedelivery + complaints + returns + scrap + profitability + convenience + growthpotential;
       
return mTotalPoints;
    }
}

[
Browsable(false),
BusinessFieldDisplayInEditor(),
Description("Rating"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public double Rating
{
   
get
   
{
       
double mRating = (double)(TotalPoints / 70);
       
return mRating;
    }
}

[
Browsable(false),
BusinessFieldDisplayInEditor(),
Description("Grade"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public String Grade
{
   
get
   
{
       
if (Rating >= 0.91) { return "A"; }
       
if (Rating >= 0.81) { return "B"; }
       
if (Rating >= 0.71) { return "C"; }
       
return "D";
    }
}

Thanks!
Bill

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Bill,

I would put a breakpoint at the TotalPoints to see what are the values of the fields you are adding, it looks like something is getting ugly there and is returning less than 0.71.

Edhy Rijo

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Yes...the Rating is coming up as zero for anything less than 70 (70/70 = 1, that looks right).  If I modify one of the integer values, the debugger clearly shows the TotalPoints at 68, but 68/70 = 0, for some reason.  Do I have a type problem here somewhere?  Am I misusing the custom properties in some way?

This is quite odd.
Bill

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
This works:


public double Rating
{
   
get
   
{
       
double mLimit = 70;
       
double mRating = TotalPoints / mLimit;
       
return mRating;
    }
}

Why?

(scratches head)
(contemplates retirement)
(waits eagerly for "yabba-dabba-doo time")

Bill

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
It looks like a type problem, I use VB instead of C#, but I guess this would also work.


public double Rating
{
   
get
   
{
        mRating = TotalPoints / 70;
       
return (double) mRating;
    }
}


Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Nope, it won't. In VB, the concept works (dividing two integers, casting to double..get correct answer). In C#, it does integer division, then the case...hence getting zero. In C# you have to cast all the numbers to double before you do the calculation:



// This returns zero

double mRating = (double)(68 / 70);



// This returns correct answer (.97...)

double mRating = (double)68 / (double)70;




A great tool to investigate this sort of thing is Snippet Compiler (http://www.sliver.com/dotnet/SnippetCompiler/). It allows you to try out little snippets of code (instead of having to start another VS instance and creating a project...yada yada).
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search