Foxtable(狐表)用户栏目专家坐堂 → 这样的功能代码怎么写呢?请大师指点~~~


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

主题:这样的功能代码怎么写呢?请大师指点~~~

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


加好友 发短信
等级:童狐 帖子:221 积分:1745 威望:0 精华:0 注册:2014/1/7 12:37:00
这样的功能代码怎么写呢?请大师指点~~~  发帖心情 Post By:2014/4/14 10:05:00 [显示全部帖子]

我设计了一个独立窗口,里面有起始时间、结束时间、客户名称、货物种类等可以选择的值,同时还有几个值是要根据这些条件对表进行统计的。我应该如何着手写代码呢?

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


加好友 发短信
等级:童狐 帖子:221 积分:1745 威望:0 精华:0 注册:2014/1/7 12:37:00
  发帖心情 Post By:2014/4/14 10:05:00 [显示全部帖子]


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

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


加好友 发短信
等级:童狐 帖子:221 积分:1745 威望:0 精华:0 注册:2014/1/7 12:37:00
  发帖心情 Post By:2014/4/14 10:07:00 [显示全部帖子]

统计条件并不是每次都全部有的哦,说明下


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


加好友 发短信
等级:童狐 帖子:221 积分:1745 威望:0 精华:0 注册:2014/1/7 12:37:00
  发帖心情 Post By:2014/4/14 14:27:00 [显示全部帖子]

Dim dt As DataTable = DataTables("进出库信息记录")
Dim tbl As Table = Tables("进出库信息记录")
Dim form4 As winform.form = forms("常用信息统计")
Dim d1 As Date = Form4.controls("DateTimePicker1").value
Dim d2 As Date = Form4.controls("DateTimePicker2").value
Dim lbl2 As winform.control = Form4.controls("label2")
Dim lbl4 As winform.control = Form4.controls("label4")
Dim lbl6 As winform.control = Form4.controls("label6")
Dim lbl8 As winform.control = Form4.controls("label8")
Dim lbl10 As winform.control = Form4.controls("label10")
Dim lbl12 As winform.control = Form4.controls("label12")
Dim Tatol As Decimal
Dim tatol1 As Decimal
Dim tatol2 As Decimal
Dim Tatol3 As Decimal
Dim tatol4 As Decimal
Dim tatol5 As Decimal
Dim Tatol6 As Decimal
Dim Tatol7 As Decimal
If e.Form.controls("DateTimePicker2").value Is Nothing Then
    e.Form.controls("Label2").text = 0
    e.Form.controls("Label4").text = 0
    e.Form.controls("Label6").text = 0
    e.Form.controls("Label8").text = 0
    e.Form.controls("Label10").text = 0
    e.Form.controls("Label12").text = 0
End If
If e.Form.controls("DateTimePicker2").value IsNot Nothing  And e.Form.controls("DateTimePicker1").value Is  Nothing  Then
    Tatol = Tables("进出库信息记录").compute("sum(吨位)","([进出库分类]= '进库' or [进出库分类]= '对过') and [日期] = '"& e.Form.controls("DateTimePicker2").Value & "'")
    e.Form.controls("Label2").text = Round2(Tatol,2)
    tatol1=dt.compute("sum(吨位)","([进出库分类]='进库' Or [进出库分类]='转存') And [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
    tatol2=dt.compute("sum(吨位)","[进出库分类]='出库'And [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
    tatol3 = tatol1-tatol2        
    e.Form.controls("Label4").text = Round2(Tatol3,2)
     Tatol4 = Tables("进出库信息记录").compute("sum(车船数)","[到发方式]='火车' and [日期] = '"& e.Form.controls("DateTimePicker2").Value & "'")
    e.Form.controls("Label6").text = Round2(Tatol4,2)
     Tatol5 = Tables("进出库信息记录").compute("sum(过磅吨位)","[日期] = '"& e.Form.controls("DateTimePicker2").Value & "'")
    e.Form.controls("Label8").text = Round2(Tatol5,2)
     Tatol6 = Tables("进出库信息记录").compute("sum(车船数)","[到发方式]='船舶' and [日期] = '"& e.Form.controls("DateTimePicker2").Value & "'")
     e.Form.controls("Label10").text = Round2(Tatol6,2)
    Tatol7 = Tables("进出库信息记录").compute("sum(二码头对过)","[日期] = '"& e.Form.controls("DateTimePicker2").Value & "'")
    e.Form.controls("Label12").text =  Round2(Tatol7,2)
End If
If e.Form.controls("DateTimePicker2").value IsNot Nothing  And e.Form.controls("DateTimePicker1").value IsNot  Nothing  Then
    If e.Form.controls("ComboBox1").value Is Nothing  And e.Form.controls("ComboBox2").value Is  Nothing And e.Form.controls("ComboBox3").value Is  Nothing  Then
    Tatol = Tables("进出库信息记录").compute("sum(吨位)","([进出库分类]= '进库' or [进出库分类]= '对过') and [日期] >= '"& e.Form.controls("DateTimePicker1").Value & "'and [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
    e.Form.controls("Label2").text = Round2(Tatol,2)
    tatol1=dt.compute("sum(吨位)","([进出库分类]='进库' Or [进出库分类]='转存') And [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
    tatol2=dt.compute("sum(吨位)","[进出库分类]='出库'And [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
    tatol3 = tatol1-tatol2        
    e.Form.controls("Label4").text = Round2(Tatol3,2)
     Tatol4 = Tables("进出库信息记录").compute("sum(车船数)","[到发方式]='火车' and [日期] >= '"& e.Form.controls("DateTimePicker1").Value & "'and [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
    e.Form.controls("Label6").text = Round2(Tatol4,2)
     Tatol5 = Tables("进出库信息记录").compute("sum(过磅吨位)","[日期] >= '"& e.Form.controls("DateTimePicker1").Value & "'and [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
    e.Form.controls("Label8").text = Round2(Tatol5,2)
     Tatol6 = Tables("进出库信息记录").compute("sum(车船数)","[到发方式]='船舶' and [日期] >= '"& e.Form.controls("DateTimePicker1").Value & "'and [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
     e.Form.controls("Label10").text = Round2(Tatol6,2)
    Tatol6 = Tables("进出库信息记录").compute("sum(二码头对过)","[日期] >= '"& e.Form.controls("DateTimePicker1").Value & "'and [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
    e.Form.controls("Label12").text = Round2(Tatol7,2)
    End If
    If e.Form.controls("ComboBox1").value IsNot Nothing  And e.Form.controls("ComboBox2").value Is  Nothing And e.Form.controls("ComboBox3").value Is  Nothing  Then
    Tatol = Tables("进出库信息记录").compute("sum(吨位)","([进出库分类]= '进库' or [进出库分类]= '对过') and ([日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'and [日期] >= '"& e.Form.controls("DateTimePicker2").Value & "')")
    e.Form.controls("Label2").text = Round2(Tatol,2)
    tatol1=dt.compute("sum(吨位)","([进出库分类]='进库' Or [进出库分类]='转存') And [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
    tatol2=dt.compute("sum(吨位)","[进出库分类]='出库'And [日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'")
    tatol3 = tatol1-tatol2        
    e.Form.controls("Label4").text = Round2(Tatol3,2)
     Tatol4 = Tables("进出库信息记录").compute("sum(车船数)","[到发方式]='火车' and ([日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'and [日期] >= '"& e.Form.controls("DateTimePicker2").Value & "')")
    e.Form.controls("Label6").text = Round2(Tatol4,2)
     Tatol5 = Tables("进出库信息记录").compute("sum(过磅吨位)","[日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'and [日期] >= '"& e.Form.controls("DateTimePicker2").Value & "'")
    e.Form.controls("Label8").text = Round2(Tatol5,2)
     Tatol6 = Tables("进出库信息记录").compute("sum(车船数)","[到发方式]='船舶' and ([日期] <= '"& e.Form.controls("DateTimePicker2").Value & "'and [日期] >= '"& e.Form.controls("DateTimePicker2").Value & "')")     
     e.Form.controls("Label10").text = Round2(Tatol6,2)
    Tatol6 = Tables("进出库信息记录").compute("sum(二码头对过)","[日期] = '"& e.Form.controls("DateTimePicker2").Value & "'")
    e.Form.controls("Label12").text = Round2(Tatol7,2)
    End If


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


加好友 发短信
等级:童狐 帖子:221 积分:1745 威望:0 精华:0 注册:2014/1/7 12:37:00
  发帖心情 Post By:2014/4/14 14:27:00 [显示全部帖子]

请大师看一下,这个代码可以简化不?

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


加好友 发短信
等级:童狐 帖子:221 积分:1745 威望:0 精华:0 注册:2014/1/7 12:37:00
  发帖心情 Post By:2014/4/14 14:52:00 [显示全部帖子]

我也是这样的想法 但是怎么做到呢?是不是用这样的代码啊:

With e.Form.Controls("cmbProduct")
    
If .Value IsNot Nothing Then
        Filter = 
"产品 = '" & .Value & "'"
    
End If
End
 With
With
 e.Form.Controls("cmbCustomer")
    
If .Value IsNot Nothing Then
        
If Filter > "" Then
            Filter = Filter & 
" And "
        
End If
        Filter = Filter & 
"客户 = '" & .Value & "'"
    
End If
End
 With

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


加好友 发短信
等级:童狐 帖子:221 积分:1745 威望:0 精华:0 注册:2014/1/7 12:37:00
  发帖心情 Post By:2014/4/15 11:15:00 [显示全部帖子]

我这个代码可以简化不?


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


加好友 发短信
等级:童狐 帖子:221 积分:1745 威望:0 精华:0 注册:2014/1/7 12:37:00
  发帖心情 Post By:2014/4/15 14:33:00 [显示全部帖子]

这个代码中,这个Filter = Filter & " And 发热用法有没有例子或者专门的说明啊,想学一下

With e.Form.Controls("cmbCustomer")
    
If .Value IsNot Nothing Then
        
If Filter > "" Then
            Filter = Filter & 
" And "
        
End If
        Filter = Filter & 
"客户 = '" & .Value & "'"
    
End If
End
 With


 回到顶部