Solved

Issues with Date Range Picker

Posted on 2008-10-06
14
329 Views
Last Modified: 2010-04-21
I am working on Date Range Picker where a user can pick specific date and according to the date range (parameter passed) he will be displayed the report. Right now everything works fine untill a user chooses his start date and end date as the same day. eg start date 10/06/2008 and enddate 10/06/2008, the report then errors out.

I want to insert a logic below, if the SelectedBeginDate = SelectedEndDate. I want SelectedEndDate added by a day. Say a user chooses start date 10/06/2008 and enddate 10/06/2008 ..the end date should be converted as 10/07/2008..I have been trying this for couple of hours but in vain...How do i do this?..please advice
Private Function DateRangeIsValid(ByVal dateRange As DateRangePicker) As Boolean

        If (IsNothing(dateRange.SelectedBeginDate) And IsNothing(dateRange.SelectedEndDate)) Then

            Return True

        Else

            If (IsNothing(dateRange.SelectedBeginDate) And Not IsNothing(dateRange.SelectedEndDate)) Or _

               (Not IsNothing(dateRange.SelectedBeginDate) And IsNothing(dateRange.SelectedEndDate)) Then

                Return False

            End If
 

        End If

        Return dateRange.SelectedEndDate.Value.Date >= dateRange.SelectedBeginDate.Value.Date

    End Function
 

End Class

Open in new window

0
Comment
Question by:Kerau
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22653577
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 22653656
I've never used your control so I don't know if this will work:
(at the very least you can simplify your logic in the beginning like this)

    Private Function DateRangeIsValid(ByVal dateRange As DateRangePicker) As Boolean
        If IsNothing(dateRange.SelectedBeginDate) AndAlso IsNothing(dateRange.SelectedEndDate) Then
            Return True ' Both are Nothing
        ElseIf IsNothing(dateRange.SelectedBeginDate) OrElse IsNothing(dateRange.SelectedEndDate) Then
            Return False ' Only one is Nothing
        End If

        If dateRange.SelectedEndDate.Value.Date = dateRange.SelectedBeginDate.Value.Date Then
            dateRange.SelectedEndDate.Value = dateRange.SelectedEndDate.Value.AddDays(1)
        End If

        Return dateRange.SelectedEndDate.Value.Date >= dateRange.SelectedBeginDate.Value.Date
    End Function
0
 

Author Comment

by:Kerau
ID: 22653680
Thanks to both of you IDLE_MIND and ASPSQLSERVERCOM. I will check this and get back to you asap
0
 

Author Comment

by:Kerau
ID: 22653767
'dateRange.SelectedEndDate.Value = dateRange.SelectedEndDate.Value.AddDays(1)  ' It says expression is a value and therefore can't be the target of an assignment
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 22653821
Can you do it this way?

        If dateRange.SelectedEndDate.Value.Date = dateRange.SelectedBeginDate.Value.Date Then
            Dim dt As Date = dateRange.SelectedEndDate.Value.AddDays(1)
            dateRange.SelectedEndDate.Value = New Date(dt.Year, dt.Month, dt.Day)
        End If
0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22653846
use
Dim dtDate As Date
        dtDate = DateTime.Parse(stDate, Globalization.CultureInfo.CreateSpecificCulture("en-CA"))
        dtDate = dtDate.AddDays(1)
0
 

Author Comment

by:Kerau
ID: 22653899
Idle MInd its showing up the same error

.....says expression is a value and therefore can't be the target of an assignment
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 22653939
I'm not sure how to fix it then sorry...
0
 

Author Comment

by:Kerau
ID: 22653992
Should i write something on the btn_submit event ...what would you suggest?????
   Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        If Page.IsValid Then

            Dim urlString As String = ""

            Select Case Me.ddlReports.SelectedValue

                Case "abc.aspx"

                    urlString = String.Format("abc.aspx?dteBegin={0}&dteEnd={1}", Me.drpReportDates.SelectedBeginDate.Value.ToShortDateString, Me.drpReportDates.SelectedEndDate.Value.ToShortDateString)

                Case "bcd.aspx"

                    urlString = String.Format("bcd.aspx?dteBegin={0}&dteEnd={1}", Me.drpReportDates.SelectedBeginDate.Value.ToShortDateString, Me.drpReportDates.SelectedEndDate.Value.ToShortDateString)

            End Select

            Dim scriptString As New StringBuilder

            scriptString.Append("<script language=JavaScript>")

            scriptString.Append("window.open('" + urlString + "')")

            scriptString.Append("</script>")

            If (Not ClientScript.IsStartupScriptRegistered("Startup")) Then

                ClientScript.RegisterStartupScript(GetType(Page), "Startup", scriptString.ToString)

            End If

        End If

    End Sub

Open in new window

0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 50 total points
ID: 22654749
I don't write web stuff so I'm not sure what the best approach is...

Can't you leave the Function like this?

    Private Function DateRangeIsValid(ByVal dateRange As DateRangePicker) As Boolean
        If IsNothing(dateRange.SelectedBeginDate) AndAlso IsNothing(dateRange.SelectedEndDate) Then
            Return True ' Both are Nothing
        ElseIf IsNothing(dateRange.SelectedBeginDate) OrElse IsNothing(dateRange.SelectedEndDate) Then
            Return False ' Only one is Nothing
        End If

        Return dateRange.SelectedEndDate.Value.Date >= dateRange.SelectedBeginDate.Value.Date
    End Function

Then adjust the dates AFTER you call the function?

    ' ...from where ever you call DateRangeIsValid() above...
    If DateRangeIsValid(someDateRange) Then
        Dim beginDate As Date = dateRange.SelectedBeginDate.Value.Date
        Dim endDate as Date = dateRange.SelectedEndDate.Value.Date
        endDate = IIf(endDate = beginDate, endDate.AddDays(1),  endDate)

        ' ...do something with "beginDate" and "endDate"...

    End If

But again, I don't do web stuff and I haven't used this control before so I may not be making any sense...apologies if this is the case.  =)
0
 
LVL 7

Assisted Solution

by:ASPSQLServerCOM
ASPSQLServerCOM earned 50 total points
ID: 22659855
 Private Function DateRangeIsValid(ByVal dateRange As DateRangePicker) As Boolean
Dim dtDate As Date
       
        If IsNothing(dateRange.SelectedBeginDate) AndAlso IsNothing(dateRange.SelectedEndDate) Then
            Return True ' Both are Nothing
        ElseIf IsNothing(dateRange.SelectedBeginDate) OrElse IsNothing(dateRange.SelectedEndDate) Then
            Return False ' Only one is Nothing
        End If

        If dateRange.SelectedEndDate.Value.Date = dateRange.SelectedBeginDate.Value.Date Then
 dtDate = DateTime.Parse(dateRange.SelectedEndDate.Value, Globalization.CultureInfo.CreateSpecificCulture("en-CA"))
        dtDate = dtDate.AddDays(1)

            dateRange.SelectedEndDate.Value = dtDate.ToString
        End If

        Return dateRange.SelectedEndDate.Value.Date >= dateRange.SelectedBeginDate.Value.Date
    End Function

Or could you please tell us exactly what is the programming logic you want to implement
0
 

Author Comment

by:Kerau
ID: 22660120
.....says expression is a value and therefore can't be the target of an assignment.

Now if you are looking for an exact logic, please refer to my comment on ID:22653992 for codes. Here is the issue, if the selected case is abc.aspx, i don't have to add any date and it works fine with date params as 10/07/2008 to 10/07/2008.  But if the selected case is bcd.aspx, the report errors out stating "Failed to retrieve data from the database. Error in File C:\WINDOWS\TEMP\{864593B4-3C48-485A-8E24-B40C9BEDE6AE}.rpt".

Right now What i did on the statement: "Return dateRange.SelectedEndDate.Value.Date >= dateRange.SelectedBeginDate.Value.Date" removed "=" (without the quotes) from the statement and it works fine. But it doesn't allow user to choose/validate the same day on DateRangePicker, which again is kinda workaround :). But the requirement suggests that we need to be able to pass same date on the DateRangePicker. Any ideas....
0
 
LVL 18

Accepted Solution

by:
David Robitaille earned 400 total points
ID: 22671249
0
 

Author Closing Comment

by:Kerau
ID: 31503548
Thanks All
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I build my own IDE using ASP.NET MVC? 2 34
What .NET URL re-routing tool did I use? 2 38
Receiving a string from a WebService Push 21 38
Entity Framework 7 33
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now