private void GetBaseIndex(CalcLocalIdentity lid, out int row, out int column) { CalcCellIdentity objA = lid as CalcCellIdentity; if (!object.ReferenceEquals(objA, null)) { row = objA.RowIndex; column = objA.ColumnIndex; } else { CalcRangeIdentity identity2 = lid as CalcRangeIdentity; if (!object.ReferenceEquals(identity2, null)) { row = identity2.RowIndex; row = (row < 0) ? 0 : row; column = identity2.ColumnIndex; column = (column < 0) ? 0 : column; } else { row = -1; column = -1; } } }
/// <summary> /// Determines whether the specified <see cref="T:Dt.CalcEngine.CalcCellIdentity" /> /// is equal to the current <see cref="T:Dt.CalcEngine.CalcCellIdentity" />. /// </summary> /// <param name="other"> /// The <see cref="T:Dt.CalcEngine.CalcCellIdentity" /> to compare with the /// current <see cref="T:Dt.CalcEngine.CalcCellIdentity" />. /// </param> /// <returns> /// <see langword="true" /> if the specified <see cref="T:Dt.CalcEngine.CalcCellIdentity" /> /// is equal to the current <see cref="T:Dt.CalcEngine.CalcCellIdentity" />; /// otherwise, <see langword="false" />. /// </returns> protected override bool CompareTo(CalcIdentity other) { CalcCellIdentity objA = other as CalcCellIdentity; if (object.ReferenceEquals(objA, null)) { return false; } return ((this._rowIndex == objA._rowIndex) && (this._columnIndex == objA._columnIndex)); }
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; } }
/// <summary> /// Gets the value 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 value. /// If the <paramref name="id" /> is not recognized, return <see cref="F:Dt.CalcEngine.CalcErrors.Reference" />. /// </returns> public virtual object GetValue(CalcIdentity id) { if (id is CalcExternalIdentity) { CalcExternalIdentity identity = id as CalcExternalIdentity; ICalcSource source = identity.Source; if (source != null) { CalcLocalIdentity identity3; CalcLocalIdentity identity2 = identity.ConvertToLocal(); if ((this.ArrayFormulaMode || (this.RowCount > 1)) || (this.ColumnCount > 1)) { identity3 = new CalcRangeIdentity(this.Row, this.Column, this.RowCount, this.ColumnCount); } else { identity3 = new CalcCellIdentity(this.Row, this.Column); } return(source.GetEvaluatorContext(identity3).GetValue(identity2)); } } else if ((this.Source != null) && (id is CalcLocalIdentity)) { CalcRangeIdentity objA = id as CalcRangeIdentity; if (object.ReferenceEquals(objA, null)) { return(this.Source.GetValue(id as CalcLocalIdentity)); } if (objA._isFullColumn && objA._isFullRow) { return(this.Source.GetValue(new CalcCellIdentity(this.Row, this.Column))); } if (objA._isFullColumn) { return(this.Source.GetValue(new CalcCellIdentity(this.Row, objA._columnIndex))); } if (objA._isFullRow) { return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, this.Column))); } if (((objA._rowCount == 1) && (objA._columnIndex <= this.Column)) && (this.Column < (objA._columnIndex + objA._columnCount))) { return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, this.Column))); } if (((objA._columnCount == 1) && (objA._rowIndex <= this.Row)) && (this.Row < (objA._rowIndex + objA._rowCount))) { return(this.Source.GetValue(new CalcCellIdentity(this.Row, objA._columnIndex))); } if ((objA._rowCount == 1) && (objA._columnCount == 1)) { return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, objA._columnIndex))); } return(CalcErrors.Value); } return(CalcErrors.Reference); }
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); }
/// <summary> /// Sets the formula. /// </summary> /// <param name="id">The id.</param> /// <param name="formula">The formula.</param> /// <param name="isArrayFormula">Indicates the formula is array formula or not.</param> /// <exception cref="T:System.ArgumentNullException"><paramref name="id" /> is <see langword="null" />.</exception> public void SetFormula(CalcCellIdentity id, string formula, bool isArrayFormula = false) { if (object.ReferenceEquals(id, null)) { throw new ArgumentNullException("id"); } CalcExpression expr = this.Parser.Parse(formula, this.Source.GetParserContext(id)); this.SetExpression(id, expr, isArrayFormula); }
private void ExpandSharedFormula(CalcExpression expr, CalcRangeIdentity rangeId) { for (int i = rangeId.RowIndex; i < (rangeId.RowIndex + rangeId.RowCount); i++) { for (int j = rangeId.ColumnIndex; j < (rangeId.ColumnIndex + rangeId.ColumnCount); j++) { CalcCellIdentity id = new CalcCellIdentity(i, j); this.SetExpression(id, expr, false); } } }
/// <summary> /// hdt 唐忠宝增加 /// </summary> /// <param name="cellId"></param> /// <returns></returns> private IEnumerable <CalcNode> EnumerateIntersectedNodesExcludeSelf(CalcCellIdentity cellId) { foreach (CalcNode iteratorVariable0 in this.Graph.GetAllRangeNodes()) { CalcRangeIdentity id = iteratorVariable0.Id as CalcRangeIdentity; if ((!object.ReferenceEquals(id, null) && (((cellId.RowIndex >= id.RowIndex) && (cellId.RowIndex < (id.RowIndex + id.RowCount))) || id._isFullColumn)) && (((cellId.ColumnIndex >= id.ColumnIndex) && (cellId.ColumnIndex < (id.ColumnIndex + id.ColumnCount))) || id._isFullRow)) { yield return(iteratorVariable0); } } }
private static bool IsIntersected(CalcCellIdentity cellId, CalcRangeIdentity rangeId) { if (rangeId._isFullColumn && rangeId._isFullRow) { return(true); } if (rangeId._isFullColumn) { return(InRange(cellId._columnIndex, rangeId._columnIndex, rangeId._columnIndex + rangeId._columnCount)); } if (rangeId._isFullRow) { return(InRange(cellId._rowIndex, rangeId._rowIndex, rangeId._rowIndex + rangeId._rowCount)); } return(InRange(cellId._rowIndex, rangeId._rowIndex, rangeId._rowIndex + rangeId._rowCount) && InRange(cellId._columnIndex, rangeId._columnIndex, rangeId._columnIndex + rangeId._columnCount)); }
/// <summary> /// Sets the expression. /// </summary> /// <param name="id">The id.</param> /// <param name="expr">The exception.</param> /// <param name="isArrayFormula">Indicates the expression is array formula or not.</param> /// <exception cref="T:System.ArgumentNullException"><paramref name="id" /> is <see langword="null" />.</exception> public void SetExpression(CalcCellIdentity id, CalcExpression expr, bool isArrayFormula = false) { if (object.ReferenceEquals(id, null)) { throw new ArgumentNullException("id"); } if (this.Service.IsGraphSuspended) { this._tmpFormulas[id] = new Tuple <CalcExpression, bool>(expr, isArrayFormula); } else { this.Graph.SetNode(id, expr, this.Source.GetEvaluatorContext(id), this.Source, isArrayFormula); this._formulas[id] = expr; } }
private static bool IsContains(CalcLocalIdentity id1, CalcLocalIdentity id2) { CalcRangeIdentity rangeId = id1 as CalcRangeIdentity; if (rangeId == null) { return(false); } CalcRangeIdentity identity2 = id2 as CalcRangeIdentity; CalcCellIdentity identity3 = id2 as CalcCellIdentity; if (identity3 != null) { return(IsContains(rangeId, identity3.RowIndex, identity3.ColumnIndex, 1, 1)); } return((identity2 != null) && IsContains(rangeId, identity2.RowIndex, identity2.ColumnIndex, identity2.RowCount, identity2.ColumnCount)); }
/// <summary> /// Gets the array formula. /// </summary> /// <param name="id">The id.</param> /// <param name="range">The range that the array formula was set.</param> /// <returns>A <see langword="string" /> indicates the array formula.</returns> public string GetArrayFormulaByCell(CalcCellIdentity id, out CalcRangeIdentity range) { if (object.ReferenceEquals(id, null)) { throw new ArgumentNullException("id"); } if (!this.IsIsIntersectantWithArrayFormula(id)) { range = null; return(null); } range = this.Graph.GetArrayFormulaRange(id, false); if (range == null) { return(null); } return(this.GetFormula(range)); }
private static void LocalId2Index(CalcLocalIdentity item, out int startRow, out int startCol, out int endRow, out int endCol) { CalcCellIdentity identity = item as CalcCellIdentity; CalcRangeIdentity identity2 = item as CalcRangeIdentity; if (identity != null) { startRow = endRow = identity.RowIndex; startCol = endCol = identity.ColumnIndex; } else { startRow = identity2.RowIndex; startCol = identity2.ColumnIndex; endRow = (identity2.RowIndex + identity2.RowCount) - 1; endCol = (identity2.ColumnIndex + identity2.ColumnCount) - 1; } startRow = (startRow < 0) ? 0 : startRow; startCol = (startCol < 0) ? 0 : startCol; endRow = (endRow < 0) ? 0xfffff : endRow; endCol = (endCol < 0) ? 0x3fff : endCol; }
/// <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); } } }
/// <summary> /// Initializes a new instance of the <see cref="T:Dt.CalcEngine.CalcCellIdentity" /> class. /// </summary> /// <param name="cellIdentity"> /// The source <see cref="T:Dt.CalcEngine.CalcCellIdentity" /> /// from which to create the new <see cref="T:Dt.CalcEngine.CalcCellIdentity" />. /// </param> /// <param name="rowOffset"> /// The amount to offset the row index. /// </param> /// <param name="columnOffset"> /// The amount to offset the column index. /// </param> public CalcCellIdentity(CalcCellIdentity cellIdentity, int rowOffset, int columnOffset) : this(cellIdentity.RowIndex + rowOffset, cellIdentity.ColumnIndex + columnOffset) { }
internal bool EvaluateFormula(CalcCalculationManager mgr, DirtyItem dirtyItem) { CalcLocalIdentity id = dirtyItem.Id as CalcLocalIdentity; if (object.ReferenceEquals(id, null)) { return(false); } CalcExpression objA = mgr.GetExpression(id); if (object.ReferenceEquals(objA, null)) { return(false); } ICalcSource source = mgr.Source; Dictionary <CalcLocalIdentity, CalcExpression> dictionary = new Dictionary <CalcLocalIdentity, CalcExpression>(); if ((id is CalcRangeIdentity) && mgr.Graph.IsSharedFormula(id as CalcRangeIdentity)) { List <CalcLocalIdentity> dirtySubIds = new List <CalcLocalIdentity>(); SharedFormulaDirtyItem item = dirtyItem as SharedFormulaDirtyItem; if ((item != null) && !item.IsFullRangeDirty) { dirtySubIds = (dirtyItem as SharedFormulaDirtyItem).DirtySubIds; } else { dirtySubIds.Add(id); } foreach (CalcLocalIdentity identity3 in dirtySubIds) { int num; int num2; int num3; int num4; bool flag; CalcRangeIdentity identity4 = identity3 as CalcRangeIdentity; CalcReferenceHelper.Id2Range(source, identity3, out num, out num2, out num3, out num4, out flag); for (int i = num; i < (num + num3); i++) { for (int j = num2; j < (num2 + num4); j++) { if ((identity4 != null) && (identity4.IsFullRow || identity4.IsFullColumn)) { new FullBandMappingVisitor(identity4.IsFullRow, identity4.IsFullRow ? i : j).Visit(objA, 0, 0); } CalcCellIdentity identity5 = new CalcCellIdentity(i, j); CalcExpression expression = mgr.GetExpression(identity5); if (((expression != null) && (expression == objA)) && !mgr.Graph.IsIsIntersectantWithArrayFormula(identity5)) { dictionary[identity5] = objA; } } } } } else { dictionary.Add(id, objA); } foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair in dictionary) { id = pair.Key; object obj2 = mgr.Evaluator.Evaluate(pair.Value, source.GetEvaluatorContext(id)); while (!(id is CalcRangeIdentity) && ((obj2 is CalcReference) || (obj2 is CalcArray))) { if (obj2 is CalcReference) { obj2 = ExtractValueFromReference(id, obj2); } if (obj2 is CalcArray) { obj2 = (obj2 as CalcArray).GetValue(0); } } source.SetValue(id, obj2); } return(true); }