以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]关于条件判断问题?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=55725)

--  作者:sxy_123456
--  发布时间:2014/8/22 8:42:00
--  [求助]关于条件判断问题?
我原来的代码是这样的,根据产品编号来判断,现在我想改成根据产品编号的前6位做判断如何修改代码?
If e.DataCol.Name = "本次数量" Then
    If e.DataRow.IsNull("中标工程名称") = False AndAlso e.DataRow.IsNull("产品编号") = False _
        AndAlso e.DataRow.IsNull("本次数量") = False AndAlso e.DataRow.IsNull("第几次采购") = False Then
        Dim sum As Double = e.DataTable.Compute("Sum(本次数量)","中标工程名称 = \'" & e.DataRow("中标工程名称") & "\' And 产品编号 = \'" & _
              e.DataRow("产品编号") & "\' And 第几次采购 <= \'" & e.DataRow("第几次采购") & "\'")
        e.DataRow("剩余数量") = e.DataRow("成本预算数量") - sum
       
    End If

End If
If e.DataCol.Name = "产品编号" Then
    Dim fdr As DataRow = DataTables("材料费预算表").Find("中标工程名称 = \'" & e.DataRow("中标工程名称") & "\' and 产品编号 = \'" & e.NewValue & "\'")
    If fdr IsNot Nothing Then
        e.DataRow("成本预算数量") = fdr("数量")
        e.DataRow("成本预算单价") = fdr("单价")
    Else
        fdr = DataTables("产品价格库").Find("产品编号 = \'" & e.NewValue & "\'")
        e.DataRow("成本预算数量") = 0
        If fdr IsNot Nothing Then
            e.DataRow("成本预算单价") = fdr("单价")
        End If
    End If
End If

--  作者:Bin
--  发布时间:2014/8/22 8:48:00
--  
("SubString([产品编号],0,6) = \'" & e.NewValue & "\'")
--  作者:sxy_123456
--  发布时间:2014/8/22 9:12:00
--  
修改后出错,哪里改错了?
If e.DataCol.Name = "本次数量" Then
    If e.DataRow.IsNull("中标工程名称") = False AndAlso e.DataRow.IsNull("SubString([产品编号],0,6)") = False _
        AndAlso e.DataRow.IsNull("本次数量") = False AndAlso e.DataRow.IsNull("第几次采购") = False Then
        Dim sum As Double = e.DataTable.Compute("Sum(本次数量)","中标工程名称 = \'" & e.DataRow("中标工程名称") & "\' And SubString([产品编号],0,6) = \'" & _
              e.DataRow("SubString([产品编号],0,6)") & "\' And 第几次采购 <= \'" & e.DataRow("第几次采购") & "\'")
        e.DataRow("剩余数量") = e.DataRow("成本预算数量") - sum
       
    End If

End If
If e.DataCol.Name = "SubString([产品编号],0,6)" Then
    Dim fdr As DataRow = DataTables("材料费预算表").Find("中标工程名称 = \'" & e.DataRow("中标工程名称") & "\' and SubString([产品编号],0,6) = \'" & e.NewValue & "\'")
    If fdr IsNot Nothing Then
        e.DataRow("成本预算数量") = fdr("数量")
        e.DataRow("成本预算单价") = fdr("单价")
    Else
        fdr = DataTables("产品价格库").Find("SubString([产品编号],0,6) = \'" & e.NewValue & "\'")
        e.DataRow("成本预算数量") = 0
        If fdr IsNot Nothing Then
            e.DataRow("成本预算单价") = fdr("单价")
        End If
    End If
End If


--  作者:Bin
--  发布时间:2014/8/22 9:13:00
--  
出什么错?
--  作者:有点甜
--  发布时间:2014/8/22 9:16:00
--  

If e.DataCol.Name = "本次数量" Then
    If e.DataRow.IsNull("中标工程名称") = False AndAlso e.DataRow.IsNull("产品编号") = False _
        AndAlso e.DataRow.IsNull("本次数量") = False AndAlso e.DataRow.IsNull("第几次采购") = False Then
        Dim sum As Double = e.DataTable.Compute("Sum(本次数量)","中标工程名称 = \'" & e.DataRow("中标工程名称") & "\' And SubString([产品编号],0,6) = \'" & _
              e.DataRow("产品编号") & "\' And 第几次采购 <= \'" & e.DataRow("第几次采购") & "\'")
        e.DataRow("剩余数量") = e.DataRow("成本预算数量") - sum
      
    End If


End If
If e.DataCol.Name = "产品编号" Then
    Dim fdr As DataRow = DataTables("材料费预算表").Find("中标工程名称 = \'" & e.DataRow("中标工程名称") & "\' and SubString([产品编号],0,6) = \'" & e.NewValue & "\'")
    If fdr IsNot Nothing Then
        e.DataRow("成本预算数量") = fdr("数量")
        e.DataRow("成本预算单价") = fdr("单价")
    Else
        fdr = DataTables("产品价格库").Find("SubString([产品编号],0,6) = \'" & e.NewValue & "\'")
        e.DataRow("成本预算数量") = 0
        If fdr IsNot Nothing Then
            e.DataRow("成本预算单价") = fdr("单价")
        End If
    End If
End If


--  作者:sxy_123456
--  发布时间:2014/8/22 10:52:00
--  
出错提示
图片点击可在新窗口打开查看此主题相关图片如下:qq截图20140822105048.png
图片点击可在新窗口打开查看
我的编号格式是100105001,100105002,100105003
[此贴子已经被作者于2014-8-22 10:53:42编辑过]

--  作者:有点甜
--  发布时间:2014/8/22 10:55:00
--  

1、编号列,不能有空行的数据;

 

2、试试改成 SubString([产品编号],1,6)


--  作者:sxy_123456
--  发布时间:2014/8/22 11:11:00
--  
现在不报错了,可是剩余数量的计算结果不对,不是[成本预算数量]-[前几次本次数量之和],而是剩余数量=成本预算数量。
--  作者:有点甜
--  发布时间:2014/8/22 11:17:00
--  

 

[此贴子已经被作者于2014-8-22 11:17:57编辑过]

--  作者:有点甜
--  发布时间:2014/8/22 11:20:00
--  

试试改成 SubString([产品编号],0,6)

 

如果不行,做个例子发上来看看。