ASP.NET MVC企业级程序设计 (入住退房,删除)

发布于:2024-05-16 ⋅ 阅读:(140) ⋅ 点赞:(0)

目录

效果图

实现过程 

控制器代码

DAL

 BLL

Index 


效果图

实现过程 

控制器代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            ViewData["Show"] = BLL.BllManager.Show();
            return View();
        }
        public ActionResult delect(int id)
        {

          
            BLL.BllManager.Delect(id);
            return RedirectToAction("Index");
        }
        public ActionResult order(int id) {
            BLL.BllManager.order(id);
            return RedirectToAction("Index");
        }
    }
}

DAL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Model;
namespace MvcApplication1.DAL
{
    public class DalService
    {
        public static List<Room> Show() {
            HotelEntities db = new HotelEntities();
            return db.Rooms.ToList();
        }


        public static bool Delect(int id)
        {
            Room room = findroom(id);
            HotelEntities db = new HotelEntities();
            db.Entry(room).State = System.Data.EntityState.Deleted;
            return db.SaveChanges() > 0;
        }
        public static bool order(int id)
        {
            Room room = findroom(id);
            HotelEntities db = new HotelEntities();
            db.Entry(room).State = System.Data.EntityState.Modified;
            room.statu = room.statu == 0 ? 1 : 0;
            return db.SaveChanges() > 0;
        }
        public static Room findroom(int id)
        {
            HotelEntities db = new HotelEntities();

            return db.Rooms.SingleOrDefault(x => x.TID == id);


        }

    }
}

 BLL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Model;
namespace MvcApplication1.BLL
{
    public class BllManager
    {

        public static List<Room> Show()
        {
            return DAL.DalService.Show();
        }
         
        public static bool Delect(int id)
        {
            return DAL.DalService.Delect(id);
        }
        public static bool order(int id)
        {
            return DAL.DalService.order(id);
        }
       


    }
}

Index 

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        <h1>酒店管理</h1>
        <table border="1">
            <tr style="background-color:aqua">
                <td>编号</td>
                <td>房间类型</td>
                <td>房间号</td>
                <td>单价</td>
                <td>内线电话</td>
                <td>状态</td>
                <td>删除</td>
            </tr>
           @{
               foreach (var item in ViewData["Show"] as List<MvcApplication1.Model.Room> )
               {
                   <tr >
                       <td>@item.TID</td>
                       <td>@item.TypeName</td>
                        <td>@item.Name</td>
                        <td>@item.Price</td>
                        <td>@item.Phone</td>
                       @if (item.statu==0)
                       {
                           <td><span style="color:red">未入住</span>@Html.ActionLink("入住", "order", new {id=@item.TID })</td>
                       }else{
                      <td><span style="color:green">已入住</span>@Html.ActionLink("退房", "order", new {id=@item.TID })</td> 
                       }      



                        <td>@Html.ActionLink("删除", "delect", new {id=@item.TID})</td>
                        

                   </tr>
               }
               }
        </table>
    </div>
</body>
</html>


网站公告

今日签到

点亮在社区的每一天
去签到