Foxtable(狐表)用户栏目专家坐堂 → 两个日期间天数的计算


  共有2527人关注过本帖平板打印复制链接

主题:两个日期间天数的计算

美女呀,离线,留言给我吧!
xiaohuli
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:461 积分:3442 威望:0 精华:0 注册:2014/2/8 11:13:00
两个日期间天数的计算  发帖心情 Post By:2015/7/31 0:17:00 [只看该作者]

在绘制甘特图的时候,我写了如下代码,但代码总是有错误。周期列是表中没有的,我想通过查询表中的开始日期和结束日期来计算出周期,但是计算周期的时候不对,请老师们帮忙看看。

If DrawGannt Then
    Dim r As Row  = Tables("任务_Table1").Rows(e.Row.Index)
    Dim dt1 As Date = r("开始日期")
    Dim dt2 As Date = r("结束日期")
    Dim dt As Date = e.Col.Name.Replace("年","-").Replace("月_","-")
    If dt>=dt1 AndAlso dt<=dt2 Then
        e.StartDraw()
        If dt < Date.Today Then
            e.Graphics.FillRectangle(Brushes.Green,e.x ,e.y + 5, e.Width, e.Height - 10)
        Else
            e.Graphics.FillRectangle(Brushes.Red,e.x ,e.y + 3, e.Width, e.Height - 7)
        End If
        If r.IsNull("计划任务") = False Then
            Dim tp As TimeSpan
            Dim dr As Date
            tp = (dr("开始日期") - dr("结束日期")).TotalDays()
         
            Dim day As Double = tp / r("计划任务") * r("累计完成")
            If dt <= dt1.AddHours(24 * day) Then
                Dim d As Integer = math.Floor(day)
                If (dt-dt1).Days < d Then '满格
                    e.Graphics.FillRectangle(Brushes.Yellow,e.x ,e.y + 8, e.Width, e.Height - 16)
                Else
                    Dim width As Integer = (day - d) * e.width
                    e.Graphics.FillRectangle(Brushes.Yellow,e.x ,e.y + 8, width, e.Height - 16)
                End If
            End If
        End If
        e.EndDraw()
    End If
End If
'
'
'
'


 回到顶部