0

I have a project using C# in Lightswitch 2012 that has the following tables:

Clients

  • Id - Integer
  • CaseID - Long Integer
  • FullName - String
  • Address - String
  • Tracking - TrackingItem Collection

Staff

  • Id - Integer
  • PIN - Integer
  • FullName - String
  • Tracking - TrackingItem Collection

Tracking

  • Id - Integer
  • Client - Client
  • Staff - StaffItem
  • StartDate - Date
  • StartTime - DateTime
  • EndTime - DateTime
  • Units - Double (calculated field)
  • TogetherTime - Boolean

Relationships are as follows: Each tracking object must have at least one Client and at least one Staff, and each Client and Staff can have many Tracking objects. I currently have a query called TrackingFilter that lets users filter the Tracking table on a search screen called SearchTrackingFilter by client name, staff name, a date range, and whether or not the item is marked as together time. This also displays the calculated field "Units" in the results table. What I am trying to do is add a text field to the screen above the results table that shows the total number of units that the query returned with whatever criteria the user selected. I'm a bit stuck at this point and don't know what to do. I can add labels and such to the screen just fine, but I can't seem to edit any sort of code or anything that would let me add up the total number of units returned by the query. Any help would be appreciated.

Robert B
  • 3,933
  • 2
  • 13
  • 6

1 Answers1

0

i had the same requirement. You can access the DataWorkspace with this.DataWorkspace.ApplicationData and add your filter parameters to it.

For example:

IDataServiceQueryable<Invoice> queryInvoiceTotal = this.DataWorkspace.ApplicationData.Invoices;
if (drdCustomer != null)
    queryInvoiceTotal = queryInvoiceTotal.Where(q => q.Customer.Id == this.drdCustomer.Id);
if (InvoiceState != null)
    queryInvoiceTotal = queryInvoiceTotal.Where(q => q.InvoiceState == InvoiceState);
if (InvoiceDateStart != null)
    queryInvoiceTotal = queryInvoiceTotal.Where(q => q.Date >= InvoiceDateStart);
if (InvoiceDateEnd != null)
    queryInvoiceTotal = queryInvoiceTotal.Where(q => q.Date <= InvoiceDateEnd);
var data = queryInvoiceTotal.Execute();
decimal? totalNetto = data.Sum(q => q.SumNetto);

You could also access the so called VisualCollection query in the screen, but pls note that this would only summarize the data which is currently visible in the screen/grid. So e.g. if you are only showing 45 items per page it would only summarize those 45 items up.