コード例 #1
0
ファイル: SheetRangeReference.cs プロジェクト: Daoting/dt
        /// <summary>
        ///
        /// </summary>
        /// <param name="references"></param>
        public SheetRangeReference(ICollection <CalcReference> references)
        {
            if ((references == null) || (references.Count == 0))
            {
                throw new ArgumentNullException();
            }
            CalcReference reference = null;

            foreach (CalcReference reference2 in references)
            {
                if (reference == null)
                {
                    reference = reference2;
                }
                else
                {
                    if ((reference2.GetType() != reference.GetType()) || (reference2.RangeCount != reference.RangeCount))
                    {
                        throw new ArgumentException();
                    }
                    for (int i = 0; i < reference.RangeCount; i++)
                    {
                        if (((reference2.GetColumn(i) != reference.GetColumn(i)) || (reference2.GetColumnCount(i) != reference.GetColumnCount(i))) || ((reference2.GetRow(i) != reference.GetRow(i)) || (reference2.GetRowCount(i) != reference.GetRowCount(i))))
                        {
                            throw new ArgumentException();
                        }
                    }
                }
            }
            this._references = new List <CalcReference>();
            this._references.AddRange(references);
        }
コード例 #2
0
 public static bool IsSubtotal(object o, int row, int column, short rangeId = 0)
 {
     if (o is CalcReference)
     {
         CalcReference reference = (CalcReference)o;
         return(reference.IsSubtotal(rangeId, row, column));
     }
     return(false);
 }
コード例 #3
0
ファイル: CalcReferenceHelper.cs プロジェクト: Daoting/dt
        internal static void Id2Range(ICalcSource source, CalcIdentity Id, out int row, out int col, out int rowCount, out int colCount, out bool searchRange)
        {
            int num;
            int num2;

            colCount    = num = 1;
            rowCount    = num2 = num;
            row         = col = num2;
            searchRange = false;
            CalcCellIdentity  objA      = Id as CalcCellIdentity;
            CalcRangeIdentity identity2 = Id as CalcRangeIdentity;

            if (!object.ReferenceEquals(objA, null))
            {
                row         = objA.RowIndex;
                col         = objA.ColumnIndex;
                rowCount    = colCount = 1;
                searchRange = true;
            }
            else if (!object.ReferenceEquals(identity2, null))
            {
                if (identity2.IsFullColumn || identity2.IsFullRow)
                {
                    CalcReference reference = source.GetReference(identity2) as CalcReference;
                    row      = reference.GetRow(0);
                    col      = reference.GetColumn(0);
                    rowCount = reference.GetRowCount(0);
                    colCount = reference.GetColumnCount(0);
                }
                if (identity2.IsFullRow)
                {
                    row      = identity2.RowIndex;
                    rowCount = identity2.RowCount;
                }
                else if (identity2.IsFullColumn)
                {
                    col      = identity2.ColumnIndex;
                    colCount = identity2.ColumnCount;
                }
                else
                {
                    row      = identity2.RowIndex;
                    rowCount = identity2.RowCount;
                    col      = identity2.ColumnIndex;
                    colCount = identity2.ColumnCount;
                }
                searchRange = true;
            }
            else
            {
                int num5;
                int num6;
                colCount = num5 = 0;
                rowCount = num6 = num5;
                row      = col = num6;
            }
        }
コード例 #4
0
 private static object ExtractValueFromReference(CalcLocalIdentity localId, object value)
 {
     for (CalcReference reference = value as CalcReference; (reference != null) && !(localId is CalcRangeIdentity); reference = value as CalcReference)
     {
         CalcCellIdentity objA = localId as CalcCellIdentity;
         int rowCount          = reference.GetRowCount(0);
         int columnCount       = reference.GetColumnCount(0);
         if (((reference.RangeCount <= 0) || (rowCount <= 0)) || (columnCount <= 0))
         {
             value = CalcErrors.Reference;
         }
         else
         {
             try
             {
                 if (!object.ReferenceEquals(objA, null))
                 {
                     if ((reference.RangeCount != 1) || ((rowCount > 1) && (columnCount > 1)))
                     {
                         value = CalcErrors.Value;
                     }
                     else
                     {
                         int rowOffset    = objA.RowIndex - reference.GetRow(0);
                         int columnOffset = objA.ColumnIndex - reference.GetColumn(0);
                         if ((rowCount == 1) && (columnCount == 1))
                         {
                             value = reference.GetValue(0, 0, 0);
                         }
                         else if (((rowCount == 1) && (columnCount > 1)) && ((columnOffset >= 0) && (columnOffset < columnCount)))
                         {
                             value = reference.GetValue(0, 0, columnOffset);
                         }
                         else if (((rowCount > 1) && (columnCount == 1)) && ((rowOffset >= 0) && (rowOffset < rowCount)))
                         {
                             value = reference.GetValue(0, rowOffset, 0);
                         }
                         else
                         {
                             value = CalcErrors.Value;
                         }
                     }
                 }
                 else
                 {
                     value = reference.GetValue(0, 0, 0);
                 }
             }
             catch (InvalidCastException)
             {
                 value = CalcErrors.Value;
             }
         }
     }
     return(value);
 }
コード例 #5
0
 public static bool IsSubtotal(object o, int i, short rangeId = 0)
 {
     if (o is CalcReference)
     {
         CalcReference reference   = (CalcReference)o;
         int           columnCount = reference.GetColumnCount(rangeId);
         return(reference.IsSubtotal(rangeId, i / columnCount, i % columnCount));
     }
     return(false);
 }
コード例 #6
0
 public static int GetLength(object o, short rangeId = 0)
 {
     if (o is CalcArray)
     {
         CalcArray array = (CalcArray)o;
         return(array.RowCount * array.ColumnCount);
     }
     if (o is CalcReference)
     {
         CalcReference reference = (CalcReference)o;
         return(reference.GetRowCount(rangeId) * reference.GetColumnCount(rangeId));
     }
     return(1);
 }
コード例 #7
0
 public static object GetValue(object o, int row, int column, short rangeId = 0)
 {
     if (o is CalcArray)
     {
         CalcArray array = (CalcArray)o;
         return(array.GetValue(row, column));
     }
     if (o is CalcReference)
     {
         CalcReference reference = (CalcReference)o;
         return(reference.GetValue(rangeId, row, column));
     }
     return(o);
 }
コード例 #8
0
 public static object GetValue(object o, int i, short rangeId = 0)
 {
     if (o is CalcArray)
     {
         CalcArray array       = (CalcArray)o;
         int       columnCount = array.ColumnCount;
         return(array.GetValue(i / columnCount, i % columnCount));
     }
     if (o is CalcReference)
     {
         CalcReference reference = (CalcReference)o;
         int           num2      = reference.GetColumnCount(rangeId);
         return(reference.GetValue(rangeId, i / num2, i % num2));
     }
     return(o);
 }
コード例 #9
0
ファイル: CalcEvaluatorContext.cs プロジェクト: Daoting/dt
 /// <summary>
 /// Gets the reference at specified position which indicated by <paramref name="id" />.
 /// </summary>
 /// <param name="id">A <see cref="T:Dt.CalcEngine.CalcIdentity" /> indicates the identity of a address.</param>
 /// <returns>
 /// An <see cref="T:System.Object" /> indicates the reference.
 /// If the <paramref name="id" /> is not recognized, return <see cref="F:Dt.CalcEngine.CalcErrors.Reference" />.
 /// </returns>
 public virtual object GetReference(CalcIdentity id)
 {
     if (id is CalcExternalIdentity)
     {
         CalcExternalIdentity identity = id as CalcExternalIdentity;
         ICalcSource          source   = identity.Source;
         if (source != null)
         {
             return(source.GetReference(identity.ConvertToLocal()));
         }
     }
     else
     {
         if (id is CalcSheetRangeIdentity)
         {
             IMultiSourceProvider provider = this.Source as IMultiSourceProvider;
             if (provider == null)
             {
                 return(CalcErrors.Reference);
             }
             try
             {
                 CalcSheetRangeIdentity identity2  = id as CalcSheetRangeIdentity;
                 CalcLocalIdentity      identity3  = identity2.ConvertToLocal();
                 List <CalcReference>   references = new List <CalcReference>();
                 foreach (ICalcSource source2 in provider.GetCalcSources(identity2.StartSource, identity2.EndSource))
                 {
                     CalcReference item = source2.GetReference(identity3) as CalcReference;
                     if (item != null)
                     {
                         references.Add(item);
                     }
                 }
                 return(new SheetRangeReference(references));
             }
             catch
             {
                 return(CalcErrors.Reference);
             }
         }
         if ((this.Source != null) && (id is CalcLocalIdentity))
         {
             return(this.Source.GetReference(id as CalcLocalIdentity));
         }
     }
     return(CalcErrors.Reference);
 }
コード例 #10
0
        private object ExtractValueFromReference(CalcReference reference, int row, int col)
        {
            SheetRangeReference reference2 = reference as SheetRangeReference;

            if ((reference2 != null) && (reference2.SheetCount != 1))
            {
                return(CalcErrors.Reference);
            }
            int rowCount    = reference.GetRowCount(0);
            int columnCount = reference.GetColumnCount(0);

            if (((reference.RangeCount <= 0) || (rowCount <= 0)) || (columnCount <= 0))
            {
                return(CalcErrors.Reference);
            }
            try
            {
                if ((reference.RangeCount == 1) && ((rowCount <= 1) || (columnCount <= 1)))
                {
                    int rowOffset    = row - reference.GetRow(0);
                    int columnOffset = col - reference.GetColumn(0);
                    if ((rowCount == 1) && (columnCount == 1))
                    {
                        return(reference.GetValue(0, 0, 0));
                    }
                    if (((rowCount == 1) && (columnCount > 1)) && ((columnOffset >= 0) && (columnOffset < columnCount)))
                    {
                        return(reference.GetValue(0, 0, columnOffset));
                    }
                    if (((rowCount > 1) && (columnCount == 1)) && ((rowOffset >= 0) && (rowOffset < rowCount)))
                    {
                        return(reference.GetValue(0, rowOffset, 0));
                    }
                }
                return(CalcErrors.Value);
            }
            catch (InvalidCastException)
            {
                return(CalcErrors.Value);
            }
        }
コード例 #11
0
 public UnaryCompositeConcreteReference(CalcReference source, int row, int column, int rowCount, int columnCount, Func <object, object> action) : base(source, row, column, rowCount, columnCount)
 {
     this.Action = action;
 }
コード例 #12
0
ファイル: ConcreteReference.cs プロジェクト: Daoting/dt
 public ConcreteReference(CalcReference source, int row, int column, int rowCount, int columnCount)
 {
     this._source = source;
     this._ranges = new Range[] { new Range(row, column, rowCount, columnCount) };
 }
コード例 #13
0
ファイル: ConcreteReference.cs プロジェクト: Daoting/dt
 public ConcreteReference(CalcReference source, Range[] areas)
 {
     this._source = source;
     this._ranges = areas;
 }
コード例 #14
0
 /// <summary>
 /// Invalidates the specified id.
 /// </summary>
 /// <param name="id">The data address.</param>
 /// <param name="autoCalculate">if set to <see langword="true" /> automatically calculate immediately.</param>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="id" /> is <see langword="null" />.</exception>
 public void Invalidate(CalcLocalIdentity id, bool autoCalculate = true)
 {
     if (object.ReferenceEquals(id, null))
     {
         throw new ArgumentNullException("id");
     }
     if (!this.Graph.IsEmpty)
     {
         CalcNode objA = this.Graph.GetNode(id);
         if (!object.ReferenceEquals(objA, null))
         {
             objA.MarkAsDirty(this.Service, autoCalculate, true, true, true);
         }
         else if (objA == null)
         {
             CalcNode.CreateTempNode(this.Source, id).MarkAsDirty(this.Service, autoCalculate, true, true, true);
         }
         else
         {
             CalcCellIdentity identity = id as CalcCellIdentity;
             if (!object.ReferenceEquals(identity, null))
             {
                 foreach (CalcNode node2 in this.Graph.GetAllDependentRangeNodes(identity.RowIndex, identity.ColumnIndex, 1, 1))
                 {
                     node2.MarkAsDirty(this.Service, autoCalculate, false, true, true);
                 }
             }
             else
             {
                 CalcRangeIdentity identity2 = id as CalcRangeIdentity;
                 if (!object.ReferenceEquals(identity2, null))
                 {
                     if (identity2.IsFullColumn && identity2.IsFullRow)
                     {
                         this.InvalidateAllIdentity();
                         return;
                     }
                     if (!identity2.IsFullColumn && !identity2.IsFullRow)
                     {
                         foreach (CalcNode node3 in this.Graph.GetAllDependentRangeNodes(identity2.RowIndex, identity2.ColumnIndex, identity2.RowCount, identity2.ColumnCount))
                         {
                             node3.MarkAsDirty(this.Service, autoCalculate, true, true, true);
                         }
                         for (int i = 0; i < identity2.RowCount; i++)
                         {
                             for (int j = 0; j < identity2.ColumnCount; j++)
                             {
                                 CalcNode node = this.Graph.GetNode(new CalcCellIdentity(identity2.RowIndex + i, identity2.ColumnIndex + j));
                                 if (!object.ReferenceEquals(node, null))
                                 {
                                     node.MarkAsDirty(this.Service, autoCalculate, false, true, true);
                                 }
                             }
                         }
                     }
                     else
                     {
                         int columnIndex;
                         int columnCount;
                         if (identity2.IsFullColumn)
                         {
                             columnIndex = identity2.ColumnIndex;
                             columnCount = identity2.ColumnCount;
                         }
                         else
                         {
                             columnIndex = identity2.RowIndex;
                             columnCount = identity2.RowCount;
                         }
                         foreach (CalcNode node5 in this.Graph.GetBandDependentNodes(columnIndex, columnCount, identity2.IsFullRow))
                         {
                             node5.MarkAsDirty(this.Service, autoCalculate, true, true, true);
                         }
                         CalcReference reference = this.Evaluator.Evaluate(new CalcRangeExpression(columnIndex, columnCount, false, false, true), this.Source.GetEvaluatorContext(identity2)) as CalcReference;
                         if (!object.ReferenceEquals(reference, null) && (reference.RangeCount == 1))
                         {
                             for (int k = 0; k < reference.GetRowCount(0); k++)
                             {
                                 for (int m = 0; m < reference.GetColumnCount(0); m++)
                                 {
                                     CalcNode node6 = this.Graph.GetNode(new CalcCellIdentity(reference.GetRow(0) + k, reference.GetColumn(0) + m));
                                     if (!object.ReferenceEquals(node6, null))
                                     {
                                         node6.MarkAsDirty(this.Service, autoCalculate, false, true, true);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         foreach (CalcLocalIdentity identity3 in this.Graph.GetAllVolantedIdeneities())
         {
             this.Graph.EnsureNode(identity3, null).MarkAsDirty(this.Service, autoCalculate, true, true, true);
         }
         if (autoCalculate)
         {
             this.Service.Recalculate(0xc350, false);
         }
     }
 }
コード例 #15
0
 public TernaryCompositeConcreteReference(CalcReference source, int row, int column, int rowCount, int columnCount, Func <object, object, object, object> action, object operand1, object operand2) : base(source, row, column, rowCount, columnCount)
 {
     this.Action   = action;
     this.Operand1 = operand1;
     this.Operand2 = operand2;
 }
コード例 #16
0
 public BinaryCompositeConcreteReference(CalcReference source, int row, int column, int rowCount, int columnCount, Func <object, object, object> action, object operand1, bool switchOrder = false) : base(source, row, column, rowCount, columnCount)
 {
     this.Action     = action;
     this.Operand1   = operand1;
     this.SwithOrder = switchOrder;
 }
コード例 #17
0
 public CellInfoReference(CalcReference source, int row, int column, int rowCount, int columnCount, CellInfoType type) : base(source, row, column, rowCount, columnCount)
 {
     this.Type = type;
 }