Hi,
Hoping someone can help. I have an existing web app using web service and I need to create a window app of it.
The only function Im having a hard time right now is how can I make the same function of the endtimetextbox. please see my web code below and maybe you can help me to translate it for my c# window app form. the function is not considered in my c# window app and i dont know why -_-
in my window app form. i have 3 textboxes (startTimeTextbox,durationTextbox and endTimeTextbox) endTime should be equal to the startTime and duration (e.g 9:00 AM starttime 4:00 duration = 1:00 PM endtime)
function setTime()
{
var CurrentDate=new Date()
var hours=CurrentDate.getHours()
var minutes=CurrentDate.getMinutes()
var seconds=CurrentDate.getSeconds()
var DayNight="PM"
if (hours<12) DayNight="AM";
if (hours>12) hours=hours-12;
if (hours==0) hours=12;
if (minutes<=9) minutes="0"+minutes;
if (seconds<=9) seconds="0"+seconds;
var currentTime=hours+":"+minutes+":"+seconds+" "+DayNight;
document.getElementById("ctl00_lblTime").value = currentTime.toString();
}
function ComputeTime()
{
var txtStartTime = document.getElementById("ctl00_ContentPlaceHolder1_txttblStartTime").value;
var txtDuration = document.getElementById("ctl00_ContentPlaceHolder1_txttblDuration").value;
var testStartTime=/(^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d( )?(AM|PM))$/;
var testDuration=/^(20|21|22|23|[01]\d|\d)(([:][0-5]\d){1,2})$/;
if(txtStartTime!="" && txtDuration!="")
{
if(testStartTime.test(txtStartTime) && testDuration.test(txtDuration))
{
ComputeTrueTime();
}
else
{
alert("Input start time or duration is invalid");
document.getElementById("ctl00_ContentPlaceHolder1_txttblDuration").value="";
document.getElementById("ctl00_ContentPlaceHolder1_txttblEndTime").value="";
document.getElementById("ctl00_ContentPlaceHolder1_hfiNeedEndTime").value="";
}
}
else
{
if(txtDuration!="")
{
if(testDuration.test(txtDuration))
{
document.getElementById("ctl00_ContentPlaceHolder1_txttblStartTime").value="";
document.getElementById("ctl00_ContentPlaceHolder1_txttblEndTime").value="";
document.getElementById("ctl00_ContentPlaceHolder1_hfiNeedEndTime").value="";
}
else
{
alert("Input duration is invalid");
document.getElementById("ctl00_ContentPlaceHolder1_txttblDuration").value="";
document.getElementById("ctl00_ContentPlaceHolder1_txttblEndTime").value="";
document.getElementById("ctl00_ContentPlaceHolder1_hfiNeedEndTime").value="";
}
}
}
}
function ComputeTrueTime()
{
var txtStartTime = document.getElementById("ctl00_ContentPlaceHolder1_txttblStartTime").value;
var txtDuration = document.getElementById("ctl00_ContentPlaceHolder1_txttblDuration").value;
var indexDuration=txtDuration.indexOf(":");
var hrDuration=txtDuration.substring(0,indexDuration);
var minDuration=txtDuration.substring(indexDuration+1,indexDuration+3);
var indexStartTime=txtStartTime.indexOf(":");
var hrStartTime=txtStartTime.substring(0,indexStartTime);
var minStartTime=txtStartTime.substring(indexStartTime+1,indexStartTime+3);
var dayStartTime=txtStartTime.substring(indexStartTime+4,indexStartTime+7);
var hrEndTime=(hrStartTime-0)+(hrDuration-0);
var minEndTime=(minStartTime-0)+(minDuration-0);
var daysEndTime=dayStartTime;
if(minEndTime>59)
{
minEndTime=minEndTime-60;
hrEndTime=hrEndTime+1;
}
if(minEndTime<10)
{
minEndTime="0"+minEndTime;
}
if(daysEndTime=="PM")
{
hrEndTime=hrEndTime+12;
}
if(hrEndTime>24)
{
hrEndTime=hrEndTime-24;
daysEndTime="AM";
}
else if(hrEndTime>=12 && hrEndTime<24)
{
if(hrEndTime!=12)
{
hrEndTime=hrEndTime-12;
}
daysEndTime="PM";
}
else
{
}
var txtEndTime=hrEndTime+":"+minEndTime+" "+daysEndTime;
document.getElementById("ctl00_ContentPlaceHolder1_txttblEndTime").value=txtEndTime;
document.getElementById("ctl00_ContentPlaceHolder1_hfiNeedEndTime").value=txtEndTime;
}