# 打印配置

默认只需后台初始化打印的表与字段及后台管理页面【打印管理】设计模板


//1、在Startup.cs文件ConfigureContainer中初始化打印配置

public void ConfigureContainer(ContainerBuilder builder)
{

 /**********************************打印配置****************************************************/
       PrintContainer.Instance
                 /*****************[全国城市]单表打印*****************/
                 .Use<Sys_Region>(
                   //主表配置
                   name: "地址打印管理",
                   //主表可以打印的字段
                   printFields: x => new { x.name, x.code, x.mername, x.pinyin, x.Lat, x.Lng }
                 )


                 //主从明细表同时打印(注意Use第一个参数是主表,第二个明细表)
                 .Use<Demo_Order, Demo_OrderList>(
                   //主表配置
                   name: "订单打印管理",
                   //主表可以打印的字段
                   printFields: x => new { x.OrderNo, x.OrderStatus, x.OrderType, x.OrderDate, x.TotalPrice, x.TotalQty },

                   //明细表配置
                   detailName: "订单详情",
                   //明细表可以打印的字段
                   detailPrintFields: c => new { c.GoodsCode, c.GoodsName, c.Specs, c.Price, c.Qty }
                 )


                 /*****************[订单表]打印配置(主从明细表明细表(一对一))*****************/
                 .Use<Demo_Order,Demo_OrderList>(
                   //主表配置
                   name: "订单打印管理",
                   //主表可以打印的字段
                   printFields: x => new { x.OrderNo, x.OrderStatus, x.OrderType, x.OrderDate, x.TotalPrice, x.TotalQty },
                   //主表自定义打印的字段,没有就填null;需要在:PrintCustom类QueryResult字自定义返回这些字段的值
                   customFields: new List<CustomField>() {
                            new CustomField() { Name="自定义1",   Field="test1"  } ,
                            new CustomField() {  Name="自定义2",  Field="test2" }
                    },
                   //明细表配置
                   detail:new PrintDetailOptions<Demo_OrderList>() {
                       Name = "订单详情",
                       PrintFields = c => new { c.GoodsCode, c.GoodsName, c.Specs, c.Price, c.Qty },
                       //明细表自定义的字段,没有就填null;需要在:PrintCustom类QueryResult字自定义返回这些字段的值
                       CustomFields = new List<CustomField>() {
                            new CustomField() { Name="明细自定义1",   Field="test1"  } ,
                            new CustomField() { Name="明细自定义2",  Field="test2" }
                       }
                   }
                 )

                 
                 /*****************[产品表]打印配置(一对多打印)*****************/
                 .Use<Demo_Product, Demo_ProductSize, Demo_ProductColor>(
                       //主表配置
                       name: "一对多打印测试",
                       //主表可以打印的字段
                       printFields: x => new { x.ProductName, x.ProductCode, x.AuditStatus, x.Price, x.Remark, x.CreateDate },
                       //主表自定义打印的字段,没有就填null;需要在:PrintCustom类QueryResult字自定义返回这些字段的值
                       customFields:null,//配置同上
                       //明细表[产品尺寸]打印配置
                       detail1: new PrintDetailOptions<Demo_ProductSize>()
                       {
                           Name = "产品尺寸",
                           //明细表打印的字段
                           PrintFields = x => new { x.ProductId, x.Size, x.Unit, x.Remark, x.Creator, x.CreateDate },
                           //明细表自定义的字段,需要在:PrintCustom类QueryResult字自定义返回这些字段的值
                           CustomFields = null //自定义字段同上配置一样
                       },
                       //明细表[产品颜色]打印配置
                       detail2: new PrintDetailOptions<Demo_ProductColor>()
                       {
                           Name = "产品颜色",
                           //明细表打印的字段
                           PrintFields = x => new { x.ProductId,x.Img,x.Color, x.Qty, x.Unit, x.Remark, x.Creator, x.CreateDate },
                           //明细表自定义的字段需要在:PrintCustom类QueryResult字自定义返回这些字段的值
                           CustomFields = null //自定义字段同上配置一样
                       }
                );
}

//2、后台管理,打印设计中,点击新建配置打印名称,再点击表格操作列,设置打印模板
//3、菜单配置,勾上打印按钮
//4、打开后台管理页面就可以看到打印按钮了,点击打印选择第二步配置的模板会自动跳转



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

# 打印分页问题

An image

# 打印文本与表格重叠问题

使用长文本配置