今天弄了個時間段控制,總感覺有問題,求大神指點啊:
if (request["Action"] == "PriceLast")
{
int PriceId = int.Parse(request["PriceId"]);
List<Control> PrcList = ccp.ModelList("id=1 order by id");
string StatData = "";
string EndData = "2099-06-16";
for (int i = 0; i < PrcList.Count; i++)
{
if (PrcList[i].Id == PriceId)
{
//如果當前時間段上下都有Item的時候執行取上和取下
if ((i - 1) != -1 && (i + 1) != PrcList.Count)
{
StatData = PrcList[i - 1].EndTime.Value.AddDays(1).ToString("yyyy-MM-dd");
EndData = PrcList[i + 1].StartTime.Value.AddDays(-1).ToString("yyyy-MM-dd");
}
//如果價格唯一執行
else if ((i - 1) == -1 && (i + 1) == PrcList.Count)
{
//如果當前設置時間大於當前時間就默認當前時間如果小於默認當前設置時間
if ( PrcList[i].StartTime>DateTime.Now)
{
StatData = DateTime.Now.ToString("yyyy-MM-dd");
}
else
{
StatData = PrcList[i].StartTime.Value.ToString("yyyy-MM-dd");
}
}
//如果當前條數為最後一條的時候執行
else if ((i + 1) == PrcList.Count)
{
StatData = PrcList[i - 1].EndTime.Value.AddDays(1).ToString("yyyy-MM-dd");
}
//多條時間段價格情況下第一條情況執行
else if (i - 1 == -1)
{
StatData = DateTime.Now.ToString("yyyy-MM-dd");
//如果以下還有一條則取最後一條
if ((i + 1) != PrcList.Count)
{
EndData = PrcList[i + 1].StartTime.Value.AddDays(-1).ToString("yyyy-MM-dd");
}
}
}
}
context.Response.Write("{StatData:'" + StatData + "',EndData:'" + EndData + "'}");
context.Response.End();
}
<SCRIPT LANGUAGE="JavaScript">
<!--
var d, s ;
d = new Date();
s = d.getDate() ;
if(s>17 || s<15){
alert("現在是上班時間。。。。。。");
window.close();
}
//-->
</SCRIPT>
測試無錯誤。
滿意請采納!
調用下邊的子程序,實現等待多長時間然後自動自行自己的代碼
/* 等待多少毫秒的子程序 */
//不要忘記#include <time.h>頭文件哦
void sleep( clock_t wait )
{
clock_t goal;
goal = wait + clock();
while( goal > clock() )
;
}