以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]运行时偶尔会出现以下错误,要怎么解决啊。  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=180731)

--  作者:tusanmuli123
--  发布时间:2022/10/15 8:47:00
--  [求助]运行时偶尔会出现以下错误,要怎么解决啊。
运行时偶尔会出现以下错误,要怎么解决啊
图片点击可在新窗口打开查看此主题相关图片如下:错误提示.png
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2022/10/15 8:57:00
--  
提示的意思是某一行已经被删除,但是仍然有代码使用了这个被删除的行。这种一般是表事件的处理有问题导致的
--  作者:tusanmuli123
--  发布时间:2022/10/15 9:03:00
--  
这个表的datacolchanged事件编辑了以下代码,是执行时有冲突吗?

If e.DataCol.name = "审核" Then
    If e.DataRow("审核") = True Then
        e.DataRow("审核人") = user.name
        e.DataRow("审核日期") = Date.Today
    Else
        e.DataRow("审核人") = Nothing
        e.DataRow("审核日期") = Nothing
    End If
End If

If e.DataCol.Name = "数量" Then
    If e.DataRow("库存数") < 0 Then
        MessageBox.Show("库存不够!我不是信用卡,不能透支哦!", "提示")
        e.DataRow("数量") = Nothing
    End If 
End If

If e.DataCol.name = "数量" Then
    Dim pr As DataRow = e.DataRow.GetParentRow("订单管理") 
    If pr IsNot Nothing Then
        DataTables("订单管理").DataCols("欠货数").RaiseDataColChanged(pr) 
    End If
End If

If e.DataCol.name = "数量" Then
    DataTables("订单管理").DataCols("库存数").RaiseDataColChanged 
End If



Dim dr As DataRow
dr = DataTables("订单管理").Find("订单编号 = \'" & e.DataRow("订单号") & "\' and 产品名称= \'" & e.DataRow("产品名称") & "\'")
If dr IsNot Nothing Then
    e.DataRow("欠货数") = dr("欠货数") 
End If

If e.DataCol.Name = "数量" Then
    If e.DataRow("欠货数") < 0 Then
        MessageBox.Show("超出订单数量!请重新输入。", "提示")
        e.DataRow("数量") = Nothing
    End If 
End If

--  作者:有点蓝
--  发布时间:2022/10/15 9:47:00
--  
这个表以及"订单管理"表所有事件代码发上来
--  作者:tusanmuli123
--  发布时间:2022/10/15 9:50:00
--  
订单表的datacolchanged事件代码

If e.DataCol.Name = ("欠货数") Then
    Dim a As DataRow
    a = DataTables("产品表").Find("产品名称 = \'" & e.DataRow("产品名称") & "\'")
    If a IsNot Nothing Then
        e.DataRow("欠货数材料KG") = e.DataRow("欠货数") * (((a("产品重量g") + a("水口重量g")) * (1 - a("水口比例") / 100)) / 1000)
    End If
End If

If e.DataCol.Name = ("库存数") Then
    Dim a As DataRow
    a = DataTables("产品表").Find("产品名称 = \'" & e.DataRow("产品名称") & "\'")
    If a IsNot Nothing Then
        e.DataRow("库存数材料KG") = e.DataRow("库存数") * (((a("产品重量g") + a("水口重量g")) * (1 - a("水口比例") / 100)) / 1000)
    End If
End If

If e.DataCol.Name = ("订单数量") Then
    Dim a As DataRow
    a = DataTables("产品表").Find("产品名称 = \'" & e.DataRow("产品名称") & "\'")
    If a IsNot Nothing Then
        e.DataRow("欠货数材料KG") = e.DataRow("欠货数") * (((a("产品重量g") + a("水口重量g")) * (1 - a("水口比例") / 100)) / 1000)
    End If 
End If

If e.DataCol.Name = "产品名称" Then \'如果内容发生变动的是品名列
    If e.NewValue Is Nothing Then \'如果新值是空白,也就是品名列的内容为空
        e.DataRow("单价") = Nothing \'那么清空此行单价列的内容
    Else
        Dim dr As DataRow
        \'否则在产品表查找同名的产品行,将找到的行赋值给变量dr
        dr = DataTables("产品表").Find("[产品名称] = \'" & e.NewValue & "\'")
        If dr IsNot Nothing Then \'如果找到了同名的产品行,也就是dr不是Nothing
            e.DataRow("单价") = dr("单价") 
        End If
    End If
End If

If e.DataCol.Name = "产品名称" Then
    If e.NewValue Is Nothing Then
        e.DataRow("材料用量KG") = Nothing 
    Else
        Dim a As DataRow
        a = DataTables("产品表").Find("产品名称 = \'" & e.NewValue & "\'")
        If a IsNot Nothing Then
            e.DataRow("材料用量KG") = e.DataRow("订单数量") * (((a("产品重量g") + a("水口重量g")) * (1 - a("水口比例") / 100)) / 1000)
        End If
    End If
End If

If e.DataCol.Name = "订单数量" Then
    If e.NewValue Is Nothing Then
        e.DataRow("材料用量KG") = Nothing 
    Else
        Dim a As DataRow
        a = DataTables("产品表").Find("产品名称 = \'" & e.datarow("产品名称") & "\'")
        If a IsNot Nothing Then
            e.DataRow("材料用量KG") = e.DataRow("订单数量") * (((a("产品重量g") + a("水口重量g")) * (1 - a("水口比例") / 100)) / 1000)
        End If
    End If
End If

--  作者:有点蓝
--  发布时间:2022/10/15 9:53:00
--  
看不出什么,做个例子发上来测试一下
--  作者:tusanmuli123
--  发布时间:2022/10/15 9:55:00
--  
订单管理prepareedit事件代码

If user.group <> "经理" Then
    If user.group<> "主管" Then
        e.Cancel = True
    End If
End If



If e.Col.Name = ("欠货数材料KG") Then
    If e.Row("欠货数") > 0 Then
        Dim a As DataRow
        a = DataTables("产品表").Find("产品名称 = \'" & e.Row("产品名称") & "\'")
        If a IsNot Nothing Then
            e.Row("欠货数材料KG") = e.Row("欠货数") * (((a("产品重量g") + a("水口重量g")) * (1 - a("水口比例") / 100)) / 1000)
        End If
    Else 
        Dim b As Integer = 0
        e.Row("欠货数材料KG") = b
    End If
    
End If

If e.Col.Name = ("库存数材料KG") Then
    If e.Row("库存数") > 0 Then
        Dim a As DataRow
        a = DataTables("产品表").Find("产品名称 = \'" & e.Row("产品名称") & "\'")
        If a IsNot Nothing Then
            e.Row("库存数材料KG") = e.Row("库存数") * (((a("产品重量g") + a("水口重量g")) * (1 - a("水口比例") / 100)) / 1000)
        End If
    Else 
        Dim b As Integer = 0
        e.Row("库存数材料KG") = b
    end if
End If

订单管理afteredit事件代码

If e.Col.Name = ("产品名称") Then
    Dim a As DataRow
    a = DataTables("产品表").Find("产品名称 = \'" & e.Row("产品名称") & "\'")
    If a IsNot Nothing Then
        e.Row("材料名称") = a("材料") 
    End If
End If

订单管理drawcell事件代码

If e.Col.Name = "单价" Then \'请改为实际列名
    If user.group <> "经理" Then \'如果不是指定用户
        e.Text = "***" \'则修改显示内容
    End If
End If
If e.Col.Name = "金额" Then \'请改为实际列名
    If user.group <> "经理" Then \'如果不是指定用户
        e.Text = "***" \'则修改显示内容
    End If
End If
If e.Col.Name = "报价材料单价" Then \'请改为实际列名
    If user.group <> "经理" Then \'如果不是指定用户
        e.Text = "***" \'则修改显示内容
    End If
End If

--  作者:有点蓝
--  发布时间:2022/10/15 10:19:00
--  
下面代码放到datacolchanged事件,不应该在prepareedit、afteredit事件

If e.Col.Name = ("欠货数材料KG") Then
    If e.Row("欠货数") > 0 Then
        Dim a As DataRow
        a = DataTables("产品表").Find("产品名称 = \'" & e.Row("产品名称") & "\'")
        If a IsNot Nothing Then
            e.Row("欠货数材料KG") = e.Row("欠货数") * (((a("产品重量g") + a("水口重量g")) * (1 - a("水口比例") / 100)) / 1000)
        End If
    Else 
        Dim b As Integer = 0
        e.Row("欠货数材料KG") = b
    End If
    
End If

If e.Col.Name = ("库存数材料KG") Then
    If e.Row("库存数") > 0 Then
        Dim a As DataRow
        a = DataTables("产品表").Find("产品名称 = \'" & e.Row("产品名称") & "\'")
        If a IsNot Nothing Then
            e.Row("库存数材料KG") = e.Row("库存数") * (((a("产品重量g") + a("水口重量g")) * (1 - a("水口比例") / 100)) / 1000)
        End If
    Else 
        Dim b As Integer = 0
        e.Row("库存数材料KG") = b
    end if
End If

订单管理afteredit事件代码

If e.Col.Name = ("产品名称") Then
    Dim a As DataRow
    a = DataTables("产品表").Find("产品名称 = \'" & e.Row("产品名称") & "\'")
    If a IsNot Nothing Then
        e.Row("材料名称") = a("材料") 
    End If
End If

--  作者:tusanmuli123
--  发布时间:2022/10/15 10:43:00
--  
链接到的表很多,不知道要怎么做案例上来。我发现是因为删除了订单表的行,就会出现这个错误提示。要怎么避免出现这个错误呢?
[此贴子已经被作者于2022/10/15 10:47:15编辑过]

--  作者:有点蓝
--  发布时间:2022/10/15 11:06:00
--  
看8楼