订阅
纠错
加入自媒体

Web应用开发:ASP.NET 大学场地预约借用系统

2021-06-09 14:13
程序猿声
关注

5.2 后台

登录页面

后台代码进行校验,需要先将密码转成MD5密文,然后实行字符串匹配:

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)

   //放一个Cookie来指示是哪名用户登陆了
   HttpCookie cookie = new HttpCookie("login_name", username);
   Response.Cookies.Add(cookie);
   Response.Redirect("indextem.aspx");

else

   Response.Write("<script language=javascript>alert('用户名或密码错误');</script>");

注册页面的前端类似,后端代码以数据库插入为主,需要判断用户名是否重复,如下:

var name = Request["regName"];
if (!string.IsNullOrEmpty(name))

   if (DBHelper.ExecuteQuery("select * from WebUser where username='" + name + "'").Tables[0].Rows.Count > 0)
   {
       //检测该用户名是否注册
       Response.Write("<script language=javascript>alert('注册失败,用户名已被使用!');</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 = "注册成功,您的用户名:" + name + " ,现在去登录试试吧~";
           Response.Write("<script language=javascript>alert('" + str + "');</script>");
       }
       else
       {
           Response.Write("<script language=javascript>alert('注册失败,数据库出错!');</script>");
       }
   }

预约页面

预定的后台处理代码,后台需要做预定冲突的检测:

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"];
//预定时间区间判断
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++)

   //大于已预约右边,小于已预约左边
   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("该时间段已经有别人预约啦,请重新选择!");

else

   string customerName = context.Request.Cookies["login_name"].Value;
   string myRemark = context.Request["myRemark"];
   if (string.IsNullOrEmpty(myRemark))
   {
       myRemark = "无";
   }
   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;
   //插入到数据库中去
   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("预定成功!");
   }
   else
   {
       context.Response.Write("后台数据插入出错!");
   }

获取预订时间段后台处理代码:

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;

取消预约的代码:

//删除预订的数据
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("取消预订完成,共取消 " + totalCancel.ToString() + " 间教室!");

6、运行效果图

登录

注册:

预订(可以手动刷新教室信息):

<上一页  1  2  3  4  下一页>  余下全文
声明: 本文由入驻维科号的作者撰写,观点仅代表作者本人,不代表OFweek立场。如有侵权或其他问题,请联系举报。

发表评论

0条评论,0人参与

请输入评论内容...

请输入评论/评论长度6~500个字

您提交的评论过于频繁,请输入验证码继续

暂无评论

暂无评论

人工智能 猎头职位 更多
扫码关注公众号
OFweek人工智能网
获取更多精彩内容
文章纠错
x
*文字标题:
*纠错内容:
联系邮箱:
*验 证 码:

粤公网安备 44030502002758号