Solved

Auto refresh page when condition is met

Posted on 2009-05-07
4
575 Views
Last Modified: 2012-06-27
I have an asp page that needs to be auto refreshed when following conditions are met:

If DatePart(DateInterval.Hour, Now()) >= 4 And DatePart(DateInterval.Hour, Now()) <= 15 Then
            strShift = "1st Shift"
        Else
            strShift = "2nd Shift"
        End If

        '     Determine Number of Trucks
        If strShift = "1st Shift" Then
            q = "SELECT V.CVEHICLENUMBER AS [VEHICLE_NUMBER], COUNT(YMH.IYARDMOVEHISTORYID) AS [COUNT], CAST(AVG((DATEDIFF(S, DADDED, DARCHIVED) / 60.0)) AS DECIMAL(4,2)) AS [CYCLE_TIME] FROM YARDMOVEHISTORY AS YMH WITH(NOLOCK) JOIN VEHICLES AS V WITH(NOLOCK) ON V.IVEHICLEID = YMH.IVEHICLEID WHERE (DATEPART(HH,YMH.DADDED) BETWEEN 4 AND 15) AND DATEDIFF(D,DADDED,GETDATE()) = 0 AND YMH.CSTATUS = 'COMPLETE' AND YMH.ISITEID IN ('1','2') AND V.LACTIVE = '1' GROUP BY V.CVEHICLENUMBER ORDER BY V.CVEHICLENUMBER;"
            cDA.RunQueryDataSetResult(DS, CSYMS, q, "trucks")
        End If

        If strShift = "2nd Shift" And DatePart(DateInterval.Hour, Now()) >= 16 And DatePart(DateInterval.Hour, Now()) <= 23 Then
            q = "SELECT V.CVEHICLENUMBER AS [VEHICLE_NUMBER], COUNT(YMH.IYARDMOVEHISTORYID) AS [COUNT], CAST(AVG((DATEDIFF(S, DADDED, DARCHIVED) / 60.0)) AS DECIMAL(4,2)) AS [CYCLE_TIME] FROM YARDMOVEHISTORY AS YMH WITH(NOLOCK) JOIN VEHICLES AS V WITH(NOLOCK) ON V.IVEHICLEID = YMH.IVEHICLEID WHERE (DATEPART(HH,YMH.DADDED) BETWEEN 16 AND 23) AND DATEDIFF(D,DADDED,GETDATE()) = 0 AND YMH.CSTATUS = 'COMPLETE' AND YMH.ISITEID IN ('1','2') AND V.LACTIVE = '1' GROUP BY V.CVEHICLENUMBER ORDER BY V.CVEHICLENUMBER;"
            cDA.RunQueryDataSetResult(DS, CSYMS, q, "trucks")
        End If

        If strShift = "2nd Shift" And DatePart(DateInterval.Hour, Now()) >= 0 And DatePart(DateInterval.Hour, Now()) <= 3 Then
            q = "SELECT V.CVEHICLENUMBER AS [VEHICLE_NUMBER], COUNT(YMH.IYARDMOVEHISTORYID) AS [COUNT], CAST(AVG((DATEDIFF(S, DADDED, DARCHIVED) / 60.0)) AS DECIMAL(4,2)) AS [CYCLE_TIME] FROM YARDMOVEHISTORY AS YMH WITH(NOLOCK) JOIN VEHICLES AS V WITH(NOLOCK) ON V.IVEHICLEID = YMH.IVEHICLEID WHERE ((DATEPART(HH,YMH.DADDED) BETWEEN 16 AND 23) AND DATEDIFF(D,DADDED,GETDATE()) = 1 AND YMH.CSTATUS = 'COMPLETE' AND YMH.ISITEID IN ('1','2') AND V.LACTIVE = '1') OR ((DATEPART(HH,YMH.DADDED) BETWEEN 0 AND 3) AND DATEDIFF(D,DADDED,GETDATE()) = 0 AND YMH.CSTATUS = 'COMPLETE' AND YMH.ISITEID IN ('1','2') AND V.LACTIVE = '1') GROUP BY V.CVEHICLENUMBER ORDER BY V.CVEHICLENUMBER;"
            cDA.RunQueryDataSetResult(DS, CSYMS, q, "trucks")
        End If

How would I do that? I currently use a timer with an interval of 5000 but I want it to refresh only when the next shift starts.

Thanks
0
Comment
Question by:JessyRobinson1234
  • 2
4 Comments
 
LVL 13

Expert Comment

by:Onthrax
ID: 24330628
You would need to look into Ajax. You could make request to the server using javascript, determing your statement.

If DatePart(DateInterval.Hour, Now()) >= 4 And DatePart(DateInterval.Hour, Now()) <= 15 Then

If it's met, you can refresh the page.

Take a look into Ajax and let me know if you have any more questions.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24331143
JessyRobinson1234,

It seems the condition for the refresh uses ASP code.  Is that correct?  You need to change that.  Can you send something in Javascript to the browser to use for the refresh?  More exact than the interval of 5 seconds but still in Javascript?  Otherwise you will need to use an interval and just check a number of times.  The ASP code can't know that something has changed and "push" it to the browser and page (i.e. force the refresh).  AJAX could be useful but just in the fact that it wouldn't be a complete page reload (i.e. the browser and Javascript could check in the background).

Let me know if you have any questions or need more information.

b0lsc0tt
0
 

Author Comment

by:JessyRobinson1234
ID: 24367517
Here's the asp snippet of the ASPX page:

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"  />
            </Triggers>
            <ContentTemplate>
 chart code...
            </ContentTemplate>
        </asp:UpdatePanel>

I would like to manage the trigger and refresh the update panel programmatically based on the time of the day (Like Onthrax indicated)

If DatePart(DateInterval.Hour, Now()) >= 4 And DatePart(DateInterval.Hour, Now()) <= 15 Then

Update panel and run the associated query to feed the chart.

I have no idea how to even start on this.
0
 
LVL 13

Accepted Solution

by:
Onthrax earned 500 total points
ID: 24372061
I hadn't realised you were using asp.NET. For future questions this would be relevant to state as classic asp requires a different approach than asp.net.

Anyways, as you are using asp.net you can easily trigger an updatepanel by javascript.

Check out this tutorial: http://www.asp.net/learn/ajax-videos/video-172.aspx

Hope this helps...
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 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

14 Experts available now in Live!

Get 1:1 Help Now