以文本方式查看主题

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

--  作者:longyanlin
--  发布时间:2017/8/21 13:33:00
--  代码修改

老师,我做了个“计件工资”表,里面有列“计件工资,计时工资,扣保险,扣房租”等列名称,再做个按钮,使用如下代码,想提取“计件明细表”里的计件工资,和“计时明细表”里面的计时工资,以及提取“其它明细表”里面的扣保险,扣房租等内容,求代码修改。(现在代码只能提取一个表的内容,其它的不知道怎样写了),感谢!

Dim dic As new Dictionary(of String,Integer)
DataTables("计件工资").DataRows.Clear()
For Each dr1 As Row In Tables("计件明细").Rows
    For Each dr2 As DataRow In DataTables("计件明细").Select("[姓名] = \'" & dr1("姓名") & "\'")
        Dim nm As String = dr2("姓名")
        Dim vl As Integer = dr1("计件工资")
        If dic.ContainsKey(nm) = False
            dic.Add(nm,vl)
        Else
            dic(nm) = dic(nm)+ vl
        End If
    Next
Next

For Each key As String In dic.keys
    Dim dr As DataRow = DataTables("计件工资").AddNew()
    dr("姓名") = key
    dr("计件工资") = dic(key)
Next

 


--  作者:有点甜
--  发布时间:2017/8/21 15:33:00
--  

DataTables("计件工资").DataRows.Clear()

For Each xm As String In DataTables("计件明细").GetValues("姓名")
    Dim fdr As DataRow = DataTables("计件工资").find("[姓名] = \'" & xm & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("计件工资").AddNew
        fdr("姓名") = xm
    End If
    fdr("计件工资") = DataTables("计件明细").compute("sum(计件工资)", "姓名 = \'" & xm & "\'")
Next
For Each xm As String In DataTables("计时明细").GetValues("姓名")
    Dim fdr As DataRow = DataTables("计件工资").find("[姓名] = \'" & xm & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("计件工资").AddNew
        fdr("姓名") = xm
    End If
    fdr("计时工资") = DataTables("计时明细").compute("sum(计时工资)", "姓名 = \'" & xm & "\'")
Next
For Each xm As String In DataTables("其它明细").GetValues("姓名")
    Dim fdr As DataRow = DataTables("计件工资").find("[姓名] = \'" & xm & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("计件工资").AddNew
        fdr("姓名") = xm
    End If
    fdr("扣保险") = DataTables("其它明细").compute("sum(扣保险)", "姓名 = \'" & xm & "\'")
    fdr("扣房租") = DataTables("其它明细").compute("sum(扣房租)", "姓名 = \'" & xm & "\'")
Next


 


--  作者:longyanlin
--  发布时间:2017/8/21 15:59:00
--  

谢谢老师,以上代码能实现,但是是提取DATATABLE的数据,所以在单独计算某个人或者是某个时间段就会不方便,能否加一个ComboBox1,代表姓名,一个DateTimePicker1,代表工资的日期开始,和一个DateTimePicker2,代表工资日期的结束等三个控件,然后点击2楼按钮后,显示出某人或者是某月的工资


--  作者:有点甜
--  发布时间:2017/8/21 16:23:00
--  

某人某月等等条件,那就修改红色代码

 

Dim filter1 As String = "姓名=\'张三\' and 日期 >= #2017-08-01# and 日期 < #2017-09-01#"

Dim filter2 As String = "日期 >= #2017-08-01# and 日期 < #2017-09-01#"

For Each xm As String In DataTables("计件明细").GetValues("姓名", filter1)

    fdr("计件工资") = DataTables("计件明细").compute("sum(计件工资)", "姓名 = \'" & xm & "\' and " & filter2)

 

http://www.foxtable.com/webhelp/scr/1058.htm

 


--  作者:longyanlin
--  发布时间:2017/8/21 20:11:00
--  
老师,改了两小时都没有改好,小妹愚笨,请老师帮忙写下,后面对着正确的代码认真理解,谢谢甜老师
--  作者:有点蓝
--  发布时间:2017/8/21 20:17:00
--  
参考这里的设置条件方法:http://www.foxtable.com/webhelp/scr/1058.htm
--  作者:longyanlin
--  发布时间:2017/8/21 20:54:00
--  
这里是一个Table的查询,我要做的是提取3个DatatabLe的数据,不知道从那里着手,还有就是2楼代码是计件工资表里的姓名是来自DateTab1e,当某人某月没有工资记录时,计件工资表也会新增该员工工资,而一楼代码不会
[此贴子已经被作者于2017/8/21 21:10:20编辑过]

--  作者:有点蓝
--  发布时间:2017/8/21 21:16:00
--  
不管多少表用法都一样的,你要学的是如何设置条件,这个和多少个表没有关系

贴出你的代码看看


--  作者:longyanlin
--  发布时间:2017/8/21 21:36:00
--  

Dim Filter As String
With e.Form.Controls("ComboBox4")
    If .Value IsNot Nothing Then
        Filter = "姓名 = \'" & .Value & "\'"
    End If
End With

With e.Form.Controls("DateTimePicker5")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("DateTimePicker6")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 <= #" & .Value & "#"
    End If
End With
If Filter > "" Then
    Tables("计件明细").Filter = Filter
    Tables("计时明细").Filter = Filter
    Tables("其它工资").Filter = Filter
End If

DataTables("计件工资").DataRows.Clear()

For Each xm As String In DataTables("计件明细").GetValues("姓名")
    Dim fdr As DataRow = DataTables("计件工资").find("[姓名] = \'" & xm & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("计件工资").AddNew
        fdr("姓名") = xm
    End If
    fdr("计件工资") = Tables("计件明细").compute("sum(计件工资)", "姓名 = \'" & xm & "\'")
Next
For Each xm As String In DataTables("计时明细").GetValues("姓名")
    Dim fdr As DataRow = DataTables("计件工资").find("[姓名] = \'" & xm & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("计件工资").AddNew
        fdr("姓名") = xm
    End If
    fdr("其它工资") = Tables("计时明细").compute("sum(计时工资)", "姓名 = \'" & xm & "\'")
Next
For Each xm As String In DataTables("其它工资").GetValues("姓名")
    Dim fdr As DataRow = DataTables("计件工资").find("[姓名] = \'" & xm & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("计件工资").AddNew
        fdr("姓名") = xm
    End If
    fdr("奖励") = Tables("其它工资").compute("sum(奖励)", "姓名 = \'" & xm & "\'")
    fdr("罚款") = Tables("其它工资").compute("sum(罚款)", "姓名 = \'" & xm & "\'")
    fdr("房租") = Tables("其它工资").compute("sum(房租)", "姓名 = \'" & xm & "\'")
    fdr("扣水电") = Tables("其它工资").compute("sum(扣水电)", "姓名 = \'" & xm & "\'")
    fdr("保险") = Tables("其它工资").compute("sum(保险)", "姓名 = \'" & xm & "\'")
    fdr("扣其它") = Tables("其它工资").compute("sum(扣其它)", "姓名 = \'" & xm & "\'")
Next

该代码提取了三个table的数据,请老师帮忙改改,“计件工资”表只新增3个table出现的姓名,没有出现的不要新增

[此贴子已经被作者于2017/8/21 21:41:18编辑过]

--  作者:有点蓝
--  发布时间:2017/8/21 21:55:00
--  
Dim Filter As String
With e.Form.Controls("ComboBox4")
    If .Value IsNot Nothing Then
        Filter = "姓名 = \'" & .Value & "\'"
    End If
End With
Dim filter2 As String = "1=1 "
With e.Form.Controls("DateTimePicker5")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 >= #" & .Value & "#"
        filter2 = filter2 & " and 日期 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("DateTimePicker6")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 <= #" & .Value & "#"
        filter2 = filter2 & " and 日期 <= #" & .Value & "#"
    End If
End With
If Filter > "" Then
    Tables("计件明细").Filter = Filter
    Tables("计时明细").Filter = Filter
    Tables("其它工资").Filter = Filter
End If
DataTables("计件工资").DataRows.Clear()
For Each xm As String In DataTables("计件明细").GetValues("姓名",Filter)
    Dim fdr As DataRow = DataTables("计件工资").find("[姓名] = \'" & xm & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("计件工资").AddNew
        fdr("姓名") = xm
    End If
    fdr("计件工资") = Tables("计件明细").compute("sum(计件工资)", "姓名 = \'" & xm & "\' and " &  filter2 )
Next
For Each xm As String In DataTables("计时明细").GetValues("姓名",Filter)
    Dim fdr As DataRow = DataTables("计件工资").find("[姓名] = \'" & xm & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("计件工资").AddNew
        fdr("姓名") = xm
    End If
    fdr("其它工资") = Tables("计时明细").compute("sum(计时工资)", "姓名 = \'" & xm & "\' and " &  filter2)
Next
For Each xm As String In DataTables("其它工资").GetValues("姓名",Filter)
    Dim fdr As DataRow = DataTables("计件工资").find("[姓名] = \'" & xm & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("计件工资").AddNew
        fdr("姓名") = xm
    End If
    fdr("奖励") = Tables("其它工资").compute("sum(奖励)", "姓名 = \'" & xm & "\' and " &  filter2)
    fdr("罚款") = Tables("其它工资").compute("sum(罚款)", "姓名 = \'" & xm & "\' and " &  filter2)
    fdr("房租") = Tables("其它工资").compute("sum(房租)", "姓名 = \'" & xm & "\' and " &  filter2)
    fdr("扣水电") = Tables("其它工资").compute("sum(扣水电)", "姓名 = \'" & xm & "\' and " &  filter2)
    fdr("保险") = Tables("其它工资").compute("sum(保险)", "姓名 = \'" & xm & "\' and " &  filter2)
    fdr("扣其它") = Tables("其它工资").compute("sum(扣其它)", "姓名 = \'" & xm & "\' and " &  filter2)
Next