在订单明细表中,
已完成逻辑:不允许同一订单号、品名、型号规格的出现,计量单位和单价是引用品名和规格得出,
问题:同一订单号、品名、型号规格出现虽能判断并删除品名和型号,但计量单位和单价依然存在。
请指教,谢谢!
'判断同一订单号存在名称规格一样的材料
Select Case e.DataCol.name
Case "订单号"
If e.DataCol.Name= "订单号" Then
Dim dr As DataRow = e.DataTable.Find("订单号='" & e.NewValue & "' and 品名='" & e.DataRow("品名") & "' and 型号规格='" & e.DataRow("型号规格") & "'")
If dr IsNot Nothing Then
MessageBox.Show("1已经存在相同型号和规格的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
e.Cancel = True
End If
End If
Case "品名"
If e.DataCol.Name= "品名" Then
Dim dr As DataRow = e.DataTable.Find("品名='" & e.NewValue & "' and 订单号='" & e.DataRow("订单号") & "' and 型号规格='" & e.DataRow("型号规格") & "'")
If dr IsNot Nothing Then
e.DataRow("品名")=Nothing
MessageBox.Show("2同一订单号已经存在相同型号和规格的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
e.Cancel = True
Return
End If
End If
Case "型号规格"
If e.DataCol.Name= "型号规格" Then
Dim dr As DataRow = e.DataTable.Find("型号规格='" & e.NewValue & "' and 订单号='" & e.DataRow("订单号") & "' and 品名='" & e.DataRow("品名") & "'")
If dr IsNot Nothing Then
e.DataRow("品名")=Nothing
e.Cancel = True
MessageBox.Show("3已经存在相同型号和规格的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
e.Cancel = True
'e.DataRow("品名")=Nothing
End If
End If
End Select
'引用单价和计量单位
Select Case e.DataCol.Name
Case "品名","型号规格"
Dim dr As DataRow = e.DataRow
Dim pr As DataRow
If dr.IsNull("品名") Or dr.IsNull("型号规格") Then
dr("单价") = Nothing
dr("计量单位") = Nothing
Else
Dim filter As String
filter = "品名 = '" & dr("品名") & "' And 型号规格 = '" & dr("型号规格") & "'"
pr = DataTables("商品").Find(filter)
If pr IsNot Nothing Then
dr("单价") = pr("单价")
dr("计量单位") = pr("计量单位")
End If
End If
End Select