新增
Dim r As Row = Tables("登记主表").addnew
r("制单日期") = Date.Today()
Static Index As Integer = 99999
r("登记单号") = Format(Date.Today(),"yyMM") & "-" & Index
Index = Index - 1
保存
Dim dr As DataRow = Tables("登记主表").current.DataRow
Dim pf As String
If dr.RowState <> DataRowState.Added Then
Return
ElseIf dr.IsNull("制单日期") Then
e.Cancel = True
MessageBox.Show("必须输入日期!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return
Else
pf = "DDDH-" & "" & Format(dr("制单日期"), "yyyyMM")
End If
Dim cmd1 As New SQ-LCommand
Dim cmd2 As New SQ-LCommand
Dim Key As Integer
cmd1.C '设置数据源名称
cmd2.C
cmd1.commandText = "Selec-t Count(*) From [编号] Where [前缀] = '" & pf & "'"
If cmd1.ExecuteScalar = 0 Then
cmd1.commandtext = "Inse-rt Into 编号 (前缀, 顺序号) Values('" & pf & "',1)"
cmd1.ExecuteNonQuery
End If
cmd1.commandText = "Selec-t [顺序号] From [编号] Where [前缀] = '" & pf & "'"
Do
Key = cmd1.ExecuteScalar()
cmd2.commandText = "Up-date [编号] Set [顺序号] = " & (Key + 1) & " Where [顺序号] = " & Key & " And [前缀] = '" & pf & "'"
If cmd2.ExecuteNonQuery() > 0 Then
Exit Do
End If
Loop
dr("登记单号") = pf & "-" & Format(Key, "0000") '流水号的设计)
Dim r As Row = Tables("登记主表").current
r("保存状态") = True
DataTables("登记主表").Save()
DataTables("登记明细").Save()
明细表-DataColChanged
If e.DataCol.Name = "登记单号" Then '
If e.DataRow.IsNull("订单登记单号") Then '
e.DataRow("订单单号") = Nothing '
Else
'
Dim dr2 As DataRow
dr2 = DataTables("登记主表").Find("[登记单号] = '" & e.NewValue & "'")
e.DataRow("订单单号") = dr2("登记单号")
End If
End If
需求:如果明细表的订单单号已录入数据,就是录入的数据保存,否则,明细表的订单单号=主表的登记单号,就是说明细的订单单号没录入数据、为空时,从主表取值,明细表的订单单号=主表的登记单号
执行上面代码,报错,如何解决?
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2022.8.18.1
错误所在事件:表,登记明细,DataColChanged
详细错误信息:
调用的目标发生了异常。
未将对象引用设置到对象的实例。