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


    目录

    效果图

    实现过程 

    控制器代码

    DAL

     BLL

    Index 


    效果图

    实现过程 

    控制器代码

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Web;
    5. using System.Web.Mvc;
    6. namespace MvcApplication1.Controllers
    7. {
    8. public class HomeController : Controller
    9. {
    10. //
    11. // GET: /Home/
    12. public ActionResult Index()
    13. {
    14. ViewData["Show"] = BLL.BllManager.Show();
    15. return View();
    16. }
    17. public ActionResult delect(int id)
    18. {
    19. BLL.BllManager.Delect(id);
    20. return RedirectToAction("Index");
    21. }
    22. public ActionResult order(int id) {
    23. BLL.BllManager.order(id);
    24. return RedirectToAction("Index");
    25. }
    26. }
    27. }

    DAL

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Web;
    5. using MvcApplication1.Model;
    6. namespace MvcApplication1.DAL
    7. {
    8. public class DalService
    9. {
    10. public static List Show() {
    11. HotelEntities db = new HotelEntities();
    12. return db.Rooms.ToList();
    13. }
    14. public static bool Delect(int id)
    15. {
    16. Room room = findroom(id);
    17. HotelEntities db = new HotelEntities();
    18. db.Entry(room).State = System.Data.EntityState.Deleted;
    19. return db.SaveChanges() > 0;
    20. }
    21. public static bool order(int id)
    22. {
    23. Room room = findroom(id);
    24. HotelEntities db = new HotelEntities();
    25. db.Entry(room).State = System.Data.EntityState.Modified;
    26. room.statu = room.statu == 0 ? 1 : 0;
    27. return db.SaveChanges() > 0;
    28. }
    29. public static Room findroom(int id)
    30. {
    31. HotelEntities db = new HotelEntities();
    32. return db.Rooms.SingleOrDefault(x => x.TID == id);
    33. }
    34. }
    35. }

     BLL

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Web;
    5. using MvcApplication1.Model;
    6. namespace MvcApplication1.BLL
    7. {
    8. public class BllManager
    9. {
    10. public static List Show()
    11. {
    12. return DAL.DalService.Show();
    13. }
    14. public static bool Delect(int id)
    15. {
    16. return DAL.DalService.Delect(id);
    17. }
    18. public static bool order(int id)
    19. {
    20. return DAL.DalService.order(id);
    21. }
    22. }
    23. }

    Index 

    1. @{
    2. Layout = null;
    3. }
    4. "viewport" content="width=device-width" />
    5. Index
    6. 酒店管理

    7. "1">
    8. "background-color:aqua">
    9. @{
    10. foreach (var item in ViewData["Show"] as List )
    11. {
    12. @if (item.statu==0)
    13. {
    14. }else{
    15. }
    16. }
    17. }
    18. 编号房间类型房间号单价内线电话状态删除
      @item.TID@item.TypeName@item.Name@item.Price@item.Phone"color:red">未入住@Html.ActionLink("入住", "order", new {id=@item.TID })"color:green">已入住@Html.ActionLink("退房", "order", new {id=@item.TID }) @Html.ActionLink("删除", "delect", new {id=@item.TID})
  • 相关阅读:
    RabbitMq(集群搭建)
    Go基本数据类型
    python、ruby、go、java写的端口扫描工具
    面向对象进阶
    【并发编程】ThreadPoolExecutor任务提交与停止流程及底层实现【新手探索版】
    临界区(critical section 每个线程中访问 临界资源 的那段代码)和互斥锁(mutex)的区别(进程间互斥量、共享内存、虚拟地址)
    如何使用 apt-get 安装特定版本的软件包
    苹果设备连接win11开启的wifi热点的断流问题
    给定两个单链表,编写算法找出两个单链表的公共结点(暴力解题,优化解题)
    java.sql.SQLException: Value ‘xxx‘ can not be represented as java.sql.Timestamp
  • 原文地址:https://blog.csdn.net/Mr_wangzu/article/details/138546268