Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共13 条记录, 每页显示 10 条, 页签: [1] [2]
[浏览完整版]

标题:Datecolchanged 中的代码

1楼
julia 发表于:2008/12/29 14:26:00
Dim dr As DataRow = e.DataRow
Select Case e.DataCol.Name
    Case "入库数量1","入库数量","单个克重"
        If dr.IsNull("入库数量") OrElse dr.IsNull("单个克重") Then
            dr("入库数量1") = Nothing
        Else
            dr("入库数量1") = dr("入库数量") * dr("单个克重")
        End If
End Select
If e.DataCol.Name = "材料名" Then
    Dim dr As DataRow = DataTables("入录资料").Find("原材料 = " & "'" & e.DataRow("材料名") & "'" )
    If dr IsNot Nothing
        e.DataRow("材料代号")= dr("代号")
        e.DataRow("单位")= dr("单位")
        e.DataRow("规格")= dr("规格")
        e.DataRow("单个克重")= dr("单个克重")
    End If
End If




请帮我看一下以上的代码有哪里需要修改.因为现在的这个代码不能用.

1)入库数量1=入库数量*单个克重(单个克重不输的时候显示为值"2"
2)当我输入"材料名"时,主表里能自动调用"入录资料"表中的"代号","单位" "规格" 及"单个克重"
2楼
czy 发表于:2008/12/29 14:44:00

Dim dr As DataRow = e.DataRow
Select Case e.DataCol.Name
    Case "入库数量1","入库数量","单个克重"
        If dr.IsNull("入库数量") OrElse dr.IsNull("单个克重") Then
            dr("入库数量1") = Nothing
        Else
            dr("入库数量1") = dr("入库数量") * dr("单个克重")
        End If
End Select

If e.DataCol.Name = "材料名" Then
    Dim dr1 As DataRow = DataTables("入录资料").Find("原材料  = '" & e.NewValue & "'")
    If dr1 IsNot Nothing
        e.DataRow("材料代号")= dr1("代号")
        e.DataRow("单位")= dr1("单位")
        e.DataRow("规格")= dr1("规格")
        e.DataRow("单个克重")= dr1("单个克重")
    End If
End If

3楼
ybil 发表于:2008/12/29 14:48:00
这样试试:
Dim dr,dr1 As DataRow
dr = e.DataRow
Select Case e.DataCol.Name
    Case "入库数量","单个克重"
        If dr.IsNull("入库数量")  Then
            dr("入库数量1") = Nothing
        Else
            if dr.IsNull("单个克重") Then
                dr("入库数量1") = 2
            Else  
               dr("入库数量1") = dr("入库数量") * dr("单个克重")
            End if
        End If
   Case "材料名"
       dr1 = DataTables("入录资料").Find("原材料 = '" & dr("材料名") & "'" )
       If dr1 IsNot Nothing
          dr("材料代号")= dr("代号")
          dr("单位")= dr("单位")
          dr("规格")= dr("规格")
          dr("单个克重")= dr("单个克重")
      End If
End Select
4楼
smileboy 发表于:2008/12/29 14:48:00

单个克重列默认值公式设为2
Dim dr As DataRow = e.DataRow
Select Case e.DataCol.Name
    Case "入库数量1","入库数量","单个克重"
        If dr.IsNull("入库数量") OrElse dr.IsNull("单个克重") Then
            dr("入库数量1") = Nothing
        Else
            dr("入库数量1") = dr("入库数量") * dr("单个克重")
        End If
End Select
If e.DataCol.Name = "材料名" Then
    Dim dr1 As DataRow = DataTables("入录资料").Find("原材料 = " & "'" & e.DataRow("材料名") & "'" )
    If dr1 IsNot Nothing
        e.DataRow("材料代号")= dr1("代号")
        e.DataRow("单位")= dr1("单位")
        e.DataRow("规格")= dr1("规格")
        e.DataRow("单个克重")= dr1("单个克重")
    End If
End If

[此贴子已经被作者于2008-12-29 14:49:43编辑过]
5楼
lxl 发表于:2008/12/29 14:55:00

如果不是为了学习代码的话,入库数量列用表达式是最好的.

6楼
julia 发表于:2008/12/29 14:56:00
不好意思,我刚才的表达可能让ybil 误解,我说的单个克重不输时,单个克重的默认值为2,这样子用代码怎么表达出来?

因为上面的代码显示,  dr("入库数量1") = dr("入库数量") * dr("单个克重") ,但必须两者都需要更新数据才能表达,但有时我只是更新"入库数量" 而如果单个重量是2时我就不想输入,这样子上面的公式也能表达出来,这样子怎么操作?
7楼
smileboy 发表于:2008/12/29 15:00:00
Dim dr As DataRow = e.DataRow
Select Case e.DataCol.Name
    Case "入库数量1","入库数量","单个克重"
        If dr.IsNull("入库数量") Then
            dr("入库数量1") = Nothing
        Else
            dr("入库数量1") = dr("入库数量") * IIF(dr("单个克重") Is Null,2,dr("单个克重"))
        End If
End Select
If e.DataCol.Name = "材料名" Then
    Dim dr1 As DataRow = DataTables("入录资料").Find("原材料 = " & "'" & e.DataRow("材料名") & "'" )
    If dr1 IsNot Nothing
        e.DataRow("材料代号")= dr1("代号")
        e.DataRow("单位")= dr1("单位")
        e.DataRow("规格")= dr1("规格")
        e.DataRow("单个克重")= dr1("单个克重")
    End If
End If

[此贴子已经被作者于2008-12-29 15:03:24编辑过]
8楼
czy 发表于:2008/12/29 15:08:00
或这样?

Dim dr As DataRow = e.DataRow
Select Case e.DataCol.Name
    Case "入库数量1","入库数量","单个克重"
        If dr.IsNull("入库数量") OrElse dr.IsNull("单个克重") Then
            dr("入库数量1") = Nothing
        Else
            If e.DataCol.Name = "单个克重" Then
               dr("入库数量1") = dr("入库数量") * dr("单个克重")
            Else
               dr("单个克重") = 2
               dr("入库数量1") = dr("入库数量") * dr("单个克重")
            End If
        End If
End Select

If e.DataCol.Name = "材料名" Then
    Dim dr1 As DataRow = DataTables("入录资料").Find("原材料  = '" & e.NewValue & "'")
    If dr1 IsNot Nothing
        e.DataRow("材料代号")= dr1("代号")
        e.DataRow("单位")= dr1("单位")
        e.DataRow("规格")= dr1("规格")
        e.DataRow("单个克重")= dr1("单个克重")
    End If
End If

9楼
lxl 发表于:2008/12/29 15:09:00
入库数量1列设计成表达式列
IsNull([入库数量],0) * IsNull([单克重量],2)
10楼
gdlgh 发表于:2008/12/29 15:10:00
呵。楼主真幸运!能让四大超级版主帮忙解答!!少有呀!!
共13 条记录, 每页显示 10 条, 页签: [1] [2]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .04297 s, 2 queries.