信息系统开发与实践项目 图书管理系统 大学编程作业(TUST 天津科技大学 2023 年)
- 信息系统开发与实践项目 图书管理系统 大学编程作业(TUST 天津科技大学 2023 年)
- 图书管理系统程序说明文档
- 1. 程序说明文档
- 2. 系统相关代码
- 3. 系统界面展示
- 4. 总结
一、项目简介
本图书管理系统,我使用了 ASP.NET MVC(Model-View-Controller)架构来制作,使用了 Visual Studio 2022 作为开发环境,使用了 C# 编程语言进行开发,使用了 Razor 页面模板引擎。实现了让管理员能够快速添加、查看、编辑和删除图书等功能,并且支持一些基本的扩展功能,并且 UI 界面较为美观易用。通过这次信息系统开发与实践项目的实践,我巩固了 ASP.NET MVC(Model-View-Controller)架构的知识,熟练应用了各个第三方开源库,为之后的 C# 后端开发的深入学习打下了基础。
这个项目是我大三写的,现在回顾已经非常粗糙,分享出来一方面希望可以帮助初学者,另一方面希望能让同学们可以从目前大学中普遍毫无价值的形式主义作业中解脱出来,更加高效地学习优质计算机知识和主流编程技术,一起发扬开源精神,感受互联网技术的美好愿景。
二、交流学习
互联网开源精神需要大家一起互相交流学习,互相支持奉献。欢迎大家与我友好交流。
加我 QQ 好友获取所有项目源码和项目文档,感谢大家的支持!
图书管理系统程序说明文档
1. 程序说明文档
1.1 系统目标
本图书管理系统应用旨在提供一种简单易用的方式来管理图书,让管理员能够快速添加、查看、编辑和删除图书,并且支持一些基本的扩展功能,同时,应用还需要提供一个良好的用户界面,方便管理员进行操作。
1.2 系统设计
1.2.1 系统架构
本图书管理系统采用了 ASP.NET MVC(Model-View-Controller)架构,将应用的业务逻辑、用户界面和数据管理分别封装在不同的组件中,使得应用更加易于维护和扩展。
- Model - 数据模型层:管理应用的数据,包括图书的编号、名称、出版社、作者、库存、价格等信息。使用 SQL Server 数据库进行存储管理。
- View - 视图层:负责应用的用户界面设计和显示,包括登录界面、主界面、添加图书界面、修改图书界面、图书详情界面和图书管理界面等。
- Controller - 控制器层:负责管理用户与应用之间的交互,接收用户的输入并处理对应的业务逻辑,包括登录验证、图书信息查询等。
1.2.2 功能实现
本图书管理系统主要实现以下功能:
- 登录界面:管理员可以输入用户名和密码进行登录,只有登录成功后才能进入主界面进行操作。
- 主界面:主界面是应用的核心功能之一,它可以显示所有已添加的图书,并支持添加、修改、查看、删除等操作。管理员可以通过点击图书列表项进入详情界面查看图书的详细信息。
- 添加图书界面:添加图书界面提供给管理员一个编辑器,让管理员可以方便地添加新的图书。
- 修改图书界面:修改图书界面提供给管理员一个编辑器,让管理员可以方便地修改图书。
- 图书详情界面:图书详情界面是一个展示已有图书信息的界面,管理员可以在此界面查看图书的详细信息,包括图书的编号、名称、出版社、作者、库存、价格等信息,并且可以进行添加、修改、查看、删除等操作。
1.2.3 系统实现
本图书管理系统使用了 Visual Studio 2022 作为开发环境,采用了 C# 编程语言进行开发。应用的 UI 设计使用了 Razor 页面模板引擎,使得应用的界面更加美观和易于维护。
在应用的设计和实现过程中,遵循了 ASP.NET MVC 的最佳实践,如尽量避免使用硬编码、将字符串和资源文件分离、使用多线程进行耗时操作等。同时,还使用了 ASP.NET 系统提供的各种 API 和功能,如 Entity Framework 数据库访问框架等。
1.3 系统部署
1.3.1 建立数据库
首先,需要在 SQL Server 中创建一个新的数据库。可以使用 SQL Server Management Studio 工具来创建数据库。具体步骤如下:
- 打开 SQL Server Management Studio 工具。
- 在对象资源管理器中,右键单击“数据库”节点,然后选择“新建数据库”。
- 在“新建数据库”对话框中,输入数据库名称(例如 itcast),然后点击“确定”按钮。
- 在“新建数据库”对话框中,选择“选项”页面,设置数据库文件和日志文件的路径,然后点击“确定”按钮。
- 完成后,在对象资源管理器中可以看到新创建的数据库。
然后,需要将系统提供的数据库文件附加到新创建的数据库中。可以按照以下步骤进行:
- 在 SQL Server Management Studio 中,右键单击新创建的数据库(例如 itcast),然后选择“附加”。
- 在“附加数据库”对话框中,点击“添加”按钮,选择系统提供的数据库文件(例如 itcast.mdf),然后点击“确定”按钮。
- 在“附加数据库”对话框中,点击“确定”按钮,等待数据库附加完成。
- 重复以上步骤,将系统提供的日志文件(例如 itcast_log.ldf)也附加到新创建的数据库中。
1.3.2 登录管理员账号
在应用部署完成后,可以使用以下管理员账号进行登录:
- 用户名:admin
密码:123456 - 用户名:MYXH
密码:520.ILY!
管理员可以使用以上账号在登录界面进行登录,成功后即可进入主界面进行操作。如果需要添加新的管理员账号,可以在数据库中的管理员表中进行添加。
2. 系统相关代码
以下是本图书管理系统的几个主要相关代码:
2.1 Models 模块
2.1.1 AdminLogin.cs
namespace Lesson1.Models
{
using System;
using System.Collections.Generic;
public partial class AdminLogin
{
public int ID { get; set; }
public string AdminName { get; set; }
public string Pwd { get; set; }
}
}
2.1.2 Book.cs
namespace Lesson1.Models
{
using System;
using System.Collections.Generic;
public partial class Book
{
public int ID { get; set; }
public string bookNum { get; set; }
public string bookName { get; set; }
public string bookConcern { get; set; }
public string bookAuthor { get; set; }
public int bookCount { get; set; }
public decimal bookPrice { get; set; }
}
}
2.1.3 Itcast.Context.cs
namespace Lesson1.Models
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class itcastEntities : DbContext
{
public itcastEntities()
: base("name=itcastEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<AdminLogin> AdminLogin { get; set; }
public DbSet<Book> Book { get; set; }
}
}
2.2 Controllers 模块
2.2.1 AdminLoginController.cs
using Lesson1.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Lesson1.Controllers
{
public class AdminLoginController :Controller
{
//
// GET: /AdminLogin/
//创建上下文对象
private itcastEntities db = new itcastEntities();
public ActionResult Index(AdminLogin admin)
{
//将获取到的用户名存储到ViewBag中
ViewBag.UserName = admin.AdminName;
return View();
}
[HttpGet]//表示只用于处理Get方式的请求
public ActionResult Login()
{
//返回一个视图
return View();
}
public ActionResult Login(AdminLogin admin)
{
//获取数据表中与admin对象中的AdminName值相同的数据
AdminLogin user = db.AdminLogin.SingleOrDefault(n => n.AdminName == admin.AdminName);
if (user == null)
{
return Content("用户不存在!");
}
else
{
if (admin.Pwd != user.Pwd)
{
return Content("密码错误!");
}
else
{
Session["User"] = admin;
//跳转到Index的方法中,并将user对象当作参数传递过去
//return RedirectToAction("Index", user);
return RedirectToAction("Index", "Book");
}
}
}
}
}
2.2.2 BookController.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Lesson1.Models;
namespace Lesson1.Controllers
{
public class BookController :Controller
{
private itcastEntities db = new itcastEntities();
// GET: /Book/
public ActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Book book)
{
if (ModelState.IsValid)
{
db.Book.Add(book);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(book);
}
public ActionResult Delete(int id = 0)
{
Book book = db.Book.Find(id);
if (book == null)
{
return HttpNotFound();
}
ViewBag.title = string.Format("删除《{0}》图书", book.bookName);
return View(book);
}
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
Book book = db.Book.Find(id);
db.Book.Remove(book);
db.SaveChanges();
return RedirectToAction("Index");
}
public ActionResult Details(int id = 0)
{
Book book = db.Book.Find(id);
if (book == null)
{
return HttpNotFound();
}
return View(book);
}
public ActionResult Edit(int id = 0)
{
Book book = db.Book.Find(id);
if (book == null)
{
return HttpNotFound();
}
ViewBag.title = string.Format("修改《{0}》图书信息", book.bookName);
return View(book);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Book book)
{
if (ModelState.IsValid)
{
db.Entry(book).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(book);
}
public ActionResult Index()
{
return View(db.Book.ToList());
}
// GET: /Book/Details/5
//
// GET: /Book/Create
//
// POST: /Book/Create
//
// GET: /Book/Edit/5
//
// POST: /Book/Edit/5
//
// GET: /Book/Delete/5
//
// POST: /Book/Delete/5
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
2.3 Views 模块
2.3.1 Login.cshtml
@model Lesson1.Models.itcastEntities @{ Layout = null; }
<!DOCTYPE html>
<html>
<head>
<title>管理系统登录</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
body {
text-align: center;
background: #4974a4;
}
#login {
width: 740px;
margin: 0 auto;
font-size: 12px;
}
#loginlogo {
width: 700px;
height: 50px;
overflow: hidden;
margin-top: 50px;
}
#loginpanel {
width: 729px;
position: relative;
height: 300px;
}
.panel-h {
width: 729px;
height: 20px;
background: url("/Content/Images/login/panel-h.gif") no-repeat;
position: absolute;
top: 0px;
left: 0px;
z-index: 3;
}
.panel-f {
width: 729px;
height: 13px;
background: url("/Content/Images/login/panel-f.gif") no-repeat;
position: absolute;
bottom: 0px;
left: 0px;
z-index: 3;
}
.panel-c {
z-index: 2;
background: url("/Content/Images/login/panel-c.gif") repeat-y;
width: 729px;
height: 300px;
}
.panel-c-l {
position: absolute;
left: 60px;
top: 40px;
}
.panel-c-r {
position: absolute;
right: 20px;
top: 50px;
width: 222px;
line-height: 200%;
text-align: left;
}
.panel-c-l h3 {
color: #556a85;
margin-bottom: 10px;
}
.panel-c-l td {
padding: 7px;
}
.login-text {
height: 24px;
left: 24px;
border: 1px solid #e9e9e9;
background: #f9f9f9;
}
.login-text-focus {
border: 1px solid #e6bf73;
}
.login-btn {
width: 114px;
height: 29px;
color: #e9ffff;
line-height: 29px;
background: url("/Content/Images/login/login-btn.gif") no-repeat;
border: none;
overflow: hidden;
cursor: pointer;
}
#txtUsername,
#code,
#txtPassword {
width: 191px;
}
#logincopyright {
text-align: center;
color: White;
margin-top: 50px;
}
a {
color: Black;
}
a:hover {
color: Red;
text-decoration: underline;
}
</style>
</head>
<body style="padding: 10px">
<form action="/AdminLogin/Login" method="post">
<div id="login">
<div id="loginlogo"></div>
<div id="loginpanel">
<div class="panel-h"></div>
<div class="panel-c">
<div class="panel-c-l">
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td align="left" colspan="2">
<h3>请使用管理系统账号登录</h3>
</td>
</tr>
<tr>
<td align="right">账号:</td>
<td align="left">
<input type="text" name="AdminName" class="login-text" />
</td>
</tr>
<tr>
<td align="right">密码:</td>
<td align="left">
<input
type="password"
name="Pwd"
id="Pwd"
class="login-text"
/>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input
type="submit"
id="btnLogin"
value="登录"
class="login-btn"
/>
</td>
</tr>
</tbody>
</table>
</div>
<div class="panel-c-r">
<p>请从左侧输入登录账号和密码登录。</p>
<p>如果遇到系统问题,请联系网络管理员。</p>
<p>如果没有账号,请联系网站管理员。</p>
</div>
</div>
</div>
<div id="logincopyright">Copyright 20101330邓磊 2023 MYXH.com</div>
</div>
</form>
</body>
</html>
2.3.2 Index.cshtml
@{ Layout = null; }
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body style="text-align: center; background: #4974A4; ">
<div style="font-weight: bold;font-size: 28px;">
<span>
欢迎 @ViewBag.UserName 日期:@DateTime.Now.ToString("yyyy-MM-dd")
@DateTime.Now.DayOfWeek
</span>
</div>
</body>
</html>
2.3.3 Index.cshtml
@model IEnumerable<Lesson1.Models.Book>
@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/BookMaster.cshtml"; }
<style type="text/css">
a:link,
a:visited {
text-decoration: none; /*超链接无下划线*/
}
a:hover {
text-decoration: none; /*鼠标放上去有下划线*/
}
</style>
<table cellpadding="0" cellspacing="0">
<tr>
<th>@Html.DisplayNameFor(model => model.bookNum)</th>
<th>@Html.DisplayNameFor(model => model.bookName)</th>
<th>@Html.DisplayNameFor(model => model.bookConcern)</th>
<th>@Html.DisplayNameFor(model => model.bookAuthor)</th>
<th>@Html.DisplayNameFor(model => model.bookCount)</th>
<th>@Html.DisplayNameFor(model => model.bookPrice)</th>
<th></th>
@*
<th>编号</th>
<th>书名</th>
<th>出版社</th>
<th>作者</th>
<th>数量</th>
<th>价格</th>
<th></th>
*@
</tr>
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.bookNum)</td>
<td>@Html.DisplayFor(modelItem => item.bookName)</td>
<td>@Html.DisplayFor(modelItem => item.bookConcern)</td>
<td>@Html.DisplayFor(modelItem => item.bookAuthor)</td>
<td>@Html.DisplayFor(modelItem => item.bookCount)</td>
<td>@Html.DisplayFor(modelItem => item.bookPrice)</td>
<td>
@Html.ActionLink("修改", "Edit", new { id = item.ID }) |
@Html.ActionLink("详情", "Details", new { id = item.ID }) |
@Html.ActionLink("删除", "Delete", new { id = item.ID })
</td>
</tr>
}
</table>
@section link{ @Html.ImageLink("Create", "Book",
"../../Content/Images/Index/add.jpg", "添加") }</Lesson1.Models.Book
>
2.3.4 Create.cshtml
@model Lesson1.Models.Book @using System.Web.Optimization @{ ViewBag.Title =
"Create"; Layout = "~/Views/Shared/BookMaster.cshtml"; }
<style type="text/css">
#myform input,
#myform textarea,
#myform select {
/*#myform input[type=text], #myform input[type=number], #myform textarea, #myform select; {*/
padding: 8px;
margin: 2px 0 5px 0;
background: #fff;
width: 210px;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
color: #555;
border: 3px solid #e0e8c6;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 3px 3px 3px #8ba82c;
-webkit-box-shadow: 3px 3px 3px #8ba82c;
box-shadow: 3px 3px 3px #8ba82c;
}
#myform textarea {
width: 390px;
height: 175px;
}
#myform input:hover,
#myform textarea:hover {
/* -- CSS3 Shadow - create a shadow around each input element -- */
-webkit-box-shadow: 0px 0px 0px #aaa;
-moz-box-shadow: 0px 0px 0px #aaa;
box-shadow: 0px 0px 0px #aaa;
}
button {
width: 150px;
color: #fff;
text-transform: uppercase;
margin-top: 10px;
border: none;
padding: 12px;
/* -- CSS3 Transition - define which property to animate (i.e. the shadow) -- */
-webkit-transition: -webkit-box-shadow 0.3s linear;
/* -- CSS3 - Rounded Corners -- */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background: #0292cd url(~/Content/Images/Index/bg_button.png) repeat-x top
left;
font-family: "MyriadProSemibold";
font-weight: normal;
font-size: 14px;
text-transform: uppercase;
}
button:hover {
-webkit-box-shadow: 0px 0px 10px #c6db6f;
-moz-box-shadow: 0px 0px 10px #c6db6f;
box-shadow: 0px 0px 10px #c6db6f;
cursor: pointer;
}
a:link.button,
a:visited.button {
width: 100px;
color: #fff;
text-transform: uppercase;
margin-top: 10px;
border: none;
padding: 12px;
/* -- CSS3 Transition - define which property to animate (i.e. the shadow) -- */
-webkit-transition: -webkit-box-shadow 0.3s linear;
/* -- CSS3 - Rounded Corners -- */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background: #0292cd url(~/Content/Images/Index/bg_button.png) repeat-x top
left;
font-family: "MyriadProSemibold";
font-weight: normal;
font-size: 14px;
text-transform: uppercase;
display: inline-block;
text-align: center;
margin-right: 10px;
}
a.button:hover {
-webkit-box-shadow: 0px 0px 10px #c6db6f;
-moz-box-shadow: 0px 0px 10px #c6db6f;
box-shadow: 0px 0px 10px #c6db6f;
cursor: pointer;
text-align: center;
}
#myform {
position: relative;
float: left;
padding: 10px 20px 20px 20px;
width: 900px;
height: 95%;
margin-right: 40px;
/*background: url(~/Content/Images/Index/green_alpha.png) repeat;*/
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.col_f_1 {
float: left;
width: 240px;
/*display: block;*/
margin-right: 50px;
}
fieldset {
border: none;
}
.col_f_2 {
float: left;
width: 240px;
/*display: block;*/
}
#main_container {
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
border: 5px solid #e0e8c6;
padding: 30px;
height: 50%;
width: 90%;
}
</style>
<div id="main_container">
@using (Html.BeginForm("Create", "Book", FormMethod.Post, new { @id = "myform"
})) { @Html.AntiForgeryToken() @Html.ValidationSummary(true)
<fieldset class="col_f_1">
@Html.LabelFor(model => model.bookNum) @Html.EditorFor(model =>
model.bookNum) @Html.ValidationMessageFor(model => model.bookNum)<br />
@Html.LabelFor(model => model.bookName)@Html.EditorFor(model =>
model.bookName) @Html.ValidationMessageFor(model => model.bookName)<br />
@Html.LabelFor(model => model.bookConcern) @Html.EditorFor(model =>
model.bookConcern) @Html.ValidationMessageFor(model => model.bookConcern)
</fieldset>
<fieldset class="col_f_2">
@Html.LabelFor(model => model.bookAuthor) @Html.EditorFor(model =>
model.bookAuthor) @Html.ValidationMessageFor(model => model.bookAuthor)
@Html.LabelFor(model => model.bookCount) @Html.EditorFor(model =>
model.bookCount) @Html.ValidationMessageFor(model => model.bookCount)
@Html.LabelFor(model => model.bookPrice) @Html.EditorFor(model =>
model.bookPrice) @Html.ValidationMessageFor(model => model.bookPrice)
</fieldset>
<div style="clear:both; margin-top:5px;">
<input
type="submit"
value="添加"
style="color: #FFFFFF; background-color: #555; height:30px; width: 100px; border: none; padding: 2px 5px 2px 5px; cursor: pointer;"
/>
</div>
}
</div>
@section link{ @Html.ImageLink("Index", "Book",
"../../Content/Images/Index/nav_hide.png", "返回主页") } @section Scripts {
@Scripts.Render("~/bundles/jqueryval") }
2.3.5 Edit.cshtml
@model Lesson1.Models.Book @using System.Web.Optimization @{ Layout =
"~/Views/Shared/BookMaster.cshtml"; }
<style type="text/css">
#myform input,
#myform textarea,
#myform select {
/*#myform input[type=text], #myform input[type=number], #myform textarea, #myform select; {*/
padding: 8px;
margin: 2px 0 5px 0;
background: #fff;
width: 210px;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
color: #555;
border: 3px solid #e0e8c6;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 3px 3px 3px #8ba82c;
-webkit-box-shadow: 3px 3px 3px #8ba82c;
box-shadow: 3px 3px 3px #8ba82c;
}
#myform textarea {
width: 390px;
height: 175px;
}
#myform input:hover,
#myform textarea:hover {
/* -- CSS3 Shadow - create a shadow around each input element -- */
-webkit-box-shadow: 0px 0px 0px #aaa;
-moz-box-shadow: 0px 0px 0px #aaa;
box-shadow: 0px 0px 0px #aaa;
}
button {
width: 150px;
color: #fff;
text-transform: uppercase;
margin-top: 10px;
border: none;
padding: 12px;
/* -- CSS3 Transition - define which property to animate (i.e. the shadow) -- */
-webkit-transition: -webkit-box-shadow 0.3s linear;
/* -- CSS3 - Rounded Corners -- */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background: #0292cd url(~/Content/Images/Index/bg_button.png) repeat-x top
left;
font-family: "MyriadProSemibold";
font-weight: normal;
font-size: 14px;
text-transform: uppercase;
}
button:hover {
-webkit-box-shadow: 0px 0px 10px #c6db6f;
-moz-box-shadow: 0px 0px 10px #c6db6f;
box-shadow: 0px 0px 10px #c6db6f;
cursor: pointer;
}
a:link.button,
a:visited.button {
width: 100px;
color: #fff;
text-transform: uppercase;
margin-top: 10px;
border: none;
padding: 12px;
/* -- CSS3 Transition - define which property to animate (i.e. the shadow) -- */
-webkit-transition: -webkit-box-shadow 0.3s linear;
/* -- CSS3 - Rounded Corners -- */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background: #0292cd url(~/Content/Images/Index/bg_button.png) repeat-x top
left;
font-family: "MyriadProSemibold";
font-weight: normal;
font-size: 14px;
text-transform: uppercase;
display: inline-block;
text-align: center;
margin-right: 10px;
}
a.button:hover {
-webkit-box-shadow: 0px 0px 10px #c6db6f;
-moz-box-shadow: 0px 0px 10px #c6db6f;
box-shadow: 0px 0px 10px #c6db6f;
cursor: pointer;
text-align: center;
}
#myform {
position: relative;
float: left;
padding: 10px 20px 20px 20px;
width: 900px;
height: 95%;
margin-right: 40px;
/*background: url(~/Content/Images/Index/green_alpha.png) repeat;*/
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.col_f_1 {
float: left;
width: 240px;
/*display: block;*/
margin-right: 50px;
}
fieldset {
border: none;
}
.col_f_2 {
float: left;
width: 240px;
/*display: block;*/
}
#main_container {
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
border: 5px solid #e0e8c6;
padding: 30px;
height: 50%;
width: 90%;
}
</style>
<div id="main_container">
@using (Html.BeginForm("Edit", "Book", FormMethod.Post, new { @id = "myform"
})) { @Html.AntiForgeryToken() @Html.ValidationSummary(true)
@Html.HiddenFor(model => model.ID)
<fieldset class="col_f_1">
@Html.LabelFor(model => model.bookNum) @Html.EditorFor(model =>
model.bookNum) @Html.ValidationMessageFor(model => model.bookNum)<br />
@Html.LabelFor(model => model.bookName)@Html.EditorFor(model =>
model.bookName) @Html.ValidationMessageFor(model => model.bookName)<br />
@Html.LabelFor(model => model.bookConcern) @Html.EditorFor(model =>
model.bookConcern) @Html.ValidationMessageFor(model => model.bookConcern)
</fieldset>
<fieldset class="col_f_2">
@Html.LabelFor(model => model.bookAuthor) @Html.EditorFor(model =>
model.bookAuthor) @Html.ValidationMessageFor(model => model.bookAuthor)
@Html.LabelFor(model => model.bookCount) @Html.EditorFor(model =>
model.bookCount) @Html.ValidationMessageFor(model => model.bookCount)
@Html.LabelFor(model => model.bookPrice) @Html.EditorFor(model =>
model.bookPrice) @Html.ValidationMessageFor(model => model.bookPrice)
</fieldset>
<div style="clear:both; margin-top:5px;">
<input
type="submit"
value="修改"
style="color: #FFFFFF; background-color: #555; height:30px; width: 100px; border: none; padding: 2px 5px 2px 5px; cursor: pointer;"
/>
</div>
}
</div>
@section link{ @Html.ImageLink("Index", "Book",
"../../Content/Images/Index/nav_hide.png", "返回主页") } @section Scripts {
@Scripts.Render("~/bundles/jqueryval") }
2.3.6 Details.cshtml
@model Lesson1.Models.Book @{ ViewBag.Title = "Details"; Layout =
"~/Views/Shared/BookMaster.cshtml"; }
<style type="text/css">
#myform input,
#myform textarea,
#myform select {
/*#myform input[type=text], #myform input[type=number], #myform textarea, #myform select; {*/
padding: 8px;
margin: 2px 0 5px 0;
background: #fff;
width: 210px;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
color: #555;
border: 3px solid #e0e8c6;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 3px 3px 3px #8ba82c;
-webkit-box-shadow: 3px 3px 3px #8ba82c;
box-shadow: 3px 3px 3px #8ba82c;
}
#myform textarea {
width: 390px;
height: 175px;
}
#myform input:hover,
#myform textarea:hover {
/* -- CSS3 Shadow - create a shadow around each input element -- */
-webkit-box-shadow: 0px 0px 0px #aaa;
-moz-box-shadow: 0px 0px 0px #aaa;
box-shadow: 0px 0px 0px #aaa;
}
button {
width: 150px;
color: #fff;
text-transform: uppercase;
margin-top: 10px;
border: none;
padding: 12px;
/* -- CSS3 Transition - define which property to animate (i.e. the shadow) -- */
-webkit-transition: -webkit-box-shadow 0.3s linear;
/* -- CSS3 - Rounded Corners -- */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background: #0292cd url(~/Content/Images/Index/bg_button.png) repeat-x top
left;
font-family: "MyriadProSemibold";
font-weight: normal;
font-size: 14px;
text-transform: uppercase;
}
button:hover {
-webkit-box-shadow: 0px 0px 10px #c6db6f;
-moz-box-shadow: 0px 0px 10px #c6db6f;
box-shadow: 0px 0px 10px #c6db6f;
cursor: pointer;
}
a:link.button,
a:visited.button {
width: 100px;
color: #fff;
text-transform: uppercase;
margin-top: 10px;
border: none;
padding: 12px;
/* -- CSS3 Transition - define which property to animate (i.e. the shadow) -- */
-webkit-transition: -webkit-box-shadow 0.3s linear;
/* -- CSS3 - Rounded Corners -- */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background: #0292cd url(~/Content/Images/Index/bg_button.png) repeat-x top
left;
font-family: "MyriadProSemibold";
font-weight: normal;
font-size: 14px;
text-transform: uppercase;
display: inline-block;
text-align: center;
margin-right: 10px;
}
a.button:hover {
-webkit-box-shadow: 0px 0px 10px #c6db6f;
-moz-box-shadow: 0px 0px 10px #c6db6f;
box-shadow: 0px 0px 10px #c6db6f;
cursor: pointer;
text-align: center;
}
#myform {
position: relative;
float: left;
padding: 10px 20px 20px 20px;
width: 900px;
height: 95%;
margin-right: 40px;
/*background: url(~/Content/Images/Index/green_alpha.png) repeat;*/
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.col_f_1 {
float: left;
width: 240px;
/*display: block;*/
margin-right: 50px;
}
fieldset {
border: none;
}
.col_f_2 {
float: left;
width: 240px;
/*display: block;*/
}
#main_container {
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
border: 5px solid #e0e8c6;
padding: 30px;
height: 50%;
width: 90%;
}
/*.pricing_table {
line-height: 150%;
font-size: 12px;
margin: 0 auto;
width: 75%;
max-width: 800px;
padding-top: 10px;
margin-top: 100px;
}*/
.price_block {
text-align: center;
width: 100%;
color: #fff;
float: left;
list-style-type: none;
transition: all 0.25s;
position: relative;
box-sizing: border-box;
margin-bottom: 10px;
border-bottom: 1px solid transparent;
}
/*Price heads*/
.book_name {
font-weight: bold;
display: block;
}
/*Price tags*/
.price {
display: table;
background: #444;
width: 100%;
height: 50px;
}
.bookName {
display: table;
background: #333;
width: 100%;
height: 50px;
}
.price_figure {
font-size: 24px;
text-transform: uppercase;
vertical-align: middle;
display: table-cell;
}
.price_number {
font-weight: bold;
display: block;
}
.price_tenure {
font-size: 11px;
}
/*Features*/
.features {
background: #def0f4;
color: #000;
}
.features li {
padding: 8px 15px;
border-bottom: 1px solid #ccc;
font-size: 18px;
list-style-type: none;
}
</style>
<div id="main_container">
<ul class="pricing_table">
<li class="price_block">
<div class="bookName">
<div class="price_figure">
<span class="book_name"
>《@Html.DisplayFor(model => model.bookName)》
</span>
</div>
</div>
<div class="price">
<div class="price_figure">
<span class="price_number"
>¥@Html.DisplayFor(model => model.bookPrice)
</span>
</div>
</div>
<ul class="features">
<li>
@Html.LabelFor(model => model.bookCount): @Html.DisplayFor(model =>
model.bookCount)
</li>
<li>
@Html.LabelFor(model => model.bookNum): @Html.DisplayFor(model =>
model.bookNum)
</li>
<li>
@Html.LabelFor(model => model.bookConcern): @Html.DisplayFor(model =>
model.bookConcern)
</li>
<li>
@Html.LabelFor(model => model.bookAuthor): @Html.DisplayFor(model =>
model.bookAuthor)
</li>
</ul>
</li>
</ul>
</div>
@section link{ @Html.ImageLink("Index", "Book",
"../../Content/Images/Index/nav_hide.png", "返回主页") }
2.3.7 Delete.cshtml
@model Lesson1.Models.Book @{ Layout = "~/Views/Shared/BookMaster.cshtml"; }
<style type="text/css">
input {
padding: 8px;
margin: 2px 0 5px 0;
background: #fff;
width: 210px;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
color: #555;
border: 3px solid #e0e8c6;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 3px 3px 3px #8ba82c;
-webkit-box-shadow: 3px 3px 3px #8ba82c;
box-shadow: 3px 3px 3px #8ba82c;
}
/*#myform input:hover, #myform textarea:hover {
-webkit-box-shadow: 0px 0px 0px #aaa;
-moz-box-shadow: 0px 0px 0px #aaa;
box-shadow: 0px 0px 0px #aaa;
}*/
button {
width: 150px;
color: #fff;
text-transform: uppercase;
margin-top: 10px;
border: none;
padding: 12px;
/* -- CSS3 Transition - define which property to animate (i.e. the shadow) -- */
-webkit-transition: -webkit-box-shadow 0.3s linear;
/* -- CSS3 - Rounded Corners -- */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background: #0292cd url(~/Content/Images/Index/bg_button.png) repeat-x top
left;
font-family: "MyriadProSemibold";
font-weight: normal;
font-size: 14px;
text-transform: uppercase;
}
button:hover {
-webkit-box-shadow: 0px 0px 10px #c6db6f;
-moz-box-shadow: 0px 0px 10px #c6db6f;
box-shadow: 0px 0px 10px #c6db6f;
cursor: pointer;
}
a:link.button,
a:visited.button {
width: 100px;
color: #fff;
text-transform: uppercase;
margin-top: 10px;
border: none;
padding: 12px;
/* -- CSS3 Transition - define which property to animate (i.e. the shadow) -- */
-webkit-transition: -webkit-box-shadow 0.3s linear;
/* -- CSS3 - Rounded Corners -- */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background: #0292cd url(~/Content/Images/Index/bg_button.png) repeat-x top
left;
font-family: "MyriadProSemibold";
font-weight: normal;
font-size: 14px;
text-transform: uppercase;
display: inline-block;
text-align: center;
margin-right: 10px;
}
a.button:hover {
-webkit-box-shadow: 0px 0px 10px #c6db6f;
-moz-box-shadow: 0px 0px 10px #c6db6f;
box-shadow: 0px 0px 10px #c6db6f;
cursor: pointer;
text-align: center;
}
/*#myform {
position: relative;
float: left;
padding: 10px 20px 20px 20px;
width: 900px;
height: 95%;
margin-right: 40px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}*/
.col_f_1 {
float: left;
width: 240px;
/*display: block;*/
margin-right: 50px;
}
fieldset {
border: none;
}
.col_f_2 {
float: left;
width: 240px;
/*display: block;*/
}
#main_container {
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
border: 5px solid #e0e8c6;
padding: 30px;
height: 50%;
width: 90%;
}
.price_block {
text-align: center;
width: 100%;
color: #fff;
float: left;
list-style-type: none;
transition: all 0.25s;
position: relative;
box-sizing: border-box;
margin-bottom: 10px;
border-bottom: 1px solid transparent;
}
/*Price heads*/
.book_name {
font-weight: bold;
display: block;
}
/*Price tags*/
.price {
display: table;
background: #444;
width: 100%;
height: 50px;
}
.bookName {
display: table;
background: #333;
width: 100%;
height: 50px;
}
.price_figure {
font-size: 24px;
text-transform: uppercase;
vertical-align: middle;
display: table-cell;
}
.price_number {
font-weight: bold;
display: block;
}
.price_tenure {
font-size: 11px;
}
/*Features*/
.features {
background: #def0f4;
color: #000;
}
.features li {
padding: 8px 15px;
border-bottom: 1px solid #ccc;
font-size: 18px;
list-style-type: none;
}
</style>
<div id="main_container">
<ul class="pricing_table">
<li class="price_block">
<div class="bookName">
<div class="price_figure">
<span class="book_name"
>《@Html.DisplayFor(model => model.bookName)》
</span>
</div>
</div>
<div class="price">
<div class="price_figure">
<span class="price_number"
>¥@Html.DisplayFor(model => model.bookPrice)
</span>
</div>
</div>
<ul class="features">
<li>
@Html.LabelFor(model => model.bookCount): @Html.DisplayFor(model =>
model.bookCount)
</li>
<li>
@Html.LabelFor(model => model.bookNum): @Html.DisplayFor(model =>
model.bookNum)
</li>
<li>
@Html.LabelFor(model => model.bookConcern): @Html.DisplayFor(model =>
model.bookConcern)
</li>
<li>
@Html.LabelFor(model => model.bookAuthor): @Html.DisplayFor(model =>
model.bookAuthor)
</li>
</ul>
</li>
</ul>
@using (Html.BeginForm()) { @Html.AntiForgeryToken()
<div style="clear:both; margin-top:5px;">
<input
type="submit"
value="删除"
style="width: 100px; height: 30px; color: #ffffff; padding-top: 2px; padding-right: 5px; padding-bottom: 2px; padding-left: 5px; border-top-color: currentColor; border-right-color: currentColor; border-bottom-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; cursor: pointer; background-color: rgb(85, 85, 85);"
/>
</div>
}
</div>
@section link{ @Html.ImageLink("Index", "Book",
"../../Content/Images/Index/nav_hide.png", "返回主页") }
2.3.8 BookMaster.cshtml
<!DOCTYPE html>
@using System.Web.Optimization
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.title</title>
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
color: #666;
font-size: 12px;
margin: 0;
line-height: 16px;
background: #fff url(~/Content/Images/Index/black_alpha.png) repeat-x
top left;
}
* {
margin: 0;
padding: 0;
list-style: none;
}
#top {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 70px;
background-color: #303030;
}
#top_logo {
width: 300px;
float: left;
vertical-align: middle;
height: 70px;
line-height: 70px;
padding: 1px 3px 3px 40px;
}
#top_links {
width: 300px;
height: 65px;
float: right;
line-height: 65px;
color: #adadad;
line-height: 65px;
position: relative;
}
#top_op {
width: 250px;
}
#top_op ul {
list-style-type: none;
}
#top_op ul li {
display: inline-block;
margin-right: 5px;
}
#top_op ul li img {
vertical-align: middle;
}
#top_links a:link,
#nav_links a:visited,
#nav_links a:hover,
#nav_links a:active {
list-style: none;
text-decoration: none;
color: #fff;
}
#top_links a:hover {
list-style: none;
text-decoration: underline;
color: #fff;
}
#top_close {
width: 80px;
position: absolute;
right: 0px;
top: 0px;
border-left: 1px solid #171717;
vertical-align: middle;
}
table {
padding: 0;
margin: 0;
position: relative;
margin: 0 auto;
}
tr th {
background: #044599 no-repeat;
text-align: center;
border-left: 1px solid #02397f;
border-right: 1px solid #02397f;
border-bottom: 1px solid #02397f;
border-top: 1px solid #02397f;
letter-spacing: 2px;
text-transform: uppercase;
font-size: 14px;
color: #fff;
height: 37px;
}
tr td {
text-align: center;
border-left: 1px solid #ececec;
border-right: 1px solid #ececec;
border-bottom: 1px solid #ececec;
font-size: 15px;
color: #909090;
height: 37px;
}
#main {
position: absolute;
left: 220px;
top: 140px;
bottom: 0px;
right: 0px;
width: auto;
z-index: 2;
overflow: hidden;
}
#side {
position: absolute;
left: 0;
top: 70px;
bottom: 0px;
width: 180px;
overflow: hidden;
}
#left_menu_cnt {
width: 180px;
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
overflow: auto;
background: #f1f1f1;
}
#left_menu_cnt #nav_module {
position: fixed;
padding-left: 10px;
background: #f1f1f1;
}
#left_menu_cnt #nav_resource {
margin-top: 60px;
overflow: auto;
}
table {
width: 100%;
margin: 0;
padding: 0;
font-family: "Microsoft Yahei";
}
#bottom {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 70px;
background-color: #303030;
text-align: center;
color: white;
margin-top: 30px;
}
#top_nav {
position: fixed;
width: 77%;
top: 70px;
left: 304px;
height: 58px;
line-height: 70px;
color: #8a8a8a;
font-size: 14px;
border-bottom: 1px solid #ededed;
}
#dleft_tab1 li {
padding: 5px;
margin: 0;
list-style: none;
line-height: 14px;
text-align: center;
white-space: nowrap;
outline: 0;
}
</style>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(function () {
$("#TabPage2 li").click(function () {
var index = $(this).index();
$(this)
.find("img")
.attr("src", "images/common/" + (index + 1) + "_hover.jpg");
$(this).css({ background: "#fff" });
$("#nav_module")
.find("img")
.attr("src", "images/common/module_" + (index + 1) + ".png");
$("#TabPage2 li").each(function (i, ele) {
if (i != index) {
$(ele)
.find("img")
.attr("src", "images/common/" + (i + 1) + ".jpg");
$(ele).css({ background: "#044599" });
}
});
});
});
</script>
</head>
<body>
<div id="top">
<div id="top_logo">
<img
alt="logo"
src="~/Content/Images/Index/logo.png"
style="vertical-align:middle;"
/>
</div>
<div id="top_links">
<div id="top_op">
<ul>
<li>
<img alt="当前用户" src="~/Content/Images/Index/user.jpg" />
<span>admin</span>
</li>
<li>
<img alt="今天是" src="~/Content/Images/Index/date.jpg" />
<span id="day_day">@DateTime.Now.ToLongDateString()</span>
</li>
</ul>
</div>
<div id="top_close">
<a href="/AdminLogin/Login" onclick="logout();" target="_parent">
<img
alt="退出系统"
title="退出系统"
src="~/Content/Images/Index/close.jpg"
style="position: relative; top: 10px; left: 25px;"
/>
</a>
</div>
</div>
</div>
<div id="side">
<div id="left_menu_cnt">
<div id="nav_resource">
<ul id="dleft_tab1">
<li>信息系统开发与实践</li>
<li>ASP.NET</li>
<li>C++</li>
<li>Python</li>
<li>Java</li>
<li>Vue</li>
<li>Unity</li>
</ul>
</div>
</div>
</div>
<div id="top_nav" style="width:75%;">
<span id="here_area">当前位置:</span>
<span style="float:right"> @RenderSection("link", required: false) </span>
</div>
<div id="main" style="clear:both;">
@RenderBody() @Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</div>
<div id="bottom">Copyright 20101330邓磊 2023 MYXH.com</div>
</body>
</html>
2.3.9 Error.aspx
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic
>" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>错误</title>
</head>
<body>
<hgroup>
<h1>错误!</h1>
<h2>处理你的请求时出错。</h2>
</hgroup>
</body>
</html></dynamic
>
2.4 App_Start 模块
2.4.1 FilterConfig.cs
using System.Web;
using System.Web.Mvc;
namespace Lesson1
{
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
}
}
2.4.2 RouteConfig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace Lesson1
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "AdminLogin", action = "Login", id = UrlParameter.Optional }
);
}
}
}
2.4.3 WebApiConfig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace Lesson1
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
3. 系统界面展示
以下是本图书管理系统的几个主要界面截图:
3.1 登录界面
管理员可以在此界面输入用户名和密码进行登录,只有在登录成功后才能进入主界面进行操作。
3.2 主界面
主界面显示了所有已添加的图书,支持添加、修改、查看、删除等操作。管理员可以通过点击图书列表项进入详情界面查看图书的详细信息。
3.3 添加图书界面
添加图书界面提供给管理员一个编辑器,让管理员可以方便地添加新的图书。管理员可以在此界面输入图书的编号、名称、出版社、作者、库存、价格等信息。
3.4 修改图书界面
修改图书界面提供给管理员一个编辑器,让管理员可以方便地修改图书。管理员可以在此界面输入图书的编号、名称、出版社、作者、库存、价格等信息。
3.5 图书详情界面
图书详情界面是一个展示已有图书信息的界面,管理员可以在此界面查看图书的详细信息,包括图书的编号、名称、出版社、作者、库存、价格等信息,并且可以进行添加、修改、查看、删除等操作。
4. 总结
本文档详细描述了一个图书管理系统的开发过程和功能实现,包括系统目标、系统设计、系统实现、系统部署和界面展示等内容。该系统采用了 ASP.NET MVC 架构,使用 C# 编程语言进行开发,采用了 Entity Framework 数据库访问框架等 ASP.NET 系统提供的 API 和功能。该系统实现了管理员登录、图书添加、编辑、查询、删除等功能,并提供了良好的用户界面。同时,本文档还提供了系统相关代码和界面截图以供参考。