需求:作为一名现场记分员,我希望详细记录比赛现场比分增长情况,以便观众及运动员、教练员及时掌握比赛状况。(满意条件:每一次比分的改变,都要形成一条记录)。
计划:估计此次工作需要长时间的努力。
需求分析: 程序需要能做到每次分数变化的时候都要记录。
设计文档:
1、排球比赛采用五局三胜制。前四局每局25分,每局比赛完成后交换场地,达到24分时,必须比赛的双方相差2分才能分出胜负;决胜局为15分,比赛的双方任何一方先达到8分时,交换场地继续比赛,当双方同时达到14分时候,也是必须相差两分才能决出胜负。
2、每加一分,数据库中的数据+1,分数列表行+1。
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | public static class SqlHelper { private static readonly string constr = ConfigurationManager.ConnectionStrings[ "player" ].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); } try { con.Open(); return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection); } catch (Exception) { con.Close(); con.Dispose(); throw ; } } } public static DataTable ExecuteDataTable( string sql, params SqlParameter[] pms) { DataTable dt = new DataTable(); using (SqlDataAdapter adapter = new SqlDataAdapter(sql, constr)) { if (pms != null ) { adapter.SelectCommand.Parameters.AddRange(pms); } adapter.Fill(dt); } return dt; } internal static void ExecuteDataTable() { throw new NotImplementedException(); } } } 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); } 第一局: if ( int .Parse(txtone.Text) < 25) { int a = int .Parse(txtone.Text); a++; txtone.Text = a.ToString(); int c = int .Parse(txtone2.Text); if (a == 25 && a - 1 > c) { MessageBox.Show( "第一局" + btnwin1.Text); lblfirst.Text = "第一局比分是" + txtone.Text + ":" + txtone2.Text; int b = int .Parse(txtscore1.Text); b++; txtscore1.Text = b.ToString(); } } else { int a = int .Parse(txtone.Text); a++; txtone.Text = a.ToString(); int c = int .Parse(txtone2.Text); if (a - 1 > c) { MessageBox.Show( "第一局" + btnwin1.Text); lblfirst.Text = "第一局比分是" + txtone.Text + ":" + txtone2.Text; int b = int .Parse(txtscore1.Text); b++; txtscore1.Text = b.ToString(); } } } else if ( int .Parse(txtscore1.Text) + int .Parse(txtscore2.Text) ==1) { //第一局结束 将数据放入到数据库中 ChaRuDAL dal = new ChaRuDAL(); //插入第一队球员信息 public int insert( string name, string score) { return dal.insert(name,score); } //插入第二队队球员信息 public int insert1( string name, string score) { return dal.insert1(name,score); } 工作人员查询 public DataTable getAllName() { string sql = "select distinct name from one" ; return SqlHelper.ExecuteDataTable(sql, null ); } //查询最高分 string sql = "select count(*) as name,score from one group by score order by count(*) desc;" ; SqlDataReader dr=SqlHelper.ExecuteReader(sql, null ); if (dr.HasRows) { dr.Read(); name= "@name" ; score= dr[ "score" ].ToString(); } 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 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(); 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(); textBox1.Text = sb.ToString(); } else { MessageBox.Show( "操作失败" ); } } |
个人总结: 上个学期,没学好,这学期我要努力奋斗。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· 为DeepSeek添加本地知识库
· 精选4款基于.NET开源、功能强大的通讯调试工具
· DeepSeek智能编程
· 大模型工具KTransformer的安装
· [计算机/硬件/GPU] 显卡