GetAggregateValue() private method

private GetAggregateValue ( int records, AggregateType kind ) : object
records int
kind AggregateType
return object
Ejemplo n.º 1
0
        internal override object Eval(DataRow row, DataRowVersion version)
        {
            if (_childTable == null)
            {
                throw ExprException.AggregateUnbound(ToString());
            }

            DataRow[] rows;

            if (_local)
            {
                rows = new DataRow[_childTable.Rows.Count];
                _childTable.Rows.CopyTo(rows, 0);
            }
            else
            {
                if (row == null)
                {
                    throw ExprException.EvalNoContext();
                }
                if (_relation == null)
                {
                    throw ExprException.AggregateUnbound(ToString());
                }
                rows = row.GetChildRows(_relation, version);
            }

            int[] records;
            if (version == DataRowVersion.Proposed)
            {
                version = DataRowVersion.Default;
            }

            List <int> recordList = new List <int>();

            for (int i = 0; i < rows.Length; i++)
            {
                if (rows[i].RowState == DataRowState.Deleted)
                {
                    if (DataRowAction.Rollback != rows[i]._action)
                    {
                        continue;
                    }
                    Debug.Assert(DataRowVersion.Original == version, "wrong version");
                    version = DataRowVersion.Original;
                }
                else if ((DataRowAction.Rollback == rows[i]._action) && (rows[i].RowState == DataRowState.Added))
                {
                    continue;
                }
                if (version == DataRowVersion.Original && rows[i]._oldRecord == -1)
                {
                    continue;
                }
                recordList.Add(rows[i].GetRecordFromVersion(version));
            }
            records = recordList.ToArray();

            return(_column.GetAggregateValue(records, _type));
        }
Ejemplo n.º 2
0
        internal override object Eval(DataRow row, DataRowVersion version)
        {
#if DEBUG
            if (CompModSwitches.AggregateNode.TraceVerbose)
            {
                Debug.WriteLine("Eval " + this.ToString() + ", version " + version.ToString());
            }
#endif
            if (table == null)
            {
                throw ExprException.AggregateUnbound(this.ToString());
            }

            DataRow[] rows;

            if (local)
            {
                rows = new DataRow[table.Rows.Count];
                table.Rows.CopyTo(rows, 0);
            }
            else
            {
                if (row == null)
                {
                    throw ExprException.EvalNoContext();
                }
                if (relation == null)
                {
                    throw ExprException.AggregateUnbound(this.ToString());
                }
                rows = row.GetChildRows(relation, version);
            }
#if DEBUG
            if (CompModSwitches.AggregateNode.TraceVerbose)
            {
                Debug.WriteLine("Eval " + this.ToString() + ", # of Rows: " + rows.Length.ToString());
            }
#endif

            int[] records;

            if (version == DataRowVersion.Proposed)
            {
                version = DataRowVersion.Default;
            }

            records = new int[rows.Length];
            for (int i = 0; i < rows.Length; i++)
            {
                records[i] = rows[i].GetRecordFromVersion(version);
            }
            return(column.GetAggregateValue(records, type));
        }