排球计分程序功能完善
2017-09-10 21:39
337 查看
利用暑假空闲时间来完善这个程序,增加了一个查询比赛的功能,并把以前的代码改进。
具体如下:
视图
首页代码
首页视图
创建比赛
创建比赛视图
详细记录
记录视图
具体如下:
视图
首页代码
public class VolleyballController : Controller { private VolleballDBContext db = new VolleballDBContext(); // // GET: /Volleyball/ public ActionResult Index() { return View(db.Volleyballs.ToList()); } [HttpPost] public ActionResult Index(string teamb, string searchString) { var VisitingteamLst = new List<string>(); var VisitingteamQry = from d in db.Volleyballs orderby d.Visitingteam select d.Visitingteam; VisitingteamLst.AddRange(VisitingteamQry.Distinct()); ViewBag.teamb = new SelectList(VisitingteamLst); var volleyballs = from v in db.Volleyballs select v; if (!String.IsNullOrEmpty(searchString)) { volleyballs = volleyballs.Where(s => s.Hometeam.Contains(searchString)); } if (string.IsNullOrEmpty(teamb)) return View(volleyballs); else { return View(volleyballs.Where(x => x.Visitingteam == teamb)); } } // // GET: /Volleyball/Details/5 public ActionResult Details(int id = 0) { Volleyball volleyball = db.Volleyballs.Find(id); if (volleyball == null) { return HttpNotFound(); } return View(volleyball); } // // GET: /Volleyball/Create public ActionResult Create() { return RedirectToAction("Index","Score"); } // // POST: /Volleyball/Create [HttpPost] public ActionResult Create(Volleyball volleyball) { if (ModelState.IsValid) { db.Volleyballs.Add(volleyball); db.SaveChanges(); return RedirectToAction("Index"); } return View(volleyball); } // // GET: /Volleyball/Edit/5 public ActionResult Edit(int id = 0) { Volleyball volleyball = db.Volleyballs.Find(id); if (volleyball == null) { return HttpNotFound(); } return View(volleyball); } // // POST: /Volleyball/Edit/5 [HttpPost] public ActionResult Edit(Volleyball volleyball) { if (ModelState.IsValid) { db.Entry(volleyball).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(volleyball); } // // GET: /Volleyball/Delete/5 public ActionResult Delete(int id = 0) { Volleyball volleyball = db.Volleyballs.Find(id); if (volleyball == null) { return HttpNotFound(); } return View(volleyball); } // // POST: /Volleyball/Delete/5 [HttpPost, ActionName("Delete")] public ActionResult DeleteConfirmed(int id) { Volleyball volleyball = db.Volleyballs.Find(id); db.Volleyballs.Remove(volleyball); db.SaveChanges(); return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { db.Dispose(); base.Dispose(disposing); } }
首页视图
@model IEnumerable<MvcApplication1.Models.Volleyball> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("创建比赛", "Create") @using (Html.BeginForm("Index","Volleyball")) { <p>主队: @Html.TextBox("SearchString") 客队:@Html.TextBox("teamb") <input type="submit" value="查询" /> </p> } </p> <table> <tr> <th> @*@Html.DisplayNameFor(model => model.Hometeam)*@@Html.Encode("主队") </th> <th> @* @Html.DisplayNameFor(model => model.Visitingteam)*@@Html.Encode("客队") </th> <th> @*@Html.DisplayNameFor(model => model.One)*@@Html.Encode("第一局") </th> <th> @*@Html.DisplayNameFor(model => model.Two)*@@Html.Encode("第二局") </th> <th> @*@Html.DisplayNameFor(model => model.Three)*@@Html.Encode("第三局") </th> <th> @*@Html.DisplayNameFor(model => model.Four)*@@Html.Encode("第四局") </th> <th> @*@Html.DisplayNameFor(model => model.Five)*@@Html.Encode("第五局") </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Hometeam) </td> <td> @Html.DisplayFor(modelItem => item.Visitingteam) </td> <td> @Html.DisplayFor(modelItem => item.One) </td> <td> @Html.DisplayFor(modelItem => item.Two) </td> <td> @Html.DisplayFor(modelItem => item.Three) </td> <td> @Html.DisplayFor(modelItem => item.Four) </td> <td> @Html.DisplayFor(modelItem => item.Five) </td> <td> @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | @Html.ActionLink("Details", "Details", new { id=item.ID }) | @Html.ActionLink("Delete", "Delete", new { id=item.ID }) </td> </tr> } </table>
创建比赛
public class ScoreController : Controller { private DetailscoreDBContext db = new DetailscoreDBContext(); // // GET: /Score/ public ActionResult Index() { return View(); } public ActionResult Score(Volleyball v) { ViewBag.hometeamscore = "0"; ViewBag.Visitingteamscore = "0"; ViewData.Add("Hometeam",v.Hometeam); ViewData.Add("Visitingteam", v.Visitingteam); return View(); } public ActionResult Score2(Detailscore detailscore) { if (ModelState.IsValid) { db.Detailscores.Add(detailscore); db.SaveChanges(); //return RedirectToAction("Index"); } //List<String> team = (from t in db.Detailscores orderby t.ID descending select t.Hometeam).ToList(); //ViewData.Add("Hometeam", team[0]); //ViewData.Add("Visitingteam", team[2]); return View("score"); } }
创建比赛视图
@model MvcApplication1.Models.Volleyball @{ ViewBag.Title = "Index"; } <h2>输入队伍</h2> @using (@Html.BeginForm("Score","Score")) { <fieldset> <legend>volleyball</legend> <div> @Html.Encode("主方队") @Html.EditorFor(Model => Model.Hometeam) </div> <div> @Html.Encode("客方队") @Html.EditorFor(Model => Model.Visitingteam) </div> <p><input type="submit" value="比赛开始"/></p> </fieldset> }
@model MvcApplication1.Models.Detailscore @{ ViewBag.Title = "Score"; ViewBag.hometeamscore = "1"; ViewBag.Visitingteamscore = "0"; } <style> .div{float:left;margin:0 auto;text-align:center;width:100px;height:100px;} </style> <h2>计分板</h2> @using (Html.BeginForm("Score2", "Score")) { @Html.ValidationSummary(true) <div style="display:none;"> <div class="editor-label"> @Html.LabelFor(model => model.Hometeam) </div> <div class="editor-field"> @Html.EditorFor(model => model.Hometeam) @Html.ValidationMessageFor(model => model.Hometeam) </div> <div class="editor-label"> @Html.LabelFor(model => model.Hometeamscore) </div> <div class="editor-field"> @Html.EditorFor(model => model.Hometeamscore) @Html.ValidationMessageFor(model => model.Hometeamscore) </div> <div class="editor-label"> @Html.LabelFor(model => model.Visitingteam) </div> <div class="editor-field"> @Html.EditorFor(model => model.Visitingteam) @Html.ValidationMessageFor(model => model.Visitingteam) </div> <div class="editor-label"> @Html.LabelFor(model => model.Visitingteamscore) </div> <div class="editor-field"> @Html.EditorFor(model => model.Visitingteamscore) @Html.ValidationMessageFor(model => model.Visitingteamscore) </div> </div> <div class="div"> <p id="home"></p> @ViewBag.hometeamscore <input onclick="funA()" type="submit" value="加分" /> </div> <div class="div"> <p id="visiting"></p> @ViewBag.Visitingteamscore <input onclick="funB()" type="submit" value="加分" /> </div> <script type="text/javascript"> var a = document.getElementById('Hometeam'); var b = document.getElementById('Visitingteam'); document.getElementById('home').innerHTML = a.value; document.getElementById('visiting').innerHTML = b.value; function funA() { document.getElementById('Hometeamscore').value = 1; document.getElementById('Visitingteamscore').value = ""; } function funB() { document.getElementById('Hometeamscore').value = ""; document.getElementById('Visitingteamscore').value = 1; } </script>
详细记录
public class DetailController : Controller { private DetailscoreDBContext db = new DetailscoreDBContext(); // // GET: /Detail/ public ActionResult Index() { return View(db.Detailscores.ToList()); }
记录视图
@model IEnumerable<MvcApplication1.Models.Detailscore> @{ ViewBag.Title = "Index"; } <style type="text/css"> table, td, th { border: thin solid black; border-collapse: collapse; padding: 5px; background-color:gray; text-align: left; margin: 10px 0; text-align:center; } </style> <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table> <tr> <th> @*@Html.DisplayNameFor(model => model.Hometeam)*@@Html.Encode("主队") </th> <th> @*@Html.DisplayNameFor(model => model.Hometeamscore)*@@Html.Encode("主队得分") </th> <th> @*@Html.DisplayNameFor(model => model.Visitingteam)*@@Html.Encode("客队") </th> <th> @*@Html.DisplayNameFor(model => model.Visitingteamscore)*@@Html.Encode("客队得分") </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Hometeam) </td> <td> @Html.DisplayFor(modelItem => item.Hometeamscore) </td> <td> @Html.DisplayFor(modelItem => item.Visitingteam) </td> <td> @Html.DisplayFor(modelItem => item.Visitingteamscore) </td> <td> @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | @Html.ActionLink("Details", "Details", new { id=item.ID }) | @Html.ActionLink("Delete", "Delete", new { id=item.ID }) </td> </tr> } </table>
相关文章推荐
- 排球记分员计分程序——完善
- 排球计分程序功能说明书
- 程序结构中的两点重要元素(续)之日志功能的完善
- MVC之排球比赛计分程序 ——(三)model类的设计与实现
- 排球计分程序重构(三)
- 排球计分程序(六)——接口的设计与实现
- MVC之排球比赛计分程序 ——(一)需求分析与数据库设计
- 排球比赛计分程序的典型用户和场景
- ASP.NET --- 制作功能完善的安装程序
- 排球计分程序重构(四)
- MVC排球比赛计分程序之拓展
- 第十六周计应151班第四组排球计分程序
- ASP.NET MVC 排球计分程序 (一)综述
- 排球计分程序(三)—— 模型类的设计与实现
- 我的一个小程序的功能完善问题
- MVC之排球比赛计分程序 ——(四)视图的设计与实现
- 排球记分员计分程序(八)————总结
- 计应1班第4小组“排球比赛计分程序”的典型用户、创立场景、用户故事
- 微信小程序教学第四章第三节(含视频):小程序中级实战教程:详情-功能完善
- ASP.NET MVC 排球计分程序 (二)一些排球计分的基本实现方式