using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Documents;
namespace VirtalWeldingView.PrintDocumentManage
{
/// <summary>
/// 通过后台代码根据数据行数渲染出相应的行
/// </summary>
public interface IDocumentRenderer
{
void Render<T>(FlowDocument doc, IList<T> list);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Documents;
using System.Windows;
using DataEntity;
namespace VirtalWeldingView.PrintDocumentManage
{
public class ClassScoreDocumentRenderer : IDocumentRenderer
{
public void Render<T>(System.Windows.Documents.FlowDocument doc, IList<T> list)
{
TableRowGroup group = doc.FindName("rowsDetails") as TableRowGroup;
Style styleCell = doc.Resources["TableCell"] as Style;
T entity = default(T);
entity = Activator.CreateInstance<T>();
foreach (var model in list)
{
if ((model as Student) != null)
{
Student item = model as Student;
TableRow row = new TableRow();
TableCell cell = new TableCell(new Paragraph(new Run(item.Student_No)));
cell.Style = styleCell;
row.Cells.Add(cell);
cell = new TableCell(new Paragraph(new Run(item.Student_Name)));
cell.Style = styleCell;
row.Cells.Add(cell);
cell = new TableCell(new Paragraph(new Run(Convert.ToString(item.SexName))));
cell.Style = styleCell;
row.Cells.Add(cell);
cell = new TableCell(new Paragraph(new Run(item.TestPaperName)));
cell.Style = styleCell;
row.Cells.Add(cell);
cell = new TableCell(new Paragraph(new Run(Convert.ToString(item.Score))));
cell.Style = styleCell;
row.Cells.Add(cell);
group.Rows.Add(row);
}
}
}
}
}