protected void Page_Load(object sender, EventArgs e)
{
//seconds = (GetEndTime() - GetStartTime()).TotalSeconds;
HienDuLieu();
}
private DateTime GetStartTime()
{
return DateTime.Now;
}
private DateTime GetEndTime(DateTime pNgay)
{
//return new DateTime(2010, 5, 06, 8, 10, 0);
return new DateTime(pNgay.Year, pNgay.Month, pNgay.Day, pNgay.Hour, pNgay.Minute, pNgay.Second);
}
private void HienDuLieu()
{
ketnoiDataContext pKetNoi = new ketnoiDataContext();
var pDauGia = from p in pKetNoi.DauGias
select p;
DS_DauGia.DataSource = pDauGia;
DS_DauGia.DataBind();
}
public string HienScript()
{
string pKQ = "";
//string pSQL = "SELECT * From giatot where isHome = 1 order by giatotID desc";
//bang pBang = new bang(pSQL);
//if (pBang.Rows.Count <= 0) return "";
for (int i = 0; i <= DS_DauGia.Items.Count - 1; i++)
{
Literal lblGiay = (Literal)DS_DauGia.Items[i].FindControl("lblGiay");
Literal lblMa = (Literal)DS_DauGia.Items[i].FindControl("lblMa");
string pMa = lblMa.Text;
DateTime pNgayKetThuc = DateTime.Parse(lblGiay.Text);
double seconds = (GetEndTime(pNgayKetThuc) - GetStartTime()).TotalSeconds;
pKQ += "<script type=\"text/javascript\">"+
"var leave" + pMa + " = " + seconds + ";"+
"CounterTimer" + pMa + "();" +
"var interv=setInterval(CounterTimer" + pMa + ",1000);" +
"function CounterTimer" + pMa + "()" +
"{"+
"var day" + pMa + " = Math.floor(leave" + pMa + " / ( 60 * 60 * 24));" +
"var hour" + pMa + " = Math.floor(leave" + pMa + " / 3600) - (day" + pMa + " * 24);" +
"var minute" + pMa + " = Math.floor(leave" + pMa + " / 60) - (day" + pMa + " * 24 *60) - (hour" + pMa + " * 60);" +
"var second" + pMa + " = Math.floor(leave" + pMa + ") - (day" + pMa + " * 24 *60*60) - (hour" + pMa + " * 60 * 60) - (minute" + pMa + "*60);" +
"hour" + pMa + "=hour" + pMa + "<10 ? \"0\" + hour" + pMa + " : hour" + pMa + ";" +
"minute" + pMa + "=minute" + pMa + "<10 ? \"0\" + minute" + pMa + " : minute" + pMa + ";" +
"second" + pMa + "=second" + pMa + "<10 ? \"0\" + second" + pMa + " : second" + pMa + ";" +
"var remain" + pMa + "=day" + pMa + " + \" days \"+hour" + pMa + " + \":\"+minute" + pMa + "+\":\"+second" + pMa + ";" +
"leave" + pMa + "=leave" + pMa + "-1;" +
"document.getElementById(\"timelabel" + pMa + "\").innerHTML=remain" + pMa + ";" +
"}"+
"</script>";
//
}
return pKQ;
}