Foxtable(狐表)用户栏目专家坐堂 → [求助]日期统计问题


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

主题:[求助]日期统计问题

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


加好友 发短信
等级:婴狐 帖子:74 积分:629 威望:0 精华:0 注册:2013/5/13 4:03:00
[求助]日期统计问题  发帖心情 Post By:2014/8/15 1:13:00 [只看该作者]

老师,我今天在学习日期统计。
看了筛选树显示统计数据  但还不能举一反三

有个案例老师能不能给知道一下

我有个信息录入表,在表里录入了,然后在窗口建立了一个TreeView(目录树)有点像下面的图

不过我的统计方式的:例如:开piao员张三2013年共开了多少次 小面是按月分 例如1月下面  1月1日开了三次piao 1月2日开了4次piao,一直到12与31日
                                    
                                    开piao员王五开了多少次
下面依次类推


[此贴子已经被作者于2014-8-18 14:25:33编辑过]

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


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/8/15 8:32:00 [只看该作者]

你的表,没看懂要怎么生成目录树,怎么统计也没看懂.

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/15 9:13:00 [只看该作者]

 也没看懂。

 

 第一级是姓名,第二级是年,第三级是月,第四级是日?


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


加好友 发短信
等级:婴狐 帖子:74 积分:629 威望:0 精华:0 注册:2013/5/13 4:03:00
  发帖心情 Post By:2014/8/15 9:22:00 [只看该作者]

统计形式像:


例如:李三   
             2013年(108张)
                1月(21张)
                    1月1日(3张)
                    1月2日(0张)
                    1月3日(1张)
                    1月4日(5张)
                    ......
                    1月31日(6张)
                 2月(80张)
                    2月1日(3张)
                    2月2日(0张)
                    2月3日(1张)
                    2月4日(5张)
                    ......
                    2月28日(6张)
                 3月(1000张)
                       3月1日(2张)

                  .........
                 12月(51222张)
一直到开的最后1天

         王五重复以上的形式


[此贴子已经被作者于2014-8-15 9:23:04编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/15 10:08:00 [只看该作者]

 。。。。。。代码

 

Dim cmd As new SQLCommand
cmd.CommandText = "Select 开piao人信息_姓名 As 姓名,开piao日期1_日期 As 日期, year(开piao日期1_日期) As 年, month(开piao日期1_日期) As 月, day(开piao日期1_日期) As 日, 1 as 开单 from {信息录入表} where 开piao人信息_姓名 Is not null " _
& " union Select 开piao人信息_姓名,开piao日期2_日期, year(开piao日期2_日期), month(开piao日期2_日期) As 月, day(开piao日期2_日期), 1 from {信息录入表} where 开piao人信息_姓名 Is not null" _
& " union Select 开piao人信息_姓名,开piao日期3_日期, year(开piao日期3_日期), month(开piao日期3_日期) As 月, day(开piao日期3_日期), 1 from {信息录入表} where 开piao人信息_姓名 Is not null"
Dim dt As DataTable = cmd.ExecuteReader

For Each ary As String() In dt.GetValues("姓名|年")
    For i As Integer = 1 To 12
        For j As Integer = 1 To Date.DaysInMonth(ary(1),i)
            Dim d As Date = new Date(ary(1), i, j)
            Dim fdr As DataRow = dt.Find("姓名 = '" & ary(0) & "' and 日期 = #" & d & "#")
            If fdr Is Nothing Then
                fdr = dt.AddNew
                fdr("姓名") = ary(0)
                fdr("日期") = d
                fdr("年") = ary(1)
                fdr("月") = i
                fdr("日") = j
                fdr("开单") = 0
            End If
        Next
    Next
Next

Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1")
tv.BuildTree(dt, "姓名|年|月|日")
For Each nd As WinForm.TreeNode In tv.AllNodes
    Select Case nd.Level
        Case 0
            nd.Text = nd.Text & "(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1") & "张)"
        Case 1
            nd.Text = nd.Text & "年(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "'") & "张)"
        Case 2
            nd.Text = nd.Text & "月(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "' and 月 = '" & nd.DataRow("月") & "'") & "张)"
        Case 3
            nd.Text = nd.DataRow("月") & "月" & nd.Text & "日(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "' and 月 = '" & nd.DataRow("月") & "' and 日 = '" & nd.DataRow("日") & "'") & "张)"
    End Select
Next


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


加好友 发短信
等级:婴狐 帖子:74 积分:629 威望:0 精华:0 注册:2013/5/13 4:03:00
  发帖心情 Post By:2014/8/15 11:41:00 [只看该作者]

老师, 谢谢你提供的代码。太感谢了。我安装你提供的代码做了修改,当系统提示
.NET Framework 版本:2.0.50727.5483
Foxtable 版本:2014.8.4.1
错误所在事件:
详细错误信息:
SELECT 子句中包含一个保留字、拼写错误或丢失的参数,或标点符号不正确。




代码如下:


Dim cmd As new SQLCommand
cmd.CommandText = "Select Masseur_Name As Name,Date①_Date As Date, year(Date①_Date) As 年, month(Date①_Date) As 月, day(Date①_Date) As 日, 1 as 开单 from {Information} where Masseur_Name Is not null " _
& " union Select Masseur_Name,Date②_Date, year(Date②_Date), month(Date②_Date) As 月, day(Date②_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date③_Date, year(Date③_Date), month(Date③_Date) As 月, day(Date③_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date④_Date, year(Date④_Date), month(Date④_Date) As 月, day(Date④_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑤_Date, year(Date⑤_Date), month(Date⑤_Date) As 月, day(Date⑤_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑥_Date, year(Date⑥_Date), month(Date⑥_Date) As 月, day(Date⑥_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑦_Date, year(Date⑦_Date), month(Date⑦_Date) As 月, day(Date⑦_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑧_Date, year(Date⑧_Date), month(Date⑧_Date) As 月, day(Date⑧_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑨_Date, year(Date⑨_Date), month(Date⑨_Date) As 月, day(Date⑨_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑩_Date, year(Date⑩_Date), month(Date⑩_Date) As 月, day(Date⑩_Date), 1 from {Information} where Masseur_Name Is not null" 

Dim dt As DataTable = cmd.ExecuteReader
For Each ary As String() In dt.GetValues("Name|年")
    For i As Integer = 1 To 12
        For j As Integer = 1 To Date.DaysInMonth(ary(1),i)
            Dim d As Date = new Date(ary(1), i, j)
            Dim fdr As DataRow = dt.Find("Name = '" & ary(0) & "' and Date = #" & d & "#")
            If fdr Is Nothing Then
                fdr = dt.AddNew
                fdr("Name") = ary(0)
                fdr("Date") = d
                fdr("年") = ary(1)
                fdr("月") = i
                fdr("日") = j
                fdr("开单") = 0
            End If
        Next
    Next
Next
Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1")
tv.BuildTree(dt, "Name|年|月|日")
For Each nd As WinForm.TreeNode In tv.AllNodes
    Select Case nd.Level
        Case 0
            nd.Text = nd.Text & "(" & dt.Compute("count(Name)", "Name = '" & nd.DataRow("Name") & "' and 开单 = 1") & "张)"
        Case 1
            nd.Text = nd.Text & "年(" & dt.Compute("count(Name)", "Name = '" & nd.DataRow("Name") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "'") & "张)"
        Case 2
            nd.Text = nd.Text & "月(" & dt.Compute("count(Name)", "Name = '" & nd.DataRow("Name") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "' and 月 = '" & nd.DataRow("月") & "'") & "张)"
        Case 3
            nd.Text = nd.DataRow("月") & "月" & nd.Text & "日(" & dt.Compute("count(Name)", "Name = '" & nd.DataRow("Name") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "' and 月 = '" & nd.DataRow("月") & "' and 日 = '" & nd.DataRow("日") & "'") & "张)"
    End Select
Next

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/15 11:51:00 [只看该作者]

你看看是不是name和date的问题,改成别的名字,比如 名字、日期 或者 tname、tdate

 

----------------------------

 

1、你加入代码output.show(cmd.CommandText) 然后在命令窗口看一下得出的sql语句是什么;

 

2、拷贝得出的sql语句,测试一下,看报什么错 http://www.foxtable.com/help/topics/1484.htm

 


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


加好友 发短信
等级:婴狐 帖子:74 积分:629 威望:0 精华:0 注册:2013/5/13 4:03:00
  发帖心情 Post By:2014/8/15 11:56:00 [只看该作者]

提示是:

无效的 SQL语句;期待 'DELETE'、'INSERT'、'PROCEDURE'、'SELECT'、或 'UPDATE'。

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/15 11:58:00 [只看该作者]

 把 As Date 改成 As 日期

 

 下面对应的也改一下


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


加好友 发短信
等级:婴狐 帖子:74 积分:629 威望:0 精华:0 注册:2013/5/13 4:03:00
  发帖心情 Post By:2014/8/15 12:10:00 [只看该作者]

继续提示:

.NET Framework 版本:2.0.50727.5483
Foxtable 版本:2014.8.4.1
错误所在事件:窗口,日期查询,AfterLoad
详细错误信息:
从字符串“”到类型“Integer”的转换无效。
输入字符串的格式不正确。



修改后的代码

Dim cmd As new SQLCommand
cmd.CommandText = "Select Masseur_Name As 姓名,Date①_Date As 日期, year(Date①_Date) As 年, month(Date①_Date) As 月, day(Date①_Date) As 日, 1 as 开单 from {Information} where Masseur_Name Is not null " _
& " union Select Masseur_Name,Date②_Date, year(Date②_Date), month(Date②_Date) As 月, day(Date②_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date③_Date, year(Date③_Date), month(Date③_Date) As 月, day(Date③_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date④_Date, year(Date④_Date), month(Date④_Date) As 月, day(Date④_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑤_Date, year(Date⑤_Date), month(Date⑤_Date) As 月, day(Date⑤_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑥_Date, year(Date⑥_Date), month(Date⑥_Date) As 月, day(Date⑥_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑦_Date, year(Date⑦_Date), month(Date⑦_Date) As 月, day(Date⑦_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑧_Date, year(Date⑧_Date), month(Date⑧_Date) As 月, day(Date⑧_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑨_Date, year(Date⑨_Date), month(Date⑨_Date) As 月, day(Date⑨_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑩_Date, year(Date⑩_Date), month(Date⑩_Date) As 月, day(Date⑩_Date), 1 from {Information} where Masseur_Name Is not null" 

Dim dt As DataTable = cmd.ExecuteReader
For Each ary As String() In dt.GetValues("姓名|年")
    For i As Integer = 1 To 12
        For j As Integer = 1 To Date.DaysInMonth(ary(1),i)
            Dim d As Date = new Date(ary(1), i, j)
            Dim fdr As DataRow = dt.Find("姓名 = '" & ary(0) & "' and 日期 = #" & d & "#")
            If fdr Is Nothing Then
                fdr = dt.AddNew
                fdr("姓名") = ary(0)
                fdr("日期") = d
                fdr("年") = ary(1)
                fdr("月") = i
                fdr("日") = j
                fdr("开单") = 0
            End If
        Next
    Next
Next
Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1")
tv.BuildTree(dt, "姓名|年|月|日")
For Each nd As WinForm.TreeNode In tv.AllNodes
    Select Case nd.Level
        Case 0
            nd.Text = nd.Text & "(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1") & "张)"
        Case 1
            nd.Text = nd.Text & "年(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "'") & "张)"
        Case 2
            nd.Text = nd.Text & "月(" & dt.Compute("count(姓名)", "Name = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "' and 月 = '" & nd.DataRow("月") & "'") & "张)"
        Case 3
            nd.Text = nd.DataRow("月") & "月" & nd.Text & "日(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "' and 月 = '" & nd.DataRow("月") & "' and 日 = '" & nd.DataRow("日") & "'") & "张)"
    End Select
Next

 回到顶部
总数 12 1 2 下一页