以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  日期比较  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=110263)

--  作者:nxqtxwz
--  发布时间:2017/11/30 8:35:00
--  日期比较

老师好!我有一个出差记录表,其中的一列是“出差时限“,这个列是用窗口输入的,想把出差时限中第一个日期与当天日期想比,如果“出差日期”<系统日期,则要求重新输入,否则正常。请问老师怎么来写代码呢。


--  作者:有点甜
--  发布时间:2017/11/30 8:38:00
--  

datacolchanging事件

 

If e.datacol.name = "出差时艰" then

    If e.NewValue < date.Today Then

        msgbox("有误")

        e.cancel = true

    End If

End If


--  作者:nxqtxwz
--  发布时间:2017/11/30 8:57:00
--  

老师,出现现面的错误怎么解决呢?表中出差时限是这样的:2017年11月7日-12月8日

 

.NET Framework 版本:2.0.50727.5485
Foxtable 版本:2017.10.26.1
错误所在事件:表,出差记录,DataColChanging
详细错误信息:
调用的目标发生了异常。
从字符串“2017年11月7日-12月8日”到类型“Date”的转换无效。


--  作者:有点甜
--  发布时间:2017/11/30 9:17:00
--  

1、规范你输入的字符,必须是同一种格式;

 

2、参考代码

 

Dim str As String = "2017年11月7日-12月8日"
Dim ary1() As String = str.split("-")
Dim ary2() As String = ary1(0).split(new Char() {"年", "月", "日"})
Dim ary3() As String = ary1(1).split(new Char() {"年", "月", "日"})
Dim d1 As Date = new Date(ary2(0), ary2(1), ary2(2))
Dim d2 As Date = new Date(ary2(0), ary3(0), ary3(1))
msgbox(d1)
msgbox(d2)
If d1 > d2 Then
    msgbox("不正确")
ElseIf d1 < Date.today Then
    msgbox("开始日期不能小于今天")
End If


--  作者:nxqtxwz
--  发布时间:2017/11/30 9:35:00
--  
老师,是不是只比较了“日”而没有比较“年”和“月”,12月的1日应该是比11月的30日大才符合实际。
--  作者:nxqtxwz
--  发布时间:2017/11/30 9:38:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:出差管理.zip


--  作者:有点甜
--  发布时间:2017/11/30 9:52:00
--  

If e.DataCol.name = "时限" Then
    Dim str As String = e.NewValue
    Dim ary1() As String = str.split("-")
    Dim ary2() As String = ary1(0).split(new Char() {"年", "月", "日"})
    Dim ary3() As String = ary1(1).split(new Char() {"年", "月", "日"})
    Dim d1 As Date = new Date(ary2(0), ary2(1), ary2(2))
    Dim d2 As Date = new Date(ary2(0), ary3(0), ary3(1))
    msgbox(d1)
    msgbox(d2)
    If d1 > d2 Then
        msgbox("不正确")
    ElseIf d1 <= Date.today Then
        msgbox("开始日期不能小于今天")
    End If
End If


--  作者:nxqtxwz
--  发布时间:2017/11/30 10:41:00
--  
老师,能不能把代码写在日期输入框的事件中呢。我用两个日期输入框输入“时限”,第一个输入框输入后即与系统日期比较,如果小于系统日期就要求重输入。第二个日期输入框输入完后和第一个对比,如果小于第一个就显示出错。
--  作者:有点甜
--  发布时间:2017/11/30 10:55:00
--  

validating事件

Dim d As String = e.sender.text
If d <> Nothing AndAlso d <= Date.today Then
    msgbox("不能早于今天")
    e.cancel = True
End If

 

validating事件

Dim d1 As Date = e.Form.Controls("DateTimePicker1").value
Dim d2 As String = e.Form.Controls("DateTimePicker2").text
If d1 <> Nothing AndAlso d2 <> Nothing AndAlso d1 > d2 Then
    msgbox("开始不能大于结束")
    e.cancel = True
End If