Dim Filter As String
Dim cmb As WinForm.ComboBox=e.Form.Controls("ComboBox1")
If cmb.Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "乡名= '" & cmb.Value & "'"
End If
Dim doc As New PrintDoc '定义一个报表
Dim rt As New prt.RenderTable '定义一个表格对象
Dim cmd As New SQLCommand '定义一个SQL命令
Dim dt As DataTable '定义一个数据表变量
Dim Count As Integer = 0
cmd.C
If cmb.Value IsNot Nothing Then
cmd.CommandText = "SELECT 乡名,村名,登记权利,林种,Count(*) AS 宗地数, Round(SUM(面积),1) AS 面积 FROM {申请表} Where 乡名 ='" & cmb.Value & "' GROUP BY 乡名,村名,登记权利,林种"
Else
cmd.CommandText = "SELECT 乡名,村名,登记权利,林种,Count(*) AS 宗地数, Round(SUM(面积),1) AS 面积 FROM {申请表} GROUP BY 乡名,村名,登记权利,林种"
End If
dt = cmd.ExecuteReader() '生成一个临时表
Dim rs As New prt.RenderText() '定义一个文本对象
rt.Width = "Parent.Width" '列宽自动
rt.Style.Spacing.Top = 4 '表格和前面对象的垂直间隔为4毫米
If cmb.Value IsNot Nothing Then
rs.Text = "" & cmb.Value & "登记权利林种宗地数面积统计表"
Else
rs.Text = "登记权利林种宗地数面积统计表"
End If
rs.Style.Font = New Font("宋体",18,FontStyle.Bold)
rs.Style.TextAlignHorz = prt.AlignHorzEnum.Center '文本内容水平居中
Doc.PageHeader = rs '作为页眉使用 '设置页眉
Dim rt1 As prt.RenderText '定义一个文本对象
rt1 = New prt.RenderText '设置文本对象的内容
rt1.Text = "单位:亩.株.块" '设置文本内容
rt1.Style.TextAlignHorz = prt.AlignHorzEnum.Right '靠右对齐
rt1.Style.Borders.Bottom = New prt.LineDef(0.3, Color.Green) '设置底边框
rt1.Style.Padding.Bottom = 0.5 '底端内容缩进0.5毫米
rt1.Style.FontSize = 10 '字体大小为8磅
doc.Body.Children.Add(rt1) '将文本对象加入到表格中
Dim rx1 As New prt.RenderTable '定义一个表格对象
rx1.Cells(0,0).Text = "第[PageNo]页 共[PageCount]页"
rx1.Style.TextAlignHorz = prt.AlignHorzEnum.Center
rx1.CellStyle.Spacing.Bottom = 0.5 '底端内容缩进0.5毫米
rx1.Style.FontSize = 10 '字体大小为8磅
Doc.PageFooter = rx1 '作为页脚使用
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All '将第一行作为表头
rt.RowGroups(0,1).Style.Font = New Font("宋体",12,FontStyle.Bold) '字体大小
For Each Col AS DataCol In Dt.DataCols
rt.Cells(0,Count).Text = Col.Name
For r As Integer = 0 To dt.DataRows.Count - 1
rt.Cells(r +1,Count).Text = dt.DataRows(r)(Col.Name)
Next
Count = Count + 1
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线
rt.CellStyle.Spacing.All = 1 '内容距离网格线1毫米
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
doc.Body.Children.Add(rt)
doc.Preview()