Beispiel #1
0
 public void FieldVerifying(PX.Data.PXCache sender, PX.Data.PXFieldVerifyingEventArgs e)
 {
     if (e.NewValue == null || !((string)e.NewValue).StartsWith("BOB-"))
     {
         throw new PXSetPropertyException("Serial Number must start with BOB-");
     }
 }
        /// <summary>
        /// Return one row which contains sum for all decimal fields and identical value if all rows contains that value otherwise is null.
        /// </summary>
        public static RecordType CalculateSumTotal <RecordType>(this IEnumerable <RecordType> rows, PX.Data.PXCache cache)
            where RecordType : PX.Data.IBqlTable, new()
        {
            var total = new RecordType();

            var properties = cache.GetAttributesOfType <PX.Data.PXUIFieldAttribute>(null, null)
                             .Select(p => new
            {
                uiAttribute       = p,
                sumGroupOperation = cache.GetAttributesOfType <PX.Data.PXDecimalAttribute>(null, p.FieldName).Any() ||
                                    cache.GetAttributesOfType <PX.Data.PXDBDecimalAttribute>(null, p.FieldName).Any()
            }).ToList();

            var propertiesWithSum    = properties.Where(p => p.sumGroupOperation).ToList();
            var propertiesWithoutSum = properties.Where(p => !p.sumGroupOperation).ToList();

            var sumAggregateValues = new decimal[propertiesWithSum.Count];
            var aggregateValues    = new object[propertiesWithoutSum.Count];

            bool firstRow = true;

            foreach (var row in rows)
            {
                for (int fieldIndex = 0; fieldIndex < propertiesWithSum.Count; fieldIndex++)
                {
                    var value = (decimal?)cache.GetValue(row, propertiesWithSum[fieldIndex].uiAttribute.FieldName);
                    sumAggregateValues[fieldIndex] += value ?? 0;
                }

                for (int fieldIndex = 0; fieldIndex < propertiesWithoutSum.Count; fieldIndex++)
                {
                    var value = cache.GetValue(row, propertiesWithoutSum[fieldIndex].uiAttribute.FieldName);
                    aggregateValues[fieldIndex] = (firstRow || aggregateValues[fieldIndex]?.Equals(value) == true) ? value : null;
                }

                firstRow = false;
            }

            for (int fieldIndex = 0; fieldIndex < propertiesWithSum.Count; fieldIndex++)
            {
                cache.SetValue(total, propertiesWithSum[fieldIndex].uiAttribute.FieldName, sumAggregateValues[fieldIndex]);
            }
            for (int fieldIndex = 0; fieldIndex < propertiesWithoutSum.Count; fieldIndex++)
            {
                cache.SetValue(total, propertiesWithoutSum[fieldIndex].uiAttribute.FieldName, aggregateValues[fieldIndex]);
            }

            return(total);
        }
Beispiel #3
0
 protected override void Batch_RowSelected(PX.Data.PXCache cache, PX.Data.PXRowSelectedEventArgs e)
 {
     base.Batch_RowSelected(cache, e);
 }