Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do I compare/validate 2 datetimePickers that are in different forms? eg.I have separate check in/out forms ,and I want to validate that a user not check out before checking in.
Posted
Comments
jackspero18 30-Jul-13 4:26am    
Pass Check In value to next Form & compare it
Sushil Mate 30-Jul-13 4:27am    
when user selects the check in date from check in form & opens the check out form you can pass the check in date from check in form, & assign that date to check out to datepicker. DateTimePicker.MinDate

C#
checkout co= new checkout(datepicker);
            co.ShowDialog(this);


C#
public CheckOut(string k)
       {

           InitializeComponent();
           lbldate.Text= k;


       }
 
Share this answer
 
v2
Both forms are User Interface components. They shouldn't store information, just visualize (including the possibility to change) it. So both forms should target the same data set. Value range checks then belong to setters in the data model part:
C#
public class SomeTimeRelatedStuff
{
    private DateTime _checkInTime;
    private DateTime _checkOutTime;

    public DateTime CheckInTime
    {
        get { return(_checkInTime); }
        set { _checkInTime = value; }
    }

    public DateTime CheckOutTime
    {
        get { return(_checkOutTime); }
    }

    public bool SetCheckOutTime(DateTime checkOutTime)
    {
        if(checkOutTime < _checkInTime)
        {
            return(false);
        }

        _checkOutTime = checkOutTime;
        return(true);
    }
}
In your UI code, you then call SetCheckOutTime() with the value that user has entered. The return value tells you if that value has been accepted.

The nice part is that the checking is done in the data class. That class should know about its data and the relations that it has to have to its several parts. That helps keeping UI code clean of business logic.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900