Foxtable(狐表)用户栏目专家坐堂 → [求教]代码优化


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

主题:[求教]代码优化

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


加好友 发短信
等级:幼狐 帖子:109 积分:1074 威望:0 精华:0 注册:2019/1/16 22:56:00
[求教]代码优化  发帖心情 Post By:2019/5/30 11:43:00 [显示全部帖子]

甜版,您之前帮我做的这个代码,我弄半天没把他放到我的窗口临时表里去,请您帮我修改下,将统计表1放到窗口表10,将统计表2放到窗口表11里,还有就是将统计表1里前段的重复值(行)那些显示为空呢,比如:销档,客户名称等这些列的重复行,麻烦您了,谢谢!
Dim ny As WinForm.ComboBox = e.Form.Controls("ComboBox10")

Dim g1 As New GroupTableBuilder("统计表1", DataTables("明细根表"))
Dim dt1 As fxDataSource
g1.Groups.AddDef("运输审核_结算月", "结算月")
g1.Groups.AddDef("销售审核_销档", "销档")
g1.Groups.AddDef("销售名称", "客户名称")
g1.Groups.AddDef("销售审核_吉", "吉")
g1.Groups.AddDef("销售审核_开piao", "piao")
g1.Totals.AddDef("销", AggregateEnum.Count,"销")
g1.Totals.AddDef("生产信息_类型", AggregateEnum.Count, "砼车数")
g1.Totals.AddDef("销量", "总方量")
g1.Totals.AddDef("销售_砼销额", "砼金额")
g1.Totals.AddDef("GDBFJE", "运输补助")
g1.Totals.AddDef("GDBCJE", "超时补助")
g1.Totals.AddDef("工地补助_工补其", "其他费用")
g1.Totals.AddDef("月调整_方量")
g1.Totals.AddDef("月调整_金额")
g1.VerticalTotal = True
g1.Filter = "[运输审核_结算月] = '" & ny.text & "' and [销] = 'X' and [生产信息_类型] = '砼'"
'g1.Build
dt1 = g1.BuildDataSource()
'
'
Dim g2 As New GroupTableBuilder("统计表1", DataTables("明细根表"))
Dim dt2 As fxDataSource
g2.Groups.AddDef("运输审核_结算月", "结算月")
g2.Groups.AddDef("销售名称", "客户名称")
g2.Totals.AddDef("生产信息_类型", AggregateEnum.Count, "水")
g2.Totals.AddDef("销售_水销额", "水金额")
g2.VerticalTotal = True
g2.Filter = "[运输审核_结算月] = '" & ny.text & "' and [生产信息_类型] = '水'"
dt2 = g2.BuildDataSource()
'g2.build

'
Dim g3 As New GroupTableBuilder("统计表2", DataTables("泵送明细"))
Dim dt3 As fxDataSource
g3.Groups.AddDef("财务结算年月")
g3.Groups.AddDef("销售工地名称")
g3.Totals.AddDef("结算_销售","泵送费用")
g3.VerticalTotal = True
g3.Filter = "[财务结算年月] = '" & ny.text & "'"
dt3 = g3.BuildDataSource()

'

Dim ar1() As String = {"结算月","客户名称"}
Dim ar2() As String = {"结算月","客户名称"}
Dim ar3() As String = {"财务结算年月","销售工地名称"}
'Dim ar4() As String = {"结算月","客户名称"}
'
'
dt1.Combine(ar1,dt2,ar2)
dt1.Combine(ar1,dt3,ar3)
'dt1.Combine(ar1,dt4,ar4)
'
dt1.show("统计表1")

Dim g4 As New GroupTableBuilder("统计表2", DataTables("明细根表"))
Dim dt4 As fxDataSource
g4.Groups.AddDef("运输审核_结算月", "结算月")
g4.Groups.AddDef("销售名称", "客户名称")
g4.Groups.AddDef("销售标号")
g4.Totals.AddDef("销售_砼销价", AggregateEnum.Average, "单价")
g4.Totals.AddDef("销量", "方/车")
g4.VerticalTotal = True
g4.Filter = "[运输审核_结算月] = '" & ny.text & "' and [销] = 'X' and [销售标号] is not Null"
'dt4 = g4.BuildDataSource()
g4.build

Dim t1 As Table = Tables("统计表1")
Dim t2 As Table = Tables("统计表2")
t1.StopRedraw
For i As Integer = 2 To t2.Cols.count-1
    t1.DataTable.DataCols.Add(t2.Cols(i).name, Gettype(String), 32, "", t2.Cols(i).caption)
Next
For i As Integer = 0 To t1.Rows.count-2
    Dim r1 As Row = t1.Rows(i)
    Dim nr1 As Row = Nothing
    For Each dr2 As DataRow In t2.DataTable.Select("结算月='" & r1("结算月") & "' and 客户名称='" & r1("客户名称") & "'")
        If nr1 Is Nothing Then
            nr1 = r1
        Else
            nr1 = t1.addnew
        End If
        For Each c As Col In t1.Cols
            nr1(c.name) = r1(c.name)
        Next
        For c As Integer = 2 To t2.Cols.count-1
            nr1(t2.cols(c).name) = dr2(t2.cols(c).name)
        Next
    Next
Next
t1.ResumeRedraw
t1.sort = "结算月,客户名称"
MainTable = t1


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


加好友 发短信
等级:幼狐 帖子:109 积分:1074 威望:0 精华:0 注册:2019/1/16 22:56:00
  发帖心情 Post By:2019/6/4 16:44:00 [显示全部帖子]

甜版所做第2点,在只有2行及以下重复的话,就能实现,但要是三行级以上重复的话,就只会两行两行比,请甜版解决三行及以上重复的

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


加好友 发短信
等级:幼狐 帖子:109 积分:1074 威望:0 精华:0 注册:2019/1/16 22:56:00
  发帖心情 Post By:2019/6/5 9:10:00 [显示全部帖子]

第一图是原代码的输出结果

图片点击可在新窗口打开查看此主题相关图片如下:20190605001.png
图片点击可在新窗口打开查看

第二图您帮忙优化后进行比较输出的结果

图片点击可在新窗口打开查看此主题相关图片如下:20190605002.png
图片点击可在新窗口打开查看

第三图是我想要的结果

图片点击可在新窗口打开查看此主题相关图片如下:20190605003.jpg
图片点击可在新窗口打开查看

[此贴子已经被作者于2019/6/5 9:10:30编辑过]

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


加好友 发短信
等级:幼狐 帖子:109 积分:1074 威望:0 精华:0 注册:2019/1/16 22:56:00
  发帖心情 Post By:2019/6/5 11:18:00 [显示全部帖子]

Dim ny As WinForm.ComboBox = e.Form.Controls("ComboBox10")

Dim g1 As New GroupTableBuilder("统计表1", DataTables("明细根表"))
Dim dt1 As fxDataSource
g1.Groups.AddDef("运输审核_结算月", "结算月")
g1.Groups.AddDef("销售审核_销档", "销档")
g1.Groups.AddDef("销售名称", "客户名称")
g1.Groups.AddDef("销售审核_吉", "吉")
g1.Groups.AddDef("销售审核_开piao", "piao")
g1.Totals.AddDef("销", AggregateEnum.Count,"销")
g1.Totals.AddDef("生产信息_类型", AggregateEnum.Count, "砼车数")
g1.Totals.AddDef("销量", "总方量")
g1.Totals.AddDef("销售_砼销额", "砼金额")
g1.Totals.AddDef("GDBFJE", "运输补助")
g1.Totals.AddDef("GDBCJE", "超时补助")
g1.Totals.AddDef("工地补助_工补其", "其他费用")
g1.Totals.AddDef("月调整_方量")
g1.Totals.AddDef("月调整_金额")
g1.VerticalTotal = True
g1.Filter = "[运输审核_结算月] = '" & ny.text & "' and [销] = 'X' and [生产信息_类型] = '砼'"
'g1.Build
dt1 = g1.BuildDataSource()
'
'
Dim g2 As New GroupTableBuilder("统计表1", DataTables("明细根表"))
Dim dt2 As fxDataSource
g2.Groups.AddDef("运输审核_结算月", "结算月")
g2.Groups.AddDef("销售名称", "客户名称")
g2.Totals.AddDef("生产信息_类型", AggregateEnum.Count, "水")
g2.Totals.AddDef("销售_水销额", "水金额")
g2.VerticalTotal = True
g2.Filter = "[运输审核_结算月] = '" & ny.text & "' and [生产信息_类型] = '水'"
dt2 = g2.BuildDataSource()
'g2.build

'
Dim g3 As New GroupTableBuilder("统计表2", DataTables("泵送明细"))
Dim dt3 As fxDataSource
g3.Groups.AddDef("财务结算年月")
g3.Groups.AddDef("销售工地名称")
g3.Totals.AddDef("结算_销售","泵送费用")
g3.VerticalTotal = True
g3.Filter = "[财务结算年月] = '" & ny.text & "'"
dt3 = g3.BuildDataSource()

'

Dim ar1() As String = {"结算月","客户名称"}
Dim ar2() As String = {"结算月","客户名称"}
Dim ar3() As String = {"财务结算年月","销售工地名称"}
'Dim ar4() As String = {"结算月","客户名称"}
'
'
dt1.Combine(ar1,dt2,ar2)
dt1.Combine(ar1,dt3,ar3)
'dt1.Combine(ar1,dt4,ar4)
'
Tables("明细根表_Table10").DataSource = dt1

Dim g4 As New GroupTableBuilder("统计表2", DataTables("明细根表"))
Dim dt4 As fxDataSource
g4.Groups.AddDef("运输审核_结算月", "结算月")
g4.Groups.AddDef("销售名称", "客户名称")
g4.Groups.AddDef("销售标号")
g4.Totals.AddDef("销售_砼销价", AggregateEnum.Average, "单价")
g4.Totals.AddDef("销量", "方/车")
g4.VerticalTotal = True
g4.Filter = "[运输审核_结算月] = '" & ny.text & "' and [销] = 'X' and [销售标号] is not Null"
dt4 = g4.BuildDataSource()
'g4.build
Tables("明细根表_Table11").DataSource = dt4

Dim t1 As Table = Tables("明细根表_Table10")
Dim t2 As Table = Tables("明细根表_Table11")
t1.StopRedraw
For i As Integer = 2 To t2.Cols.count-1
    t1.DataTable.DataCols.Add(t2.Cols(i).name, Gettype(String), 32, "", t2.Cols(i).caption)
Next
For i As Integer = 0 To t1.Rows.count-2
    Dim r1 As Row = t1.Rows(i)
    Dim nr1 As Row = Nothing
    For Each dr2 As DataRow In t2.DataTable.Select("结算月='" & r1("结算月") & "' and 客户名称='" & r1("客户名称") & "'")
        If nr1 Is Nothing Then
            nr1 = r1
        Else
            nr1 = t1.addnew
        End If
        For Each c As Col In t1.Cols
            nr1(c.name) = r1(c.name)
        Next
        For c As Integer = 2 To t2.Cols.count-1
            nr1(t2.cols(c).name) = dr2(t2.cols(c).name)
        Next
    Next
Next
t1.ResumeRedraw
t1.sort = "结算月,客户名称"
MainTable = t1

Tables("明细根表_Table10").sort = "销档"

Dim t As Table = Tables("明细根表_Table10")
Dim pr As Row = Nothing
For Each r As Row In t.Rows
    If pr IsNot Nothing AndAlso r("客户名称") = pr("客户名称") AndAlso r("piao") = pr("piao") Then
        r("客户名称") = Nothing
        r("piao") = Nothing
    End If
    pr = r
Next

Tables("明细根表_Table10").AutoSizeCols()
Tables("明细根表_Table11").AutoSizeCols()

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


加好友 发短信
等级:幼狐 帖子:109 积分:1074 威望:0 精华:0 注册:2019/1/16 22:56:00
  发帖心情 Post By:2019/6/5 11:40:00 [显示全部帖子]

完美解决,我再加几个条件就OK了,谢谢了,蓝版

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


加好友 发短信
等级:幼狐 帖子:109 积分:1074 威望:0 精华:0 注册:2019/1/16 22:56:00
  发帖心情 Post By:2019/6/5 15:02:00 [显示全部帖子]

不好意思了老师,我在这个表里新加了DOUBLE列,在进行删除重复行时,系统提示,新加列为只读,怎么解决呢,老师

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


加好友 发短信
等级:幼狐 帖子:109 积分:1074 威望:0 精华:0 注册:2019/1/16 22:56:00
  发帖心情 Post By:2019/6/11 16:46:00 [显示全部帖子]

几经尝试,都未成功,能否请甜版帮忙 将您述代码加入,以达本人效果
现将代码传上
Dim ny As WinForm.ComboBox = e.Form.Controls("ComboBox10")

Dim g1 As New GroupTableBuilder("统计表1", DataTables("明细根表"))
Dim dt1 As fxDataSource
g1.Groups.AddDef("运输审核_结算月", "结算月")
g1.Groups.AddDef("销售审核_销档", "销档")
g1.Groups.AddDef("销售名称", "客户名称")
g1.Groups.AddDef("销售审核_吉", "吉")
g1.Groups.AddDef("销售审核_吉", "吉辅")
g1.Groups.AddDef("销售审核_开piao", "piao")
g1.Totals.AddDef("销", AggregateEnum.Count,"销")
g1.Totals.AddDef("生产信息_类型", AggregateEnum.Count, "砼车数")
g1.Totals.AddDef("销量", "当月_总方量")
g1.Totals.AddDef("销售_砼销额", "砼金额")
g1.Totals.AddDef("GDBFJE", "运输补助")
g1.Totals.AddDef("GDBCJE", "超时补助")
g1.Totals.AddDef("工地补助_工补其", "其他费用")
g1.Totals.AddDef("月调整_方量")
g1.Totals.AddDef("月调整_金额")
g1.VerticalTotal = True
g1.Filter = "[运输审核_结算月] = '" & ny.text & "' and [销] = 'X' and [生产信息_类型] = '砼'"
dt1 = g1.BuildDataSource()

Dim g2 As New GroupTableBuilder("统计表1", DataTables("明细根表"))
Dim dt2 As fxDataSource
g2.Groups.AddDef("运输审核_结算月", "结算月")
g2.Groups.AddDef("销售名称", "客户名称")
g2.Totals.AddDef("销量", "水")
g2.Totals.AddDef("销售_水销额", "水金额")
g2.VerticalTotal = True
g2.Filter = "[运输审核_结算月] = '" & ny.text & "' and [生产信息_类型] = '水'"
dt2 = g2.BuildDataSource()

Dim g3 As New GroupTableBuilder("统计表2", DataTables("泵送明细"))
Dim dt3 As fxDataSource
g3.Groups.AddDef("财务结算年月")
g3.Groups.AddDef("销售工地名称")
g3.Totals.AddDef("结算_销售","泵送费用")
g3.VerticalTotal = True
g3.Filter = "[财务结算年月] = '" & ny.text & "'"
dt3 = g3.BuildDataSource()

Dim ar1() As String = {"结算月","客户名称"}
Dim ar2() As String = {"结算月","客户名称"}
Dim ar3() As String = {"财务结算年月","销售工地名称"}

dt1.Combine(ar1,dt2,ar2)
dt1.Combine(ar1,dt3,ar3)

Tables("明细根表_Table10").DataSource = dt1

Dim g4 As New GroupTableBuilder("统计表2", DataTables("明细根表"))
Dim dt4 As fxDataSource
g4.Groups.AddDef("运输审核_结算月", "结算月")
g4.Groups.AddDef("销售名称", "客户名称")
g4.Groups.AddDef("销售标号")
g4.Totals.AddDef("销售_砼销价", AggregateEnum.Average, "单价")
g4.Totals.AddDef("销量")
g4.VerticalTotal = True
g4.Filter = "[运输审核_结算月] = '" & ny.text & "' and [销] = 'X' and [销售标号] is not Null"
dt4 = g4.BuildDataSource()

Tables("明细根表_Table11").DataSource = dt4

Dim t1 As Table = Tables("明细根表_Table10")
Dim t2 As Table = Tables("明细根表_Table11")
t1.StopRedraw
For i As Integer = 2 To t2.Cols.count-1
    t1.DataTable.DataCols.Add(t2.Cols(i).name, Gettype(String), 32, "", t2.Cols(i).caption)
Next
For i As Integer = 0 To t1.Rows.count-2
    Dim r1 As Row = t1.Rows(i)
    Dim nr1 As Row = Nothing
    For Each dr2 As DataRow In t2.DataTable.Select("结算月='" & r1("结算月") & "' and 客户名称='" & r1("客户名称") & "'")
        If nr1 Is Nothing Then
            nr1 = r1
        Else
            nr1 = t1.addnew
        End If
        For Each c As Col In t1.Cols
            nr1(c.name) = r1(c.name)
        Next
        For c As Integer = 2 To t2.Cols.count-1
            nr1(t2.cols(c).name) = dr2(t2.cols(c).name)
        Next
    Next
Next

t1.ResumeRedraw
t1.sort = "结算月,客户名称"
MainTable = t1

Tables("明细根表_Table10").sort = "销档"

DataTables("明细根表_Table10").DataCols.Add("当月_水", Gettype(Double), "iif([水] = 0,null,[水])" )
DataTables("明细根表_Table10").DataCols.Add("当月_砼水金额", Gettype(Double), "iif([吉辅] = '√',null,isnull([砼金额],0) + isnull([水金额],0))" )
DataTables("明细根表_Table10").DataCols.Add("当月_泵送金额", Gettype(Double), "iif([吉辅] = '√',null,iif([泵送费用] = 0,null,[泵送费用]))" )
DataTables("明细根表_Table10").DataCols.Add("当月_运补", Gettype(Double), "iif([吉辅] = '√',null,iif([运输补助] = 0,null,[运输补助]))" )
DataTables("明细根表_Table10").DataCols.Add("当月_超补", Gettype(Double), "iif([吉辅] = '√',null,iif([超时补助] = 0,null,[超时补助]))" )
DataTables("明细根表_Table10").DataCols.Add("当月_他费", Gettype(Double), "iif([吉辅] = '√',null,iif([其他费用] = 0,null,[其他费用]))" )
DataTables("明细根表_Table10").DataCols.Add("调整_方量", Gettype(Double), "iif([吉辅] = '√',null,iif([月调整_方量] = 0,null,[月调整_方量]))" )
DataTables("明细根表_Table10").DataCols.Add("调整_金额", Gettype(Double), "iif([吉辅] = '√',null,iif([月调整_金额] = 0,null,[月调整_金额]))" )
DataTables("明细根表_Table10").DataCols.Add("砼/水明细_浇筑标号", Gettype(String), "[销售标号]" )
DataTables("明细根表_Table10").DataCols.Add("砼/水明细_单价", Gettype(Double), "iif([吉辅] = '√',0,[单价])" )
DataTables("明细根表_Table10").DataCols.Add("砼/水明细_方/车", Gettype(Double), "销量" )
DataTables("明细根表_Table10").DataCols.Add("砼/水明细_金额", Gettype(Double), "[砼/水明细_单价] * [砼/水明细_方/车]" )
DataTables("明细根表_Table10").DataCols.Add("当月_总金额", Gettype(Double), "iif([吉辅] = '√',null,isnull([当月_砼水金额],0) + isnull([当月_泵送金额],0) + isnull([当月_运补],0) + isnull([当月_超补],0) + isnull([当月_他费],0)) " )
DataTables("明细根表_Table10").DataCols.Add("总方量", Gettype(Double), "isnull([当月_总方量],0) + isnull([调整_方量],0) " )
DataTables("明细根表_Table10").DataCols.Add("总金额", Gettype(Double), "iif([吉辅] = '√',0,isnull([当月_总金额],0) + isnull([调整_金额],0)) " )

Tables("明细根表_Table10").Cols("销").Visible = False
Tables("明细根表_Table10").Cols("吉辅").Visible = False
Tables("明细根表_Table10").Cols("砼车数").Visible = False
Tables("明细根表_Table10").Cols("砼金额").Visible = False
Tables("明细根表_Table10").Cols("运输补助").Visible = False
Tables("明细根表_Table10").Cols("超时补助").Visible = False
Tables("明细根表_Table10").Cols("其他费用").Visible = False
Tables("明细根表_Table10").Cols("月调整_方量").Visible = False
Tables("明细根表_Table10").Cols("月调整_金额").Visible = False
Tables("明细根表_Table10").Cols("水").Visible = False
Tables("明细根表_Table10").Cols("水金额").Visible = False
Tables("明细根表_Table10").Cols("泵送费用").Visible = False
Tables("明细根表_Table10").Cols("销售标号").Visible = False
Tables("明细根表_Table10").Cols("单价").Visible = False
Tables("明细根表_Table10").Cols("销量").Visible = False

Tables("明细根表_Table10").Cols("总方量").Move(7)
Tables("明细根表_Table10").Cols("总金额").Move(8)
Tables("明细根表_Table10").Cols("当月_水").Move(12)
Tables("明细根表_Table10").Cols("当月_总金额").Move(13)

Dim t As Table = Tables("明细根表_Table10")
Dim pr As Row = Nothing
For Each r As Row In t.Rows
    If pr IsNot Nothing AndAlso r("客户名称") = pr("客户名称") AndAlso r("吉") = pr("吉") AndAlso r("piao") = pr("piao") AndAlso r("总方量") = pr("总方量") AndAlso r("总金额") = pr("总金额") AndAlso r("当月_总方量") = pr("当月_总方量") AndAlso r("当月_水") = pr("当月_水") AndAlso r("当月_总金额") = pr("当月_总金额") AndAlso r("当月_砼水金额") = pr("当月_砼水金额") AndAlso r("当月_泵送金额") = pr("当月_泵送金额") AndAlso r("当月_运补") = pr("当月_运补") AndAlso r("当月_超补") = pr("当月_超补") AndAlso r("当月_他费") = pr("当月_他费") AndAlso r("调整_方量") = pr("调整_方量") AndAlso r("调整_金额") = pr("调整_金额") Then
        r("客户名称") = Nothing
        r("吉") = Nothing
        r("piao") = Nothing
        r("总方量") = Nothing
        r("总金额") = Nothing
        r("当月_总方量") = Nothing
        r("当月_水") = Nothing
        r("当月_总金额") = Nothing
        r("当月_砼水金额") = Nothing
        r("当月_泵送金额") = Nothing
        r("当月_运补") = Nothing
        r("当月_超补") = Nothing
        r("当月_他费") = Nothing
        r("调整_方量") = Nothing
        r("调整_金额") = Nothing
Else
pr = r
    End If
Next

Tables("明细根表_Table10").AutoSizeCols()
Tables("明细根表_Table11").AutoSizeCols()


 回到顶部