第十八周 最后冲刺
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十八周 最后冲刺相关的知识,希望对你有一定的参考价值。
计划
估计时间为一周,实际时间一周多一天
开发
需求分析:作为一名赛会的组织人员,我需要每场比赛的结果,以便确定各支球队的总比赛名次
生成设计文档:1.编辑能查到各支小队的大分程序界面,2.编辑总排名程序界面3.活动图
设计复审:(跟室友商量增添查询小队积分情况程序)
代码规范:Microsoft visual studio 2010 三层架构
具体设计:
具体编码:部分
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link rel="Stylesheet" href="Css/VolleyBallIndex.css" /> <script language="javascript"> function one() { var v = document.getElementById(‘one‘); if (v.style.display == "none") { v.style.display = "block"; } else if( v.style.display="block"){ v.style.display = "none"; } } </script> <style type="text/css"> #mian { height: 227px; } </style> </head> <body> <form id="form1" runat="server"> <div id="mian"> <div class="Center"> <table> <tr> <td> <asp:DropDownList ID="DropDownListA" runat="server" CausesValidation="True"> <asp:ListItem>请选择队伍</asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:DropDownList> </td><td> <asp:DropDownList ID="DropDownListB" runat="server" CausesValidation="True"> <asp:ListItem>请选择队伍</asp:ListItem> </asp:DropDownList> </td> </tr><tr><td> <a href="javascript:one()">如果没有你需要队伍名称请添加^</a> <div id="one"> <asp:TextBox ID="TeamName" runat="server"></asp:TextBox> <asp:Button ID="btnSaveName" runat="server" Text="保存名称" onclick="btnSaveName_Click" /></td> <td> <a href="javascript:one()"> <asp:Button ID="Button2" runat="server" Text="添加" /> </a> </td> </tr> </div> <tr><td> <asp:Button ID="Button1" runat="server" Text="查询排名" onclick="btnTeam_Click" /> </td><td> <asp:Button ID="btnSelect" runat="server" Text="查询比赛" onclick="btnSelect_Click" /> </td></tr> </table> </div> </div> </form> </body> </html>
public static class SqlHelper { //获取连接字符串 public static readonly string constr = ConfigurationManager.ConnectionStrings["itcast"].ConnectionString; //执行增删改 public static int ExecuteNonQuery(string sql, params SqlParameter[] pms) { using (SqlConnection con= new SqlConnection(constr)) { using (SqlCommand cmd=new SqlCommand(sql,con)) { if (pms != null) { cmd.Parameters.AddRange(pms); } con.Open(); return cmd.ExecuteNonQuery(); } } } //执行返回单个值 public static object ExecuteScalar(string sql, params SqlParameter[] pms) { using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(sql,con)) { if (pms != null) { cmd.Parameters.AddRange(pms); } con.Open(); return cmd.ExecuteScalar(); } } } //执行返回多行 public static SqlDataReader ExecuteReader(string sql, params SqlParameter[] pms) { SqlConnection con = new SqlConnection(constr); using (SqlCommand cmd=new SqlCommand(sql,con)) { if (pms != null) { cmd.Parameters.AddRange(pms); } con.Open(); return cmd.ExecuteReader(); } } //返回一张表 public static DataTable ExecuteDataTable(string sql, params SqlParameter[] pms) { DataTable dt=new DataTable(); using (SqlDataAdapter ada=new SqlDataAdapter(sql,constr)) { if (pms!= null) { ada.SelectCommand.Parameters.AddRange(pms); } ada.Fill(dt); } return dt; } }
int sA, sB; StringBuilder sb = new StringBuilder(); public string bisai(string str)//获取比赛名控件值 { return name.Text = str; } public void TeamA(string str)//获取甲方队伍名 { teamA.Text = str; } public void TeamB(string str)//获取乙方队伍名 { teamB.Text = str; } public void insert(string win) //记录插入 { string sql = "insert into paiqiu(game,teamA,teamB,one,two,three,four,five,win,qiangqing) values(@game,@teamA,@teameB,@one,@two,@three,@four,@five,@win,@qiangqing)"; SqlParameter[] sp = { new SqlParameter("@game",name.Text), new SqlParameter("@teamA",teamA.Text), new SqlParameter("@teameB",teamB.Text), new SqlParameter("@one",one), new SqlParameter("@two",two), new SqlParameter("@three",three), new SqlParameter("@four",four==null?DBNull.Value:(object)four), new SqlParameter("@five",five==null?DBNull.Value:(object)five), new SqlParameter("@win",win), new SqlParameter("@qiangqing",sb.ToString()) }; SqlHelper.ExecuteNonQuery(sql, sp); } public void insertPM( string team,int score,int chang,int ju) //排名插入 { string sql = "insert into paiming values(@game,@team,@score,@chang,@ju)"; SqlParameter[] sp = { new SqlParameter("@game",name.Text), new SqlParameter("@team",team), new SqlParameter("@score",score), new SqlParameter("@chang",chang), new SqlParameter("@ju",ju) }; SqlHelper.ExecuteNonQuery(sql, sp); } public void update(string team, int score, int chang, int ju) { string sql = "update paiming set [email protected],[email protected],[email protected] where [email protected]"; SqlParameter[] sp = { new SqlParameter("@score",score), new SqlParameter("@chang",chang), new SqlParameter("@ju",ju), new SqlParameter("@team",team) }; SqlHelper.ExecuteNonQuery(sql, sp); } public void select(string team,int score,int chang,int ju) { string sql = "select * from paiming where sname=‘"+name.Text.ToString()+"‘ and dname=‘"+team+"‘"; SqlDataReader reader=SqlHelper.ExecuteReader(sql); if (reader.HasRows) { while (reader.Read()) { int score0 = Convert.ToInt32(reader[2]) + score; int chang0 = Convert.ToInt32(reader[3]) + chang; int ju0 = Convert.ToInt32(reader[4]) + ju; update(team, score0, chang0, ju0); } } else { insertPM(team, score, chang, ju); } } string one=null, two=null, three=null, four=null, five=null; private void A_Click(object sender, EventArgs e)//甲方加分 { int a=int.Parse(scoreA.Text) + 1; int b = int.Parse(scoreB.Text); sb.AppendFormat("{0}:{1}={2}:{3}\\r\\n", teamA.Text, teamB.Text, a, b); int i=Convert.ToInt32( lblNum.Text.Substring(1, 1)); int sa = Convert.ToInt32(lblA.Text); scoreA.Text = a.ToString(); if (i < 5) { if (a >= 25 && a - b >= 2) { string str = string.Format("本局甲方:{0}胜", teamA.Text); MessageBox.Show(str); scoreA.Text = "0"; scoreB.Text = "0"; sa++; i++; lblA.Text = (sa).ToString(); lblNum.Text = "第" + i + "局"; sb.AppendFormat("第{0}局 {1}:{2}={3}:{4} 本局{5}胜\\r\\n", i - 1, teamA.Text, teamB.Text, a, b, teamA.Text); switch(i-1) { case 1:one=string.Format("{0}:{1}",a,b); break; case 2:two=string.Format("{0}:{1}",a,b); break; case 3:three=string.Format("{0}:{1}",a,b); break; case 4:four=string.Format("{0}:{1}",a,b); break; } } } else { if(a>=15&&a-b>=2) { sb.AppendFormat("第{0}局 {1}:{2}={3}:{4} 本局{5}胜\\r\\n", i - 1, teamA.Text, teamB.Text, a, b, teamA.Text); string str = string.Format("本局甲方:{0}胜", teamA.Text); MessageBox.Show(str); sa++; lblA.Text = (sa).ToString(); five=string.Format("{0}:{1}",a,b); } } if (sa == 3) { sb.AppendFormat("本场比赛甲方:{0}胜\\r\\n比赛结束",teamA.Text); string str=string.Format("本场比赛{0}胜",teamA.Text); win.Text = str; win.Visible = true; A.Visible = false; B.Visible = false; insert(teamA.Text); if (lblB.Text == "2") { sA = 2; sB = 1; } else { sA = 3; sB = 0; } select(teamA.Text.ToString(),sA,1,sa); select(teamB.Text.ToString(), sB, 0, Convert.ToInt32(lblB.Text)); } textBox1.Text = sb.ToString(); } private void B_Click(object sender, EventArgs e)//乙方加分 { int a = int.Parse(scoreB.Text) + 1; int b = int.Parse(scoreA.Text); sb.AppendFormat("{0}:{1}={2}:{3}\\r\\n", teamA.Text, teamB.Text, b, a); int i = Convert.ToInt32(lblNum.Text.Substring(1, 1)); int sa = Convert.ToInt32(lblB.Text); scoreB.Text =a.ToString(); if (i < 5) { if (a >= 25 && a - b >= 2) { string str = string.Format("本局乙方:{0}胜",teamB.Text); MessageBox.Show(str); scoreA.Text = "0"; scoreB.Text = "0"; sa++; i++; lblB.Text = (sa).ToString(); lblNum.Text = "第" + i + "局"; sb.AppendFormat("第{0}局 {1}:{2}={3}:{4} 本局{5}胜\\r\\n", i - 1, teamA.Text, teamB.Text, b, a, teamB.Text); switch (i - 1) { case 1: one = string.Format("{0}:{1}", b, a); break; case 2: two = string.Format("{0}:{1}", b, a); break; case 3: three = string.Format("{0}:{1}", b, a); break; case 4: four = string.Format("{0}:{1}", b, a); break; } } } else { if (a >= 15 && a - b >= 2) { sb.AppendFormat("第{0}局 {1}:{2}={3}:{4} 本局{5}胜\\r\\n", i-1,teamA.Text,teamB.Text ,b, a,teamB.Text); string str = string.Format("本局乙方:{0}胜", teamB.Text); MessageBox.Show(str); sa++; lblB.Text = (sa).ToString(); five = string.Format("{0}:{1}", b, a); } } if (sa == 3) { sb.AppendFormat("本场比赛乙方:{0}胜\\r\\n比赛结束", teamB.Text); string str = string.Format("本场比赛{0}胜", teamB.Text); win.Text = str; win.Visible = true; A.Visible = false; B.Visible = false; insert(teamB.Text); if (lblA.Text == "2") { sB = 2; sA = 1; } else { sB = 3; sA = 0; } select(teamB.Text.ToString(), sB, 1, sa); select(teamA.Text.ToString(), sA, 0, Convert.ToInt32(lblA.Text)); } textBox1.Text = sb.ToString(); } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)//记录显示 { if (textBox1.Visible == false) { textBox1.Visible = true; } else { textBox1.Visible = false; } } private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)//比赛重置 { this.Close(); writeHistory0 a = new writeHistory0(); a.Show(); } private void Form1_Load(object sender, EventArgs e) { sb.AppendFormat("比赛名称:{0}\\r\\n甲方:{1} 乙方:{2}\\r\\n",name.Text, teamA.Text, teamB.Text); textBox1.Text = sb.ToString(); } private void lblIndex_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)//跳转到查询 { this.Close(); historySelect a = new historySelect(); a.Show(); } private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)//退出 { Application.Exit(); } private void btn1_Click(object sender, EventArgs e)//甲方减分 { int a = int.Parse(scoreA.Text); int b = int.Parse(scoreB.Text); if (a > 0) { a--; scoreA.Text = a.ToString(); sb.AppendFormat("比赛受到争议:甲方减分\\r\\n{0}:{1}={2}:{3}\\r\\n", teamA.Text, teamB.Text, a, b); textBox1.Text = sb.ToString(); } else { MessageBox.Show("操作失败"); } } private void btn2_Click(object sender, EventArgs e)//乙方减分 { int a = int.Parse(scoreA.Text); int b = int.Parse(scoreB.Text); if (b > 0) { b--; scoreB.Text = b.ToString(); sb.AppendFormat("比赛受到争议:乙方减分\\r\\n{0}:{1}={2}:{3}\\r\\n", teamA.Text, teamB.Text, a, b); textBox1.Text = sb.ToString(); } else { MessageBox.Show("操作失败"); } }
代码复审:(跟室友讨论并简化了一些不必要的代码)
测试:程序运行没有出现错误,但是总感觉少了点什么
报告
事后总结:感觉这次冲刺的认识:
1 懂得了流程对软件编辑人员的重要性,和其指导作用
2自己的能力尚待提高,有很多不足,缺乏对本专业技术的掌握
以上是关于第十八周 最后冲刺的主要内容,如果未能解决你的问题,请参考以下文章