在销售开单界面,新增订单的时候同时向销售明细表和订单出库明细表中添加数据,销售明细表的datacolchanged没有触发,不能计算已提数量和未提数量:
此主题相关图片如下:tim截图20180506200820.jpg
但在订单出库明细窗口增加出库明细时可以正常计算:
此主题相关图片如下:tim截图20180506201731.jpg
ADD product click代码:
Dim ddh As String = e.Form.Controls("textbox2").value
Dim dr As DataRow = DataTables("销售订单").find("订单号 = '" & ddh & "'")
If dr IsNot Nothing Then
MessageBox.Show("该订单号已经存在,请重新输入订单号!", "错误提示")
Else
Dim rq As String = e.Form.Controls("DateTimePicker1").Value
'Dim khmc As String = e.Form.Controls("textbox12").Value
'Dim khdh As String = e.Form.Controls("textbox1").Value
Dim cpxh As String = e.Form.Controls("dropbox1").Value
Dim dj As String = e.Form.Controls("textbox5").Value
Dim sl As String = e.Form.Controls("NumericComboBox2").Value
If rq = "" Then
MessageBox.Show("请输入销售日期,不能为空!", "错误提示")
'ElseIf khmc = "" Then
'MessageBox.Show("客户名称不能为空,请输入!", "错误提示")
'ElseIf khdh = "" Then
'MessageBox.Show("客户电话不能为空,请输入!", "错误提示")
ElseIf cpxh = "" Then
MessageBox.Show("The product model cannot be empty,please enter产品型号不能为空,请输入!", "错误提示")
ElseIf sl = "" Then
MessageBox.Show("The quantity cannot be empty,please enter(请输入数量,不能为空!)", "错误提示")
Else
Dim tbl As Table = Tables("销售明细表")
Dim tb As Table = Tables("订单出库明细表")
Dim r As Row = tbl.AddNew()
Dim r1 As Row = tb.AddNew()
r1("提货日期") = e.Form.Controls("datetimepicker1").Text
r("订单号") = e.Form.Controls("TextBox2").Text
r1("订单号") = e.Form.Controls("TextBox2").Text
r("产品型号") = e.Form.Controls("dropbox1").Text
r1("产品型号") = e.Form.Controls("dropbox1").Text
r("产品类别") = e.Form.Controls("产品类别").Text
r("成本") = e.Form.Controls("成本").Text
r("单价") = e.Form.Controls("TextBox5").Text
r("数量") = e.Form.Controls("NumericComboBox2").Text
r1("数量") = e.Form.Controls("NumericComboBox2").Text
'r("已提数量") = e.Form.Controls("NumericComboBox1").Text
r1("已提数量") = e.Form.Controls("NumericComboBox1").Text
If tbl.Current IsNot Nothing Then
tbl.Current.Save()
'tb.Current.Save()
End If
End If
End If
e.Form.Controls("DropBox1").Value = " "
e.Form.Controls("textbox5").Value = " "
e.Form.Controls("NumericComboBox2").Value = " "
e.Form.Controls("未提数量").Text = "未知"
销售明细表datacolchanged:
If forms("销售主界面").opened = True AndAlso (e.DataCol.Name ="数量" OrElse e.DataCol.Name ="单价") Then
Dim Filter As String = "订单号 = '" & e.DataRow("订单号") & "'"
Dim sum As Double = 0
For Each r As Row In Tables("销售明细表").Rows
sum + = r("金额")
Next
Forms("销售主界面").Controls("TextBox9").Text = sum - val(Forms("销售主界面").Controls("TextBox3").Text)
End If
If e.DataCol.name = "金额" Then
Dim pr As DataRow = e.DataRow.GetParentRow("销售订单") '找出对应的父行
If pr IsNot Nothing Then
DataTables("销售订单").DataCols("总金额").RaiseDataColChanged(pr) '通知系统此父行的数量列发生了改变,触发DataColChanged事件
End If
End If
'自动输入
If e.DataCol.Name ="产品型号" Then '发生变化的是产品名称吗?
'在产品表找出该产品
Dim dr As DataRow = DataTables("产品入库表").Find("产品型号 = " & "'" & e.DataRow("产品型号") & "'" )
If dr IsNot Nothing'如果找到,则设置各列内容
e.DataRow("产品类别")= dr("产品类别")
If e.DataRow("单价") = Nothing Then
e.DataRow("单价")= dr("销售单价")
End If
End If
End If
If e.DataCol.Name = "产品型号" OrElse e.DataCol.Name = "订单号" Then '发生变化的是产品列和订单号
'则累计订单出库明细表中同名产品总的销售量,然后赋值给变动行的已提数量列
e.DataRow("已提数量") = Tables("订单出库明细表").Compute("Sum(已提数量)","产品型号 = '" & e.DataRow("产品型号") & "' And 订单号 = '" & e.DataRow("订单号") & "'")
End If
订单出库明细表datacolchanged:
Select Case e.DataCol.Name
Case "产品型号","数量","已提数量","订单号"
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [产品型号] = '" & mr("产品型号") & "'And [订单号] = '" & mr("订单号") & "'", "[_SortKey] Desc")
If dr Is Nothing Then
mr("未提数量") = mr("数量") - mr("已提数量")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [产品型号] = '" & dr("产品型号") & "'And [订单号] = '" & dr("订单号") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("未提数量") = drs(i-1)("未提数量") - drs(i)("已提数量")
Next
If e.DataCol.Name = "产品型号" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [产品型号] = '" & e.OldValue & "'And [订单号] = '" & e.OldValue & "'", "[_SortKey] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[产品型号] = '" & e.OldValue & "'", "[_SortKey]")
If dr IsNot Nothing Then
dr("未提数量") = dr("数量") - dr("已提数量")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [产品型号] = '" & dr("产品型号") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("未提数量") = drs(i-1)("未提数量") - drs(i)("已提数量")
Next
End If
End If
End Select
DataTables("销售明细表").DataCols("产品型号").RaiseDataColChanged("产品型号 = '" & e.DataRow("产品型号") & "' and 订单号 = '" & e.DataRow("订单号") & "'")'通知系统此父行的数量列发生了改变,触发DataColChanged事件
[此贴子已经被作者于2018/5/7 16:06:18编辑过]