/// <summary> /// Adds the cell. /// </summary> /// <param name="cell">The cell.</param> public void AddCell(Cell cell) { // Add _cells.Add(cell); _cellIndexHash = null; }
/// <summary> /// Deletes the cell. /// </summary> /// <param name="cell">The cell.</param> public void DeleteCell(Cell cell) { _deletedCells.Add(cell); _cells.Remove(cell); _cellIndexHash = null; }
/// <summary> /// Gets the inner cell. /// </summary> /// <param name="ColumnIndex">Index of the column.</param> /// <param name="RowIndex">Index of the row.</param> /// <returns></returns> protected Cell GetInnerCell(int ColumnIndex, int RowIndex) { Column column = (Column)_columns[ColumnIndex]; Row row = (Row)this.Rows[RowIndex]; Cell cell = this.Document.GetCell(column.Id, row.Id); if(cell!=null) { if(cell.Type==CellType.UserValue && cell.Expression==string.Empty) { CellFormat cellFormat = GetDefaultCellFormat(ColumnIndex, RowIndex); //cell.Type = cellFormat.Type; cell.Expression = cellFormat.Expression; cell.Format = cellFormat.Format; cell.ReadOnly = cellFormat.ReadOnly; } } else { CellFormat cellFormat = GetDefaultCellFormat(ColumnIndex, RowIndex); cell = new Cell(this.Document, column.Id, row.Id); cell.Type = cellFormat.Type; cell.Expression = cellFormat.Expression; cell.Format = cellFormat.Format; cell.ReadOnly = cellFormat.ReadOnly; this.Document.AddCell(cell); if(cell.Expression!=string.Empty) EvaluateAutoValue(cell); } return cell; }
/// <summary> /// Adds the cell. /// </summary> /// <param name="ColumnId">The column id.</param> /// <param name="RowId">The row id.</param> /// <param name="Value">The value.</param> /// <returns></returns> public Cell AddCell(string ColumnId, string RowId, double Value) { Cell newCell = new Cell(this, ColumnId, RowId); newCell.Value = Value; this.AddCell(newCell); return newCell; }
/// <summary> /// Recalculates the related cells. /// </summary> /// <param name="srcCell">The SRC cell.</param> private void RecalculateRelatedCells(Cell srcCell) { RaiseCellValueChanged(srcCell); ArrayList changedCells = new ArrayList(); for(int colIndex =0;colIndex<this.Columns.Length; colIndex++) { for(int rowIndex =0;rowIndex<this.Rows.Length; rowIndex++) { Cell cell = this.GetCell(colIndex, rowIndex); if(cell!=null && cell.Type== CellType.AutoCalc) { //ExpressionInfo expInfo = ExpressionInfo.Parse(cell.Expression); ExpressionInfo expInfo = cell.GetExpressionInfo(); if(expInfo.ContainsParam(srcCell.Uid)) { double oldValue = cell.Value; EvaluateAutoValue(cell); changedCells.Add(cell); } // // int index = cell.Expression.IndexOf(srcCell.Uid); // if(index!=-1) // { // char endChar = cell.Expression[index+srcCell.Uid.Length]; // if(endChar==',' || endChar==')' ) // { // double oldValue = cell.Value; // EvaluateAutoValue(cell); // // //if(oldValue!=cell.Value) // changedCells.Add(cell); // } // } } } } foreach(Cell chCell in changedCells) { RecalculateRelatedCells(chCell); } }
/// <summary> /// Gets the referenced cells. /// </summary> /// <param name="srcCell">The SRC cell.</param> /// <returns></returns> public Cell[] GetReferencedCells(Cell srcCell) { ArrayList retVal = new ArrayList(); GetReferencedCells(srcCell, retVal); return (Cell[])retVal.ToArray(typeof(Cell)); }
/// <summary> /// Raises the cell value changed. /// </summary> /// <param name="cell">The cell.</param> private void RaiseCellValueChanged(Cell cell) { if(!_changedCellList.Contains(cell)) _changedCellList.Add(cell); // else // throw new Exception("RaiseCellValueChanged Loop"); //OnCellValueChanged(cell); }
/// <summary> /// Gets the referenced cells. /// </summary> /// <param name="srcCell">The SRC cell.</param> /// <param name="refCellList">The ref cell list.</param> private void GetReferencedCells(Cell srcCell, ArrayList refCellList) { ArrayList foundList = new ArrayList(); for(int colIndex =0;colIndex<this.Columns.Length; colIndex++) { for(int rowIndex =0;rowIndex<this.Rows.Length; rowIndex++) { Cell cell = this.GetCell(colIndex, rowIndex); if(cell!=null && cell.Type== CellType.AutoCalc) { //ExpressionInfo expInfo = ExpressionInfo.Parse(cell.Expression); ExpressionInfo expInfo = cell.GetExpressionInfo(); if(expInfo.ContainsParam(srcCell.Uid)) { foundList.Add(cell); } } } } refCellList.AddRange(foundList); foreach(Cell chSrcCell in foundList) { GetReferencedCells(chSrcCell, refCellList); } }
/// <summary> /// Gets the back referenced cells. /// </summary> /// <param name="srcCell">The SRC cell.</param> /// <param name="refCellList">The ref cell list.</param> private void GetBackReferencedCells(Cell srcCell, ArrayList refCellList) { ArrayList foundList = new ArrayList(); //ExpressionInfo exInfo = ExpressionInfo.Parse(srcCell.Expression); ExpressionInfo exInfo = srcCell.GetExpressionInfo(); foreach(string strParam in exInfo.Params) { string[] strPrmSplit = strParam.Split(':'); // if(strPrmSplit[0].StartsWith("-")) // { // strPrmSplit[0] = strPrmSplit[0].Substring(1); // } Cell cell = this.GetCell(strPrmSplit[0], strPrmSplit[1]); if(cell!=null) { foundList.Add(cell); } } refCellList.AddRange(foundList); foreach(Cell chSrcCell in foundList) { GetBackReferencedCells(chSrcCell, refCellList); } }
/// <summary> /// Evaluates the auto value. /// </summary> /// <param name="srcCell">The SRC cell.</param> private void EvaluateAutoValue(Cell srcCell) { string Expression = srcCell.Expression; srcCell.SetAutoValue(_expressionParser.Parse(Expression, this)); }
/// <summary> /// Sets the inner value. /// </summary> /// <param name="ColumnIndex">Index of the column.</param> /// <param name="RowIndex">Index of the row.</param> /// <param name="Value">The value.</param> protected void SetInnerValue(int ColumnIndex, int RowIndex, string Value) { if(Value==string.Empty) { //Reset Auto calculated Cell or Delete Common Cell Cell cell = GetInnerCell(ColumnIndex, RowIndex); if(cell!=null) { if(cell.Type == CellType.Common) { // Delete Cell this.Document.DeleteCell(cell); cell.Value = 0; RecalculateRelatedCells(cell); } else if(cell.Type == CellType.UserValue) { cell.Type = CellType.AutoCalc; // Restore Expression by Default if(cell.Expression==string.Empty) { CellFormat cellFormat = GetDefaultCellFormat(ColumnIndex, RowIndex); cell.Expression = cellFormat.Expression; } if(cell.Expression!=string.Empty) EvaluateAutoValue(cell); RecalculateRelatedCells(cell); } else if(cell.Type == CellType.AutoCalc) { if(cell.Expression!=string.Empty) EvaluateAutoValue(cell); RaiseCellValueChanged(cell); } } return; } double dblValue = 0; try { dblValue = double.Parse(Value); } catch { dblValue = double.Parse(Value, System.Globalization.CultureInfo.InvariantCulture); } { Cell cell = GetInnerCell(ColumnIndex, RowIndex); if(cell==null) { cell = new Cell(this.Document, ((Column)_columns[ColumnIndex]).Id, this.Rows[RowIndex].Id); this.Document.AddCell(cell); } if(cell.Value==dblValue) return; if(cell.Type==CellType.AutoCalc) cell.Type = CellType.UserValue; cell.Value = dblValue; RecalculateRelatedCells(cell); } }