以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  ”出库数量“ <0的代码不起作用  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=69814)

--  作者:shiliang
--  发布时间:2015/6/11 11:51:00
--  ”出库数量“ <0的代码不起作用
 \'出库量大于库存量禁止出库,不能小于零
    If e.DataCol.Name = "物料代码" Then \'如果内容发生变动的是物料代码列
        If e.NewValue Is Nothing Then \'如果新值是空白,也就是物料代码列的内容为空
            e.DataRow("出库数量") = Nothing \'那么清空此行出库数量列的内容
        End If
    End If
     Dim dg As DataRow = DataTables("库存材料表").Find("[物料代码] = \'" & e.DataRow("物料代码") & "\'","_Identify Desc")\'获得最后一行
    If dg IsNot Nothing Then \'如果找到了同名的物料代码行,也就是dr不是Nothing
        If  e.DataRow("出库数量") > dg("库存数量") Then
            MessageBox.Show("出库量大于库存量!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            e.DataRow("出库数量") = dg("库存数量")
        End If
        If e.DataRow("出库数量") < 0 Then
            e.DataRow("出库数量") = Nothing
        End If
    End If



  If e.DataRow("出库数量") < 0 Then
            e.DataRow("出库数量") = Nothing
        End If
这段代码不起作用。请看一下什么原因






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

加入msgbox看看执行效果

 

If e.DataCol.Name = "物料代码" Then \'如果内容发生变动的是物料代码列
    If e.NewValue Is Nothing Then \'如果新值是空白,也就是物料代码列的内容为空
        e.DataRow("出库数量") = Nothing \'那么清空此行出库数量列的内容
    End If
End If
Dim dg As DataRow = DataTables("库存材料表").Find("[物料代码] = \'" & e.DataRow("物料代码") & "\'","_Identify Desc")\'获得最后一行
msgbox(1)
If dg IsNot Nothing Then \'如果找到了同名的物料代码行,也就是dr不是Nothing
    msgbox(2)
    If  e.DataRow("出库数量") > dg("库存数量") Then
        MessageBox.Show("出库量大于库存量!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        e.DataRow("出库数量") = dg("库存数量")
    End If
    If e.DataRow("出库数量") < 0 Then
        msgbox(3)
        e.DataRow("出库数量") = Nothing
    End If
End If


--  作者:shiliang
--  发布时间:2015/6/11 14:02:00
--  
MessageBox.Show 调试一下就好了


--  作者:大红袍
--  发布时间:2015/6/11 14:06:00
--  
 呃,跟msgbox没什么问题,是不是你数据有问题?
--  作者:shiliang
--  发布时间:2015/6/11 15:40:00
--  
数据没问题,只是调试一下就好了


--  作者:shiliang
--  发布时间:2015/6/11 16:41:00
--  
\'已记账,不能取消审核
\'----------------------------------------------
  Select Case e.DataCol.name
        Case "审核"
            If e.DataRow("记账") = True Then
                e.NewValue = True
            End If
    End Select


这段代码对吗

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

写到Datacolchanging事件

 

   Select Case e.DataCol.name

        Case "审核"
            If e.DataRow("记账") = True Then
                e.Cancel = True
            End If
    End Select

--  作者:shiliang
--  发布时间:2015/6/11 16:49:00
--  
谢谢!!!
--  作者:shiliang
--  发布时间:2015/6/11 17:37:00
--  
\'库存数量为零,不能记账
\'---------------------------------------------------------
Select Case e.DataCol.name
    Case "记账"
        If DataTables("库存材料表").DataRows.count > 0
            Dim dg As DataRow = DataTables("库存材料表").Find("[物料代码] = \'" & e.DataRow("物料代码") & "\'","_Identify Desc")\'获得最后一行
            If dg("库存数量") Is Nothing Then \'如果找到了同名的物料代码行,也就是dr是Nothing
                If e.oldvalue = False Then
                    \' e.NewValue = False
                    e.Cancel = True
                End If
            End If
        End If
End Select



请麻烦看一下代码有什么问题

--  作者:大红袍
--  发布时间:2015/6/11 17:47:00
--  
Select Case e.DataCol.name
    Case "记账"
        Dim dg As DataRow = DataTables("库存材料表").Find("[物料代码] = \'" & e.DataRow("物料代码") & "\'","_Identify Desc")\'获得最后一行
        If dg IsNot Nothing Then
            If dg("库存数量") = 0 Then
                e.cancel = True
            End If
        Else
            e.cancel = True
        End If
End Select