<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

        ASP.NET實(shí)現(xiàn)電影票信息的增刪查改功能

        來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-27 22:36:11
        文檔

        ASP.NET實(shí)現(xiàn)電影票信息的增刪查改功能

        ASP.NET實(shí)現(xiàn)電影票信息的增刪查改功能:題目 1、使用Code First技術(shù)創(chuàng)建一個Movie數(shù)據(jù)模型。 public class Movie { public int ID { get; set; } //電影編號 public string Title { get; set; } //電影名稱 public DateTime ReleaseDate { get; set
        推薦度:
        導(dǎo)讀ASP.NET實(shí)現(xiàn)電影票信息的增刪查改功能:題目 1、使用Code First技術(shù)創(chuàng)建一個Movie數(shù)據(jù)模型。 public class Movie { public int ID { get; set; } //電影編號 public string Title { get; set; } //電影名稱 public DateTime ReleaseDate { get; set

        題目

        1、使用Code First技術(shù)創(chuàng)建一個Movie數(shù)據(jù)模型。

        public class Movie
         {
         public int ID { get; set; } //電影編號
         public string Title { get; set; } //電影名稱
         public DateTime ReleaseDate { get; set; } //上映時間
         public string Genre { get; set; } //電影類型
         public decimal Price { get; set; } //電影票價
         public string Rating { get; set; } //電影分級
         }

        2、使用MVC相關(guān)技術(shù)實(shí)現(xiàn)數(shù)據(jù)的列表顯示和新增功能。

        3、完成數(shù)據(jù)的編輯、刪除、明細(xì)和條件查詢等功能。

        4、完成如下查詢:

        (1)查詢尚未上映電影的信息

        (4)查詢票價在某個區(qū)間的電影信息

        效果

        這里寫圖片描述 
        這里寫圖片描述

        (源碼在文章結(jié)尾)

        主要涉及知識點(diǎn)

        1、ASP.NET WEB MVC下的目錄結(jié)構(gòu)以及基礎(chǔ)編程

        2、Linq查詢操作

        3、Code First

        4、各模板View的建立和使用

        主要代碼

        MovieController.cs

        using ProjectThree.Models;
        using System;
        using System.Collections.Generic;
        using System.Data.Entity;
        using System.Linq;
        using System.Web;
        using System.Web.Mvc;
        namespace ProjectThree.Controllers
        {
         public class MovieController : Controller
         {
         MovieDBContext db = new MovieDBContext();
         // GET: Movie
         public ActionResult Index(string movieOn, string movieGenre,
         string searchString, string lowPrice, string highPrice)
         {
         //初始化電影是否上映下拉
         var GenreLst1 = new List<string>();
         GenreLst1.Add("是");
         GenreLst1.Add("否");
         ViewBag.movieOn = new SelectList(GenreLst1);
         //初始化電影類型下拉
         var GenreLst2 = new List<string>();
         var GenreQry = from d in db.Movies orderby d.Genre select d.Genre;
         GenreLst2.AddRange(GenreQry.Distinct()); //去重
         ViewBag.movieGenre = new SelectList(GenreLst2);
         var movies = from m in db.Movies select m;
         if (!String.IsNullOrEmpty(movieOn))
         {
         DateTime dtNow = DateTime.Now;
         if (movieOn.Equals("是"))
         { movies = movies.Where(s => DateTime.Compare(dtNow, s.ReleaseDate) > 0); }
         else if (movieOn.Equals("否"))
         { movies = movies.Where(s => DateTime.Compare(dtNow, s.ReleaseDate) <= 0); }
         }
         if (!String.IsNullOrEmpty(movieGenre))
         { movies = movies.Where(x => x.Genre == movieGenre); }
         if (!String.IsNullOrEmpty(searchString))
         { movies = movies.Where(s => s.Title.Contains(searchString)); }
         if ((!String.IsNullOrEmpty(lowPrice)) && (!String.IsNullOrEmpty(highPrice)))
         {
         try
         {
         Decimal low = Decimal.Parse(lowPrice);
         Decimal high = Decimal.Parse(highPrice);
         if (high < low)
         {
         Response.Write("<script>alert('左邊價格不可大于右邊!');</script>");
         }
         else
         {
         movies = movies.Where(s => s.Price >= low);
         movies = movies.Where(s => s.Price <= high);
         }
         }
         catch
         {
         Response.Write("<script>alert('必須輸入數(shù)字!');</script>");
         return View(movies);
         }
         }
         return View(movies);
         }
         public ActionResult Create()
         {
         return View();
         }
         [HttpPost]
         public ActionResult Create(Movie m)
         {
         if (ModelState.IsValid)
         {
         db.Movies.Add(m);
         db.SaveChanges();
         return RedirectToAction("Index", "Movie");
         }
         return View(m);
         }
         public ActionResult Delete(int? id)
         {
         Movie m = db.Movies.Find(id);
         if (m != null)
         {
         db.Movies.Remove(m);
         db.SaveChanges();
         }
         return RedirectToAction("Index", "Movie");
         }
         public ActionResult Edit(int id)
         {
         Movie stu = db.Movies.Find(id);
         return View(stu);
         }
         [HttpPost]
         public ActionResult Edit(Movie stu)
         {
         db.Entry(stu).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index", "Movie");
         }
         }
        }

        Movie.cs

        using System;
        using System.ComponentModel.DataAnnotations;
        namespace ProjectThree.Models
        {
         public class Movie
         {
         [Display(Name = "電影編號")]
         public int ID { get; set; } //電影編號
         [Display(Name = "電影名稱")]
         [Required(ErrorMessage = "必填")]
         [StringLength(60, MinimumLength = 3, ErrorMessage = "必須是[3,60]個字符")]
         public string Title { get; set; } //電影名稱
         [Display(Name = "上映時間")]
         [DataType(DataType.Date)]
         [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}",ApplyFormatInEditMode = true)]
         public DateTime ReleaseDate { get; set; } //上映時間
         [Display(Name = "電影類型")]
         [Required]
         public string Genre { get; set; } //電影類型
         [Display(Name = "電影票價")]
         [Range(1, 100)]
         [DataType(DataType.Currency)]
         public decimal Price { get; set; } //電影票價
         [Display(Name = "電影分級")]
         [StringLength(5)]
         [Required]
         public string Rating { get; set; } //電影分級
         }
        }

        MovieDBContext.cs

        using System.Data.Entity;
        namespace ProjectThree.Models
        {
         public class MovieDBContext : DbContext
         {
         public DbSet<Movie> Movies { get; set; }
         }
        }

        Index.cshtml

        @model IEnumerable<ProjectThree.Models.Movie>
        @{
         ViewBag.Title = "Index";
        }
        <p>
         @Html.ActionLink("新建", "Create")
         @using (Html.BeginForm("Index", "Movie", FormMethod.Get))
         {
         <p>
         電影是否上映:@Html.DropDownList("movieOn", "all")
         電影類型:@Html.DropDownList("movieGenre", "all")
         電影名稱:@Html.TextBox("SearchString")
         票價區(qū)間:@Html.TextBox("lowPrice")~@Html.TextBox("highPrice")
         <input type="submit" value="查詢" />
         </p>
         }
        </p>
        <table class="table">
         <tr>
         <th>
         @Html.DisplayNameFor(model => model.Title)
         </th>
         <th>
         @Html.DisplayNameFor(model => model.ReleaseDate)
         </th>
         <th>
         @Html.DisplayNameFor(model => model.Genre)
         </th>
         <th>
         @Html.DisplayNameFor(model => model.Price)
         </th>
         <th>
         @Html.DisplayNameFor(model => model.Rating)
         </th>
         <th></th>
         </tr>
        @foreach (var item in Model) {
         <tr>
         <td>
         @Html.DisplayFor(modelItem => item.Title)
         </td>
         <td>
         @Html.DisplayFor(modelItem => item.ReleaseDate)
         </td>
         <td>
         @Html.DisplayFor(modelItem => item.Genre)
         </td>
         <td>
         @Html.DisplayFor(modelItem => item.Price)
         </td>
         <td>
         @Html.DisplayFor(modelItem => item.Rating)
         </td>
         <td>
         @Html.ActionLink("編輯", "Edit", new { id=item.ID }) |
         @Html.ActionLink("詳情", "Details", new { id=item.ID }) |
         @Html.ActionLink("刪除", "Delete", new { id=item.ID }, new { onclick = "return confirm('確認(rèn)刪除嗎?')" })
         </td>
         </tr>
        }
        </table>

        Create.cshtml

        @model ProjectThree.Models.Movie
        @{
         ViewBag.Title = "Create";
        }
        @using (Html.BeginForm()) 
        {
         @Html.AntiForgeryToken()
         <div class="form-horizontal">
         <h4>Movie</h4>
         <hr />
         @Html.ValidationSummary(true, "", new { @class = "text-danger" })
         <div class="form-group">
         @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
         @Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
         </div>
         </div>
         <div class="form-group">
         @Html.LabelFor(model => model.ReleaseDate, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
         @Html.EditorFor(model => model.ReleaseDate, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model => model.ReleaseDate, "", new { @class = "text-danger" })
         </div>
         </div>
         <div class="form-group">
         @Html.LabelFor(model => model.Genre, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
         @Html.EditorFor(model => model.Genre, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model => model.Genre, "", new { @class = "text-danger" })
         </div>
         </div>
         <div class="form-group">
         @Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
         @Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
         </div>
         </div>
         <div class="form-group">
         @Html.LabelFor(model => model.Rating, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
         @Html.EditorFor(model => model.Rating, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model => model.Rating, "", new { @class = "text-danger" })
         </div>
         </div>
         <div class="form-group">
         <div class="col-md-offset-2 col-md-10">
         <input type="submit" value="Create" class="btn btn-default" />
         </div>
         </div>
         </div>
        }
        <div>
         @Html.ActionLink("Back to List", "Index")
        </div>

        Edit.cshtml

        @model ProjectThree.Models.Movie
        @{
         ViewBag.Title = "Edit";
        }
        <h2>Edit</h2>
        @using (Html.BeginForm())
        {
         @Html.AntiForgeryToken()
         <div class="form-horizontal">
         <h4>Movie</h4>
         <hr />
         @Html.ValidationSummary(true, "", new { @class = "text-danger" })
         @Html.HiddenFor(model => model.ID)
         <div class="form-group">
         @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
         @Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
         </div>
         </div>
         <div class="form-group">
         @Html.LabelFor(model => model.ReleaseDate, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
         @Html.EditorFor(model => model.ReleaseDate, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model => model.ReleaseDate, "", new { @class = "text-danger" })
         </div>
         </div>
         <div class="form-group">
         @Html.LabelFor(model => model.Genre, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
         @Html.EditorFor(model => model.Genre, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model => model.Genre, "", new { @class = "text-danger" })
         </div>
         </div>
         <div class="form-group">
         @Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
         @Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
         </div>
         </div>
         <div class="form-group">
         @Html.LabelFor(model => model.Rating, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
         @Html.EditorFor(model => model.Rating, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model => model.Rating, "", new { @class = "text-danger" })
         </div>
         </div>
         <div class="form-group">
         <div class="col-md-offset-2 col-md-10">
         <input type="submit" value="Save" class="btn btn-default" />
         </div>
         </div>
         </div>
        }
        <div>
         @Html.ActionLink("Back to List", "Index")
        </div>

        源碼地址

        http://download.csdn.net/detail/double2hao/9710754

        以上所述是小編給大家介紹的ASP.NET實(shí)現(xiàn)電影票信息的增刪查改功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        ASP.NET實(shí)現(xiàn)電影票信息的增刪查改功能

        ASP.NET實(shí)現(xiàn)電影票信息的增刪查改功能:題目 1、使用Code First技術(shù)創(chuàng)建一個Movie數(shù)據(jù)模型。 public class Movie { public int ID { get; set; } //電影編號 public string Title { get; set; } //電影名稱 public DateTime ReleaseDate { get; set
        推薦度:
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲另类无码专区首页| 亚洲一区二区三区四区视频| 粉色视频成年免费人15次| 国产v精品成人免费视频400条| 图图资源网亚洲综合网站| 久99久精品免费视频热77| 久久精品国产精品亚洲艾草网| 在线观看免费无码专区| 亚洲国产精品无码中文字| 午夜影院免费观看| 亚洲w码欧洲s码免费| 在线观看视频免费国语| 国产综合激情在线亚洲第一页| 亚洲国产成人精品无码久久久久久综合| 未满十八私人高清免费影院| 亚洲精品无码专区2| 日本视频免费高清一本18| 亚洲精品免费在线| 啦啦啦手机完整免费高清观看| 成人精品国产亚洲欧洲| 浮力影院亚洲国产第一页| 久久大香伊焦在人线免费| 亚洲AV无码一区二区三区人| 四虎影视永久免费观看| 两个人的视频www免费| 亚洲美女视频免费| 四虎在线播放免费永久视频| 精品乱子伦一区二区三区高清免费播放 | 亚洲不卡中文字幕无码| aⅴ免费在线观看| 国产99久久亚洲综合精品| 综合亚洲伊人午夜网| 91成年人免费视频| 免费无遮挡无遮羞在线看| 亚洲国产一区二区a毛片| 免费无遮挡无码视频网站| 国产精品小视频免费无限app | 无码国产精品一区二区免费模式 | 国产成人免费福利网站| a级毛片毛片免费观看久潮| 亚洲伊人久久大香线蕉|