locked
Calculating balance RRS feed

  • Question

  • I am new into programming, and there so many things I don't know yet. I have three fields on Entity Payment Details.

    1. Price Property Sring: contains the prices of services in a choice list

    2. Deposit Property Money: should contains the amount customer is depositing for a service

    3. Balance Property Money: Should display the total balance the customer is paying base on the total price and amount deposited.

    I will need help on how to achieve this using c# codes.

    Thank you very much.

    Tuesday, October 22, 2013 9:02 PM

Answers

All replies

  • You can make 'Balance' a computed property.  Please see http://msdn.microsoft.com/en-us/library/vstudio/ff852066.aspx

    In the property's compute method you can write simple code as shown below:

            partial void Balance_Compute(ref decimal result)
            {
                result = Deposit - Decimal.Parse(Price);
            }

    Wednesday, October 23, 2013 4:02 PM
    Moderator
  • Thank you very much for the help. I will try the code.
    Friday, October 25, 2013 2:09 AM
  • Tried using the supplied code, but it did not work. Converted the Balance Property to Compute Property; ran on debug mode, but it did not work.

    Is there anything I am missing?

    Furthermore, it will be great if the Lightswitch team will create a comprehensive tutorials on real business applications that involves financial transactions for beginners. Its a suggestion anyway.

    Isaac.

    Friday, November 1, 2013 10:08 AM
  • Tried using the supplied code, but it did not work. Converted the Balance Property to Compute Property; ran on debug mode, but it did not work.


    Do you get an error? If so please could you provide some details about the error.
    Friday, November 1, 2013 2:42 PM
    Moderator
  • These are the error report even before I run the debug section:

    Error    1    The best overloaded method match for 'decimal.Parse(string)' has some invalid arguments.

    Error    2    Argument 1: cannot convert from 'decimal?' to 'string'   

    Thursday, November 7, 2013 3:05 PM
  • This error happens when the argument to Parse() method is not a string.  Please see http://msdn.microsoft.com/en-us/library/cafs243z(v=vs.110).aspx

    In the Payment details entity you mentioned,  make sure Price is of type string.

    Thursday, November 7, 2013 3:44 PM
    Moderator