以文本方式查看主题

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

--  作者:deliangzhaoe
--  发布时间:2019/10/7 20:13:00
--  求助,求助
表A有日期列、企业名称列等,新增一行时日期列默认值是当前日期,当修改新增行的日期列时,不能小于本企业已有记录中最晚的日期,只能大于或等于本企业已有记录中最晚的日期,如何写代码?
谢谢!

--  作者:狐狸爸爸
--  发布时间:2019/10/7 23:12:00
--  
1、DataRowAdding事件:
http://www.foxtable.com/webhelp/topics/0630.htm

e.DataRow("日期") = Date.Today

2、用DataColChaning事件:
http://www.foxtable.com/webhelp/topics/0624.htm

Slect case e.DataCol.Name
  case "日期"
        Dim min As Date = e.DataTable.Compute("Min(日期)","企业名称 = \'" & e.DataRow("企业名称") & "\'")
        Dim max As Date = e.DataTable.Compute("Max(日期)","企业名称 = \'" & e.DataRow("企业名称") & "\'"))
        if e.NewValue < min OrElse e.NewValue > Max Then
                Messagebox.show("无效日期值")
                e.Cancel = True
        End If
End Select
[此贴子已经被作者于2019/10/7 23:12:40编辑过]

--  作者:deliangzhaoe
--  发布时间:2019/10/8 21:11:00
--  
可以了,谢谢!
\'新增行日期列不得早于上一行的日期
Select Case e.DataCol.Name
    Case "日期"
        Dim min As Date = e.DataTable.Compute("Min(日期)","企业名称 = \'" & e.DataRow("企业名称") & "\'")
        Dim max As Date = e.DataTable.Compute("Max(日期)","企业名称 = \'" & e.DataRow("企业名称") & "\'")
        If e.NewValue > min AndAlso e.NewValue < Max Then
            Dim Result As DialogResult
            Result = Messagebox.show("此日期不得早于本公司最后一行的日期,不得插入行或上下移动行!        请重新输入!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            If Result = DialogResult.OK Then
                e.DataRow("日期") = Date.Today
            End If
        End If
End Select