Ejemplo n.º 1
0
 /// <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);
 }
Ejemplo n.º 2
0
        protected override CalcExpression VisitSheetRangeExpression(CalcSheetRangeExpression expr, int baseRow, int baseColumn)
        {
            bool flag  = (this._maxRowIndex.HasValue && !expr.IsFullColumn) && expr.StartRowRelative;
            bool flag2 = (this._maxColIndex.HasValue && !expr.IsFullRow) && expr.StartColumnRelative;
            bool flag3 = (this._maxRowIndex.HasValue && !expr.IsFullColumn) && expr.EndRowRelative;
            bool flag4 = (this._maxColIndex.HasValue && !expr.IsFullRow) && expr.EndColumnRelative;

            if ((!flag && !flag2) && (!flag3 && !flag4))
            {
                return(expr);
            }
            int num  = 0x7fffffff;
            int num2 = 0x7fffffff;
            IMultiSourceProvider startSource = expr.StartSource as IMultiSourceProvider;

            if (startSource != null)
            {
                foreach (ICalcSource source in startSource.GetCalcSources(expr.StartSource, expr.EndSource))
                {
                    num  = (num >= source.GetRowCount()) ? (source.GetRowCount() - 1) : num;
                    num2 = (num2 >= source.GetColumnCount()) ? (source.GetColumnCount() - 1) : num2;
                }
            }
            else
            {
                num  = expr.StartSource.GetRowCount() - 1;
                num2 = expr.EndSource.GetRowCount() - 1;
                num  = (num >= expr.EndSource.GetRowCount()) ? (expr.EndSource.GetRowCount() - 1) : num;
                num2 = (num2 >= expr.EndSource.GetColumnCount()) ? (expr.EndSource.GetColumnCount() - 1) : num2;
            }
            CalcSheetRangeIdentity identity = this.GetId(expr, baseRow, baseColumn) as CalcSheetRangeIdentity;
            int num3 = (identity.RowIndex + identity.RowCount) - 1;
            int num4 = (identity.ColumnIndex + identity.ColumnCount) - 1;

            if (((!flag || ((identity.RowIndex >= 0) && (identity.RowIndex <= num))) && (!flag2 || ((identity.ColumnIndex >= 0) && (identity.ColumnIndex <= num2)))) && ((!flag3 || ((num3 >= 0) && (num3 <= num))) && (!flag4 || ((num4 >= 0) && (num4 <= num2)))))
            {
                return(base.VisitSheetRangeExpression(expr, baseRow, baseColumn));
            }
            return(new CalcErrorExpression(CalcErrors.Reference));
        }