Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 615
  • Last Modified:

Auto refresh page when condition is met

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
JessyRobinson1234
Asked:
JessyRobinson1234
  • 2
1 Solution
 
OnthraxCommented:
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
 
b0lsc0ttIT ManagerCommented:
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
 
JessyRobinson1234Author Commented:
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
 
OnthraxCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now