Web應(yīng)用開發(fā):ASP.NET 大學(xué)場(chǎng)地預(yù)約借用系統(tǒng)
5.2 后臺(tái)
登錄頁(yè)面
后臺(tái)代碼進(jìn)行校驗(yàn),需要先將密碼轉(zhuǎn)成MD5密文,然后實(shí)行字符串匹配:
string username = Request.Params["inputEmail"].ToString();
string password = MD5Helper.ToMD5(Request.Params["inputPassword"].ToString());
if (DBHelper.ExecuteQuery("select * from WebUser where username='" + username + "' and password='" + password + "'").Tables[0].Rows.Count > 0)
{
//放一個(gè)Cookie來(lái)指示是哪名用戶登陸了
HttpCookie cookie = new HttpCookie("login_name", username);
Response.Cookies.Add(cookie);
Response.Redirect("indextem.a(chǎn)spx");
}
else
{
Response.Write("<script language=j(luò)avascript>alert('用戶名或密碼錯(cuò)誤');</script>");
}
注冊(cè)頁(yè)面的前端類似,后端代碼以數(shù)據(jù)庫(kù)插入為主,需要判斷用戶名是否重復(fù),如下:
var name = Request["regName"];
if (!string.IsNullOrEmpty(name))
{
if (DBHelper.ExecuteQuery("select * from WebUser where username='" + name + "'").Tables[0].Rows.Count > 0)
{
//檢測(cè)該用戶名是否注冊(cè)
Response.Write("<script language=j(luò)avascript>alert('注冊(cè)失敗,用戶名已被使用。В;</script>");
}
else
{
var passwd = Request["regPassword"];
passwd = MD5Helper.ToMD5(passwd.ToString());
var telephone = Request["regTelephone"];
var sql = "INSERT INTO WebUser(username,password,telephone) VALUES ('{0}','{1}','{2}')";
sql = string.Format(sql, name, passwd, telephone);
if (SqlHelper.ExecuteSql(sql) > 0)
{
var str = "注冊(cè)成功,您的用戶名:" + name + " ,現(xiàn)在去登錄試試吧~";
Response.Write("<script language=j(luò)avascript>alert('" + str + "');</script>");
}
else
{
Response.Write("<script language=j(luò)avascript>alert('注冊(cè)失敗,數(shù)據(jù)庫(kù)出錯(cuò)!');</script>");
}
}
}
預(yù)約頁(yè)面
預(yù)定的后臺(tái)處理代碼,后臺(tái)需要做預(yù)定沖突的檢測(cè):
string[] bookTime = context.Request["bookTime"].Split('-');
string bookSt = bookTime[0].Trim();
string bookEt = bookTime[1].Trim();
string bookDate = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
string roomNumber = context.Request["roomNo"];
//預(yù)定時(shí)間區(qū)間判斷
var bookInfoSql = "select BookSt, BookSt from BookInfo where " +
"BookDate='{0}' And RoomNumber='{1}'";
bookInfoSql = string.Format(bookInfoSql, bookDate, roomNumber);
DataTable dtBookInfo = SqlHelper.getDataTable(bookInfoSql);
Boolean notOverlap = true;
for (int i = 0; i < dtBookInfo.Rows.Count; i++)
{
//大于已預(yù)約右邊,小于已預(yù)約左邊
notOverlap &= ( (string.Compare(bookSt, dtBookInfo.Rows[i][1].ToString().Trim(), true) > 0) ||
(string.Compare(bookEt, dtBookInfo.Rows[i][0].ToString().Trim(), true) < 0) );
}
if (!notOverlap)
{
context.Response.Write("該時(shí)間段已經(jīng)有別人預(yù)約啦,請(qǐng)重新選擇。ⅲ
}
else
{
string customerName = context.Request.Cookies["login_name"].Value;
string myRemark = context.Request["myRemark"];
if (string.IsNullOrEmpty(myRemark))
{
myRemark = "無(wú)";
}
DateTime dt1 = DateTime.Parse(bookDate + " " + bookSt);
DateTime dt2 = DateTime.Parse(bookDate + " " + bookEt);
TimeSpan ts = dt2.Subtract(dt1);
double bookDurationHours = Math.Round(ts.TotalHours, 2);
DataTable dtLastID = SqlHelper.getDataTable("select top 1 ID from BookInfo order by ID DESC");
string insIdStr = dtLastID.Rows[0][0].ToString();
int insId = int.Parse(insIdStr) + 1;
//插入到數(shù)據(jù)庫(kù)中去
var bookSql = "INSERT INTO BookInfo(ID, CustomerName,MyRemark,BookDate,BookSt,BookDuration,RoomNumber,BookEt) " +
"VALUES ({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}')";
bookSql = string.Format(bookSql, insId, customerName, myRemark, bookDate, bookSt, bookDurationHours,
roomNumber, bookEt);
if (SqlHelper.ExecuteSql(bookSql) > 0)
{
context.Response.Write("預(yù)定成功。ⅲ;
}
else
{
context.Response.Write("后臺(tái)數(shù)據(jù)插入出錯(cuò)。ⅲ;
}
}
獲取預(yù)訂時(shí)間段后臺(tái)處理代碼:
string roomNum = context.Request["roomNo"];
var sqlBookSp = "select BookSt, BookEt from BookInfo " +
"where BookDate = '" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "' and RoomNumber = '{0}' order by BookSt";
sqlBookSp = string.Format(sqlBookSp, roomNum);
DataTable dtTimeSp = SqlHelper.getDataTable(sqlBookSp);
string sJson2 = JsonConvert.SerializeObject(dtTimeSp);
context.Response.Write(sJson2);
break;
取消預(yù)約的代碼:
//刪除預(yù)訂的數(shù)據(jù)
string[] delListStr = context.Request["cancel"].Split(',');
int totalCancel = 0;
foreach(var delRoom in delListStr)
{
var delSql = "delete from BookInfo where ID = " + delRoom;
if (SqlHelper.ExecuteSql(delSql) > 0)
{
totalCancel++;
}
}
context.Response.Write("取消預(yù)訂完成,共取消 " + totalCancel.ToString() + " 間教室。ⅲ;
6、運(yùn)行效果圖
登錄
注冊(cè):
預(yù)訂(可以手動(dòng)刷新教室信息):
發(fā)表評(píng)論
請(qǐng)輸入評(píng)論內(nèi)容...
請(qǐng)輸入評(píng)論/評(píng)論長(zhǎng)度6~500個(gè)字
最新活動(dòng)更多
-
10月31日立即下載>> 【限時(shí)免費(fèi)下載】TE暖通空調(diào)系統(tǒng)高效可靠的組件解決方案
-
即日-11.13立即報(bào)名>>> 【在線會(huì)議】多物理場(chǎng)仿真助跑新能源汽車
-
11月28日立即報(bào)名>>> 2024工程師系列—工業(yè)電子技術(shù)在線會(huì)議
-
12月19日立即報(bào)名>> 【線下會(huì)議】OFweek 2024(第九屆)物聯(lián)網(wǎng)產(chǎn)業(yè)大會(huì)
-
即日-12.26火熱報(bào)名中>> OFweek2024中國(guó)智造CIO在線峰會(huì)
-
即日-2025.8.1立即下載>> 《2024智能制造產(chǎn)業(yè)高端化、智能化、綠色化發(fā)展藍(lán)皮書》
推薦專題
- 1 【一周車話】沒(méi)有方向盤和踏板的車,你敢坐嗎?
- 2 特斯拉發(fā)布無(wú)人駕駛車,還未迎來(lái)“Chatgpt時(shí)刻”
- 3 特斯拉股價(jià)大跌15%:Robotaxi離落地還差一個(gè)蘿卜快跑
- 4 馬斯克給的“驚喜”夠嗎?
- 5 打完“價(jià)格戰(zhàn)”,大模型還要比什么?
- 6 馬斯克致敬“國(guó)產(chǎn)蘿卜”?
- 7 神經(jīng)網(wǎng)絡(luò),誰(shuí)是盈利最強(qiáng)企業(yè)?
- 8 比蘋果偉大100倍!真正改寫人類歷史的智能產(chǎn)品降臨
- 9 諾獎(jiǎng)進(jìn)入“AI時(shí)代”,人類何去何從?
- 10 Open AI融資后成萬(wàn)億獨(dú)角獸,AI人才之爭(zhēng)開啟
- 高級(jí)軟件工程師 廣東省/深圳市
- 自動(dòng)化高級(jí)工程師 廣東省/深圳市
- 光器件研發(fā)工程師 福建省/福州市
- 銷售總監(jiān)(光器件) 北京市/海淀區(qū)
- 激光器高級(jí)銷售經(jīng)理 上海市/虹口區(qū)
- 光器件物理工程師 北京市/海淀區(qū)
- 激光研發(fā)工程師 北京市/昌平區(qū)
- 技術(shù)專家 廣東省/江門市
- 封裝工程師 北京市/海淀區(qū)
- 結(jié)構(gòu)工程師 廣東省/深圳市