以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  为什么代码不起作用  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=70048)

--  作者:shiliang
--  发布时间:2015/6/15 10:25:00
--  为什么代码不起作用
\'出库量大于库存量禁止出库,不能小于零
\'-------------------------------------------------------------------------------------------
Select Case e.DataCol.name
    Case "物料代码"
        If e.newvalue Is Nothing Then \'如果新值是空白,也就是物料代码列的内容为空
            \' msgbox("物料代码为空")
            e.DataRow("出库数量") = Nothing \'那么清空此行出库数量列的内容
        Else
            Dim dg As DataRow = DataTables("库存材料表").Find("[物料代码] = \'" & e.NewValue & "\'","_Identify Desc")\'获得最后一行
            If dg Is Nothing Then \'如果找到了同名的物料代码行,也就是dr不是Nothing
                \'msgbox("在库存没找到物料")
                \'e.Cancel = True
                e.NewValue = Nothing
                If dg IsNot Nothing Then
                    If e.DataRow("出库数量") <= 0 Then
                        e.DataRow("出库数量") = Nothing
                    End If
                    If  e.DataRow("出库数量") >= dg("库存数量") Then
                        \'MsgBox("出库量不能大于库存量!")
                        e.DataRow("出库数量") = dg("库存数量")
                    End If
                End If
            End If
        End If
End Select


代码写在“DataColChanging”事件中,但是不起作用


--  作者:大红袍
--  发布时间:2015/6/15 10:43:00
--  

Select Case e.DataCol.name
    Case "物料代码"
        If e.newvalue Is Nothing Then \'如果新值是空白,也就是物料代码列的内容为空
            \' msgbox("物料代码为空")
            e.DataRow("出库数量") = Nothing \'那么清空此行出库数量列的内容
        Else
            Dim dg As DataRow = DataTables("库存材料表").Find("[物料代码] = \'" & e.NewValue & "\'","_Identify Desc")\'获得最后一行
            If dg Is Nothing Then \'如果找到了同名的物料代码行,也就是dr不是Nothing
                \'msgbox("在库存没找到物料")
                \'e.Cancel = True
                e.NewValue = Nothing
            Else
               
                If e.DataRow("出库数量") <= 0 Then
                    e.DataRow("出库数量") = Nothing
                ElseIf  e.DataRow("出库数量") >= dg("库存数量") Then
                    \'MsgBox("出库量不能大于库存量!")
                    e.DataRow("出库数量") = dg("库存数量")
                End If
            End If
        End If
    Case "出库数量"
        Dim dg As DataRow = DataTables("库存材料表").Find("[物料代码] = \'" & e.DataRow("物料代码") & "\'","_Identify Desc")\'获得最后一行
        If dg Is Nothing Then \'如果找到了同名的物料代码行,也就是dr不是Nothing
            \'msgbox("在库存没找到物料")
            \'e.Cancel = True
            e.NewValue = Nothing
        Else
           
            If e.newvalue <= 0 Then
                e.newValue = Nothing
            ElseIf  e.newvalue >= dg("库存数量") Then
                \'MsgBox("出库量不能大于库存量!")
                e.newvalue = dg("库存数量")
            End If
        End If
       
End Select


--  作者:shiliang
--  发布时间:2015/6/15 10:54:00
--  
谢谢!!!


--  作者:shiliang
--  发布时间:2015/6/15 11:30:00
--  
 Case "记账"
        Dim Sun As Integer
        Sun =  DataTables("材料发放明细表").Compute("Sum(出库数量)", "[物料代码] = \'" & Vars("物料代码") & "\'")
        If "记账" = False Then
            If sun >= dg("库存数量") Then
                
                \'ElseIf  e.newvalue  >= dg("库存数量") Then
                MsgBox("出库量不能大于库存量!")
                e.newvalue = dg("库存数量")
            End If
        End If
End Selec

麻烦帮我改一下代码,谢谢!!!

--  作者:shiliang
--  发布时间:2015/6/15 11:49:00
--  
新的出库数量与未记账的出库数量之和不能大于库存量,该如写代码
--  作者:大红袍
--  发布时间:2015/6/15 11:51:00
--  
Case "记账"
        Dim Sun As Integer
        Sun =  DataTables("材料发放明细表").Compute("Sum(出库数量)", "[物料代码] = \'" & e.DataRow("物料代码") & "\'")
        If e.DataRow"记账") = False Then
            If sun >= dg("库存数量") Then
                MsgBox("出库量不能大于库存量!")
                e.DataRow("库存数量") = dg("库存数量")
            End If
        End If
End Selec

--  作者:shiliang
--  发布时间:2015/6/15 15:09:00
--  

图片点击可在新窗口打开查看此主题相关图片如下:qq图片20150615151003.png
图片点击可在新窗口打开查看

--  作者:shiliang
--  发布时间:2015/6/15 15:10:00
--  
提示错误


--  作者:大红袍
--  发布时间:2015/6/15 15:11:00
--  

 

[此贴子已经被作者于2015/6/15 15:11:08编辑过]

--  作者:大红袍
--  发布时间:2015/6/15 15:13:00
--  
Case "记账"
        Dim Sun As Integer
        Sun =  DataTables("材料发放明细表").Compute("Sum(出库数量)", "[物料代码] = \'" & e.DataRow("物料代码") & "\'")
        If e.DataRow("记账") = False Then
            If sun >= e.DataRow("库存数量") Then
                MsgBox("出库量不能大于库存量!")
                e.Cancel = True
            End If
        End If
End Selec