以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  请教单元格变色。  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=123086)

--  作者:jamhuton
--  发布时间:2018/8/7 16:46:00
--  请教单元格变色。
drawcell代码

If e.Col.Name = "卸箱日期" Then
    If e.Row.IsNull("卸箱日期") = False
        If e.Row("卸箱日期").AddDays(14) < Date.Today Then
            e.Style = "超期1"
        ElseIf e.Row("卸箱日期").AddDays(21) < Date.Today Then
            e.Style = "超期2"
        ElseIf e.Row("卸箱日期").AddDays(28) < Date.Today Then
            e.Style = "超期3"
        End If
    End If
End If

这代码只能显示第一个样式的颜色,下面2个显示不出来。
另外,如果我需要在另外一个单元格“送货日期”执行颜色变化,代码如何修改?

--  作者:有点甜
--  发布时间:2018/8/7 17:29:00
--  

If e.Col.Name = "送货日期" Then
    If e.Row.IsNull("卸箱日期") = False
        If e.Row("卸箱日期").AddDays(28) < Date.Today Then
            e.Style = "超期3"
        ElseIf e.Row("卸箱日期").AddDays(21) < Date.Today Then
            e.Style = "超期2"
        ElseIf e.Row("卸箱日期").AddDays(14) < Date.Today Then
            e.Style = "超期1"
        End If
    End If
End If

--  作者:jamhuton
--  发布时间:2018/8/8 9:15:00
--  
甜老师,
这代码貌似没执行


--  作者:jamhuton
--  发布时间:2018/8/8 9:16:00
--  
可以了,谢谢甜老师


--  作者:jamhuton
--  发布时间:2018/8/8 10:02:00
--  
甜老师,还有问题,如果送货日期填入了,用送货日期来代替今天的日期来执行代码呢?
--  作者:有点甜
--  发布时间:2018/8/8 10:26:00
--  
If e.Col.Name = "送货日期" Then
    Dim d As Date = e.Row("送货日期")
    If d = Nothing Then d = Date.Today
    If e.Row.IsNull("卸箱日期") = False
        If e.Row("卸箱日期").AddDays(28) < d Then
            e.Style = "超期3"
        ElseIf e.Row("卸箱日期").AddDays(21) < d Then
            e.Style = "超期2"
        ElseIf e.Row("卸箱日期").AddDays(14) < d Then
            e.Style = "超期1"
        End If
    End If
End If

--  作者:jamhuton
--  发布时间:2018/8/8 15:32:00
--  
谢谢老师

If e.DataCol.Name = "提箱日期" Then
    If e.newvalue = Nothing Then
        e.DataRow("月份1")= Nothing
        e.DataRow("年份1")= Nothing
        e.DataRow("滞箱天数") > 0
    Else
        e.DataRow("月份1") = format(e.newvalue, "yyyyMM")
        e.DataRow("年份1") = format(e.newvalue, "yyyy")
    End If
End If
我要达到“滞箱天数”大于0时再执行这个代码。


--  作者:jamhuton
--  发布时间:2018/8/8 15:35:00
--  
If e.DataCol.Name = "提箱日期" Then
    If e.newvalue = Nothing And e.DataRow("滞箱天数") > 0 Then
        e.DataRow("月份1")= Nothing
        e.DataRow("年份1")= Nothing
    Else
        e.DataRow("月份1") = format(e.newvalue, "yyyyMM")
        e.DataRow("年份1") = format(e.newvalue, "yyyy")
    End If
End If
改成这样貌似也不行

--  作者:有点甜
--  发布时间:2018/8/8 15:36:00
--  
If e.DataCol.Name = "提箱日期" orelse e.datacol.name = "滞箱天数" Then
    If e.DataRow("滞箱天数") <= 0 Then
        e.DataRow("月份1")= Nothing
        e.DataRow("年份1")= Nothing
    Else
        e.DataRow("月份1") = format(e.DataRow("提箱日期"), "yyyyMM")
        e.DataRow("年份1") = format(e.DataRow("提箱日期"), "yyyy")
    End If
End If

--  作者:jamhuton
--  发布时间:2018/8/8 15:43:00
--  
谢谢