If Tables(e.Form.Name & "_table1").Rows.Count>0 Then Dim doc As New PrintDoc '定义一个报表 Dim r As Row =CurrentTable.Current Dim rt As New prt.RenderTable() '定义一个表格对象 doc.Body.Children.Add(rt) '将表格对象加入到报表中 rt.Style.GridLines.All = New prt.Linedef '设置网格线 rt.CellStyle.Spacing.All = 1 '内容距离网格线1毫米 '设置主标题 rt.Cells(0,0).text = "装柜通知单" rt.Cells(0,0).SpanCols = 8 '合并第一行全部单元格,用于显示主标题 rt.Cells(0,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '主标题居中 rt.Cells(0,0).Style.Font = New Font("宋体", 16, FontStyle.Bold) '设置主标题字体 rt.Rows(0).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉第一行的网格线 rt.Cells(1,0).SpanCols = 8 '合并地二行全部单元格,用于显示副标题 rt.Cells(1,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '副标题内容居中 rt.Rows(1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉第二行的网格线 rt.Rows(1).Style.Borders.Bottom = New prt.Linedef '恢复第二行底端的网格线 rt.Rows(1).Height = 3 '设置第二行的高度,拉开和表格主体的距离. '设置列标题 rt.Cols(0).Width =40 rt.Cols(1).Width =40 rt.Cols(3).Width =20 rt.Cols(4).Width =20 rt.Cols(5).Width =20 rt.Cols(6).Width =20 rt.Cols(6).Width =20 rt.Cols(7).Width =20 rt.cells(2,0).Text = "客户" '设置第一行第一个单元格的内容 rt.Cells(2,1).Text = "订单号" '设置第一行第四个单元格的内容 rt.Cells(2,3).Text = "装柜量" '设置第一行第四个单元格的内容 rt.Cells(2,6).Text = "装柜日期" '设置第一行第四个单元格的内容 rt.Cells(2,7).Text = "空集装箱重" '设置第一行第四个单元格的内容 rt.cells(2,0).SpanCols = 1 '合并第一行前三个单元格 rt.Cells(2,1).SpanCols = 2 '合并第一行最后三个单元格 rt.Cells(2,3).SpanCols = 3 '合并第一行最后三个单元格 rt.Cells(3,0).Text= 1 rt.Cells(3,1).Text =00 ''r("订单号") rt.Cells(3,3).Text= 1 rt.Cells(3,6).Text = 1 rt.Cells(3,1).SpanCols = 2 '合并第一行最后三个单元格 rt.Cells(3,3).SpanCols = 3 '合并第一行最后三个单元格 rt.Cells(4,0).Text= "目的港:" rt.Cells(4,1).Text = "提单号:" rt.Cells(4,3).Text = "箱号:" rt.Cells(4,6).Text= "铅封号:" rt.Cells(4,1).SpanCols = 2 '合并第一行最后三个单元格 rt.Cells(4,3).SpanCols = 3 '合并第一行最后三个单元格 rt.Cells(4,6).SpanCols = 2 '合并第一行最后三个单元格 rt.Cells(5,0).Text= "产品名称" rt.Cells(5,1).Text = "客人编码" rt.Cells(5,2).Text = "藤/布/玻璃" rt.Cells(5,3).Text= "包装方式" rt.Cells(5,4).Text = "数量" rt.Cells(5,5).Text = "装箱数量" rt.Cells(5,6).Text = "实际装柜明细" rt.Cells(5,7).Text = "累计" rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中 rt.Style.TextAlignVert = prt.AlignVertEnum.Center '垂直居中 rt.RowGroups(0,4).Header = prt.TableHeaderEnum.All '前四行作为表头 Dim cmd As New SQLCommand '定义一个SQL命令 Dim dt As DataTable '定义一个数据表变量 Dim Count As Integer = 0 cmd.CommandText = "select 产品名称,客人编码,藤布玻璃,包装方式,数量,装箱数量 from {装柜通知单} where 单据编号='" & r("单据编号") & "' order by 行号, 客人编码 " dt = cmd.ExecuteReader() '生成一个临时表 Dim fidx As Integer = -1 For i As Integer = 0 To dt.DataRows.Count-1 count = 0 For Each Col As DataCol In Dt.DataCols rt.Cells(i+6,Count).Text = dt.DataRows(i)(Col.Name) rt.Rows(i+6).Height =10 Count = Count + 1 Next If i < dt.DataRows.count - 1 Then If dt.DataRows(i)("客人编码") = dt.DataRows(i+1)("客人编码") Then If fidx = -1 Then fidx = i End If Else If fidx > -1 Then rt.Cells(fidx+6,1).SpanRows = i-fidx+1 rt.Cells(fidx+6,3).SpanRows = i-fidx+1 rt.Cells(fidx+6,5).SpanRows = i-fidx+1 fidx = -1 End If End If Else rt.Cells(fidx+6,1).SpanRows = i-fidx+1 rt.Cells(fidx+6,3).SpanRows = i-fidx+1 rt.Cells(fidx+6,5).SpanRows = i-fidx+1 fidx = -1 End If Next rt.Cells(dt.DataRows.Count +7,0).Text = "合计箱数:" rt.Cells(dt.DataRows.Count +8,0).Text = "制表: 审核: 装箱人:" rt.Cells(dt.DataRows.Count +7,0).SpanCols = 8 rt.Cells(dt.DataRows.Count +8,0).SpanCols = 8 rt.RowGroups(dt.DataRows.Count +7,dt.DataRows.Count +8).Footer = prt.TableHeaderEnum.All '前四行作为表头 doc.PageSetting.Landscape = True '横向打印 Doc.PageSetting.LeftMargin = 10 '设置左边距 Doc.PageSetting.RightMargin = 10 '设置右边距 Doc.PageSetting.TopMargin = 5 '设置上边距 Doc.PageSetting.BottomMargin = 5 '设置下边距 Doc.Preview() '预览报表 End If
|