예제 #1
0
        /// <summary>
        /// 格式化表格模板
        /// </summary>
        /// <param name="tableTemplate"></param>
        /// <param name="modelProcessor"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        private Table CreateTableTemplateItem(TemplateItem tableTemplate, IModelProcessor modelProcessor, object model)
        {
            var table = new Table();

            table.Margin  = tableTemplate.Margin;
            table.Padding = tableTemplate.Padding;
            if (!string.IsNullOrWhiteSpace(tableTemplate.FontFamily))
            {
                table.FontFamily = new Typeface(tableTemplate.FontFamily).FontFamily;
            }
            if (tableTemplate.Size > 0)
            {
                table.FontSize = tableTemplate.Size;
            }
            SetControlFontStyle(tableTemplate.FontStyle, table);
            SetControlFontWeight(tableTemplate.FontWeight, table);
            var items    = modelProcessor.GetItems(tableTemplate.BindingData, model);
            var rowGroup = new TableRowGroup();
            var header   = new TableRow();//create header

            foreach (var item in tableTemplate.Children)
            {
                var cell = new TableCell();

                if (item.TableHeader != null)
                {
                    var content       = CreateTextTemplateItem(item.TableHeader, modelProcessor, model);
                    var textContainer = new Paragraph();
                    textContainer.Inlines.Add(content);
                    cell.Blocks.Add(textContainer);
                }
                if (item.InTableColumnSpan > 0)
                {
                    cell.ColumnSpan = item.InTableColumnSpan;
                }
                header.Cells.Add(cell);
            }
            rowGroup.Rows.Add(header);

            foreach (var context in items) //create Item
            {
                var row = new TableRow();
                foreach (var item in tableTemplate.Children)
                {
                    var content       = CreateTextTemplateItem(item, modelProcessor, context);
                    var textContainer = new Paragraph();
                    textContainer.Inlines.Add(content);
                    var cell = new TableCell();
                    if (item.InTableColumnSpan > 0)
                    {
                        cell.ColumnSpan = item.InTableColumnSpan;
                    }
                    cell.Blocks.Add(textContainer);
                    row.Cells.Add(cell);
                }
                rowGroup.Rows.Add(row);
            }
            table.RowGroups.Add(rowGroup);
            return(table);
        }