Web應(yīng)用開發(fā):ASP.NET 大學(xué)場(chǎng)地預(yù)約借用系統(tǒng)
可以在HTML頁面編寫元素,然后使用js動(dòng)態(tài)生成,例如:
<table class="primary" id="roomInfo" style="width: 100%"></table>
document.getElementById("roomInfo").innerHTML = creatRoomTable(result);
也可以直接在aspx文件中使用C#的腳本進(jìn)行生成:
<%
System.Data.DataSet ds2 = MyDBUtils.DBHelper.ExecuteQuery("select BookInfo.ID, BookInfo.RoomNumber, RoomType, RoomPeople, MyRemark,BookSt, " +
"BookEt, BookDuration from BookInfo join RoomInfo on " +
"BookInfo.RoomNumber = RoomInfo.RoomNumber where " +
"BookDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' and CustomerName='" + Request.Cookies["login_name"].Value + "'");
for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
{
Context.Response.Write("<tr>");
for (int j = 1; j < 8; j++)
{
Context.Response.Write("<td>");
Context.Response.Write(ds2.Tables[0].Rows[i][j].ToString());
Context.Response.Write("</td>");
}
Context.Response.Write("<td>");
Context.Response.Write("<label><input type='checkbox' name='checkbokRoom' value='" + ds2.Tables[0].Rows[i][0].ToString()+"-"+ ds2.Tables[0].Rows[i][1].ToString() + "' /><span class='checkable'>退訂</span></label>");
Context.Response.Write("</td>");
Context.Response.Write("</tr>");
}
%>
表格中的radio單選按鈕,需要綁定單擊的事件,這部分代碼獲取選中的場(chǎng)地所預(yù)約的時(shí)間段,并將其顯示到表格下方的框框中,為AJAX局部更新,改變選中的場(chǎng)地時(shí)(單選按鈕的改變),也會(huì)在下面更新該場(chǎng)地的預(yù)約時(shí)間段:
function getRoomTimeSpan() {
var roomNumber = getSelectedRadioValue();
//發(fā)送請(qǐng)求獲預(yù)約的時(shí)間段
$.a(chǎn)jax({
type: 'get',
url: 'RoomBookHandler.a(chǎn)shx',
async: true,
data: {
action: 'getBookTime',
roomNo: roomNumber
},
success: function (result) {
var dataList = JSON.parse(result);
var footerStr = '<footer id="bookTimeSpan" >';
for (var ind in dataList) {
footerStr += '<span class="label warning" >';
footerStr += dataList[ind].BookSt.toString().trim().substring(0, 5);
footerStr += ' - ';
footerStr += dataList[ind].BookEt.toString().trim().substring(0, 5);
footerStr += '</span >';
}
footerStr += '</footer >';
document.getElementById("bookTimeSpan").innerHTML = footerStr;
},
error: function () {
alert('獲取數(shù)據(jù)失。。В
}
});
}
時(shí)間段的選擇使用了一個(gè)時(shí)間選擇控件,效果如下:
預(yù)定時(shí),獲取用戶輸入的一系列數(shù)據(jù),然后使用AJAX發(fā)送到后臺(tái)進(jìn)行處理:
function bookRoom() {
var bookT = document.getElementById("timeArrange").value;
if (bookT === "") {
alert("必須選擇要借用的時(shí)間范圍。ⅲ;
return false;
}
var myR = document.getElementById("myRemarks").value;
var roomNumber = getSelectedRadioValue();
if (roomNumber === "") {
alert("必須選擇要借用的教室。ⅲ;
return false;
}
//要發(fā)送的數(shù)據(jù),教室號(hào),預(yù)定開始時(shí)間-結(jié)束時(shí)間,我的備注
$.a(chǎn)jax({
type: 'post',
url: 'RoomBookHandler.a(chǎn)shx',
async: true,
data: {
action: 'bookRoom',
roomNo: roomNumber,
bookTime: bookT,
myRemark: myR
},
success: function (result) {
alert(result);
getRoomTimeSpan();
updateBookedTable();
},
error: function () {
alert('請(qǐng)求失。。В;
}
});
}
注意,如果用戶輸入不合法,比如未選中時(shí)間段,未選中教室,時(shí)間段沖突等都無法有效完成預(yù)定。
預(yù)約成功顯示預(yù)約的教室:
表格創(chuàng)建代碼與場(chǎng)地顯示的表格創(chuàng)建代碼類似,取消預(yù)約的需要將取消的預(yù)定號(hào)(預(yù)定號(hào)綁定到了checkbox的value中)發(fā)送到后臺(tái),進(jìn)行記錄刪除:
function cancelBook() {
var checkList = [];
var timeSpanUpList = [];
var checkbokContext = document.getElementsByName("checkbokRoom");
for (i = 0; i < checkbokContext.length; ++i) {
if (checkbokContext[i].checked) {
var dataStr = checkbokContext[i].value.split('-');
checkList.push(dataStr[0]);
timeSpanUpList.push(dataStr[1]);
}
}
if (checkList.length == 0) {
alert("請(qǐng)選擇您需要取消預(yù)約的教室。ⅲ;
return false;
}
var cancelListStr = checkList.join(','); //轉(zhuǎn)成1,3,4這種形式,后臺(tái)再解析
$.a(chǎn)jax({
type: 'post',
url: 'RoomBookHandler.a(chǎn)shx',
async: true,
data: {
action: 'cancelBook',
cancel: cancelListStr
},
success: function (result) {
alert(result);
//刷新本表
updateBookedTable();
//刷新foot
if (timeSpanUpList.indexOf(getSelectedRadioValue()) 。 -1) {
getRoomTimeSpan();
}
},
error: function () {
alert('連接失。。В;
}
});
}
成功以后,更新該表格。但是需要注意的是,此外還做了一個(gè)小細(xì)節(jié),取消某一時(shí)間段以后,如果恰好在場(chǎng)地展示頁面選中的也是這個(gè)教室,那么下面的預(yù)約時(shí)間段也會(huì)同步更新,采用的同樣為AJAX技術(shù)。
success: function (result) {
alert(result);
//刷新本表
updateBookedTable();
//刷新foot
if (timeSpanUpList.indexOf(getSelectedRadioValue()) 。 -1) {
getRoomTimeSpan();
}
},
歷史預(yù)約表格的生成,采用的是aspx中嵌入腳本的形式生成的:
<table class="primary" style="width: 100%">
<tr>
<th>教室號(hào)</th>
<th>教室類型</th>
<th>容納人數(shù)</th>
<th>我的備注</th>
<th>日期</th>
<th>開始時(shí)間</th>
<th>結(jié)束時(shí)間</th>
<th>借用時(shí)長(小時(shí))</th>
</tr>
<tbody>
<%
System.Data.DataSet ds3 = MyDBUtils.DBHelper.ExecuteQuery("select BookInfo.RoomNumber, RoomType, RoomPeople, MyRemark,BookDate,BookSt, " +
"BookEt, BookDuration from BookInfo join RoomInfo on " +
"BookInfo.RoomNumber = RoomInfo.RoomNumber " +
"where BookDate < '" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") +"' and CustomerName='" + Request.Cookies["login_name"].Value + "'");
for (int i = 0; i < ds3.Tables[0].Rows.Count; i++)
{
Context.Response.Write("<tr>");
for (int j = 0; j < 8; j++)
{
Context.Response.Write("<td>");
Context.Response.Write(ds3.Tables[0].Rows[i][j].ToString());
Context.Response.Write("</td>");
}
Context.Response.Write("</tr>");
}
%>
</tbody>
</table>
檢索的時(shí)候,系統(tǒng)將自動(dòng)從預(yù)訂表中檢索該用戶在今天之前的預(yù)約信息,并展示出來。

發(fā)表評(píng)論
請(qǐng)輸入評(píng)論內(nèi)容...
請(qǐng)輸入評(píng)論/評(píng)論長度6~500個(gè)字
最新活動(dòng)更多
-
6月20日立即下載>> 【白皮書】精準(zhǔn)測(cè)量 安全高效——福祿克光伏行業(yè)解決方案
-
7月3日立即報(bào)名>> 【在線會(huì)議】英飛凌新一代智能照明方案賦能綠色建筑與工業(yè)互聯(lián)
-
7月22-29日立即報(bào)名>> 【線下論壇】第三屆安富利汽車生態(tài)圈峰會(huì)
-
7.30-8.1火熱報(bào)名中>> 全數(shù)會(huì)2025(第六屆)機(jī)器人及智能工廠展
-
7月31日免費(fèi)預(yù)約>> OFweek 2025具身機(jī)器人動(dòng)力電池技術(shù)應(yīng)用大會(huì)
-
免費(fèi)參會(huì)立即報(bào)名>> 7月30日- 8月1日 2025全數(shù)會(huì)工業(yè)芯片與傳感儀表展
推薦專題
- 1 AI 眼鏡讓百萬 APP「集體失業(yè)」?
- 2 大廠紛紛入局,百度、阿里、字節(jié)搶奪Agent話語權(quán)
- 3 深度報(bào)告|中國AI產(chǎn)業(yè)正在崛起成全球力量,市場(chǎng)潛力和關(guān)鍵挑戰(zhàn)有哪些?
- 4 上海跑出80億超級(jí)獨(dú)角獸:獲上市公司戰(zhàn)投,干人形機(jī)器人
- 5 國家數(shù)據(jù)局局長劉烈宏調(diào)研格創(chuàng)東智
- 6 下一代入口之戰(zhàn):大廠為何紛紛押注智能體?
- 7 百億AI芯片訂單,瘋狂傾銷中東?
- 8 Robotaxi新消息密集釋放,量產(chǎn)元年誰在領(lǐng)跑?
- 9 格斗大賽出圈!人形機(jī)器人致命短板曝光:頭腦過于簡(jiǎn)單
- 10 一文看懂視覺語言動(dòng)作模型(VLA)及其應(yīng)用