Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Auto refresh page when condition is met

Posted on 2009-05-07
4
Medium Priority
?
598 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

604 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