preventing users from adding back dated data through data entry

Answered preventing users from adding back dated data through data entry

  • Friday, July 27, 2012 7:12 AM
     
     

    Hi

    Is there a way to prevent users from entering back dated values ?

    I used the following code, but a change in system date will make it void, I have a field called Tdate (TDate = Today).

    Private Sub Tdate_Validate(results As EntityValidationResultsBuilder)
                ' results.AddPropertyError("<Error-Message>")
                If Tdate < Today Then
                    results.AddPropertyError("Date cannot be backdated")
                End If
                If Tdate > Today Then
                    results.AddPropertyError("Date cannot be future dated")
                End If
            End Sub

    • Edited by M.Prasad Friday, July 27, 2012 7:18 AM change
    •  

All Replies

  • Friday, July 27, 2012 10:31 AM
     
     

    Hi, M.Prasad.

    With my applications, I use an additional date test. Get the latest saved date from Tdate and:

    dim latestDate = MyCollection.Max(Function(n) n.TDate)

    If (Tdate < Today) OrElse (Tdate < latestDate) then

       results.AddProperty(".......")

    You can improve this method: every time that your application is openned, save the current date and used it to avoid back date input.

    I hope it helps you.

    Best regards,


    Ciro

  • Friday, July 27, 2012 11:34 AM
    Moderator
     
     Answered
    If you don't want dates prior to today's date, & you also don't want dates that are after today's date, why don't you just set the property to today's date in the EntityName_Created method, then make the property read-only on the screen?

    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    • Proposed As Answer by Brian Kidd Friday, July 27, 2012 4:29 PM
    • Marked As Answer by M.Prasad Tuesday, July 31, 2012 3:32 AM
    •