客车网上售票系统之用户管理
1、今日完成任务:
(1)后台登录页面设计、功能实现
(2)后台用户管理页面设计
(3)用户信息修改、删除、查看
(4)修改密码
2、核心源码:
登录后台代码:
/// <summary> ///登录 /// </summary> /// <returns></returns> [HttpPost] public ActionResult Index(UserInfo user) { if (!string.IsNullOrEmpty(user.UserName) && !string.IsNullOrEmpty(user.Password)) { var aa = db.UserInfo.Where(a => a.UserName == user.UserName && a.Password == user.Password).FirstOrDefault(); if (aa != null) { Session["userID"] = aa.UserID; Session["userName"] = aa.UserName; int isAdmin = (int)aa.ISAdmin; if (isAdmin==1) { return RedirectToAction("Index", "Admin"); } else { Response.Write("<script>alert('您不是后台管理员,不能登录后台!!!')</script>"); } } else { Response.Write("<script>alert('用户名或密码输入错误!!!')</script>"); } } else { Response.Write("<script>alert('用户名或密码不能为空!!!')</script>"); } return View(); }
登录页面代码:
@{ ViewBag.Title = "后台登录页面"; Layout = null; } <script src="~/Scripts/jquery-1.10.2.min.js"></script> <script src="~/Scripts/bootstrap.min.js"></script> <link href="~/Content/Site.css" rel="stylesheet" type="text/css" /> <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" /> <script src="~/Scripts/modernizr-2.6.2.js"></script> <link rel="stylesheet" href="~/Content/bootstrap.css"> <link rel="stylesheet" href="~/Content/font-awesome.min.css"> <link rel="stylesheet" href="~/Content/style.css"> <link rel="stylesheet" href="~/Content/plugin.css"> <link rel="stylesheet" href="~/Content/landing.css"> <!--[if lt IE 9]> <script src="~/Scripts/ie/respond.min.js"></script> <script src="~/Scripts/ie/html5.js"></script> <![endif]--> <div class="container"> <div class="main padder"> <div class="row"> <div class="col-lg-8 col-offset-8 m-t-large"> <section class="panel"> <header class="panel-heading text-center" style="font-size:20px; font-weight:bold; color:#4b5c56;"> 客车网上售票系统后台登录 </header> <br /> <form action="/Login/Index" class="padder" method="post"> <div class="block" style="margin-left:62px;"> <label class="control-label">用户名:</label> <input type="text" placeholder="用户名" class="form-control" name="UserName"> </div> <br /> <div class="block" style="margin-left:62px;"> <label class="control-label">密码:</label> <input type="password" id="inputPassword" placeholder="密码" class="form-control" name="Password"> </div> <br /> @*<button type="submit" class="btn btn-info btn-group btn-large" >登录</button>*@ <button type="submit" class="btn btn-primary" style="width:281px; margin-left:62px;">登录</button> <div class="line line-dashed m-t-large"></div> </form> </section> </div> </div> </div> </div> <script src="~/Scripts/jquery.min.js"></script> <!-- Bootstrap --> <script src="~/Scripts/bootstrap.js"></script> <!-- app --> <script src="~/Scripts/app.js"></script> <script src="~/Scripts/app.plugin.js"></script> <script src="~/Scripts/app.data.js"></script> <script src="~/Scripts/jquery.min.js"></script> <!-- app --> <!-- Sparkline Chart --> <script src="~/Scripts/charts/sparkline/jquery.sparkline.min.js"></script> <!-- Easy Pie Chart --> <script src="~/Scripts/charts/easypiechart/jquery.easy-pie-chart.js"></script> <script src="~/Scripts/ie/excanvas.js"></script>
登录页面截图:
用户管理后台代码:
public ActionResult Index() { if (Session["userID"] == null) { return RedirectToAction("Index", "Login"); } var list = db.UserInfo.ToList(); return View(list); } [HttpPost] public ActionResult Index(UserInfo user) { var list = db.UserInfo.ToList(); if (!string.IsNullOrEmpty(user.UserRealName)) { list = list.Where(a => a.UserRealName.Contains(user.UserRealName)).ToList(); } if (user.ISAdmin!=0) { list = list.Where(a => a.ISAdmin == user.ISAdmin).ToList(); } return View(list); }
个人信息修改后台代码:
/// <summary> /// 显示个人信息 /// </summary> /// <returns></returns> public ActionResult EditUser(string uid) { UserInfo user=null; if (!string.IsNullOrEmpty(uid)) { int uuid = int.Parse(uid); user = db.UserInfo.Where(a => a.UserID == uuid).FirstOrDefault(); } return View(user); } [HttpPost] public ActionResult EditUser(UserInfo user) { UserInfo u = user; DbEntityEntry<UserInfo> entry = db.Entry<UserInfo>(u); entry.State = EntityState.Modified; int data = db.SaveChanges(); if (data > 0) { Response.Write("<script>alert('修改成功!!!')</script>"); return RedirectToAction("Index", "UserManage"); } else { Response.Write("<script>alert('修改失败,数据异常!!!')</script>"); } return View(); }
个人信息修改页面设计截图:
3、遇到的问题:
(1)后台页面设计
(2)下载的模版样式跟自带的bootstrap冲突
4、解决的方法:
(1)去网上下载一些模版,把样式修改修改
(2)把冲突的样式删掉