如下代码,不报错了,逻辑自己看一下
With e.Form.Controls("日期")
If .Value Is Nothing Then
Return
End If
End With
Tables("材料月报2_Table1").StopRedraw
Dim Filter As String
Dim curD As Date=e.Form.Controls("日期").Value '当前日期
Dim lastD As Date = curD.AddMonths(-1) '上一个月的日期
Dim lastD2 As New Date(lastD.Year, lastD.Month, Date.DaysInMonth(lastD.Year,lastD.Month)) '上个月的最后一天
Filter = Filter & "日期 > #" & lastD2 & "#" & " And 日期 <= #" & curD & "#"
Dim jb As new SQLJoinTableBuilder("查询表2","计划")
jb.C
jb.Filter = Filter
jb.AddTable("计划","板料编码","材料","板料编码")
jb.AddCols("日期","实剪","{材料}.板料编码","{材料}.板料规格","宽","厚","长")
jb.AddExp("实重", "[实剪] * 7.85 * 0.9 * [厚] * [宽] * [长] / 1000000000")
jb.Build()
Dim bd1 As New GroupTableBuilder("统计表5", jb.BuildSQL,"sl")
Dim dt1 As fxDataSource
Bd1.Groups.AddDef("日期",DateGroupEnum.Year,"年") '添加日期列用于分组,并用"年"代替原名称
bd1.Groups.AddDef("日期","月") '添加日期列用于分组,并用"月"代替原名称
bd1.Groups.AddDef("板料编码") '根据型号分组
bd1.Groups.AddDef("板料规格") '根据型号分组
bd1.Totals.AddDef("实剪","耗用_数量") '对数量进行统计
bd1.Totals.AddDef("实重","耗用_重量") '对金额进行统计
bd1.Filter = Filter
dt1 = bd1.BuildDataSource()
Dim bd2 As New SQLGroupTableBuilder("统计表6","材料入库")
Bd2.C
Dim dt2 As fxDataSource
Bd2.Groups.AddDef("日期",DateGroupEnum.Year,"年") '添加日期列用于分组,并用"年"代替原名称
bd2.Groups.AddDef("日期","月") '添加日期列用于分组,并用"月"代替原名称
bd2.Groups.AddDef("板料编码") '根据型号分组
Bd2.Groups.AddDef("板料规格") '根据型号分组
Bd2.Totals.AddDef("数量","入库_数量") '对数量进行统计
bd2.Totals.AddDef("重量","入库_重量") '对重量进行统计
bd2.Totals.AddDef("金额","入库_金额") '对重量进行统计
bd2.Filter = Filter
dt2 = bd2.BuildDataSource()
Dim nms As String() = {"年","月","板料编码","板料规格"} '指定连接列
dt2.Combine(nms,dt1,nms)
Tables("材料月报2_Table1").DataSource = dt2 '将统计结果绑定到Table
With DataTables("材料月报2_Table1").DataCols '用表达式列计算库存数据
.Add("期初_数量",Gettype(Double),"","期初_数量")
.Add("期初_重量",Gettype(Double),"","期初_重量")
.Add("期初_金额",Gettype(Double),"","期初_金额")
End With
Filter = "日期 <= #" & lastD2 & "#"
Dim dt_rk As DataTable
Dim dt_hy As DataTable
Dim cmd As new SQLCommand
Cmd. C
cmd.CommandText = "select * from {材料入库} where " & Filter
dt_rk = cmd.ExecuteReader
cmd.CommandText = "select {计划}.板料编码,{计划}.板料规格,日期,实剪 as 耗用_数量, 实剪 * 长 * 宽 * 厚 * 7.85 * 0.9 / 1000000000 AS 耗用_重量 FROM {计划} INNER JOIN {材料} ON {计划}.板料编码 = {材料}.板料编码 where " & Filter
output.show(cmd.commandText)
dt_hy = cmd.ExecuteReader
For Each r As Row In Tables("材料月报2_Table1").Rows
Filter = "板料编码 = '" & r("板料编码") & "'"
r("期初_数量") = dt_rk.Compute("sum(数量)", filter) - dt_hy.Compute("sum(耗用_数量)", filter)
r("期初_重量") = dt_rk.Compute("sum(重量)", filter) - dt_hy.Compute("sum(耗用_重量)", filter)
Next
DataTables("材料月报2_Table1").DataCols.Add("加权平均单价", Gettype(Double), "(期初_金额+入库_金额)/(期初_重量+入库_重量)")
With DataTables("材料月报2_Table1").DataCols '用表达式列计算库存数据
.Add("库存_数量",Gettype(Double), "IsNull([期初_数量],0) + IsNull([入库_数量],0) - ISNULL([耗用_数量],0)", "库存_数量")
.Add("库存_重量",Gettype(Double), "IsNull([期初_重量],0) + IsNull([入库_重量],0) - ISNULL([耗用_重量],0) ", "库存_重量")
.Add("库存_金额",Gettype(Double), "加权平均单价 * 库存_重量", "库存_金额")
End With
Tables("材料月报2_Table1").SetColVisibleWidth("年|30|月|30|板料编码|120|板料规格|120|加权平均单价|80|期初_数量|80|期初_重量|80|期初_金额|80|入库_数量|80|入库_重量|80|入库_金额|80|耗用_数量|80|耗用_重量|80|库存_数量|80|库存_重量|80|库存_金额|80")
Tables("材料月报2_Table1").DefaultRowHeight = 35
DataTables("材料月报2_Table1").DataCols("加权平均单价").SetFormat("#,###.00")
DataTables("材料月报2_Table1").DataCols("期初_数量").SetFormat("#,###.")
DataTables("材料月报2_Table1").DataCols("期初_重量").SetFormat("#,###.00")
DataTables("材料月报2_Table1").DataCols("期初_金额").SetFormat("#,###.00")
DataTables("材料月报2_Table1").DataCols("入库_数量").SetFormat("#,###.00")
DataTables("材料月报2_Table1").DataCols("入库_重量").SetFormat("#,###.00")
DataTables("材料月报2_Table1").DataCols("入库_金额").SetFormat("#,###.00")
DataTables("材料月报2_Table1").DataCols("耗用_数量").SetFormat("#,###.00")
DataTables("材料月报2_Table1").DataCols("耗用_重量").SetFormat("#,###.00")
DataTables("材料月报2_Table1").DataCols("库存_数量").SetFormat("#,###.00")
DataTables("材料月报2_Table1").DataCols("库存_重量").SetFormat("#,###.00")
DataTables("材料月报2_Table1").DataCols("库存_金额").SetFormat("#,###.00")
Tables("材料月报2_Table1").ResumeRedraw