1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Linq;
- using InABox.Core;
- using Syncfusion.Data;
- namespace InABox.DynamicGrid;
- public class DynamicGridDoubleAggregate : ISummaryAggregate
- {
- public int Count { get; private set; }
- public double Sum { get; private set; }
- public Action<IEnumerable, string, PropertyDescriptor> CalculateAggregateFunc()
- {
- return CalculateAggregate;
- }
- private void CalculateAggregate(IEnumerable items, string property, PropertyDescriptor args)
- {
- if (items is IEnumerable<DataRowView> rows)
- {
- if (string.Equals(args.Name, "Count"))
- {
- Count = rows.Count();
- }
- else if (string.Equals(args.Name, "Sum"))
- {
- Sum = 0;
- foreach (var row in rows)
- if (row[property] is TimeSpan)
- Sum += (double)row[property];
- }
- }
- else
- {
- Logger.Send(LogType.Error, "", $"Attempting to calculate aggregate on invalid data type '{items.GetType()}'.");
- }
- }
- }
|