以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  【问题解决,但是有了新的问题】请问大家:如何找出标记了的客户最近一次拜访日期,请看例子  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=40901)

--  作者:VICMA
--  发布时间:2013/10/5 19:17:00
--  【问题解决,但是有了新的问题】请问大家:如何找出标记了的客户最近一次拜访日期,请看例子
想做一个按钮,点击后计算所有标记了的客户,他们最近一次拜访的日期与今天比较,如果大于五天则提醒,用一个对话框显示“您有?个客户已经5天没有拜访”这样的提醒,


多谢啦!
 下载信息  [文件大小:   下载次数: ]
点击浏览该文件:客户拜访.foxdb


代码如下:多谢 有点甜老师

Dim dt As DataTable = DataTables("表A")
Dim names As List(Of String) = dt.GetUniqueValues("姓名 is not null", "姓名")
Dim count As Integer = 0
For Each name As String In names
    Dim fdr As DataRow = dt.Find("姓名 = \'" & name & "\'", "日期 desc")
    If fdr IsNot Nothing AndAlso fdr("日期") <= Date.Today.AddDays(-5) Then
        count += 1
    End If
Next
msgbox(count)


请大家看例子,问题已经解决,但是有了新的问题,想将得到名字用表A筛选出来,告诉用户哪些客户需要拜访, 请大家帮忙看看,多谢了!


[此贴子已经被作者于2013-10-6 8:36:20编辑过]

--  作者:有点甜
--  发布时间:2013/10/5 19:42:00
--  
 参考下面的代码

Dim filter As String = "标记 = true and 日期 <= #" & Date.Today.AddDays(-5) & "#"
Dim count As Integer = DataTables("表A").Compute("count(_Identify)", filter)
msgbox(count)
Tables("表A").Filter = filter

--  作者:VICMA
--  发布时间:2013/10/5 21:19:00
--  
以下是引用有点甜在2013-10-5 19:42:00的发言:
 参考下面的代码

Dim filter As String = "标记 = true and 日期 <= #" & Date.Today.AddDays(-5) & "#"
Dim count As Integer = DataTables("表A").Compute("count(_Identify)", filter)
msgbox(count)
Tables("表A").Filter = filter

非常感谢您的解答,但是还有一个问题:客户拜访的表中含有很多的历史数据,可能同一个客户我拜访了很多次,我需要找出每一个客户最近一次的拜访记录,然后在比较每一个客户的拜访时间和今天的差,您的代码找出来了所有历史数据中标记了并且日期小于今天-5,但是我只需要找出最近一次的结果即可,不然只要我打开表就会提示,因为以往的记录都符合您的条件。
问题变成了:找出每一个标记了的客户的最近拜访时间;比较这些时间同今天;如果有5天差值;就显示有多少这样的人数;

感谢帮忙看看。


--  作者:有点甜
--  发布时间:2013/10/5 21:36:00
--  
 参考代码

Dim dt As DataTable = DataTables("表A")
Dim names As List(Of String) = dt.GetUniqueValues("姓名 is not null", "姓名")
Dim count As Integer = 0
For Each name As String In names
    Dim fdr As DataRow = dt.Find("姓名 = \'" & name & "\'", "日期 desc")
    If fdr IsNot Nothing AndAlso fdr("日期") <= Date.Today.AddDays(-5) Then
        count += 1
    End If
Next
msgbox(count)

--  作者:VICMA
--  发布时间:2013/10/5 22:53:00
--  
以下是引用有点甜在2013-10-5 21:36:00的发言:
 参考代码

Dim dt As DataTable = DataTables("表A")
Dim names As List(Of String) = dt.GetUniqueValues("姓名 is not null", "姓名")
Dim count As Integer = 0
For Each name As String In names
    Dim fdr As DataRow = dt.Find("姓名 = \'" & name & "\'", "日期 desc")
    If fdr IsNot Nothing AndAlso fdr("日期") <= Date.Today.AddDays(-5) Then
        count += 1
    End If
Next
msgbox(count)

非常感谢您的解答,find方法用的太妙了!


--  作者:VICMA
--  发布时间:2013/10/6 0:18:00
--  
以下是引用有点甜在2013-10-5 21:36:00的发言:
 参考代码

Dim dt As DataTable = DataTables("表A")
Dim names As List(Of String) = dt.GetUniqueValues("姓名 is not null", "姓名")
Dim count As Integer = 0
For Each name As String In names
    Dim fdr As DataRow = dt.Find("姓名 = \'" & name & "\'", "日期 desc")
    If fdr IsNot Nothing AndAlso fdr("日期") <= Date.Today.AddDays(-5) Then
        count += 1
    End If
Next
msgbox(count)

您好,这个问题解决了,现在还想将所有符合条件的名字列出来,或者通过筛选将表A筛选成所有符合条件的表,不知您有没有办法,多谢了!



--  作者:有点甜
--  发布时间:2013/10/6 10:50:00
--  
 回复6楼

Dim dt As DataTable = DataTables("表A")
Dim names As List(Of String) = dt.GetUniqueValues("姓名 is not null", "姓名")
Dim count As Integer = 0
Dim idxs As String = ""
For Each name As String In names
    Dim fdr As DataRow = dt.Find("姓名 = \'" & name & "\'", "日期 desc")
    If fdr IsNot Nothing AndAlso fdr("日期") <= Date.Today.AddDays(-5) Then
        count += 1
        idxs += fdr("_identify") & ","
    End If
Next
msgbox(count)
If count > 0 Then
    Tables(dt.Name).Filter = "_identify in (" & idxs.Trim(",") & ")"
End If