以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  能不能把datacolchanged事件里的代码放在按键上去实现  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=77447)

--  作者:sf020cf
--  发布时间:2015/11/18 14:09:00
--  能不能把datacolchanged事件里的代码放在按键上去实现

红版 datacolchanged的事件代码能不能放到按键上实行

Select Case e.DataCol.name
    Case "司机", "车牌", "出车日期","项目","城市","客户","车型","地点"
        Dim filter As String = "司机 = \'" & e.DataRow("司机") & "\' and 车牌 = \'" & e.DataRow("车牌") & "\' and 出车日期 = #" & e.DataRow("出车日期") & "#"
        Dim drs As List(of DataRow) = e.DataTable.Select(filter)
        For Each dr As DataRow In drs
            If DataTables("价目表").DataCols.Contains("车型_" & e.DataRow("车型")) Then
                Dim jdrs As List(of DataRow) = DataTables("价目表").Select("项目 like \'%" & e.DataRow("项目") & "%\' and 城市 like \'%" & e.DataRow("城市") & "%\'")
                For Each jdr As DataRow In jdrs
                    If e.DataRow("地点") Like "*" & jdr("地点") & "*" Then
                        e.DataRow("运费") = jdr("车型_" & e.DataRow("车型"))
                        Exit For
                    End If
                Next
            End If
        Next
        drs = e.DataTable.Select(filter, "运费 desc")
        For i As Integer = 0 To drs.Count - 1
           
            Select Case drs(i)("车型")
                Case "9M6"
                    drs(i)("点费") = 80
                Case "6M2","6M8","7M6"
                    drs(i)("点费") = 60
                Case "4M5","4M2"
                    drs(i)("点费") = 30
            End Select
           
            If i = 0 Then
                drs(i)("点费") = Nothing
            Else
                drs(i)("运费") = Nothing
            End If
        Next
        For Each str As String In e.DataTable.GetValues("送货地址", filter)
            drs = e.DataTable.Select(filter & " and 送货地址 = \'" & str & "\'")
            For i As Integer = 0 To drs.Count - 1
                If i > 0 Then
                    drs(i)("点费") = Nothing
                End If
            Next
        Next
End Select

计算运费与点费的  并且单击值计算当前表 比如目录树筛选出某个司机的订单 按下按键 只计算当前司机的运费和点费

 


--  作者:大红袍
--  发布时间:2015/11/18 14:36:00
--  

比如代码

 

DataTables("员工").DataCols("司机").RaiseDataColChanged("司机 = \'" & e.node.Text & "\'")


--  作者:sf020cf
--  发布时间:2015/11/18 15:21:00
--  

我的意思是能否把代码写在控件上 不写在datacolchanged事件里 单击按钮就执行一次

 


--  作者:大红袍
--  发布时间:2015/11/18 15:55:00
--  
Dim dt As DataTable = DataTables("表a")
For Each ary() As String In dt.GetValues("司机|车牌|出车日期")
    Dim filter As String = "司机 = \'" & ary(0) & "\' and 车牌 = \'" & ary(1) & "\' and 出车日期 = #" & ary(2) & "#"
    Dim drs As List(of DataRow) = dt.Select(filter)
    For Each dr As DataRow In drs
        If DataTables("价目表").DataCols.Contains("车型_" & dr("车型")) Then
            Dim jdrs As List(of DataRow) = DataTables("价目表").Select("项目 like \'%" & dr("项目") & "%\' and 城市 like \'%" & dr("城市") & "%\'")
            For Each jdr As DataRow In jdrs
                If dr("地点") Like "*" & jdr("地点") & "*" Then
                    dr("运费") = jdr("车型_" & dr("车型"))
                    Exit For
                End If
            Next
        End If
    Next
    drs = dt.Select(filter, "运费 desc")
    For i As Integer = 0 To drs.Count - 1
       
        Select Case drs(i)("车型")
            Case "9M6"
                drs(i)("点费") = 80
            Case "6M2","6M8","7M6"
                drs(i)("点费") = 60
            Case "4M5","4M2"
                drs(i)("点费") = 30
        End Select
       
        If i = 0 Then
            drs(i)("点费") = Nothing
        Else
            drs(i)("运费") = Nothing
        End If
    Next
    For Each str As String In dt.GetValues("送货地址", filter)
        drs = dt.Select(filter & " and 送货地址 = \'" & str & "\'")
        For i As Integer = 0 To drs.Count - 1
            If i > 0 Then
                drs(i)("点费") = Nothing
            End If
        Next
    Next
Next

--  作者:sf020cf
--  发布时间:2015/11/18 17:38:00
--  

Dim dt As DataTable = DataTables("应付款项")
Dim p As WinForm.ProgressBar
p = e.Form.Controls("ProgressBar1")
Dim arys As List(of String()) = dt.GetValues( "司机|车牌|出车日期", "出车日期 is not null ")

If arys.count > 0 Then
    p.Visible = True
    p.Maximum =  arys.Count - 1 \'设置最大值
    p.Minimum = 0 \'设置最小值
    p.Value = 0 \'设置当前值
End If

Dim idx As Integer = 0
DataTables("应付款项").StopRedraw

For Each ary() As String In  arys
    idx += 1
    p.Value = idx \'加在这里
    Dim filter As String = "司机 = \'" & ary(0) & "\' and 车牌 = \'" & ary(1) & "\' and 出车日期 = #" & ary(2) & "#"
    Dim drs As List(of DataRow) = dt.Select(filter)
    For Each dr As DataRow In drs
        If DataTables("价目表").DataCols.Contains("车型_" & dr("车型")) Then
            Dim jdrs As List(of DataRow) = DataTables("价目表").Select("项目 like \'%" & dr("项目") & "%\' and 城市 like \'%" & dr("城市") & "%\'")
            For Each jdr As DataRow In jdrs
                If dr("地点") Like "*" & jdr("地点") & "*" Then
                    dr("运费") = jdr("车型_" & dr("车型"))
                    Exit For
                End If
            Next
        End If
    Next

    drs = dt.Select(filter, "运费 desc")
    For i As Integer = 0 To drs.Count - 1
       
        Select Case drs(i)("车型")
            Case "9M6"
                drs(i)("点费") = 80
            Case "6M2","6M8","7M6"
                drs(i)("点费") = 60
            Case "4M5","4M2"
                drs(i)("点费") = 30
        End Select
       
        If i = 0 Then
            drs(i)("点费") = Nothing
        Else
            drs(i)("运费") = Nothing
        End If
    Next
    For Each str As String In dt.GetValues("送货地址", filter)
        drs = dt.Select(filter & " and 送货地址 = \'" & str & "\'")
        For i As Integer = 0 To drs.Count - 1
            If i > 0 Then
                drs(i)("点费") = Nothing
            End If
        Next
    Next
Next
DataTables("应付款项").ResumeRedraw
p.Visible = False

 

我把进度条加进去了 进度条也显示 最后也隐藏了 运费跟点费没算出来

 


--  作者:大红袍
--  发布时间:2015/11/18 17:41:00
--  
那你重置列是否可以计算?
--  作者:sf020cf
--  发布时间:2015/11/18 18:01:00
--  

datacolchanged事件里只剩下 客户列变化之后跨表引用的代码了 计算的代码都在按键上了

 


--  作者:大红袍
--  发布时间:2015/11/18 18:08:00
--  
以下是引用sf020cf在2015/11/18 18:01:00的发言:

datacolchanged事件里只剩下 客户列变化之后跨表引用的代码了 计算的代码都在按键上了

 

 

代码应该是没有问题的,无法计算运费,就是没有找到对应的地点。

 

单独导出一几个对应表的数据,做个小例发上来测试。


--  作者:sf020cf
--  发布时间:2015/11/19 9:53:00
--  

控件单击事件比datacolchanged事件快

按键没有重置代码了 想计算当前表 并且只计算运费与点费还未赋值的行 (有的行计算过后也不一定有值 因为地址相同只赋一次值)

这样代码能这样改吗:

Dim arys As List(of String()) = DataTables("应付款项").GetValues( "司机|车牌|出车日期", "出车日期 is not null and 运费 is null and 点费 is null")
长此以往

数据越来越多 代码会把所有的数据都筛选出空值计算吧?

我在刷新按钮中加了日期选定 来刷新数据  怎样才能只计算刷新出来的数据


--  作者:大红袍
--  发布时间:2015/11/19 10:53:00
--  

这样写

 

Dim filter As String = Tables("应付款项").Filter
Dim arys As List(of String()) = DataTables("应付款项").GetValues( "司机|车牌|出车日期", "出车日期 is not null and 运费 is null and 点费 is null and " & iif(filter>"", filter, "1=1"))