以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 这问题怎么破? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=51576) |
-- 作者:石四 -- 发布时间:2014/5/29 10:27:00 -- 这问题怎么破? 结转需先加载当年数据,加载与结转代码有冲突,该怎么处理?
代码:
Dim y As Integer = Date.Today.Year Dim m As Integer = Date.Today.Month Dim dt1 As New Date(y, 1, 1) Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) \'获取本月的最后一天 Dim Filter As String Filter = "日期 >= #" & dt1 & "# And 日期 <= #" & dt2 & "#" DataTables("外协加工").LoadFilter = Filter DataTables("外协加工").Load
Dim s As String = Format(Date.Today, "yyyyMM") If s <> "" Then Tables("外协在制").StopRedraw() \'停止重绘 DataTables("外协在制").DataRows.Clear Dim dt_in As List(Of DataRow) dt_in = DataTables("外协加工").Select("零件图号 is not null", "零件图号,零件名称,加工单位,月份") \'排序取出 入仓 全部数据 Dim r As Row Dim sum_curr_count, sum_prev_count As Integer
r = Tables("外协在制").AddNew r("零件图号") = dt_in(0)("零件图号") r("零件名称") = dt_in(0)("零件名称") r("加工单位") = dt_in(0)("加工单位") r("月份") = s If dt_in(0)("月份") < s Then \'之前月 sum_prev_count = sum_prev_count + dt_in(0)("出库数量") Else If dt_in(0)("月份") = s Then \'本月份 sum_curr_count = sum_curr_count + dt_in(0)("出库数量") End If
For i As Integer = 1 To dt_in.Count - 1 \'写入型号和规格,同时统计入仓数量和金额 If dt_in(i)("零件图号") <> dt_in(i-1)("零件图号") OrElse dt_in(i)("零件名称") <> dt_in(i-1)("零件名称") Then \'不同产品 r("本月出库") = sum_curr_count r("上月在制") = sum_prev_count \'暂存
r = Tables("外协在制").AddNew \'插入新数据 r("零件图号") = dt_in(i)("零件图号") r("零件名称") = dt_in(i)("零件名称") r("加工单位") = dt_in(i)("加工单位") r("月份") = s sum_curr_count = 0 sum_prev_count = 0
End If
If dt_in(i)("月份") < s Then \'之前月 sum_prev_count = sum_prev_count + dt_in(i)("出库数量")
Else If dt_in(i)("月份") = s Then \'本月份
sum_curr_count = sum_curr_count + dt_in(i)("出库数量") End If Next
r("本月出库") = sum_curr_count r("上月在制") = sum_prev_count \'暂存
For Each dr As DataRow In DataTables("外协在制").DataRows \'填充统计数据 sum_curr_count = 0 \'累计本月出仓数量 sum_prev_count = 0 \'累计之前出仓数量 Dim drs_out As List(Of DataRow) Dim filter As String = "零件图号 = \'" & dr("零件图号") & "\' And 零件名称 = \'" & dr("零件名称") & "\'" drs_out = DataTables("外协入库").Select(filter, "月份") \'排序取出 出仓 全部数据 For Each dr_out As DataRow In drs_out If dr_out("月份") < s Then sum_prev_count = sum_prev_count + dr_out("入库数量") Else If dr_out("月份") = s Then sum_curr_count = sum_curr_count + dr_out("入库数量") Else Exit For End If Next
Dim sum_in_prev_count As Integer = dr("上月在制") \'从表中取出暂存数据 dr("本月入库") = sum_curr_count dr("上月在制") = sum_in_prev_count - sum_prev_count dr("本月在制") = dr("上月在制") + dr("本月出库") - dr("本月入库") Next Tables("外协在制").ResumeRedraw() End If
Forms("外协在制").Open() [此贴子已经被作者于2014-5-29 10:28:28编辑过]
|
-- 作者:Bin -- 发布时间:2014/5/29 10:29:00 -- 你外面已经声明过一次Filter了,你又重新声明一次,当然会报错冲突 你可以改为 Filter2 不能声明两个一样名称的变量.
|
-- 作者:石四 -- 发布时间:2014/5/29 10:42:00 -- 以下是引用Bin在2014-5-29 10:29:00的发言:
你外面已经声明过一次Filter了,你又重新声明一次,当然会报错冲突 你可以改为 Filter2 不能声明两个一样名称的变量. 哦,好啦。 |