首页 > 代码库 > 十八周个人作业

十八周个人作业

计划:

估计这个任务需要多少时间完成:4-5天。

开发:

需求分析:作为一个赛会的组织人员,我需要知道每场比赛的结果对队伍进行积分,以便对队伍进行排名。

设计文档:①排球计分程序的加分②比赛积分的排名。

代码规范:根据Visual Studio 2010规范去写。

具体设计:活动图

技术分享技术分享
具体编码:
     Action action = new Action();
        int i = 1;
        StringBuilder sb = new StringBuilder();
        //插入比赛记录
        public void INSERT() 
        {
            Model M = new Model();
            M.IDA = textBox1.Text.Trim().ToString();
            M.IDB = textBox2.Text.Trim().ToString();
            M.ONE = txtCount1.Text.Trim().Substring(4, 4);
            M.TWO = txtCount2.Text.Trim().Substring(4, 4);
            M.THREE = txtCount3.Text.Trim().Substring(4, 4);
            if (txtCount4.Text =="")
            {
                M.FOUR = null;
            }
            else
            {
                M.FOUR = txtCount4.Text.Trim().Substring(4, 4);
            }
            if (txtCount5.Text =="")
            {
                M.FIVE= null;
            }
            else
            {
                M.FIVE = txtCount5.Text.Trim().Substring(4, 4);
            }
           
            M.SUM = txtH1.Text.ToString() + ":" + txtL1.Text.ToString();
            M.Detail = sb.ToString();
            action.InsertPK(M);
        }
        //根据队伍名字查询积分
        public int SELECT(string Name) 
        {
            string sql = "select Grade from paiming where Name=@Name";
            SqlParameter pms = new SqlParameter("@Name",Name);
            return (int)SqlHelper.ExecuteScalar(sql,pms);
        }
        //根据队伍名字更新积分
        public void UPDATE(string Name,int Grade) 
        {
            string sql = "update paiming set Grade=@Grade where Name=@Name";
            SqlParameter[] pms = { new SqlParameter("@Grade",Grade),
                                 new SqlParameter("Name",Name)};
            int count = SqlHelper.ExecuteNonQuery(sql,pms);
        }
       
        //加分
        private void btnH_Click(object sender, EventArgs e)
        {
            int H = Convert.ToInt32(txtH.Text);
            int L = Convert.ToInt32(txtL.Text);
            int H1 = Convert.ToInt32(txtH1.Text);
            int L1 = Convert.ToInt32(txtL1.Text);
            txtH.Text = (H+1).ToString();
            sb.AppendFormat("第{0}个球   {1}:{2}\r\n",H+1,H+1,L);
            if (H >= 24 && (H - L) > 0)
            {
                txtH1.Text = (Convert.ToInt32(txtH1.Text) + 1).ToString();
                if((H1+L1)==0){
                txtCount1.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                }
                if ((H1 + L1) == 1)
                {
                    txtCount2.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                }
                if ((H1 + L1) == 2)
                {
                    txtCount3.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                }
                if ((H1 + L1) == 3)
                {
                    txtCount4.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                }
                if ((H1 + L1) == 4)
                {
                    txtCount5.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                }
                txtH.Text = "0";
                txtL.Text = "0";
              
                if (txtH1.Text == "3")
                {
                    MessageBox.Show(textBox1.Text+"胜利");
                    INSERT();
                    int fen = SELECT(textBox1.Text);
                    int fen2 = SELECT(textBox2.Text);
                    if (int.Parse(txtH1.Text) == 3 && int.Parse(txtL1.Text) == 0) 
                    {
                        UPDATE(textBox1.Text, fen + 3);
                    }
                    if (int.Parse(txtH1.Text) == 3 && int.Parse(txtL1.Text) == 1)
                    {
                        UPDATE(textBox1.Text, fen + 3);
                    }
                    if (int.Parse(txtH1.Text) == 3 && int.Parse(txtL1.Text) == 2)
                    {
                        UPDATE(textBox1.Text, fen + 2);
                        UPDATE(textBox2.Text, fen2 + 1);
                    }
                  
                    txtH.Text = "0";
                    txtH1.Text = "0";
                    txtL.Text = "0";
                    txtL1.Text = "0";
                    txtCount1.Clear();
                    txtCount2.Clear();
                    txtCount3.Clear();
                    txtCount4.Clear();
                    txtCount5.Clear();

                }
            }
            if (H1 + L1 > 3)
            {
                if (H >= 14 && (H - L) > 1)
                {
                    txtH1.Text = (Convert.ToInt32(txtH1.Text) + 1).ToString();
                   
                    if ((H1 + L1) == 4)
                    {
                        txtCount5.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text + "\r\n";
                    }
                    txtH.Text = "0";
                    txtL.Text = "0";
                  
                    if (txtH1.Text == "3")
                    {
                        MessageBox.Show(textBox1.Text + "胜利");
                        INSERT();
                        int fen = SELECT(textBox1.Text);
                        int fen2 = SELECT(textBox2.Text);
                        if (int.Parse(txtH1.Text) == 3 && int.Parse(txtL1.Text) == 0)
                        {
                            UPDATE(textBox1.Text, fen + 3);
                        }
                        if (int.Parse(txtH1.Text) == 3 && int.Parse(txtL1.Text) == 1)
                        {
                            UPDATE(textBox1.Text, fen + 3);
                        }
                        if (int.Parse(txtH1.Text) == 3 && int.Parse(txtL1.Text) == 2)
                        {
                            UPDATE(textBox1.Text, fen + 2);
                            UPDATE(textBox2.Text, fen2 + 1);
                        }
                        txtH.Text = "0";
                        txtH1.Text = "0";
                        txtL.Text = "0";
                        txtL1.Text = "0";
                        txtCount1.Clear();
                        txtCount2.Clear();
                        txtCount3.Clear();
                        txtCount4.Clear();
                        txtCount5.Clear();
                        i = 1;
                    }
                }
            }
        }
        //加分
        private void btnL_Click(object sender, EventArgs e)
        {
            
            int H = Convert.ToInt32(txtH.Text);
            int L = Convert.ToInt32(txtL.Text);
            int H1 = Convert.ToInt32(txtH1.Text);
            int L1 = Convert.ToInt32(txtL1.Text);
            txtL.Text = (L+1).ToString();
            sb.AppendFormat("第{0}个球   {1}:{2}\r\n", L + 1, H, L+1);
            if (L>= 24&&(L-H )>0)
            {
                txtL1.Text = (Convert.ToInt32(txtL1.Text) + 1).ToString();
                if((H1+L1)==0){
                txtCount1.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                } if ((H1 + L1) == 1)
                {
                    txtCount2.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                }
                if ((H1 + L1) == 2)
                {
                    txtCount3.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                }
                if ((H1 + L1) == 3)
                {
                    txtCount4.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                }
                if ((H1 + L1) == 4)
                {
                    txtCount5.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                }
                txtH.Text = "0";
                txtL.Text = "0";
               
                if (txtL1.Text=="3")
                {
                    MessageBox.Show(textBox2.Text + "胜利");
                    INSERT();
                    int fen = SELECT(textBox2.Text);
                    int fen2 = SELECT(textBox1.Text);
                    if (int.Parse(txtL1.Text) == 3 && int.Parse(txtH1.Text) == 0)
                    {
                        UPDATE(textBox2.Text, fen + 3);
                    }
                    if (int.Parse(txtL1.Text) == 3 && int.Parse(txtH1.Text) == 1)
                    {
                        UPDATE(textBox2.Text, fen + 3);
                    }
                    if (int.Parse(txtL1.Text) == 3 && int.Parse(txtH1.Text) == 2)
                    {
                        UPDATE(textBox2.Text, fen + 2);
                        UPDATE(textBox1.Text, fen2 + 1);
                    }
                    txtH.Text = "0";
                    txtH1.Text = "0";
                    txtL.Text = "0";
                    txtL1.Text = "0";
                    txtCount1.Clear();
                    txtCount2.Clear();
                    txtCount3.Clear();
                    txtCount4.Clear();
                    txtCount5.Clear();
                }
            }
            if(H1+L1>3)
            {
                if (L >= 14 && (L - H) > 1)
                {
                    txtL1.Text = (Convert.ToInt32(txtL1.Text) + 1).ToString();
                    if((H1+L1)==4){
                    txtCount5.Text += "" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
                    }
                    txtH.Text = "0";
                    txtL.Text = "0";
                   
                    if (txtL1.Text == "3")
                    {
                        MessageBox.Show(textBox2.Text + "胜利");
                        INSERT();
                        int fen = SELECT(textBox2.Text);
                        if (int.Parse(txtL1.Text) == 3 && int.Parse(txtH1.Text) == 0)
                        {
                            UPDATE(textBox2.Text, fen + 3);
                        }
                        if (int.Parse(txtL1.Text) == 3 && int.Parse(txtH1.Text) == 1)
                        {
                            UPDATE(textBox2.Text, fen + 3);
                        }
                        if (int.Parse(txtL1.Text) == 3 && int.Parse(txtH1.Text) == 2)
                        {
                            UPDATE(textBox2.Text, fen + 2);
                            UPDATE(textBox1.Text, fen + 1);
                        }
                        txtH.Text = "0";
                        txtH1.Text = "0";
                        txtL.Text = "0";
                        txtL1.Text = "0";
                        txtCount1.Clear();
                        txtCount2.Clear();
                        txtCount3.Clear();
                        txtCount4.Clear();
                        txtCount5.Clear();
                        i = 1;
                    }
                }
            }
           
        }
        //减分
        private void btnH1_Click(object sender, EventArgs e)
        {
            if (int.Parse(txtH.Text) > 0)
            {
                txtH.Text = (Convert.ToInt32(txtH.Text) - 1).ToString();
            }
        }
        //减分
        private void btnL1_Click(object sender, EventArgs e)
        {
            if (int.Parse(txtH.Text) > 0)
            {
                txtL.Text = (Convert.ToInt32(txtL.Text) - 1).ToString();
            }
        }

      
        //排名
        private void button1_Click(object sender, EventArgs e)
        {
            paiming p = new paiming();
            p.Show();
        }

 

十八周个人作业