在设计专来报表时的代码如下:
Dim MyReport As New PrintDoc, MyTable As New prt.RenderTable, MyImage1 As New prt.RenderImage, MyImage2 As New prt.RenderImage, Header As New prt.RenderText
Dim ChartBar As New ChartBuilder, ChartPie As New ChartBuilder, MySeries As WinForm.ChartSeries
Dim MyCommand As New SQLCommand, TmpTable As DataTable
Dim StartMonth As String, EndMonth As String, c As Integer
Dim 总及时率 As Single, 总延期率 As Single
'定义变量,变量赋值以及变量判断
StartMonth = InputBox("请输入查询开始月份,格式为四位年份+两位月份,如201010", "开始月份")
EndMonth = InputBox("请输入查询结束月份,格式为四位年份+两位月份,如201106,结束月份必须大于开始月份", "结束月份")
If startm" Then MessageBox.Show("请正确输入开始与结束月份!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information):exit Sub
If startmonth>= EndMonth Then MessageBox.show("结束日期必须大于开始日期!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information):exit Sub
'生成临时查询表
MyCommand.C
MyCommand.CommandText = "SELECT 供方名称,SUM(及时次数+延期次数) AS 订单汇总, SUM(及时次数) AS 及时批数 ,SUM(延期次数) AS 延期批数,ROUND(及时批数/订单汇总,2) As 及时率,ROUND(延期批数/订单汇总,2) As 延期率,0.05 AS 目标延期率 " & _
"FROM {采购跟踪} " & _
"WHERE 会计期间>=" & Chr(34) & StartMonth & Chr(34) & " And 会计期间<=" & Chr(34) & EndMonth & Chr(34) & _
"GROUP BY 供方名称"
TmpTable = MyCommand.ExecuteReader
总及时率 = Math.Round(TmpTable.compute("AVG(及时率)"), 2)
总延期率 = Math.Round(TmpTable.compute("AVG(延期率)"), 2)
'将临时查询表的数据写入到报表上的打印表中
With TmpTable
For Each Col As DataCol In .DataCols
MyTable.Cells(0, c).Text = Col.Name
For r As Integer=0 To .DataRows.count-1
If c >= .DataCols.Count - 3 Then
MyTable.Cells(r + 1, c).Text = Format(.DataRows(r)(Col.Name), "0.0%") '后面三列设置成百分比样式
Else
MyTable.Cells(r + 1, c).Text = .DataRows(r)(Col.Name)
End If
Next
c = c + 1
Next
End With
'设置打印表格式
With MyTable
.Width = 130
.Height = 98
.Style.FontSize = 8
.style.gridlines.all=new prt.linedef(color.gray)
.Style.TextAlignVert = prt.AlignVertEnum.Center
.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center
.Rows(0).Style.FontBold = True
.cols(0).cellstyle.Spacing.Left = 2
For c = 1 To .cols.Count - 1
.cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right
.cols(c).cellstyle.Spacing.Right = 2
Next
End With
MyReport.body.Children.Add (MyTable)
'画饼图
With ChartPie
.ChartType = ChartTypeEnum.Pie
.visualeffect = True
.LegendVisible = True
.LegendCompass = CompassEnum.north
.Width = 515
.Height = 370
End With
MySeries = ChartPie.serieslist.Add
With MySeries
.Length = 1
.Text = "总及时率"
.y(0) = 总及时率
End With
MySeries = ChartPie.serieslist.Add
With MySeries
.Length = 1
.Text = "总延期率"
.y(0) = 总延期率
.Offset = 20
.linecolor = Color.red
End With
MyImage1.image = ChartPie.image
'myimage1.style.borders.all=new prt.linedef(color.red) '这句用于调试时候给图表所在图片对象加的边框
MyReport.body.Children.Add (MyImage1)
'画下面的大图表
With ChartBar
.DataTable = TmpTable
.visualeffect = True
.Width = 1010
.Height = 340
.Axisy.Text = "延期批数"
.axisy2.Text = "延期率"
.LegendVisible = True
.LegendCompass = CompassEnum.north
.ChartType = ChartTypeEnum.Bar
End With
MySeries = ChartBar.serieslist.Add
With MySeries
.x.DataField = "供方名称"
.y.DataField = "延期批数"
.Text = "延期批数"
End With
MySeries = ChartBar.serieslist2.Add
With MySeries
.x.DataField = "供方名称"
.y.DataField = "延期率"
.Text = "延期率"
.markshape = MarkShapeEnum.diamond
.MarkSize = 4
End With
MySeries = ChartBar.serieslist2.Add
With MySeries
.x.DataField = "供方名称"
.y.DataField = "目标延期率"
.Text = "目标延期率"
.linecolor = Color.green
.markshape = MarkShapeEnum.Box
.markcolor = Color.green
.MarkSize = 3
End With
MyImage2.image = ChartBar.image
'myimage2.style.borders.all=new prt.linedef(color.red) '这句用于调试时候给图表所在图片对象加的边框
MyReport.body.Children.Add (MyImage2)
'页面设置
With MyReport.PageSetting
.Landscape = True
.LeftMargin = 15
.RightMargin = 15
.TopMargin = 10
.BottomMargin = 0
End With
With Header
.Text = "采购部" & Mid(StartMonth, 1, 4) & "." & Mid(StartMonth, 5, 2) & "-" & Mid(EndMonth, 1, 4) & "." & Mid(EndMonth, 5, 2) & "交货月及时率"
.Style.TextAlignHorz = prt.AlignHorzEnum.Center
.style.font=new font("黑体",14,FontStyle.Bold)
.Style.padding.bottom = 5
End With
With MyReport
.Stacking = prt.StackingRulesEnum.InlineLeftToRight
.PageHeader = Header
.preview()
End With
[此贴子已经被作者于2011-8-30 10:40:52编辑过]