MVC之排球比赛计分程序 ——(八)具体代码(2)

2021-07-15 14:05

阅读:376

标签:search   edit   submit   sub   void   经验   isnull   date   each   

三、TeamController具体代码如下:

public class TeamController : Controller
    {
        private CountScoreDBContext db = new CountScoreDBContext();

        //
        // GET: /Team/

        public ActionResult Index()
        {
            return View(db.Team.ToList());
        }

        //
        // GET: /Team/Details/5

        public ActionResult Details(int id = 0)
        {
            Team team = db.Team.Find(id);
            if (team == null)
            {
                return HttpNotFound();
            }
            return View(team);
        }

        //
        // GET: /Team/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Team/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(Team team)
        {
            if (ModelState.IsValid)
            {
                db.Team.Add(team);
                db.SaveChanges();
                return RedirectToAction("Create","Score");
            }

            return View(team);
        }

        //
        // GET: /Team/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Team team = db.Team.Find(id);
            if (team == null)
            {
                return HttpNotFound();
            }
            return View(team);
        }

        //
        // POST: /Team/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Team team)
        {
            if (ModelState.IsValid)
            {
                db.Entry(team).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(team);
        }

        //
        // GET: /Team/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Team team = db.Team.Find(id);
            if (team == null)
            {
                return HttpNotFound();
            }
            return View(team);
        }

        //
        // POST: /Team/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Team team = db.Team.Find(id);
            db.Team.Remove(team);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }

视图:

1、Index.cshtml

@model IEnumerable

@{
    ViewBag.Title = "Index";
}

开始比赛


    @Html.ActionLink("添加新的比赛队伍", "Create")



   
       
       
       
       
   

@foreach (var item in Model) {
   


       
       
       
       
   
}


            @Html.DisplayNameFor(model => model.TName)
       

            @Html.DisplayNameFor(model => model.TResult)
       

            @Html.DisplayNameFor(model => model.TParentId)
       

            @Html.DisplayFor(modelItem => item.TName)
       

            @Html.DisplayFor(modelItem => item.TResult)
       

            @Html.DisplayFor(modelItem => item.TParentId)
       

            @Html.ActionLink("编辑", "Edit", new { id=item.TId }) |
            @Html.ActionLink("详细信息", "Details", new { id=item.TId }) |
            @Html.ActionLink("删除比赛", "Delete", new { id=item.TId })
       

2、Edit.cshtml

@model MvcVolleyball.Models.Team

@{
    ViewBag.Title = "Edit";
}

修改数据

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

   


        Team

        @Html.HiddenFor(model => model.TId)

       


            @Html.LabelFor(model => model.TName)
       

       

            @Html.EditorFor(model => model.TName)
            @Html.ValidationMessageFor(model => model.TName)
       

       


            @Html.LabelFor(model => model.TResult)
       

       

            @Html.EditorFor(model => model.TResult)
            @Html.ValidationMessageFor(model => model.TResult)
       

       


            @Html.LabelFor(model => model.TParentId)
       

       

            @Html.EditorFor(model => model.TParentId)
            @Html.ValidationMessageFor(model => model.TParentId)
       

       


           
       


   
}


    @Html.ActionLink("返回首页", "Index")

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

3、Details.cshtml

@model MvcVolleyball.Models.Team

@{
    ViewBag.Title = "Details";
}

详细信息


    Team

   


         @Html.DisplayNameFor(model => model.TName)
   

   

        @Html.DisplayFor(model => model.TName)
   

   


         @Html.DisplayNameFor(model => model.TResult)
   

   

        @Html.DisplayFor(model => model.TResult)
   

   


         @Html.DisplayNameFor(model => model.TParentId)
   

   

        @Html.DisplayFor(model => model.TParentId)
   



    @Html.ActionLink("编辑", "Edit", new { id=Model.TId }) |
      @Html.ActionLink("详细信息", "Index","Score" )
    @Html.ActionLink("返回首页", "Index")

4、Delete.cshtml

@model MvcVolleyball.Models.Team

@{
    ViewBag.Title = "Delete";
}

Delete

确定删除?



    Team

   


         @Html.DisplayNameFor(model => model.TName)
   

   

        @Html.DisplayFor(model => model.TName)
   

   


         @Html.DisplayNameFor(model => model.TResult)
   

   

        @Html.DisplayFor(model => model.TResult)
   

   


         @Html.DisplayNameFor(model => model.TParentId)
   

   

        @Html.DisplayFor(model => model.TParentId)
   


@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
   


        |
        @Html.ActionLink("返回首页", "Index")
   


}

5、Create.cshtml

@model MvcVolleyball.Models.Team

@{
    ViewBag.Title = "Create";
}

请输入比赛双方队伍名称

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

   


        Team

       


            @Html.LabelFor(model => model.TName)
       

       

            @Html.EditorFor(model => model.TName)
            @Html.ValidationMessageFor(model => model.TName)
       

       


            @Html.LabelFor(model => model.TResult)
       

       

            @Html.EditorFor(model => model.TResult)
            @Html.ValidationMessageFor(model => model.TResult)
       

       


            @Html.LabelFor(model => model.TParentId)
       

       

            @Html.EditorFor(model => model.TParentId)
            @Html.ValidationMessageFor(model => model.TParentId)
       

       


           
       


   
}

 

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

四、SpecatorController具体代码如下:

 public class SpectatorController : Controller
    {
        //
        // GET: /Spectator/
        private CountScoreDBContext db = new CountScoreDBContext();
        public ActionResult SearchIndex(string searchString)
        {
            var team = from m in db.Team
                       select m;
            if (!String.IsNullOrEmpty(searchString))
            {
                team = team.Where(s => s.TName.Contains(searchString));
            }
            return View(team);
        }
        public ActionResult SearchJu(int id=0)
        {
            Ju ju = db.Ju.Find(id);
            if (ju == null)
            {
                return HttpNotFound();
            }
            return View(new List() { ju });
            //var juu = from m in db.Ju
            //         select m;
            //if (juu == null)
            //{
            //    juu = juu.Where(s => s.TJId == id);
            //}
            //return View(ju);
          
        }
        public ActionResult SearchScore()
        {
            return View(db.Score.ToList());
          
        }

1、SearchIndex.cshtml

@model IEnumerable

@{
    ViewBag.Title = "SearchIndex";
}

观众界面


    @*@Html.ActionLink("Create New", "Create")*@
    @using (Html.BeginForm()){

Title: @Html.TextBox("SearchString")



}


   
       
       
       
       
   

@foreach (var item in Model) {
   


       
       
   
       
   
}


            @Html.DisplayNameFor(model => model.TName)
       

            @Html.DisplayNameFor(model => model.TResult)
       

            @Html.DisplayFor(modelItem => item.TName)
       

            @Html.DisplayFor(modelItem => item.TResult)
       

            @*@Html.ActionLink("Edit", "Edit", new { id=item.TId }) |*@
            @Html.ActionLink("详细","SearchJu", "Spectator",new { id=item.TId }) 
            @* |@Html.ActionLink("Delete", "Delete", new { id=item.TId })*@
       

2、SearchJu.cshtml

@model IEnumerable

@{
    ViewBag.Title = "SearchJu";
}

局分



   
       
       
       
       
   

@foreach (var item in Model) {
   


       
       
       
     
   
}
     
  @Html.ActionLink("详细", "SearchScore","Spectator")
     


            @Html.DisplayNameFor(model => model.JUCi)
       

            @Html.DisplayNameFor(model => model.JScore)
       

            @Html.DisplayFor(modelItem => item.JUCi)
       

            @Html.DisplayFor(modelItem => item.JScore)
       


    @Html.ActionLink("返回首页", "SearchIndex")

3、SearchScore.cshtml

@model IEnumerable

@{
    ViewBag.Title = "Index";
}

具体分数


    @Html.ActionLink("返回首页", "SearchIndex")
   



   
       
       
       
      
       
   

@foreach (var item in Model) {
   


       
       
       
      
     
   
}


            @Html.DisplayNameFor(model => model.AScore)
       

            @Html.DisplayNameFor(model => model.BScore)
       

            @Html.DisplayNameFor(model => model.Note)
       

            @Html.DisplayFor(modelItem => item.AScore)
       

            @Html.DisplayFor(modelItem => item.BScore)
       

            @Html.DisplayFor(modelItem => item.Note)
       

 @Html.ActionLink("返回上一层", "SearchJu","Spectator")

测试了软件的功能,都能实现其功能。到这里,排球计分程序,算是完成了初步的功能与实现。也可以使用它的功能来记录分数了,在未来的日子里,还将要对此软件进行更深一步的研究,与设计,目前此软件的功能就先做到这里。到这里,我们的博客也快要结束了。在这个阶段的最后一篇博客里,我们将要讲述对此软件制作的总结与经验,也算是对此软件制作的一个小收尾。

MVC之排球比赛计分程序 ——(八)具体代码(2)

标签:search   edit   submit   sub   void   经验   isnull   date   each   

原文地址:http://www.cnblogs.com/150902yt/p/7073048.html


评论


亲,登录后才可以留言!