Foxtable(狐表)用户栏目专家坐堂 → [讨论](已完成)狐爸及各位高手,能实现吗?帮助里有年月日的计算表达式,有没有计算周表达式啊?


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

主题:[讨论](已完成)狐爸及各位高手,能实现吗?帮助里有年月日的计算表达式,有没有计算周表达式啊?

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


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

 木有,这个比较麻烦,不好判断。

 

 用代码吧,用函数直接可以解决。


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


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

 如下代码

 

Dim frm As WinForm.Form = Args(0)
Dim cmd As New SQLCommand
cmd.ConnectionName = erp1 ' "基础档案"
Dim tbnm As String = frm.TableName 'tb0.Name ' frm.Name ' & "_Table1"    '
cmd.CommandText = "select * from {数据表} where 表名 = '" & tbnm & "'"
Dim dt1 As DataTable = cmd.ExecuteReader
Dim nm As String '筛选列
Dim nms As String()
If dt1.DataRows.Count = 0 Then ' Is Nothing Then
    MessageBox.Show("无此""" & tbnm & """数据表")
    Return Nothing
Else
    Dim dr As DataRow = dt1.DataRows(0)
    Dim spc As WinForm.SplitContainer = frm.Controls("SplitContainer1")
    Dim btn As WinForm.Button = frm.Controls("Button筛选显示")
    If dr("生成目录树的各列_显示") = False Then
        spc.Panel1.Collapsed = True
        Return Nothing
    End If
    spc.Panel1.Collapsed = False
    Dim trv1 As WinForm.TreeView = frm.Controls("TreeView1")
    If trv1.Nodes.Count > 0 Then
    End If
    nm = dr("生成目录树的各列_设置")
    If nm > "" Then
        nms = nm.Split("|")
        For i As Integer = 0 To nms.Length - 1  ' Each nm1 As String In nms
            If nms(i).EndsWith(" YM") Then
                Dim nm1s As String() = nms(i).Split(" ")
                If DataTables(frm.Name).DataCols.Contains(nm1s(0) & "年") = False Then
                    DataTables(frm.Name).DataCols.Add(nm1s(0) & "年",Gettype(String),"SubString(Convert([日期],'System.String'),1,4) + '年'") ',SubString([日期],1,4))  'Year(nm1s(0)))
                End If
                If DataTables(frm.Name).DataCols.Contains(nm1s(0) & "月") = False Then
                    DataTables(frm.Name).DataCols.Add(nm1s(0) & "月",Gettype(String),"IIF(SubString(Convert([日期],'System.String'),6,IIF(SubString(Convert([日期],'System.String'),7,1) In ('-','/'),1,2)) > '09',SubString(Convert([日期],'System.String'),6,IIF(SubString(Convert([日期],'System.String'),7,1) In ('-','/'),1,2)),SubString(Convert([日期],'System.String'),7,IIF(SubString(Convert([日期],'System.String'),6,1) In ('-','/'),1,1))) + '月'") ' ,SubString([日期],6,2))  'Month(nm1s(0)))
                End If
                Dim nmst As New List(Of String)
                nmst.AddRange(nms)
                nmst(i) = nm1s(0) & "年"
                nmst.Insert(i + 1,nm1s(0) & "月")
                nms = nmst.ToArray()
                nm = nm.Replace(" YM","年|" & nm1s(0) & "月")
            ElseIf nms(i).EndsWith(" YW") Then
                Dim nm1s As String() = nms(i).Split(" ")
                If DataTables(frm.Name).DataCols.Contains(nm1s(0) & "年") = False Then
                    DataTables(frm.Name).DataCols.Add(nm1s(0) & "年",Gettype(String),"SubString(Convert([日期],'System.String'),1,4) + '年'") ',SubString([日期],1,4))  'Year(nm1s(0)))
                End If
                If DataTables(frm.Name).DataCols.Contains(nm1s(0) & "周") = False Then
                    MessageBox.Show("这里怎么写周的表达式?" & vbcrlf & "请修改内部函数treeview")
                    DataTables(frm.Name).DataCols.Add(nm1s(0) & "周",Gettype(String))
                    For Each mdr As DataRow In DataTables(frm.Name).DataRows
                        mdr(nm1s(0) & "周") = DatePart("ww", mdr("日期"))
                    Next
                Else
                    For Each mdr As DataRow In DataTables(frm.Name).DataRows
                        mdr(nm1s(0) & "周") = Format(DatePart("ww", mdr("日期")), "00") & "周"
                    Next
                End If
                nm = nm.Replace(nms(i), nm1s(0) & "年|" & nm1s(0) & "周")
            End If
        Next
        btn.Text = "关闭"
    Else
        MessageBox.Show("请设置筛选列")
        Return Nothing
    End If
End If
Dim txtsz As WinForm.TextBox = frm.Controls("TextBox设置")
txtsz.Value = nm
cmd.ConnectionName = erp2 ' "收发明细"
If frm.Opened = False Then
    frm.Open
End If
Dim tbl As WinForm.Table = frm.Controls("Table1")
Dim tb As Table = tbl.Table
Dim dt As DataTable  = tb.DataTable ' Tables(frm.Name & "_Table1").DataTable

Dim trv As WinForm.TreeView = frm.Controls("TreeView1")
trv.BuildTree(dt, nm) ' "年|月|材料名称|规格型号")
trv.StopRedraw

nms = nm.Split("|")
For Each nd As WinForm.TreeNode In trv.AllNodes
    Dim Value() As String
    Dim Filter As String
    Dim d1 As Date
    Dim d2 As Date
    Value = nd.FullName.Split("\") '注意这里用FullName属性,不能用FullPath属性nd.Level
    Filter = nms(0) & " = '" & Value(0) & "'"
    For i As Integer = 1 To nd.Level
        Filter = Filter & " And " & nms(i) & " = '" & Value(i) & "'"
    Next
    nd.Text = nd.text & "(" & dt.Compute("Count(单号)",Filter) & "条)"
Next
If trv.AllNodes.Count > 0 Then
    trv.Nodes.Insert("显示所有行",0)
    trv.Nodes(0).Text = trv.Nodes(0).Text & "(" & dt.Compute("Count(单号)") & "条)"
    trv.Nodes(0).Checked = True
    tb.Filter = ""
End If
trv.ResumeRedraw
tbl.Select()


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


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

以下是引用yinyb36在2014-4-27 17:01:00的发言:
参考了下代码,谢谢有点甜!
可惜不是表达式,每次重建目录树都要循环一下表来赋值,速度和效率都没表达式高

 

周的表达式,是很麻烦的,而且是不确定的。无法用表达式去完成。

 

表达式其实效率更低。

 

或者你可以用 sql 语句的方式去建立目录树 http://www.foxtable.com/help/topics/2054.htm

 


 回到顶部