Foxtable(狐表)用户栏目专家坐堂 → 下面,重复地写代码 ,怎么优化好呢?


  共有1921人关注过本帖树形打印复制链接

主题:下面,重复地写代码 ,怎么优化好呢?

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/7/18 23:15:00 [显示全部帖子]

Select Case e.DataCol.Name
    Case "数量"
        Dim dr As DataRow = DataTables("fa piao库存").find(" 名称 =  '" & e.DataRow("名称") & "' and 规格 =  '" & e.DataRow("规格") & "' and 单位 =  '" & e.DataRow("单位") & "'  ")
        Dim drs As List(Of DataRow) = DataTables("fa piao主表").Select(" 业务类型 = '收进fa piao' ")
        Dim Values As new List(of  String )
        For Each dr2 As DataRow In drs
            Values.Add( CStr(dr2("autoid")))
        Next
        Dim str As String = String.Join("','",Values.ToArray)
        Dim drs1 As List(Of DataRow) = DataTables("fa piao主表").Select(" 业务类型 = '开出fa piao' ")
        Dim Values1 As  new List(of  String)
        For Each dr1 As DataRow In drs1
            Values1.Add( CStr(dr1("autoid")))
        Next
        Dim str1 As String = String.Join("','",Values1.ToArray)
        If dr Is Nothing Then
            Dim n As Integer = DataTables("fa piao库存").SQLCompute(" max(autoid) ") +1
            Dim dd As Row = Tables("fa piao库存").AddNew()
            dd("AutoID") = n
            dd("名称") = e.DataRow("名称")
            dd("规格") = e.DataRow("规格")
            dd("单位") = e.DataRow("单位")
            dd("单价") = e.DataRow("单价")
            dd("含税单价") = e.DataRow("含税单价")
            dd.save
           
        End If
        dr("入库数量") = DataTables("fa piao内容明细表").SQLCompute("sum(数量)"," 名称 =  '" & e.DataRow("名称") & "' and 规格 =  '" & e.DataRow("规格") & "' and 单位 =  '" & e.DataRow("单位") & "' and MainID in (' " &  str & "') ")
        dr("出库数量") = DataTables("fa piao内容明细表").SQLCompute("sum(数量)"," 名称 =  '" & e.DataRow("名称") & "' and 规格 =  '" & e.DataRow("规格") & "' and 单位 =  '" & e.DataRow("单位") & "' and MainID in (' " &  str1 & "')  ")
        dr.save
End Select

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/7/18 23:46:00 [显示全部帖子]

elect Case e.DataCol.Name
    Case "数量"
        Dim dr As DataRow = DataTables("fa piao库存").find(" 名称 =  '" & e.DataRow("名称") & "' and 规格 =  '" & e.DataRow("规格") & "' and 单位 =  '" & e.DataRow("单位") & "'  ")
        Dim drs As List(Of DataRow) = DataTables("fa piao主表").Select(" 业务类型 = '收进fa piao' ")
        Dim Values As new List(of  String )
        For Each dr2 As DataRow In drs
            Values.Add( CStr(dr2("autoid")))
        Next
        Dim str As String = String.Join("','",Values.ToArray)
        Dim drs1 As List(Of DataRow) = DataTables("fa piao主表").Select(" 业务类型 = '开出fa piao' ")
        Dim Values1 As  new List(of  String)
        For Each dr1 As DataRow In drs1
            Values1.Add( CStr(dr1("autoid")))
        Next
        Dim str1 As String = String.Join("','",Values1.ToArray)
        If dr Is Nothing Then
            Dim n As Integer = DataTables("fa piao库存").SQLCompute(" max(autoid) ") +1
            dr = dataTables("fa piao库存").AddNew()
            dr("AutoID") = n
            dr("名称") = e.DataRow("名称")
            dr("规格") = e.DataRow("规格")
            dr("单位") = e.DataRow("单位")
            dr("单价") = e.DataRow("单价")
            dr("含税单价") = e.DataRow("含税单价")
            
        End If
        dr("入库数量") = DataTables("fa piao内容明细表").SQLCompute("sum(数量)"," 名称 =  '" & e.DataRow("名称") & "' and 规格 =  '" & e.DataRow("规格") & "' and 单位 =  '" & e.DataRow("单位") & "' and MainID in (' " &  str & "') ")
        dr("出库数量") = DataTables("fa piao内容明细表").SQLCompute("sum(数量)"," 名称 =  '" & e.DataRow("名称") & "' and 规格 =  '" & e.DataRow("规格") & "' and 单位 =  '" & e.DataRow("单位") & "' and MainID in (' " &  str1 & "')  ")
        dr.save
End Select

 回到顶部