示例#1
0
 private static void RunColCalcRecursive(CalcExpressionVm calcToRun, List<CalcExpressionVm> allColCalcs, RowVm row)
 {
     var expandedColCalc = ExpandColCalcForRow(calcToRun, row);
     var targetCell = row.Cells.FirstOrDefault(c => c.GridCode == expandedColCalc.TargetGridCode && c.RowCode == expandedColCalc.TargetRowCode && c.ColCode == expandedColCalc.TargetColCode);
     if (targetCell == null) return;
     EvaluateExpressionAndAssign(expandedColCalc, targetCell);
     if (!UpdateContextIsCellValue(calcToRun.UpdateContext)) return;
     var cascadedColCalcs = allColCalcs.Where(c => c.Operands.Any(o => o.GridCode == targetCell.GridCode && o.ColCode == targetCell.ColCode)).ToList();
     if (cascadedColCalcs.Any())
     {
         cascadedColCalcs.ForEach(cc =>
         {
             RunColCalcRecursive(cc, allColCalcs, row);
         });
     }
 }
示例#2
0
 private static CalcExpressionVm ExpandColCalcForRow(CalcExpressionVm colCalc, RowVm row)
 {
     var calc =  new CalcExpressionVm()
     {
         TargetGridCode = colCalc.TargetGridCode,
         TargetColCode = colCalc.TargetColCode,
         TargetRowCode = row.RowCode,
         Expression = colCalc.Expression.Split('.').Aggregate((c, n) => n == "" ? c + "." + row.RowCode + n : c + "." + n),
         UpdateContext = colCalc.UpdateContext,
         Operands = colCalc.Operands.Select(o => new CalcOperandVm()
         {
             GridCode = o.GridCode,
             ColCode = o.ColCode,
             RowCode = row.RowCode
         }).ToList()
     };
     foreach (var operand in calc.Operands)
     {
         var cell = row.Cells.FirstOrDefault(c => c.GridCode == operand.GridCode && c.RowCode == operand.RowCode && c.ColCode == operand.ColCode);
         var cellValue = GetCellValue(cell);
         var operandToken = GetCellToken(operand.GridCode, operand.RowCode, operand.ColCode);
         calc.Expression = calc.Expression.Replace(operandToken, cellValue.ToString(CultureInfo.CurrentCulture));
     }
     return calc;
 }
示例#3
0
        private static void RunRowCalcSumChildrenLoop(RowVm targetRow, GridVm grid)
        {
            while (true)
            {
                var resultDic = new Dictionary<string, double>();
                //Go through operand rows and add up numeric and percent cells, saving into dictionary
                foreach (var operandRowCode in targetRow.ChildRowCodes)
                {
                    var operandRow = grid.Rows.FirstOrDefault(r => r.RowCode == operandRowCode);
                    if (operandRow == null) continue;
                    foreach (var cell in operandRow.Cells.Where(CellIsNumericOrPercent))
                    {
                        if (resultDic.ContainsKey(cell.ColCode))
                        {
                            resultDic[cell.ColCode] = resultDic[cell.ColCode] + GetCellValue(cell);
                        }
                        else
                        {
                            resultDic.Add(cell.ColCode, GetCellValue(cell));
                        }
                    }
                }

                foreach (var cell in targetRow.Cells.Where(CellIsNumericOrPercent))
                {
                    if(resultDic.ContainsKey(cell.ColCode)) cell.Value = FormatCellValue(resultDic[cell.ColCode], cell);
                }

                if (!string.IsNullOrEmpty(targetRow.ParentRowCode))
                {
                    var parentRow = grid.Rows.FirstOrDefault(r => r.RowCode == targetRow.ParentRowCode);
                    if (parentRow != null)
                    {
                        targetRow = parentRow;
                        continue;
                    }
                }
                break;
            }
        }
示例#4
0
        private static int GetCellSpan(GridVm grid, RowVm row, ColumnVm col, int? cellSpanAttrib)
        {
            if (row.Type != Literals.Attribute.RowType.Header && row.Type != Literals.Attribute.RowType.Blank) return cellSpanAttrib ?? col.ColSpan;

            if (col.ColCode != Literals.UniversalColCode.RowText) return 0;

            var span = grid.Columns.Count(c => c.Level == 0 && !c.IsHidden);
            span += (grid.HasSelectCol ? 1 : 0) + (grid.HasCollapseCol ? 1 : 0) + (grid.HasAddCol ? 1 : 0) + (grid.HasDeleteCol ? 1 : 0);
            return span;
        }
示例#5
0
 private static CellVm BuildCellVmFromAttributes(GridVm grid, RowVm row, ColumnVm col, Attributes cellAttrib)
 {
     var overrideColSettings = cellAttrib.OverrideColSettings ?? false;
     var cellType = overrideColSettings ? cellAttrib.Type            : col.Type;
     var decimals = overrideColSettings ? cellAttrib.DecimalPlaces   : col.DecimalPlaces;
     var maxChars = overrideColSettings ? cellAttrib.MaxChars        : col.MaxChars;
     var cellVal = cellAttrib.Value;
     var textColor = "";
     if (row.Type != Literals.Attribute.RowType.Blank && (IsNumericOrPercentType(cellType)))
     {
         double parsedNum;
         var parsed = double.TryParse(cellAttrib.Value, out parsedNum);
         if (parsed)
         {
             cellVal = String.Format("{0:n" + decimals + "}", parsedNum);
             //if (parsedNum < 0) textColor = "red";
         }
     }
     if (!string.IsNullOrEmpty(cellAttrib.HoverBase)) textColor = "green";
     if (!string.IsNullOrEmpty(cellAttrib.HoverAddition))
     {
         double parsedHoverAddition;
         var parsed = double.TryParse(cellAttrib.HoverAddition, out parsedHoverAddition);
         if (parsed && parsedHoverAddition != 0)
         {
             textColor = "red";
         }
     }
     //var valParsed = double.TryParse(cellVal, out numval);
     var span = cellAttrib.ColSpan ?? col.ColSpan;
     return new CellVm()
     {
         GridCode = grid.GridCode,
         RowCode = row.RowCode,
         ColCode = col.ColCode,
         Type = cellType,
         MaxChars = maxChars,
         DecimalPlaces = decimals,
         ColSpan = GetCellSpan(grid, row, col, cellAttrib.ColSpan),
         ColumnHeader = col.DisplayText,
         Indent = cellAttrib.Indent ?? 0,
         IsEditable = (cellAttrib.IsEditable ?? false) && row.IsEditable && col.IsEditable && grid.IsEditable,
         //IsHidden = cellAttrib.IsHidden ?? false,  //todo: DisplayInCycle
         IsHidden = cellAttrib.DisplayInCycle == "None",
         Value = cellVal,
         //NumValue = valParsed ? numval : 0,
         Width = (span == 1 ? col.Width : "100%"),
         Alignment = cellAttrib.Alignment ?? "right",
         HoverBase = cellAttrib.HoverBase,
         HoverAddition = cellAttrib.HoverAddition,
         TextColor = textColor,
         Calcs = null
     };
 }
示例#6
0
 private static void AppendTemplateRowstoRowVm(RowVm rowVm, List<RowVm> templateRowVms, List<UspGetRowRelationship_Result> templateRowRelations)
 {
     var templateRows = templateRowRelations.Where(rr => rr.ParRowCode == rowVm.RowCode).ToList();
     if (!templateRows.Any()) return;
     var childTemplateRowCodes = templateRows.Select(tr => tr.ChRowCode);
     rowVm.TemplateRows = templateRowVms.Where(r => childTemplateRowCodes.Contains(r.RowCode)).OrderBy(t => t.DisplayOrder).ToList();
 }