以文本方式查看主题

-  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=93670)

--  作者:紫色幽魂
--  发布时间:2016/12/3 22:04:00
--  [求助]日期比较
请问下这段代码是哪儿出错了
Select Case e.DataCol.Name
    Case "料单_完成时间"
        If e.DataRow.IsNull("料单_完成时间") = False Then
            Dim d As DataRow = e.DataRow
            If d("料单_开始时间") > d("料单_完成时间") Then
                MessageBox.Show("完成时间不能小于开始时间","请注意",MessageBoxButtons.OK,MessageBoxIcon.Error)
                e.Cancel = True
            End If
        Else
            e.DataRow("料单_耗时") = Nothing
        End If
End Select

--  作者:有点色
--  发布时间:2016/12/4 15:35:00
--  
 有什么问题?报什么错?
--  作者:紫色幽魂
--  发布时间:2016/12/4 21:02:00
--  
我的目的是在选择完成时间的时候不能选择早于开始的时间,现在是能够选择早于开始的时间,再次选择的时候会出错,并提示设置的对话框;选择晚与开始的时间正常,不能删除单元格,也会提示
--  作者:有点酸
--  发布时间:2016/12/4 22:54:00
--  
Select Case e.DataCol.Name
    Case "料单_完成时间","料单_开始时间"
        If e.DataRow.IsNull("料单_完成时间") = False  AndAlso e.DataRow.IsNull("料单_开始时间") = False Then
            Dim d As DataRow = e.DataRow
            If d("料单_开始时间") > d("料单_完成时间") Then
                MessageBox.Show("完成时间不能小于开始时间","请注意",MessageBoxButtons.OK,MessageBoxIcon.Error)
                e.Cancel = True
            End If
        Else
            e.DataRow("料单_耗时") = Nothing
        End If
End Select

--  作者:紫色幽魂
--  发布时间:2016/12/4 23:01:00
--  
谢谢!
请问这段代码又有什么问题呢,错误提示:未将对象引用设置到对象的实例。
我的意思是料单完成时间为空,就不能增加关联行
Dim dr As DataRow = e.DataRow.GetParentRow("主表")
If dr IsNot Nothing Then
    If dr.IsNull("料单_完成时间")  = True Then
        e.Cancel = True
    End If
End If

--  作者:有点酸
--  发布时间:2016/12/4 23:07:00
--  
单单这个代码,不可能出现你所说的提示。
参考:
http://www.foxtable.com/webhelp/scr/1485.htm

可以先自行找出出错的代码,这样基本就知道原因了,搞不定,在贴出代码,告知错误代码位置和错误提示。

--  作者:紫色幽魂
--  发布时间:2016/12/4 23:08:00
--  
http://pan.baidu.com/s/1jII30W2
还是不行,完成时间还是能选择小于开始的时间,麻烦再帮我看看了

--  作者:有点酸
--  发布时间:2016/12/4 23:19:00
--  
代码写在DataColChanged事件中:

Select Case e.DataCol.Name
    Case "料单_完成时间","料单_开始时间"
        If e.DataRow.IsNull("料单_完成时间") = False  AndAlso e.DataRow.IsNull("料单_开始时间") = False Then
            Dim d As DataRow = e.DataRow
            If d("料单_开始时间") > d("料单_完成时间") Then
                MessageBox.Show("完成时间不能小于开始时间","请注意",MessageBoxButtons.OK,MessageBoxIcon.Error)
                e.DataRow(e.DataCol.name) = e.oldValue
            End If
        Else
            e.DataRow("料单_耗时") = Nothing
        End If
End Select

--  作者:紫色幽魂
--  发布时间:2016/12/5 13:41:00
--  
谢谢