第十七周个人作业

计划:

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

开发:

需求分析:作为一个赛事管理者,我希望能够方便知道每场比赛中队伍的总场数,胜负场,总得分,总得分,积分,C值,Z值,以便对队伍进行排名。

设计文档:

根据计分方式:比赛结果为3:0、3:1时,胜队积3分,负队积0分;比赛结果为3:2时,胜队积2分,负队积1分;积分高者排名在前。

在之前的计分程序中判断比分是否为3:0,3:1就可以了。

(目前实现可以计算需求中的所有都可以进行计算,但是排名时用C值和Z值排名还未实现)

具体设计:

model类
namespace Model
{
    public class volleycount
    {
        public int ID;
        public string team;//队伍名
        public int total;//总场数
        public int victorycount;//胜场
        public int defeatcount;//负场
        public int count;//积分
        public int totalvictory;//总胜场
        public int totaldefeat;//总负场
        public double Cvalue;
        public int totalvictorycount;//总得分
        public int totaldefeatcount;//总失分
        public double Zvalue;
    }
}
Dal层
 public DataTable SelectvolleyTeamRank()
       {
           string sql = "select * from VollballCount order by count desc";
           DataTable dt = SqlHelper.ExecuteDataTable(sql);
           return dt;
       }
       public int Selectrankcount()
       {
           string sql = "select count(*) from VollballCount";
           int count = (int)SqlHelper.ExecuteScalar(sql);
           return count;
       }
       public volleycount SelectTeamRank(string team)
       {
           string sql = "select * from VollballCount where team=@team";
           SqlParameter pms = new SqlParameter("@team",team);
           SqlDataReader reader = SqlHelper.ExecuteReader(sql,pms);
           volleycount rank= new volleycount();
           if (reader.HasRows)
           {
              
               if (reader.Read()) 
               {
                   rank.ID = (int)reader["ID"];
                   rank.team = reader["team"].ToString();
                   rank.total = (int)reader["total"];
                   rank.victorycount = (int)reader["victorycount"];
                   rank.defeatcount = (int)reader["defeatcount"];
                   rank.count = (int)reader["count"];
                   rank.totalvictory = (int)reader["totalvictory"];
                   rank.totaldefeat = (int)reader["totaldefeat"];
                   rank.Cvalue = reader.GetDouble(7);
                   rank.totalvictorycount = (int)reader["totalvictorycount"];
                   rank.totaldefeatcount = (int)reader["totaldefeacount"];
                   rank.Zvalue = reader.GetDouble(10);
                   
               }
              
           }
           return rank;
       }
       public int UpdateRank(volleycount rank)
       {
           string sql = "update VollballCount set team=@team,total=@total,victorycount=@victorycount,defeatcount=@defeatcount,count=@count,totalvictory=@totalvictory,totaldefeat=@totaldefeat,Cvalue=@Cvalue,totalvictorycount=@totalvictorycount,totaldefeacount=@totaldefeacount,Zvalue=@Zvalue where ID=@ID";
           SqlParameter[] pms = new SqlParameter[]{
                      new SqlParameter ("@team",rank.team),
                      new SqlParameter("@total",rank.total),
                      new SqlParameter("@victorycount",rank.victorycount),
                      new SqlParameter("@defeatcount",rank.defeatcount),
                      new SqlParameter("@count",rank.count),
                      new SqlParameter("@totalvictory",rank.totalvictory),
                      new SqlParameter("@totaldefeat",rank.totaldefeat),
                      new SqlParameter("@Cvalue",(float)rank.totalvictory/rank.totaldefeat),
                      new SqlParameter("@totalvictorycount",rank.totalvictorycount),
                      new SqlParameter("@totaldefeacount",rank.totaldefeatcount),
                      new SqlParameter("@Zvalue",(float)rank.totalvictorycount/rank.totaldefeatcount),
                      new SqlParameter("@ID",rank.ID)
           };
           int count = SqlHelper.ExecuteNonQuery(sql,pms);
           return count;
       }
BLL层
public DataTable SelectvolleyTeamRank()
        {
            return dal.SelectvolleyTeamRank();
        }
        public int Selectrankcount()
        {
            return dal.Selectrankcount();
        }
        public volleycount SelectTeamRank(string team)
        {
            return dal.SelectTeamRank(team);
        }
        public void UpdateRank(volleycount rank)
        {
             dal.UpdateRank(rank) ;
        }
UI层
namespace volleyball
{
    public partial class Scoreing : Form
    {
        public string TeamA;
        public string TeamB;
        public int ScoreA = 0;//比分
        public int ScoreB=0;
        public int count = 1;//局数
        public int TeamScoreA = 0;//局比分
        public int TeamScoreB = 0;
        public StringBuilder sb=new StringBuilder();
        VolleybalScore score=new VolleybalScore();   
        volleyBll bll = new volleyBll();
        volleycount RankA;
        volleycount RankB;
        public Scoreing()
        {
            InitializeComponent();
        }

        private void Scoreing_Load(object sender, EventArgs e)
        {
            lblTeamA.Text = TeamA;
            lblTeamB.Text = TeamB;
            jushucount(count);
            score.Teams = TeamA + ":" + TeamB;
            RankA=bll.SelectTeamRank(TeamA);
            RankB = bll.SelectTeamRank(TeamB);
        }

        private void btnAddTeamA_Click(object sender, EventArgs e)
        {
            ScoreA++;
            showScore();
            victory();
            jushucount(count);
            RankA.totalvictorycount++;
            RankB.totaldefeatcount++;
        }

        private void btnAddteamB_Click(object sender, EventArgs e)
        {
            ScoreB++;
            showScore();
            victory();
            jushucount(count);
            RankB.totalvictorycount++;
            RankA.totaldefeatcount++;
        }
        private void showScore()
        {
            lblScoreB.Text = ScoreB.ToString();
            lblScoreA.Text = ScoreA.ToString();
        }
        private void victory()
        {
            if (count < 5)
            {
                if ((ScoreA >= 24 && Math.Abs(ScoreA - ScoreB) >= 2) || (ScoreB >= 24 && Math.Abs(ScoreA - ScoreB) >= 2))
                {
                    if (ScoreA - ScoreB >= 2)
                    {
                        MessageBox.Show(lblCount.Text + TeamA + "胜利");
                        TeamScoreA++;
                        if (TeamScoreA == 3)
                        {
                            if (Math.Abs(TeamScoreA - TeamScoreB) >= 2)
                            {
                                sb.AppendFormat("第{0}局,{1}:{2}\r", count, ScoreA, ScoreB);
                                lblBigScore.Text = sb.ToString();
                                MessageBox.Show("比赛结束" + TeamA + "胜利");
                                score.Victory = TeamA + TeamScoreA.ToString() + ":" + TeamScoreB.ToString();
                                score.thirdScore = ScoreA.ToString() + ":" + ScoreB.ToString();
                                bll.InsertScore(score);
                                count = 1;
                                ScoreA = 0;
                                ScoreB = 0;
                                showScore();
                                lblCount.Text = "第一局";
                                RankA.total++;
                                RankB.total++;
                                RankA.victorycount++;
                                RankB.defeatcount++;
                                RankA.count += 3;
                                RankA.totalvictory++;
                                bll.UpdateRank(RankA);
                                bll.UpdateRank(RankB);
                            }
                        }
                        sb.AppendFormat("第{0}局,{1}:{2}\r", count, ScoreA, ScoreB);
                        lblBigScore.Text = sb.ToString();
                        if (count == 1)
                        { score.firstScore = ScoreA.ToString() + ":" + ScoreB.ToString(); }
                        else if (count == 2)
                        { score.secondScore = ScoreA.ToString() + ":" + ScoreB.ToString(); }
                        else if (count == 3)
                        { score.thirdScore = ScoreA.ToString() + ":" + ScoreB.ToString(); }
                        else if (count == 4)
                        { score.fourthScore = ScoreA.ToString() + ":" + ScoreB.ToString(); }
                        count++;
                        ScoreA = 0;
                        ScoreB = 0;
                        showScore();
                    }

                    if (ScoreB - ScoreA >= 2)
                    {
                        MessageBox.Show(lblCount.Text + TeamB + "胜利");
                        TeamScoreB++;
                        if (TeamScoreB == 3)
                        {
                            if (Math.Abs(TeamScoreA - TeamScoreB) >= 2)
                            {
                                sb.AppendFormat("第{0}局,{1}:{2}\r", count, ScoreA, ScoreB);
                                lblBigScore.Text = sb.ToString();
                                MessageBox.Show("比赛结束" + TeamB + "胜利");
                                score.Victory = TeamB + TeamScoreB.ToString() + ":" + TeamScoreA.ToString();
                                score.thirdScore = ScoreA.ToString() + ":" + ScoreB.ToString();
                                bll.InsertScore(score);
                                count = 1;
                                ScoreA = 0;
                                ScoreB = 0;
                                showScore();
                                lblCount.Text = "第一局";
                                RankB.total++;
                                RankA.total++;
                                RankB.victorycount++;
                                RankA.defeatcount++;
                                RankB.count += 3;
                                RankB.totalvictory++;
                                bll.UpdateRank(RankA);
                                bll.UpdateRank(RankB);
                            }
                        }
                        sb.AppendFormat("第{0}局,{1}:{2}\r", count, ScoreA, ScoreB);
                        lblBigScore.Text = sb.ToString();
                        if (count == 1)
                        { score.firstScore = ScoreA.ToString() + ":" + ScoreB.ToString(); }
                        else if (count == 2)
                        { score.secondScore = ScoreA.ToString() + ":" + ScoreB.ToString(); }
                        else if (count == 3)
                        { score.thirdScore = ScoreA.ToString() + ":" + ScoreB.ToString(); }
                        else if (count == 4)
                        { score.fourthScore = ScoreA.ToString() + ":" + ScoreB.ToString(); }
                        count++;
                        ScoreA = 0;
                        ScoreB = 0;
                        showScore();
                    }
                }
            }
            else if (count == 5)
            {
                if ((ScoreA >= 15 && Math.Abs(ScoreA - ScoreB) >= 2) || (ScoreB >= 15 && Math.Abs(ScoreA - ScoreB) >= 2))
                {
                    if (ScoreA - ScoreB >= 2)
                    {
                        sb.AppendFormat("第{0}局,{1}:{2}\r", count, ScoreA, ScoreB);
                        lblBigScore.Text = sb.ToString();
                        MessageBox.Show("比赛结束"+lblCount.Text + TeamA + "胜利");
                        TeamScoreA++;
                        score.Victory = TeamA + TeamScoreA.ToString() + ":" + TeamScoreB.ToString();
                      
                        score.fifthScore = ScoreA.ToString() + ":" + ScoreB.ToString();
                        RankA.total++;
                        RankB.total++;
                        RankA.victorycount++;
                        RankB.defeatcount++;
                        RankA.count += 2;
                        RankB.count++;
                        RankA.totalvictory++;
                        bll.UpdateRank(RankA);
                        bll.UpdateRank(RankB);
                    }
                    if (ScoreB - ScoreA >= 2)
                    {
                        sb.AppendFormat("第{0}局,{1}:{2}/0", count, ScoreA, ScoreB);
                        lblBigScore.Text = sb.ToString();
                        MessageBox.Show("比赛结束"+lblCount.Text + TeamB + "胜利");
                        TeamScoreB++;
                        score.Victory = TeamB + TeamScoreB.ToString() + ":" + TeamScoreA.ToString();                        
                        score.fifthScore = ScoreA.ToString() + ":" + ScoreB.ToString();
                        RankB.total++;
                        RankA.total++;
                        RankB.victorycount++;
                        RankA.defeatcount++;
                        RankB.count += 2;
                        RankA.count++;
                        RankB.totalvictory++;
                        bll.UpdateRank(RankA);
                        bll.UpdateRank(RankB);
                    }
                    count=1;
                    ScoreA = 0;
                    ScoreB = 0;
                    showScore();
                    bll.InsertScore(score);
                }

            }
               
            }
         private void jushucount(int count)
        { 
            if(count==1)
            {
                lblCount.Text= "第一局";
            }
            else if (count == 2)
            {
                lblCount.Text = "第二局";
            }
            else if (count == 3)
            { lblCount.Text = "第三局"; }
            else if (count == 4)
            { lblCount.Text = "第四局"; }
            else if (count == 5)
            {
                lblCount.Text = "第五局";
            }
            else
            {
                lblCount.Text = "第一局";
            }
        }
         
        }
       


    }
排名显示
 public partial class Ranking : Form
    {
        public Ranking()
        {
            InitializeComponent();
        }
        public volleyBll bll = new volleyBll();
        private void Ranking_Load(object sender, EventArgs e)
        {
            dgvVolleyRankLoad();
        }
        private void dgvVolleyRankLoad()
        {
            dgvVolleyRank.DataSource = bll.SelectvolleyTeamRank();
            int count = bll.Selectrankcount();
            for (int i = 0; i < count; i++)
            {
                this.dgvVolleyRank.Rows[i].Cells[0].Value = i + 1;
            }
        }
    }

程序运行截图

 

posted @ 2017-01-02 21:39  colorful丶  阅读(241)  评论(2编辑  收藏  举报