p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: ASP.NET 4 Website Programming Problem Design Solution (http://p2p.wrox.com/forumdisplay.php?f=540)
-   -   Code for Call timer (http://p2p.wrox.com/showthread.php?t=94350)

gallbat April 2nd, 2015 02:40 AM

Code for Call timer
 
I hardly understood this code, but what this essentially does is; In the code behind it calculates the timespan in milliseconds, and In the asp page, we call getSecs() function on load, which will calculate the call timer. (They want to capture, how much time a customer care associate is spending on the call, in HH:MM:SS format). When the application page loads it should be 00:00:00 and it should increment the timer as the time progress. We doesn't want to refresh the time, when we refresh the page or when we browse thru other tabs / windows. We do reset the time when we hit "New Trip" or "Close without Save" or "Clone trip" buttons, and after saving the trip. To rest the trip we use 3 lines in below if condition. This code doesn't seem to be working all the time, we get some negative hours, and incorrect minutes at times, not sure what is the issue.. can you please look into it, when you get some time.. if you could rewrite the code or point me to right direction, that would be really helpful.

In the code behind we are using this code

if (Session["calltimer"] == null)
{
TimeSpan t = (DateTime.Now - new DateTime(1970, 01, 01).AddMilliseconds(0));
Session["calltimer"] = (Int64)(t.TotalMilliseconds + 0.5);
txtstarttimeforcurrentcall.Text = Session["calltimer"].ToString();
}
else
{
txtstarttimeforcurrentcall.Text = Session["calltimer"].ToString();
}

Onload we are using this code....

function getSecs() {
var myTime1 = new Date();
var numCurrTimer = document.getElementById('txtstarttimeforcurrentcal l').value;
//alert(txtValue);
strSS = (Math.round((myTime1.getTime() - numCurrTimer) / 1000)) % 60;
strMin = Math.round((Math.round((myTime1.getTime() - numCurrTimer) / 1000) - 30) / 60) % 60;
strHR = Math.ceil(((Math.round((myTime1.getTime() - numCurrTimer) / 1000)) / 60) / 60) - 9;
if (strHR == -1) strHR = 0;
strHR = "0" + strHR;
strMin = strMin + "";
strSS = strSS + "";
if ((strMin.length) == 1) strMin = "0" + strMin;
if ((strSS.length) == 1) strSS = "0" + strSS;
document.getElementById("txtCurrentCall").value = strHR + ":" + strMin + ":" + strSS;
window.setTimeout('getSecs()', 1000);
}
Reply With Quote

Watch Furious 7 Online


All times are GMT -4. The time now is 07:18 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.