码迷,mamicode.com
首页 > 其他好文 > 详细

第五组作业

时间:2016-12-25 01:40:24      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:public   查询   代码规范   显示   ble   帕斯卡   images   需要   substring   

计划

        估计此程序需要5-6天。

  • 开发
  • 需求分析

         作为一名现场记分员,我希望详细记录比赛现场比分增长情况,以便观众及运动员、教练员及时掌握比赛状况。(满意条件:精确到每一局的具体比分增长情况)。

          从分析用例故事可以知道完成此程序需要这两项任务:选择队伍和记录比赛分数

          以下为改程序的活动图:

 

 技术分享

 

  • 代码规范:使用Vs2010和帕斯卡命名法和骆驼命名法 。

 

  • 具体编码
  • 技术分享技术分享

     

     

  • 比赛及队名部分
  •  private void lblIndex_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                this.Close();
                historySelect a = new historySelect();
                a.Show();
            }
  •         private void begin_Click(object sender, EventArgs e)
            {
                if (textName.Text.Trim() == "" || Ateam.Text.Trim() == "" || Bteam.Text.Trim() == "")
                {
                    MessageBox.Show("比赛名、队伍名均不能为空");
                }
                else
                {
                    writeHistory1 w = new writeHistory1();
                    w.bisai(textName.Text);
                    w.TeamA(Ateam.Text);
                    w.TeamB(Bteam.Text);
                    w.Show();
                    this.Close();
                }
               
            }

            private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
               Application.Exit();
            }

  • 计分部分
  • 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 writeHistory1()
            {
                InitializeComponent();
            }
            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);
                }
                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);
                }
                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();
            }
            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);
            }

            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("操作失败");
                }
            }

 

第五组作业

标签:public   查询   代码规范   显示   ble   帕斯卡   images   需要   substring   

原文地址:http://www.cnblogs.com/ljc960321/p/6218745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!