Calculated Columns Question

Calculated Columns Question

Old forum URL: forums.lhotka.net/forums/t/992.aspx


Sarosh posted on Wednesday, August 23, 2006

Hi!

I have just started using CSLA.NET (2.0.3) and am about to create my fist App.

The application I am working on is kind of simple, it has one main transaction table which uses about 8 lookup tables (8 FK's) but requires about 30 calulated columns. UI will be like a spreadsheet. (Grid based)

My question is should the BO's handle the calulations or should they be defined in the Database (SQL2005 DB) Since I am using SQL2005 should I define them as Calculated Columns or just regular Columns which will be updated by the BO's. There will be quite a few Reports which will require those Calculated Columns as well so if BO are used for the calcs will the Reports be able to use the BO's

Thanks.

Sarosh

ajj3085 replied on Wednesday, August 23, 2006

I would think that the calcs should be in the business layer.  If the calcs are based on any other modifable property, you have no choice really.  It will be easier to maintain the calcs in .Net (usually). 

Your reports should be able to use the BOs, but it depends on the reporting technology you're using; Crystal, MS Reports, etc.

Sarosh replied on Wednesday, August 23, 2006

Hi!

I am not clear on how to implement the calc columns in the CSLA.NET BO's any example will be great.

e.g. ColumnD = (ColumnA * ColumnB) + ColumnC

Sarosh

Brian Criswell replied on Wednesday, August 23, 2006

Create a read-only property on your object.

public int ColumnD
{
    get
    {
       return (this.ColumnA * this.ColumnB) + this.ColumnC;
    }
}

Sarosh replied on Wednesday, August 23, 2006

Hi!

Yes, that should do it.

Thanks a lot for the info.

Sarosh

Adam replied on Wednesday, June 03, 2009

I have created a public readonly value like so;

public decimal VATAmount { get { return NetAmount * (AppliedVATPercentage / 100); } }

which works a treat but when I update the NetAmount cell on the client UI the calculated value won't update is there anyway to get the values to update on-the-fly in the client UI. I am using Silverlight with CSLAlight 3.6.2.0

Many thanks

Adam

shawndewet replied on Wednesday, June 03, 2009

I think you may have to set your PropertyChangedMode to 'Xaml' (as opposed to the default 'Windows') ... this will cause the PropertyChanged Event to fire for all properties, instead of just the one that changed.

Adam replied on Wednesday, June 03, 2009

Hi Shawn

Thanks for the info but I have tried the following line in both App.xaml.cs Application_Startup and in the constructor for my invoice viewer without success.

//Fire events for all xaml not just the current control http://forums.lhotka.net/forums/thread/23824.aspx
            Csla.ApplicationContext.PropertyChangedMode = Csla.ApplicationContext.PropertyChangedModes.Xaml;

Any other ideas or am I using this incorrectly?

Adam

tetranz replied on Wednesday, June 03, 2009

I think you just need to fire a PropertyChanged("VATAmount") whenever NetAmount changes. I haven't used SilverLight but, as I understand it, it's not like WinForms where a change on one property causes all to refresh. That always seemed like a bug in WinForms but it is useful in situations like this. It sounds like Shawn's suggestion is trying to make SilverLight behave more like WinForms but ... "only update the properly that changed" is surely the cleaner, more logical way to go.

Adam replied on Thursday, June 04, 2009

Brilliant, that works a treat - OnPropertyChnaged("VATAmount") in the Setting for the property that changes!

Then only question now is I need to update the Invoice's Totals but can't see how to do that from the property that changes. InvoiceItem( BusinessBase) is a child of InvoiceItemList(BusinessListBase) which is a child of Invoice(BusinessBase)

Any ideas?

Copyright (c) Marimer LLC