Foxtable(狐表)用户栏目专家坐堂 → 请教需要这样的功能用代码可以实现吗?如何实现?


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

主题:请教需要这样的功能用代码可以实现吗?如何实现?

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


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
  发帖心情 Post By:2009/5/11 17:38:00 [显示全部帖子]

试试:

Dim Tj,T As String
Dim dr As DataRow
Dim n1,n2,n As Integer
Dim dt1,dt2 As DataTable
dt1 = DataTables("表A")
dt2 = DataTables("表B")
Dim tb As Table = Tables("表B")
for each dr in dt1.select("路名 is not null")
    Tj = "路名 ='" & dr("路名") & "' and 状态 = '在用'"
    n1 = val(dt2.Compute("min(房)",Tj))
    n2 = val(dt2.Compute("max(房)",Tj))
    if n2 > n1 AndAlso n1 > 0 then
        tb.Redraw = False      
        For n = n1+1 to n1+3
           T = Tj.Replace("在用","虚拟") & " and 房 = '" & n & "'"
           if dt2.Find(T) is not Nothing then
            Dim r As  Row = tb.addnew
            r("路名") = dr("路名")
            r("街名") = dr("街名")
            r("号") = dr("号")
            r("栋") = dr("栋")
            r("房") = n
            r("状态") ="虚拟"
         end if
        Next
        For n = n2-3 to n2-1
            T = Tj.Replace("在用","虚拟") & " and 房 = '" & n & "'"
            if dt2.Find(T) is not Nothing then
            Dim r As  Row = tb.addnew
            r("路名") = dr("路名")
            r("街名") = dr("街名")
            r("号") = dr("号")
            r("栋") = dr("栋")
            r("房") = n
            r("状态") ="虚拟"
            end if
        Next
        tb.Redraw = true
    end if
Next

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


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
  发帖心情 Post By:2009/5/12 17:09:00 [显示全部帖子]

Dim n1,n2,Tj,T As String
Dim Row,n,i As Integer
Dim tb1,tb2 As Table
tb1 = Tables("表A")
tb2 = Tables("表A.表B")
tb1.Filter = "路名 is not null"

for Row = 0 to tb1.Rows.count-1
    tb1.Select(row,0)
    Tj = "路名 ='" & tb1.rows(row)("路名") & "' and 状态 = '在用'"
    n1 = tb2.Compute("min(房)",Tj)
    n2 = tb2.Compute("max(房)",Tj)
    if val(n2) > val(n1) AndAlso val(n1) > 0 then
        tb2.Redraw = False
        For n = n1.substring(0,1) to n2.substring(0,1)
            For i = 1 to 4
                T =  n & "0" & i
                if T <> n1 AndAlso T <> n2 Then
                    Dim r As  Row = tb2.addnew
                    r("房") = T
                    r("状态") ="虚拟"
                end if
            Next           
        Next       
        tb2.Redraw = true
    end if
Next

[此贴子已经被作者于2009-5-12 17:14:47编辑过]

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


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
  发帖心情 Post By:2009/5/13 12:13:00 [显示全部帖子]

以下是引用hejfen在2009-5-13 12:04:00的发言:

先多谢DON提供的代码,但还是存在一个问题,房号的判断问题,如最小房号204,最大房号401,这种情况就出现问题了,将:n1 = tb2.Compute("min(房)",Tj),改成: n1 = tb2.Compute("min(房.SubString(0,房.Length - 2))",Tj),行吗?但我试过出错。

如最小房号204,最大房号401时,生成什么房号吗?

205,206,207,398,399,400?

[此贴子已经被作者于2009-5-13 12:16:00编辑过]

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


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
  发帖心情 Post By:2009/5/13 15:17:00 [显示全部帖子]

最小房号204,最大房号401时,生成如下,哪里不对?
201 虚拟
202 虚拟
203 虚拟
301 虚拟
302 虚拟
303 虚拟
304 虚拟
402 虚拟
403 虚拟
404 虚拟


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


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
  发帖心情 Post By:2009/5/13 15:39:00 [显示全部帖子]

那13楼的代码没问题,就是按这思路生成.

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


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
  发帖心情 Post By:2009/5/13 16:20:00 [显示全部帖子]

以下是引用hejfen在2009-5-13 16:16:00的发言:
  For i = 1 to 4,不对,i是动态的,是要根据房号的房如401的“01”到204的“04”获取。

哦,那203 至 408生成什么?208 至 402又生成什么?

[此贴子已经被作者于2009-5-13 16:21:21编辑过]

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


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
  发帖心情 Post By:2009/5/13 17:35:00 [显示全部帖子]

Dim n1,n2,Tj,T As String
Dim Row,n,i,max,min As Integer
Dim tb1,tb2 As Table
tb1 = Tables("表A")
tb2 = Tables("表A.表B")
tb1.Filter = "路名 is not null"

for Row = 0 to tb1.Rows.count-1
    tb1.Select(row,0)
    Tj = "路名 ='" & tb1.rows(row)("路名") & "' and 状态 = '在用'"
    n1 = tb2.Compute("min(房)",Tj)
    n2 = tb2.Compute("max(房)",Tj)
    min = Math.Min(val(n1.substring(1)),val(n2.substring(1)))+1
    max = Math.Max(val(n1.substring(1)),val(n2.substring(1)))-1
   
    if val(n2) > val(n1) AndAlso val(n1) > 0 then
        tb2.Redraw = False
        For n = n1.substring(0,1) to n2.substring(0,1)
            For i = min to max
                T =  n & "0" & i            
                    Dim r As  Row = tb2.addnew
                    r("房") = T
                    r("状态") ="虚拟"            
            Next
        Next
        tb2.Redraw = true
    end if
Next


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


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
  发帖心情 Post By:2009/5/14 11:49:00 [显示全部帖子]

如下无法达标,俺也没辙了.
Dim Row,n,i,max,min As Integer
Dim n1,n2,Zy,T As String
Dim tb1,tb2 As Table
Dim r,r1,r2 as row

tb1 = Tables("表A")
tb2 = Tables("表A.表B")
tb1.Filter = "路名 is not null"

With DataTables("表B").DataCols
    If .Contains("Y") = False Then
        .Add("Y", GetType(Integer),"SubString([房],2,2)")
    End If
    for Row = 0 to tb1.Rows.count-1
        tb1.Select(row,0)
        r = tb1.Rows(Row)
       for each r1 in tb2.rows
          zy =zy & "|" & r1("房")
       Next
        n1 = tb2.Compute("min(房)")
        n2 = tb2.Compute("max(房)")
        min = tb2.Compute("min(Y)")
        max = tb2.Compute("max(Y)")
        if val(n2) > val(n1) AndAlso val(n1) > 0 then
            tb2.Redraw = False
            For n = n1.substring(0,1) to n2.substring(0,1)
                For i = min to max
                    T =  n & "0" & i                 
                    if Zy.IndexOf(T) = -1 then
                       r2 = tb2.addnew
                       r2("房") = T
                       r2("状态") ="虚拟"
                    end if
                Next
            Next
            tb2.Redraw = true
        end if
    Next
    .Delete("Y")
End with

[此贴子已经被作者于2009-5-14 13:27:40编辑过]

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


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
  发帖心情 Post By:2009/5/18 13:58:00 [显示全部帖子]

以下是引用hejfen在2009-5-18 11:20:00的发言:

还有个小问题,原来有的房号不用生成的的问题,  if T <> n1 AndAlso T <> n2 Then,只是最大和最小两个房号不重复,如果我有其它房号,还是会重复的,另外层号 n1 = tb2.Compute("min(房)",Tj),    n2 = tb2.Compute("max(房)",Tj),如果有房号1101,即11层01房,会被识别是最小值。高手还有更简单的代码吗?

可想而知:你没看26楼代码.另如你一开始就清楚明白说出要求,问题早就解决了,何需如此时日!

Dim Row,n,n1,n2,i,max,min As Integer
Dim Zy,T As String
Dim tb1,tb2 As Table
Dim r,r1,r2 as row

tb1 = Tables("表A")
tb2 = Tables("表A.表B")
tb1.Filter = "路名 is not null"

With DataTables("表B").DataCols
    If .Contains("层") = False  AndAlso .Contains("房号") = False Then
        .Add("层", GetType(Integer),"SubString([房],1,Len([房])-2)")
        .Add("房号", GetType(Integer),"SubString([房],Len([房])-1,2)")
    End If
    for Row = 0 to tb1.Rows.count-1
        tb1.Select(row,0)
        r = tb1.Rows(Row)
       for each r1 in tb2.rows
          zy =zy & "|" & r1("房")
       Next
        n1 = tb2.Compute("min(层)")
        n2 = tb2.Compute("max(层)")
        min = tb2.Compute("min(房号)")
        max = tb2.Compute("max(房号)")
        if n2 > n1 AndAlso n1 > 0 then
            tb2.Redraw = False
            For n = n1 to n2
                For i = min to max
                    T =  n & format(i,"00")                 
                    if Zy.IndexOf(T) = -1 then
                       r2 = tb2.addnew
                       r2("房") = T
                       r2("状态") ="虚拟"
                    end if
                Next
            Next
            tb2.Redraw = true
        end if
    Next
    .Delete("房号")
    .Delete("层")
End with

[此贴子已经被作者于2009-5-18 14:11:51编辑过]

 回到顶部