论坛工程师:您好!
对上表有两个想法:前面您给的指导,还不能自动更新,必须通过“重置”后才可以更新数据。请按如下给予修改。
<!--[if !supportLists]-->一、
<!--[endif]-->简单的做法:当“日报记录表”里数据的【连铸_6M】或【连铸_9M】列发生变化时,“日报表”和“月报表”的统计数据“出坯量”等数据,按年、月的选择自动更新变化。请给予帮助。
<!--[if !supportLists]-->二、
<!--[endif]-->复杂一点的程序:当“日报记录”表里的数据发生变化时,能自动生成日报表、月报表、年报表。请给予帮助指导。
溧阳光明:陈志刚
2018-08-06
如下面的程序:
<!--[if !supportLists]-->1.
<!--[endif]-->月报表的项目事件中DataColChanged:
Select Case e.DataCol.Name
Case "年","月","单位"
If e.DataRow.IsNull("年") OrElse e.DataRow.IsNull("月") OrElse e.DataRow.IsNull("单位") Then
e.DataRow("连铸_6M") = Nothing
e.DataRow("出坯量") = Nothing
Else
Dim d As Date = new Date(e.DataRow("年"),e.DataRow("月"),1)
Dim Filter As String = "日期 >= #" & d & "# and 日期 < #"
& d.AddMonths(1) & "# and 单位='"
& e.DataRow("单位")
& "'"
e.DataRow("连铸_6M") = Tables("日报表").Compute("sum(连铸_6M)",Filter )
e.DataRow("出坯量") = Tables("日报表").Compute("sum(出坯量)",Filter )
e.DataRow("电炉_耗电") = Tables("日报表").Compute("sum(电炉_耗电)",Filter )
e.DataRow("出库物资") = Tables("日报表").Compute("sum(出库物资)",Filter )
End If
End Select
2. 日报表的项目事件中DataColChanged:
Select Case e.DataCol.Name
Case "连铸_6M","连铸_9M","连铸_每米重量","液氩"
If e.DataRow.IsNull("日期") = False AndAlso
e.DataRow.IsNull("单位") = False
Dim pr As DataRow
Dim d As Date = e.DataRow("日期")
pr = DataTables("月报表").Find("月 = " & d.Month & " and 年 = " &
d.Year & " and 单位='" & e.DataRow("单位") &
"'")
If pr IsNot Nothing Then
DataTables("月报表").DataCols("月").RaiseDataColChanged(pr)
End If
End If
Case "日期"
If e.OldValue <> Nothing Then
Dim pr As DataRow
Dim d As Date = e.OldValue
pr = DataTables("月报表").Find("月 = " & d.Month & " and 年 = " &
d.Year & " and 单位='" & e.DataRow("单位") &
"'")
If pr IsNot Nothing Then
DataTables("月报表").DataCols("月").RaiseDataColChanged(pr)
End If
End If
If e.NewValue <> Nothing Then
Dim pr As DataRow
Dim d As Date = e.NewValue
pr = DataTables("月报表").Find("月 = " & d.Month & " and 年 = " &
d.Year & " and 单位='" & e.DataRow("单位") &
"'")
If pr IsNot Nothing Then
DataTables("月报表").DataCols("月").RaiseDataColChanged(pr)
End If
End If
Case "单位"
If e.OldValue <> Nothing Then
Dim pr As DataRow
Dim d As Date = e.DataRow("日期")
pr = DataTables("月报表").Find("月 = " & d.Month & " and 年 = " &
d.Year & " and 单位='" & e.OldValue
& "'")
If pr IsNot Nothing Then
DataTables("月报表").DataCols("月").RaiseDataColChanged(pr)
End If
End If
If e.NewValue <> Nothing Then
Dim pr As DataRow
Dim d As Date = e.DataRow("日期")
pr = DataTables("月报表").Find("月 = " & d.Month & " and 年 = " &
d.Year & " and 单位='" & e.NewValue
& "'")
If pr IsNot Nothing Then
DataTables("月报表").DataCols("月").RaiseDataColChanged(pr)
End If
End If
End Select
3. “日记表”的项目事件中DataColChanged:
Select Case e.DataCol.Name
Case "日期","单位","连铸_6M","连铸_9M","连铸_每米重量"
If e.DataRow.IsNull("日期")
= False AndAlso
e.DataRow.IsNull("单位")
= False
Dim
pr As DataRow
Dim
d As Date = e.DataRow("日期")
pr
= DataTables("月报表").Find("月 = "
& d.Month & " and 年 = " &
d.Year & " and 单位='"
& e.DataRow("单位")
& "'")
If pr IsNot Nothing Then
DataTables("月报表").DataCols("月").RaiseDataColChanged(pr)
End
If
End If
End Select
[此贴子已经被作者于2018/8/6 19:12:43编辑过]