-- 作者:yankunhao
-- 发布时间:2011/8/30 10:23:00
-- 关于专业报表出错问题
在设计专来报表时的代码如下:
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编辑过]
|
-- 作者:yankunhao
-- 发布时间:2011/8/30 11:18:00
--
我怀疑是产生临时表的那段代码有问题,但我改为如下的测试也一样有问题:
\'生成临时查询表 MyCommand.C MyCommand.CommandText = "SELECT 供方名称,SUM(及时次数+延期次数) AS 订单汇总, SUM(及时次数) AS 及时批数 ,SUM(延期次数) AS 延期批数,ROUND(及时批数/订单汇总,2) As 及时率,ROUND(延期批数/订单汇总,2) As 延期率,0.05 AS 目标延期率" & _ "FROM {采购跟踪} WHERE 会计期间>= \'" & StartMonth & "\'And 会计期间<= \'" & EndMonth & "\'& GROUP BY 供方名称" TmpTable = MyCommand.ExecuteReader
[此贴子已经被作者于2011-8-30 11:20:39编辑过]
|
-- 作者:yankunhao
-- 发布时间:2011/8/30 15:08:00
--
现在初步找到问题所在了,代码是在内部表中用试用版测是可以生成到所要的4楼报表,但当将代码用在外部数据表时就报错,所以应该是生成临时查询表的代码有错,问题是我在菜单中测试SQL代码时发现问题,得不到所要的数据,如下表中的及时率和延期率,按理应得出小数点的,但显示的是整数,这是什么道理呢?谁能帮我看看呢?
此主题相关图片如下:16.jpg
[此贴子已经被作者于2011-8-30 15:11:02编辑过]
|