Check that the start date cannot exceed the end time

Source: Internet
Author: User

1, winform
 
[Csharp]
# Region calendar Control
 
Private void dteStartDate_Validating (object sender, CancelEventArgs e)
{
If (! CheckStartDateEndDate (true ))
{
XtraMessageBox. Show ("start date cannot be later than end date ");
DteStartDate. Focus ();
E. Cancel = true;
}
}
 
Private void dteEndDate_Validating (object sender, CancelEventArgs e)
{
If (! CheckStartDateEndDate (false ))
{
XtraMessageBox. Show ("the end date cannot be earlier than the start date ");
DteEndDate. Focus ();
E. Cancel = true;
}
}
 
# Endregion
 
Private bool CheckStartDateEndDate (bool bLeaveFromStartDate)
{
If (! (String. IsNullOrEmpty (dteStartDate. Text) | string. IsNullOrEmpty (dteEndDate. Text )))
{
If (Convert. ToDateTime (dteStartDate. Text)> Convert. ToDateTime (dteEndDate. Text ))
{
If (bLeaveFromStartDate)
{
Return false;
}
Else
{
Return false;
}
}
}
Return true;
}
 
2. web
 
 
 
[Csharp]
If (txtStartDate. Value = null |! PageValidate. IsDateTime (txtStartDate. Value. ToString ()))
 
StrErr + = "enter the correct start date! \ N ";
 
If (txtEndDate. Value = null |! PageValidate. IsDateTime (txtEndDate. Value. ToString ()))
 
StrErr + = "Enter the end date of the correct www.2cto.com! \ N ";
 
 
If (Convert. ToDateTime (txtStartDate. Value. ToString (). CompareTo (Convert. ToDateTime (txtEndDate. Value. ToString ()> 0)
{
StrErr + = "the start time cannot be later than the end time! \ N ";
}
 
# Region date format judgment
/// <Summary>
/// Date Format String judgment
/// </Summary>
/// <Param name = "str"> </param>
/// <Returns> </returns>
Public static bool IsDateTime (string str)
{
Try
{
If (! String. IsNullOrEmpty (str ))
{
DateTime. Parse (str );
Return true;
}
Else
{
Return false;
}
}
Catch
{
Return false;
}
}
# Endregion
 
 
From the column keenweiwei

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.