代码:
If e.DataCol.name = "录入日期" Then
Dim d As Date = e.NewValue
If d = Nothing Then
e.DataRow("月份") = Nothing
e.DataRow("年份") = Nothing
Else
e.DataRow("月份") = Format(d, "yyyyMM")
e.DataRow("年份") = Format(d, "yyyy")
End If
End If
If e.DataCol.name = "录入日期" Then
Dim dr As DataRow = DataTables("结账").sqlfind("月份 = '" & e.DataRow("月份") & "'and 结账 = 1 ")
If dr IsNot Nothing Then
MessageBox.show("该日期所属" & e.DataRow("月份") & "已关账,不允许录入(已结账)月份日期!!!")
e.DataRow("录入日期") = e.OldValue
End If
End If
'If e.DataCol.name = "录入日期" Then
'Dim d As Date = e.NewValue
'If d = Nothing Then
'e.DataRow("月份") = Nothing
'e.DataRow("年份") = Nothing
'Else
'e.DataRow("月份") = Format(d, "yyyyMM")
'e.DataRow("年份") = Format(d, "yyyy")
'End If
'End If
'If e.DataCol.Name = "录入日期" Then
'If e.DataRow.IsNull("录入日期") Then
'e.DataRow("入库单号") = Nothing
'Else
'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 = 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(入库单号)","录入日期 >= '" & fd & "' And 录入日期 <= '" & ld & "' And [_Identify] <> " & e.DataRow("_Identify")) '取得该月的最大编号
'If max > "" Then '如果存在最大编号
'idx = CInt(max.Substring(7,6)) + 1 '获得最大编号的后三位顺序号,并加1
'Else
'idx = 1 '否则顺序号等于1
'End If
'e.DataRow("入库单号") = bh & "-" & Format(idx,"000000") & "BCPRK"
'End If
'End If
'End If
If e.DataCol.Name = "供应商名称" Then '
Dim dr As DataRow
dr = gysxxb.sqlFind("供应商名称 = '" & e.DataRow("供应商名称") & "'" )
If dr IsNot Nothing '如果找到, 则设置各列内容
e.DataRow("供应商编号")= dr("供应商编号")
e.DataRow("供应商首字符")= dr("供应商首字符")
e.DataRow("税率")= dr("税率")
Else
e.DataRow("供应商编号")= Nothing
e.DataRow("供应商首字符")= Nothing
e.DataRow("税率")= Nothing
End If
End If
Select Case e.DataCol.name
Case "入库类型"
If Tables("半成品入库主表").current("入库类型") <> "采购入库" OrElse Tables("半成品入库主表").current("入库类型") <> "委外加工入库" Then
If e.newValue <> "采购入库" OrElse e.newValue <> "委外加工入库" Then
For Each pr As DataRow In DataTables("应付款采购主表").Select("入库单号= '" & e.DataRow("入库单号") & "'")
If pr IsNot Nothing Then
e.DataRow("结算单号") = Nothing
pr.Delete()
End If
Next
End If
End If
If Tables("半成品入库主表").current("入库类型") = "采购入库" OrElse Tables("半成品入库主表").current("入库类型") = "委外加工入库" Then
Dim dr1 As DataRow = DataTables("应付款采购主表").sqlFind("入库单号= '" & e.DataRow("入库单号") & "'")
If dr1 Is Nothing Then
dr1 = DataTables("应付款采购主表").AddNew()
dr1("入库单号") = e.DataRow("入库单号")
dr1("供应商名称") = e.DataRow("供应商名称")
dr1("供应商首字符") = e.DataRow("供应商首字符")
dr1("仓库名称") = e.DataRow("仓库名称")
dr1("录入日期") = e.DataRow("录入日期")
dr1("年份") = e.DataRow("年份")
dr1("月份") = e.DataRow("月份")
dr1("录入人") = e.DataRow("录入人")
dr1("入库类型") = e.DataRow("入库类型")
dr1("税率") = e.DataRow("税率")
e.DataRow("结算单号") = dr1("结算单号")
Else
dr1("入库类型") = e.DataRow("入库类型")
End If
dr1.Save
End If
Case "供应商名称","仓库名称","录入日期","录入人","入库类型","税率","供应商首字符","结算单号","供应商编号","送货单号码","年份","月份"
Dim drs As List(of DataRow) = DataTables("应付款采购主表").SQLSelect("入库单号= '" & e.DataRow("入库单号") & "'")
For Each dr As DataRow In drs
dr("供应商名称") = e.DataRow("供应商名称")
dr("入库类型") = e.DataRow("入库类型")
dr("录入日期") = e.DataRow("录入日期")
dr("年份") = e.DataRow("年份")
dr("月份") = e.DataRow("月份")
dr("录入人") = e.DataRow("录入人")
dr("税率") = e.DataRow("税率")
dr("供应商首字符") = e.DataRow("供应商首字符")
dr("供应商编号") = e.DataRow("供应商编号")
dr("仓库名称") = e.DataRow("仓库名称")
dr("送货单号码") = e.DataRow("送货单号码")
Next
DataTables("应付款采购主表").SQLUpdate(drs)
End Select
DataTables("应付款采购主表").DeleteFor("入库单号= '" & e.OldValue & "'")
Select Case e.DataCol.Name
Case "审核人","审核日期","供应商名称","生产岗位","入库类型","仓库名称","供应商首字符","录入日期","录入人","供应商编号","结算单号","送货单号码","年份","月份"
Dim Filter As String = "[入库单号] = '" & e.DataRow("入库单号") & "'"
Dim nm As String = e.DataCol.Name
DataTables("半成品入库明细表").ReplaceFor(nm, e.DataRow(nm), Filter)
End Select
If DataTables("半成品入库主表").HasChanges Then
DataTables("半成品入库主表") .Save()
End If
If DataTables("应付款采购主表").HasChanges Then
DataTables("应付款采购主表") .Save()
End If