예제 #1
0
        /// <summary>
        /// Adds a new data PdfPCell to the MainTable
        /// </summary>
        /// <param name="rowValues"></param>
        /// <param name="backgroundColor"></param>
        /// <param name="foreColor"></param>
        /// <param name="columnNumber"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public CellAttributes AddRowCell(IList <CellData> rowValues, BaseColor backgroundColor, BaseColor foreColor, int columnNumber)
        {
            var col = SharedData.PdfColumnsAttributes[columnNumber];

            checkProperty(columnNumber, col);

            object data;

            if (col.IsCalculatedField)
            {
                data = FuncHelper.ApplyCalculatedFieldFormula(col.CalculatedFieldFormula, rowValues);
                rowValues.Add(new CellData {
                    PropertyName = col.PropertyName, PropertyValue = data, FormattedValue = data.ToSafeString()
                });
            }
            else
            {
                CellData pdfCellData;
                if (col.PropertyIndex >= 0)
                {
                    pdfCellData = rowValues.FirstOrDefault(x => x.PropertyName == col.PropertyName && x.PropertyIndex == col.PropertyIndex);
                }
                else
                {
                    pdfCellData = rowValues.FirstOrDefault(x => x.PropertyName == col.PropertyName);
                }

                if (pdfCellData == null)
                {
                    var propertiesList = rowValues.Select(x => x.PropertyName).Aggregate((p1, p2) => p1 + ", " + p2);
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                      "'{0}' property not found. Available properties list: {1}", col.PropertyName, propertiesList));
                }
                data = pdfCellData.PropertyValue;
            }

            return(AddGeneralCell(
                       backgroundColor,
                       foreColor,
                       data,
                       columnNumber,
                       RowType.DataTableRow,
                       CellType.DataTableCell,
                       rowValues,
                       setItemTemplate: true));
        }