コード例 #1
0
    private DateTime?GetValidStartDate(TextBox startDateTextBox)
    {
        DateTime startDate = DateTime.MinValue;

        if (String.IsNullOrEmpty(startDateTextBox.Text))
        {
            return(startDate);
        }

        if (!DateTime.TryParse(startDateTextBox.Text, out startDate))
        {
            throw new ArgumentException("Starting Date format is incorrect, please use MM/DD/YYYY format (ex 08/22/2008)");
        }

        if (startDate <= MinDateTime ||
            startDate >= MaxDateTime)
        {
            throw new ArgumentOutOfRangeException("StartingDate", String.Format("Starting Date format is incorrect, it must be between %0 and %1", MinDateTime.ToString(), MaxDateTime.ToString()));
        }

        return(startDate);
    }
コード例 #2
0
    private DateTime?GetValidEndDate(TextBox endDateTextBox)
    {
        DateTime endDate = DateTime.Now;

        if (String.IsNullOrEmpty(endDateTextBox.Text))
        {
            endDate = MaxDateTime;
        }
        else if (!DateTime.TryParse(endDateTextBox.Text, out endDate))
        {
            throw new ArgumentException("End Date format is incorrect, please use MM/DD/YYYY format (ex 04/21/2009)");
        }

        if (endDate < MinDateTime ||
            endDate > MaxDateTime)
        {
            throw new ArgumentOutOfRangeException("Ending Date", String.Format("End Date format is incorrect, it must be between %0 and %1", MinDateTime.ToString(), MaxDateTime.ToString()));
        }

        return(endDate);
    }