Dim dr As DataRow = e.DataRow
Select Case e.DataCol.Name
Case "生产令号"
If dr.IsNull("生产令号") Then
dr("编制日期") = Nothing
Else
dr("编制日期") = Date.today
End If
End Select
If e.DataCol.Name = "生产令号" Then '如果内容发生变动的是品名列
If e.NewValue Is Nothing Then '如果新值是空白,也就是品名列的内容为空
e.DataRow("项目名称") = Nothing
Else
Dim dr3 As DataRow
dr3 = DataTables("生产令号").Find("[生产令号] = '" & e.NewValue & "'")
If dr3 IsNot Nothing Then '如果找到了同名的产品行,也就是dr不是Nothing
e.DataRow("项目名称") = dr3("项目名称")
End If
End If
End If
Dim dr1 As DataRow = e.DataRow
Select Case e.DataCol.Name
Case "编制日期"
If e.DataRow.IsNull("编制日期") Then
dr1("年度") = Nothing
Else
dr1("年度") = Left(e.DataRow("编制日期") ,4)
End If
End Select
If e.DataCol.Name = "编制日期" OrElse e.DataCol.Name = "合同性质_一单一招" OrElse e.DataCol.Name = "合同性质_年度合同" Then
If e.DataRow.IsNull("编制日期") Then
e.DataRow("工作联系单编号") = Nothing
Else
If e.DataRow("合同性质_一单一招") = True Then
Dim d As Date = e.DataRow("编制日期")
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 = "WX-" & Format(d,"yyyyMM") '生成编号的前6位,4位年,2位月.
If e.DataRow("工作联系单编号").StartsWith(bh) = False '如果编号的前6位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.SQLCompute("Max(工作联系单编号)","工作联系单编号 like '" & bh & "%' and 编制日期 >= #" & fd & "# And 编制日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该月的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(10,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("工作联系单编号") =bh & "-" & Format(idx,"000")
e.DataRow.Save
End If
ElseIf e.DataRow("合同性质_年度合同") = True Then
Dim d As Date = e.DataRow("编制日期")
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 = "ND-" &Format(d,"yyyyMM") '生成编号的前6位,4位年,2位月.
If e.DataRow("工作联系单编号").StartsWith(bh) = False '如果编号的前6位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.SQLCompute("Max(工作联系单编号)","工作联系单编号 like '" & bh & "%' and 编制日期 >= #" & fd & "# And 编制日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该月的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(10,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("工作联系单编号") = bh & "-" & Format(idx,"000")
e.DataRow.Save
End If
End If
End If
End If
Select Case e.DataCol.Name
Case "结算"
If e.DataRow("结算") = True Then
Dim dr3 As Row = Tables("外协作结算清单").AddNew()
dr3("结算日期") = Date.today
dr3("协作合同编号") = e.DataRow("协作合同编号")
dr3("生产令号") = e.DataRow("生产令号")
dr3("项目名称") = e.DataRow("项目名称")
dr3("协作内容") = e.DataRow("协作内容")
dr3.Move(0)
End If
End Select
Select Case e.DataCol.Name
Case "合同签订","生产令号","协作内容","合同类别","合同性质_一单一招"
If e.DataRow("合同签订") = False OrElse e.DataRow.IsNull("生产令号") = True OrElse e.DataRow.IsNull("协作内容") = True OrElse e.DataRow.IsNull("合同类别") = True OrElse e.DataRow("合同性质_一单一招") = False Then
DataTables("外协作合同台账").DeleteFor("工作联系单编号='" & e.DataRow("工作联系单编号") & "'")
Else
Dim ndr As Row = Tables("外协作合同台账").AddNew
ndr("工作联系单编号") = e.DataRow("工作联系单编号")
ndr("生产令号") = e.DataRow("生产令号")
ndr("协作内容") = e.DataRow("协作内容")
ndr("合同性质_一单一招") = e.DataRow("合同性质_一单一招")
ndr("合同类别") = e.DataRow("合同类别")
ndr.Move(0)
End If
End Select
Select Case e.DataCol.Name
Case "生产令号","协作内容","合同类别"
Dim Filter As String = "[工作联系单编号] = '" & e.DataRow("工作联系单编号") & "'"
Dim drs As List(Of DataRow) = DataTables("外协作合同台账").Select(Filter)
For Each dr4 As DataRow In drs
dr4(e.DataCol.Name) = e.NewValue
Next
End Select