以文本方式查看主题

-  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=1293)

--  作者:号子
--  发布时间:2008/12/1 18:20:00
--  [求助]请高手帮精简优化代码
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:汽车管理系统.table

请帮我优化开票记录的datacolchanged事件代码。合并更好,谢谢先
--  作者:ybil
--  发布时间:2008/12/1 23:29:00
--  

呵呵,长点但条理清晰些:

Dim sh,fh, ss,fs As string
Dim sk,fk As Boolean
dim dr1,dr2 as datarow
dim Dt as datatable = datatables("基本资料")


sk = e.datarow("收货_抵扣")
fk = e.datarow("发货_抵扣")
sh = e.datarow("收货_单位")
fh = e.datarow("发货_单位")
ss = e.datarow("收货_税号")
fs = e.datarow("发货_税号")
dr1 = Dt.find("[客户名称]= \'" & sh & "\'")
dr2 = Dt.find("[客户名称]= \'" & fh & "\'")


If e.DataCol.Name = "收货_单位" Then
    if dr1 isNot nothing Then
         e.datarow("收货_税号") = IIF(sk = true,"+","") & dr1("税号")
    Else
         e.datarow("收货_税号") = Nothing
         e.datarow("收货_抵扣") = false
    End if

Elseif e.DataCol.Name = "收货_抵扣"  then
    If sk = true then
        e.datarow("发货_抵扣") = false
        e.datarow("收货_税号") = IIF(ss.substring(0,1)="+","","+") & dr1("税号")
        e.datarow("发货_税号") = dr2("税号").Replace("+","")
    Else
        e.datarow("收货_税号") = dr1("税号").Replace("+","")
    End IF

ElseIf e.DataCol.Name = "发货_单位" Then
    if dr2 isNot nothing Then
        e.datarow("发货_税号") = IIF(fk = true,"+","") & dr2("税号")
    Else
        e.datarow("发货_税号") = Nothing
        e.datarow("发货_抵扣") = false
    End if

Elseif e.DataCol.Name = "发货_抵扣"  then
    If fk = true then
        e.datarow("收货_抵扣") = false
        e.datarow("发货_税号") = IIF(fs.substring(0,1)="+","","+") & dr2("税号")
        e.datarow("收货_税号") = dr1("税号").Replace("+","")
    Else
        e.datarow("发货_税号") = dr2("税号").Replace("+","")
    End IF
End IF

[此贴子已经被作者于2008-12-1 23:31:05编辑过]

--  作者:号子
--  发布时间:2008/12/3 8:44:00
--  
授人鱼不如授人以渔,加点注释好吗,麻烦你了,有些看的懂,有些还不清楚。
[此贴子已经被作者于2008-12-3 8:44:18编辑过]