Ejemplo n.º 1
0
        public int Count(AggrFn fn, string scope, bool runningValue)
        {
            Context ctxt = _currentContext;

            PushContextState();
            try
            {
                if (scope != null && scope != string.Empty)
                {
                    ctxt = ctxt.FindContextByGroupName(scope, _rpt);
                }
                int ct = 0;

                int top = (runningValue) ? ctxt.RowIndex : ctxt.Rows.Count - 1;
                for (int i = 0; i <= top; i++)
                {
                    ctxt.RowIndex = i;

                    object value = fn();
                    if (value != null && !Convert.IsDBNull(value))
                    {
                        ct++;
                    }
                }

                return(ct);
            }
            finally
            {
                PopContextState();
            }
        }
Ejemplo n.º 2
0
        public object Previous(AggrFn fn, string scope)
        {
            Context ctxt = _currentContext;

            PushContextState();
            try
            {
                if (scope != null && scope != string.Empty)
                {
                    ctxt = ctxt.FindContextByGroupName(scope, _rpt);
                }

                if (ctxt.RowIndex > 0)
                {
                    ctxt.RowIndex--;;
                    object value = fn();

                    return(value);
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                PopContextState();
            }
        }
Ejemplo n.º 3
0
        public object RunningValue(AggrFn fn, RunningValueFunction function, string scope)
        {
            switch (function)
            {
            case RunningValueFunction.Sum:
                return(Sum(fn, scope, true));

            case RunningValueFunction.Avg:
                return(Avg(fn, scope, true));

            case RunningValueFunction.Max:
                return(Max(fn, scope, true));

            case RunningValueFunction.Min:
                return(Min(fn, scope, true));

            case RunningValueFunction.Count:
                return(Count(fn, scope, true));

            case RunningValueFunction.CountDistinct:
                return(CountDistinct(fn, scope, true));

            case RunningValueFunction.StDev:
                return(StDev(fn, scope, true));

            case RunningValueFunction.StDevP:
                return(StDevP(fn, scope, true));

            default:
                throw new Exception("Unknown function " + function + " in RunningValue");
            }
        }
Ejemplo n.º 4
0
        public object First(AggrFn fn, string scope)
        {
            try
            {
                PushContextState();
                if (scope != null && scope != string.Empty)
                {
                    _currentContext = _currentContext.FindContextByGroupName(scope, _rpt);
                }

                if (_currentContext.Rows.Count > 0)
                {
                    _currentContext.RowIndex = 0;
                    object value = fn();

                    return(value);
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                PopContextState();
            }
        }
Ejemplo n.º 5
0
        public object sum(AggrFn fn)
        {
            int     rowIndex  = _currentContext.RowIndex;
            bool    doub      = false;
            decimal decValue  = 0;
            double  doubValue = 0;

            for (int i = 0; i < _currentContext.Rows.Count; i++)
            {
                _currentContext.RowIndex = i;

                object value = fn();
                if (value is System.Single || value is System.Double && !doub)
                {
                    doub      = true;
                    doubValue = (double)decValue;
                }
                if (doub)
                {
                    doubValue += (double)value;
                }
                else
                {
                    decValue += Convert.ToDecimal(value);
                }
            }

            _currentContext.RowIndex = rowIndex;
            return((doub) ? (object)doubValue : (object)decValue);
        }
Ejemplo n.º 6
0
        public object Avg(AggrFn fn, string scope, bool runningValue)
        {
            Context ctxt = _currentContext;

            PushContextState();
            try
            {
                if (scope != null && scope != string.Empty)
                {
                    ctxt = ctxt.FindContextByGroupName(scope, _rpt);
                }
                int     ct        = 0;
                bool    dec       = false;
                decimal decValue  = 0;
                double  doubValue = 0;

                int top = (runningValue) ? ctxt.RowIndex : ctxt.Rows.Count - 1;
                for (int i = 0; i <= top; i++)
                {
                    ctxt.RowIndex = i;

                    object value = fn();
                    if (value != null && !Convert.IsDBNull(value))
                    {
                        if (value is decimal && !dec)
                        {
                            dec      = true;
                            decValue = Convert.ToDecimal(doubValue);
                        }
                        if (dec)
                        {
                            decValue += Convert.ToDecimal(value);
                        }
                        else
                        {
                            doubValue += Convert.ToDouble(value);
                        }
                        ct++;
                    }
                }

                return((dec) ? (object)(decValue / ct) : (object)(doubValue / ct));
            }
            finally
            {
                PopContextState();
            }
        }
Ejemplo n.º 7
0
        public float StDevP(AggrFn fn, string scope, bool runningValue)
        {
            Context ctxt = _currentContext;

            PushContextState();
            try
            {
                if (scope != null && scope != string.Empty)
                {
                    ctxt = ctxt.FindContextByGroupName(scope, _rpt);
                }
                int    ct   = 0;
                double sum1 = 0;
                double sum2 = 0;

                int top = (runningValue) ? ctxt.RowIndex : ctxt.Rows.Count - 1;
                for (int i = 0; i <= top; i++)
                {
                    ctxt.RowIndex = i;

                    object value = fn();
                    if (value != null && !Convert.IsDBNull(value))
                    {
                        sum1 += Convert.ToDouble(value);
                        sum2 += (Convert.ToDouble(value) * Convert.ToDouble(value));
                        ct++;
                    }
                }

                if (ct > 1)
                {
                    return((float)(Math.Sqrt((ct * sum2) - (sum1 * sum1)) / (ct - 1)));
                }
                else
                {
                    return(0);
                }
            }
            finally
            {
                PopContextState();
            }
        }
Ejemplo n.º 8
0
        public int CountDistinct(AggrFn fn, string scope, bool runningValue)
        {
            Context ctxt = _currentContext;

            PushContextState();
            try
            {
                if (scope != null && scope != string.Empty)
                {
                    ctxt = ctxt.FindContextByGroupName(scope, _rpt);
                }
                List <object> valueList = new List <object>();

                int top = (runningValue) ? ctxt.RowIndex : ctxt.Rows.Count - 1;
                for (int i = 0; i <= top; i++)
                {
                    ctxt.RowIndex = i;
                    object value = fn();
                    if (value != null && !Convert.IsDBNull(value))
                    {
                        valueList.Add(value);
                    }
                }
                valueList.Sort(delegate(object v1, object v2) { return(Compare.CompareTo(v1, v2)); });

                int ct = (valueList.Count == 0) ? 0 : 1;
                for (int i = 0; i < valueList.Count - 1; i++)
                {
                    if (Compare.CompareTo(valueList[i], valueList[i + 1]) != 0)
                    {
                        ct++;
                    }
                }

                return(ct);
            }
            finally
            {
                PopContextState();
            }
        }
Ejemplo n.º 9
0
        public object Min(AggrFn fn, string scope, bool runningValue)
        {
            PushContextState();
            Context ctxt = _currentContext;

            try
            {
                if (scope != null && scope != string.Empty)
                {
                    ctxt = ctxt.FindContextByGroupName(scope, _rpt);
                }
                object maxVal = null;

                int top = (runningValue) ? ctxt.RowIndex : ctxt.Rows.Count - 1;
                for (int i = 0; i <= top; i++)
                {
                    ctxt.RowIndex = i;

                    object value = fn();
                    if (value != null && !Convert.IsDBNull(value))
                    {
                        if (maxVal == null)
                        {
                            maxVal = value;
                        }
                        else if (Compare.CompareTo(value, maxVal) < 0)
                        {
                            maxVal = value;
                        }
                    }
                }

                return(maxVal);
            }
            finally
            {
                PopContextState();
            }
        }
Ejemplo n.º 10
0
        public object CountDistinct(AggrFn fn)
        {
            List <object> valueList = new List <object>();
            int           rowIndex  = _currentContext.RowIndex;

            for (int i = 0; i < _currentContext.Rows.Count; i++)
            {
                _currentContext.RowIndex = i;
                valueList.Add(fn());
            }
            valueList.Sort(RdlEngine.Utility.ApplyCompare);

            int ct = (valueList.Count == 0)?0:1;

            for (int i = 0; i < valueList.Count - 1; i++)
            {
                if (RdlEngine.Utility.ApplyCompare(valueList[i], valueList[i + 1]) != 0)
                {
                    ct++;
                }
            }

            return(ct);
        }
Ejemplo n.º 11
0
 public object Avg(AggrFn fn, string scope)
 {
     return(Avg(fn, scope, false));
 }
Ejemplo n.º 12
0
 public object Avg(AggrFn fn)
 {
     return(Avg(fn, null));
 }
Ejemplo n.º 13
0
 public object RunningValue(AggrFn fn, RunningValueFunction function)
 {
     return(RunningValue(fn, function));
 }
Ejemplo n.º 14
0
 public object Sum(AggrFn fn)
 {
     return(Sum(fn, null));
 }
Ejemplo n.º 15
0
 public object Previous(AggrFn fn)
 {
     return(Previous(fn, null));
 }
Ejemplo n.º 16
0
 public int CountDistinct(AggrFn fn, string scope)
 {
     return(CountDistinct(fn, scope, false));
 }
Ejemplo n.º 17
0
 public object Sum(AggrFn fn, string scope)
 {
     return(Sum(fn, scope, false));
 }
Ejemplo n.º 18
0
 public object Min(AggrFn fn)
 {
     return(Min(fn, null));
 }
Ejemplo n.º 19
0
 public float StDevP(AggrFn fn, string scope)
 {
     return(StDevP(fn, scope, false));
 }
Ejemplo n.º 20
0
 public float StDevP(AggrFn fn)
 {
     return(StDevP(fn, null));
 }
Ejemplo n.º 21
0
 public object Min(AggrFn fn, string scope)
 {
     return(Min(fn, scope, false));
 }
Ejemplo n.º 22
0
 public object Last(AggrFn fn)
 {
     return(Last(fn, null));
 }
Ejemplo n.º 23
0
 public object Count(AggrFn fn)
 {
     return(_currentContext.Rows.Count);
 }
Ejemplo n.º 24
0
 public int CountDistinct(AggrFn fn)
 {
     return(CountDistinct(fn, null));
 }
Ejemplo n.º 25
0
 public object First(AggrFn fn)
 {
     return(First(fn, null));
 }
Ejemplo n.º 26
0
 public object Max(AggrFn fn)
 {
     return(Max(fn, null));
 }