父表借款表单 DataColChanged代码
'以下自动编制批号
If e.DataCol.Name = "dkrq" Then
If e.DataRow.IsNull("dkrq") Then
e.DataRow("cpbm") = Nothing
Else
Dim d As Date = e.DataRow("dkrq")
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,m,1) '获得该月的第一天
Dim ld As Date = New Date(y,m,Days) '获得该月的最后一天
Dim bh As String = Format(d,"yyyyMM") '生成编号的前6位,4位年,2位月.
If e.DataRow("cpbm").StartsWith(bh) = False '如果编号的前6位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(cpbm)","dkrq >= #" & fd & "# And dkrq <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该月的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(7,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("cpbm") = bh & "-" & Format(idx,"000")
End If
End If
End If
'计算总借款金额计算
If e.DataCol.Name = "cpbm" Then
Dim Filter As String = "[cpbm] = '" & e.NewValue & "'"
e.DataRow("fdze") = DataTables("dk_jkb").Compute("Sum(je)", Filter)
End If
子表明细表DataColChanged代码
Select Case e.DataCol.Name
Case "je"
Dim pr As DataRow
pr = DataTables("dk_cpb").Find("cpbm = '" & e.DataRow("cpbm") & "'")
If pr IsNot Nothing Then
DataTables("dk_cpb").DataCols("cpbm").RaiseDataColChanged(pr)
End If
End Select
子表明细表DataRowDeleted代码
Dim pr As DataRow
pr = DataTables("dk_cpb").Find("cpbm = '" & e.DataRow("cpbm") & "'")
If pr IsNot Nothing Then
DataTables("dk_cpb").DataCols("cpbm").RaiseDataColChanged(pr)
End If
窗口明细删除按钮代码
Dim Result As DialogResult
Result = MessageBox.Show("您确认要删除此条记录吗?删除后将不能恢复", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
Tables("dk_cpb.dk_jkb").AllowEdit=True
If Tables("dk_cpb.dk_jkb").rows.count > 0 Then '判断记录是否为空成立
Tables("dk_cpb.dk_jkb").Current.Locked = False
Else
Return
End If
Tables("dk_cpb.dk_jkb").Current.Delete
End If
DataTables("dk_jkb").Save()
If Tables("dk_cpb.dk_jkb").rows.count > 0 Then '判断记录是否为空成立
Tables("dk_cpb.dk_jkb").Current.Locked = True
Else
Return
End If
Tables("dk_cpb.dk_jkb").AllowEdit=False
出现问题:修改明细后,主表总金额会同步修改,删除明细时,一行或者全部删除完,主表总金额不会变化,有时还出现:此行已从表中移除并且没有任何数据。BeginEdit() 将允许在此行中创建新数据“提示,请老师帮修改代码,谢谢