目录
题目:
实现过程
控制器代码
DAL
BLL
Index
ADD
题目:
实现过程
控制器代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
ViewBag.list= BLL.OrderInfoManager.Show();
return View();
}
public ActionResult Jia()
{
return View();
}
[HttpPost]
public ActionResult Jia(string OrderDate, string UserName)
{
OrderInfo model = new OrderInfo();
model.OrderState = 0;
model.UserName = UserName;
model.OrderDate = Convert.ToDateTime(OrderDate);
BLL.OrderInfoManager.Add(model);
return RedirectToAction("Index");
}
public ActionResult Sent(int id)
{
BLL.OrderInfoManager.Update(id);
return RedirectToAction("Index");
}
}
}
DAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Models;
namespace MvcApplication1.DAL
{
public class OrderInfoServices
{
public static List<OrderInfo> Show() {
OrdersDBEntities db=new OrdersDBEntities();
return db.OrderInfoes.OrderBy(x=>x.OrderState).ToList();
}
public static bool Add(OrderInfo model) {
OrdersDBEntities db = new OrdersDBEntities();
db.OrderInfoes.Add(model);
return db.SaveChanges() > 0;
}
public static OrderInfo FindModel(int id) {
OrdersDBEntities db = new OrdersDBEntities();
return db.OrderInfoes.SingleOrDefault(x=>x.OrderID==id);
}
public static bool Update(int id) {
OrdersDBEntities db = new OrdersDBEntities();
OrderInfo model= FindModel(id);
db.Entry(model).State = System.Data.EntityState.Modified;
model.OrderState = model.OrderState == 0 ? 1 : 0;
return db.SaveChanges() > 0;
}
}
}
BLL
using System; using System.Collections.Generic; using System.Linq; using System.Web; using MvcApplication1.Models; namespace MvcApplication1.BLL { public class OrderInfoManager { public static List<OrderInfo> Show() { return DAL.OrderInfoServices.Show(); } public static bool Add(OrderInfo model) { return DAL.OrderInfoServices.Add(model); } public static bool Update(int id) { return DAL.OrderInfoServices.Update(id); } } }
Index
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
<center> <h1>简易订单管理系统</h1>
<a href="/Home/Jia">添加订单</a>
<table border="1">
<tr>
<th>订单编号</th>
<th>下单人</th>
<th>订单日期</th>
<th>订单状态</th>
<th>操作</th>
</tr>
@foreach (var item in @ViewBag.list as List<MvcApplication1.Models.OrderInfo>)
{
<tr>
<td>@item.OrderID</td>
<td>@item.UserName</td>
<td>@item.OrderDate.ToString("yyyy年MM月dd日")</td>
@if (@item.OrderState==0)
{
<td style="background-color:red">未发货</td>
}
else
{
<td style="background-color:white">已发货</td>
}
@if (@item.OrderState==0)
{
<td>@Html.ActionLink("发货", "Sent", new { id=@item.OrderID})</td>
}
else
{
}
</tr>
}
</table>
</center>
</div>
</body>
</html>
ADD
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Jia</title>
</head>
<body>
<div>
<center> <h1>简易订单管理系统</h1>
<a href="/Home/Index">返回首页</a>
<form method="post" action="/Home/Jia">
<label>下单人</label><input type="text" name="UserName" required/><br />
<label>订单日期</label><input type="date" name="OrderDate" required/><br />
<input type="submit" value="添加"/>
</form>
</center>
</div>
</body>
</html>