ASP.NET MVC 排球计分程序 (六)HomeController代码和一些解释
2021-07-14 17:06
标签:ssi 程序 lis == turn scores 解释 amt table Index Action方法 (默认进入的主页) AddPerson Action方法(单击主页提交 将交到AddPerson里来处理数据,并将队员 名字插入数据库) 这个Action主要写了插入名字到对应的PersonA PersonB 数据库 弹出新的界面应显示的一些内容 如队名 根据自己在数据库中插入的内容而生成的下拉列表 队名的传递也可以使用Cookie 和session这里不做解释 ViewBag.名字 可以用来传递数据 在视图中用@VieWBag名字 可以获取到自己传递的值 详情可以了解一下Rezor语法等 Admin Action方法 AddScore Action selectScore 下一篇将介绍对应视图的代码 ASP.NET MVC 排球计分程序 (六)HomeController代码和一些解释 标签:ssi 程序 lis == turn scores 解释 amt table 原文地址:http://www.cnblogs.com/zyadmin/p/7074416.htmlpublic ActionResult Index()
{
return View();
}
public ActionResult AddPerson()
{
//获取填入的衣服编号和名字 并将其写入数据库
//编号idA1 nameA1
SqlHelper.ClearBiaoRen();
//插入B的idB1 nameB1..
int numsA = 1;
//将十二个队员全部插入数据库 总共有十二个文本框 执行
while (numsA 12)
{
//获取文本框名为idB1到idB12的值
int idA = int.Parse(Request["idA" + numsA]);
//获取文本框名为nameB1到nameB12的值
string name = Request["nameA" + numsA];
//排除name为空的情况
if (string.IsNullOrEmpty(name))
{
numsA++;
continue;
}
else
{
//name不为空插入 idB1 nameA1等进数据库
string sql = "insert into PersonA values(" + idA + ",‘" + name + "‘)";
int a = SqlHelper.ExecuteNonQuery(sql, null);
if (a > 0)
{
ViewBag.IsSuccessA = "";
}
else
{
ViewBag.IsSuccessA = "A插入失败,未知错误";
}
}
numsA++;
}
//插入B的idB1 nameB1..
int numsB = 1;
//将十二个队员全部插入数据库 总共有十二个文本框 执行
while (numsB 12)
{
//获取文本框名为idB1到idB12的值
int idB = int.Parse(Request["idB" + numsB]);
//获取文本框名为nameB1到nameB12的值
string name = Request["nameB" + numsB];
//排除name为空的情况
if (string.IsNullOrEmpty(name))
{
numsB++;
continue;
}
else
{
//name不为空插入 idB1 nameA1等进数据库
string sql = "insert into PersonB values(" + idB + ",‘" + name + "‘)";
int a = SqlHelper.ExecuteNonQuery(sql, null);
if (a > 0)
{
ViewBag.IsSuccessB = "";
}
else
{
ViewBag.IsSuccessB = "B插入失败,未知错误";
}
}
numsB++;
}
//string teamAName = Request["teamAName"];
//string teamBName = Request["teamBName"];
//获取teamA teamB文本框内的值
ViewBag.teamAName = Request["teamAName"];
ViewBag.teamBName = Request["teamBName"];
//显示当前比分 局分都是0
ViewBag.dangQianA = "0";
ViewBag.dangQianB = "0";
ViewBag.juA = "0";
ViewBag.juB = "0";
List
public ActionResult Admin()
{
//获取文本框的值
//获取是A队得分还是B队得分
string teamMing = Request["teamMing"];
//获取A队的名字
string teamAName = Request["tA"];
//获取B队的名字
string teamBName = Request["tB"];
//重新将名称写入文本框
ViewBag.teamAName = teamAName;
ViewBag.teamBName = teamBName;
//获取是哪一个球员
string teamYuan = Request["teamYuan"];
//获取它是哪一种状态
string teamTai = Request["teamTai"];
//获取当前状态是否得分
string teamIsFen = Request["teamIsFen"];
//获取当前比分A队的值
//int dangQianA;
//if (string.IsNullOrEmpty(Request["dangQiangA"]))
//{
// dangQianA = 0;
//}
//else
//{
// dangQianA = int.Parse(Request["dangQiangA"]);
//}
////获取当前比分B队的值
//int dangQianB;
//if (string.IsNullOrEmpty(Request["dangQiangB"]))
//{
// dangQianB = 0;
//}
//else
//{
// dangQianB = int.Parse(Request["dangQiangB"]);
//}
////获取局比分A
//int juA;
//if (string.IsNullOrEmpty(Request["juA"]))
//{
// juA = 0;
//}
//else
//{
// juA = int.Parse(Request["juA"]);
//}
////获取局比分B
//int juB;
//if (string.IsNullOrEmpty(Request["juB"]))
//{
// juB = 0;
//}
//else
//{
// juB = int.Parse(Request["juB"]);
//}
if (teamMing == teamAName)
{
// //0 0 1 0 2 0 3 0
// //给A队加分
// if (teamIsFen == "是")
// {
// //0 1 2 3 4
// //如果A局分>=3 且局分B局分// if (juA >= 3 && juB // {
// //获胜 把文本框里的值原样返回
// ViewBag.dangQianA = dangQianA.ToString();
// ViewBag.dangQianB = dangQianB.ToString();
// ViewBag.juA = juA.ToString();
// ViewBag.juB = juB.ToString();
// }
// //进入决胜局
// else if (juA >= 3 && juB // {
// }
// else
// {
// //如果加分后A>=25且>B则获胜
// if (dangQianA >= 25 && dangQianA >= dangQianB + 2)
// {
// //A获得胜利 加局分
// ViewBag.juA = juA++;
// //清空比分
// ViewBag.dangQianA = "0";
// ViewBag.dangQianB = "0";
// //当前比分A加1
// ViewBag.dangQianA = (dangQianA++).ToString();
// }
// else
// {
// //加分后不大于25的情况
// ViewBag.dangQianA = (dangQianA++).ToString();
// }
// }
// }
// else
// {
// //等于否 则将当前分和局分原样返回
// ViewBag.dangQianA = dangQianA.ToString();
// ViewBag.dangQianB = dangQianB.ToString();
// ViewBag.juA = juA.ToString();
// ViewBag.juB = juB.ToString();
// }
//无论是否都将其插入数据库
string sql = "insert into ScoreA (personId,jiQiu,isScore) values(" + int.Parse(teamYuan) + ",‘" + teamTai + "‘,‘" + teamIsFen + "‘)";
//插入数据库
SqlHelper.ExecuteNonQuery(sql, null);
}
else
{
//给B队加分
string sql = "insert into ScoreB (personId,jiQiu,isScore) values(" + int.Parse(teamYuan) + ",‘" + teamTai + "‘,‘" + teamIsFen + "‘)";
//插入数据库
SqlHelper.ExecuteNonQuery(sql, null);
}
//三个下拉列表出现
List
");
scoreSb.Append("
");
ViewBag.selectA = scoreSb.ToString();
List
");
scoreSb.Append(" ");
for (int i = 0; i )
{
scoreSb.Append("队员
");
scoreSb.Append("击球状态
");
scoreSb.Append("是否得分
");
scoreSb.Append("
");
scoreSb.AppendFormat(" ");
}
scoreSb.Append("
{0}
", scoreA[i].personId);
scoreSb.AppendFormat("{0}
", scoreA[i].jiQiu);
scoreSb.AppendFormat("{0}
", scoreA[i].isScore);
scoreSb.Append("
");
scoreBSb.Append("
");
ViewBag.selectB = scoreBSb.ToString();
return View("AddScore");
}
");
scoreBSb.Append(" ");
for (int i = 0; i )
{
scoreBSb.Append("队员
");
scoreBSb.Append("击球状态
");
scoreBSb.Append("是否得分
");
scoreBSb.Append("
");
scoreBSb.AppendFormat(" ");
}
scoreBSb.Append("
{0}
", scoreB[i].personId);
scoreBSb.AppendFormat("{0}
", scoreB[i].jiQiu);
scoreBSb.AppendFormat("{0}
", scoreB[i].isScore);
scoreBSb.Append("
public ActionResult AddScore()
{
return View();
}
public ActionResult selectScore()
{
ViewBag.AMaxFen = SqlHelper.getAMaxScore();
ViewBag.BMaxFen = SqlHelper.getBMaxScore();
ViewBag.AFaQiu = SqlHelper.getAFaQiuMax(jiQiu.发球);
ViewBag.BFaQiu = SqlHelper.getBFaQiuMax(jiQiu.发球);
ViewBag.AYiChuan = SqlHelper.getAFaQiuMax(jiQiu.一传);
ViewBag.BYiChuan = SqlHelper.getBFaQiuMax(jiQiu.一传);
ViewBag.AKouQiu = SqlHelper.getAFaQiuMax(jiQiu.扣球);
ViewBag.BKouQiu = SqlHelper.getBFaQiuMax(jiQiu.扣球);
ViewBag.AMoQiu = SqlHelper.getAFaQiuMax(jiQiu.抹球);
ViewBag.BMoQIu = SqlHelper.getBFaQiuMax(jiQiu.抹球);
ViewBag.ALanWang = SqlHelper.getAFaQiuMax(jiQiu.拦网);
ViewBag.BLanWang = SqlHelper.getBFaQiuMax(jiQiu.拦网);
return View();
}
文章标题:ASP.NET MVC 排球计分程序 (六)HomeController代码和一些解释
文章链接:http://soscw.com/index.php/essay/105197.html