十八周个人作业

  • 计划

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

  • 开发
  • 需求分析

用户故事:作为一个赛事管理人员,我希望知道每场比赛队伍得分和积分情况,以便给每队进行排名。

从分析用例故事可以知道完成此程序需要这两项任务:选择业务和查询队伍积分排名。

以下为改程序的活动图:

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

根据《2015-2016赛季中国排球联赛竞赛规程》,积分规则如下:
1、计分方式:比赛结果为3:0、3:1时,胜队积3分,负队积0分;比赛结果为3:2时,胜队积2分,负队积1分;积分高者排名在前。 
2、当积分相等时,决定名次顺序为:①胜场;②总胜局/总输局(C值);③总得分/总失分(Z值)。 
3、当三队或三队以上Z值仍相等时,则仅在该几队之间依次按照上述第2条决定名次办法①、②、③决定。

故需要建立表头为:队伍名称,胜场,总胜局/总输局,总得分/总失分,积分,名次的数据表。

以下为部分代码:

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();
        }

计分界面:

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

比赛记录查询:

private void cmbLoad()
        {
            cmbName.Items.Clear();

string sql = "select game from paiqiu";
            SqlDataReader reader = SqlHelper.ExecuteReader(sql);
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    cmbName.Items.Add(reader[0]);
                }
            }
            reader.Close();
        }
        private void dgvLoad()
        {
            string sql = "select * from paiqiu";
            dgvGame.DataSource = SqlHelper.ExecuteDataTable(sql);
        }
        private void Form2_Load(object sender, EventArgs e)
        {
            cmbLoad();
            dgvLoad();
           
        }

private void select_Click(object sender, EventArgs e)//单个查询
        {
            StringBuilder sql = new StringBuilder("select * from paiqiu where 1=1");
            if (!string.IsNullOrEmpty(cmbName.Text))
            {
                sql.Append(" and game like ‘%" + cmbName.Text + "%‘");
            }
            SqlDataReader reader= SqlHelper.ExecuteReader(sql.ToString());
            if (reader.HasRows)
            {
                dgvGame.DataSource = SqlHelper.ExecuteDataTable(sql.ToString());
            }
            else
            {
                MessageBox.Show("没有查询到比赛记录!");
            }
        }

private void lblWrite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)//跳转计分页面
        {
            this.Close();
            writeHistory0 a = new writeHistory0();
            a.Show();
        }

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

private void dgvGame_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int x = e.ColumnIndex;
            int y = e.RowIndex;
            if(x==0&&y!=-1)
            {
                child ch = new child();
                ch.xq(dgvGame.CurrentRow.Cells[11].Value.ToString());
                ch.Show();
            }

}

private void button1_Click(object sender, EventArgs e)
        {
            selectPM sp = new selectPM();
            sp.Show();
        }

比赛排名查询:

private void selectPM_Load(object sender, EventArgs e)
        {
            string sql = "select * from paiming";
            dgvPM.DataSource = SqlHelper.ExecuteDataTable(sql);
            for (int i =1 ; i < dgvPM.Rows.Count+1 ; i++)
            {
                dgvPM.Rows[i-1].Cells["ranking"].Value = i;
            }
        }

private void dgvPM_Sorted(object sender, EventArgs e)
        {
            for (int i = 1; i < dgvPM.Rows.Count + 1; i++)
            {
                dgvPM.Rows[i - 1].Cells["ranking"].Value = i;
            }
        }

时间: 2024-10-13 17:22:26

十八周个人作业的相关文章

第十八周 个人作业

开发流程如下: ·项目计划 完成这个项目需要的时间:5-7天 ·项目开发 ·需求分析: ·作为一名排球赛事管理者,我希望能统计各个队伍间的比分情况,并计算出各个队伍的的积分,以便能给队伍进行排名. ·设计文档 ·由排球比赛用户故事的需求分析可知,此程序是用来统计各个队伍的比分和积分情况的,并按照积分高低排名. ·计划复审 ·正在进一步的商讨中. ·代码规范 ·根据Visual Studio 2010规范去写. ·具体设计 ·URL活动图如下: ·URL类图如下: public partial c

第十八周个人作业--The Final

项目计划   完成这个项目需要的时间:5-7天项目开发  需求分析:    作为一名排球赛事管理者,我希望能够根据比赛查询每场比赛的结果,以便于确定每支球队的比赛名次.  设计文档    由排球比赛用户故事的需求分析可知,此程序是用来统计各个队伍的比分和积分情况,并加以排名.  计划复审 目前在进行中 public partial class Form1 : Form{ Action action = new Action(); public void INSERT() {Model q = n

第十八周个人作业

·项目计划 完成这个项目需要的时间:5-7天 ·项目开发 ·需求分析: ·作为一名排球赛事管理者,我希望能统计各个队伍间的比分情况,对各队进行更好的排名,以便于各队能掌握自己的排名状况. ·设计文档 ·由排球比赛用户故事的需求分析可知,此程序是用来统计各个队伍的比分和积分情况的,并按照积分高低排名. ·计划复审 ·正在进一步的商讨中. ·代码规范 ·根据Visual Studio 2010规范去写. ·具体设计 ·URL活动图如下: ·URL类图如下: 部分代码: namespace Windo

一十八周入侵前端进行时!

现在的时间是:2015年3月28日 18:06:06,刚刚从图书馆飞奔归来,坐在图书馆想了一个多小时,嗯,整个计划应运而生,十八周入侵前端! 先介绍下我自己吧,我是一名大三的学生,在大连,大二的时候开始接触编程,从JAVA到PHP,在到前端,都曾涉猎,但是样样都是门外汉,今年年初的时候,决定毕业以后奔往帝都,以前端工程师的身份进入互联网行业,未来的职业生涯规划也将以此起步. 从年初到现在,断断续续的,乱七八糟的,现在有些太浮躁,所以决定静下心,不再朝三暮四,处处牵挂,就是一个字儿:前端工程师!

201671010118 2016-2017-2《Java程序设计》 第十八周学习心得

已经是第十八周的java学习了,马上面临期末考试了,立马又要进行紧张的复习状态了,感觉也没有做好准备,打算在这周认真复习,好好备战期末考试,在这学期的java学习中,遇到了很多困难也解决了很多,重点的四五六章节内容感觉会有点遗忘,第十章十二章内容的掌握还可以,Swing用户界面组件掌握的不怎么好,在私下我想用更多的时间去努力学习这章内容,复习以前的内容. 这是最后一次的总结,一学期时间很快过去了,感谢代老师以及学长学姐的帮助,学习上一直在认真帮助我们,每周的作用业会认真的给我们批阅,特别感谢老师

杨玲 201771010133《面向对象程序设计(java)》第十八周学习总结

 <面向对象程序设计(java)>第十八周学习总结 第一部分:理论知识学习部分 第二部分:实验部分 实验名称:实验十八  总复习 1.实验目的与要求 (1) 综合掌握java基本程序结构: (2) 综合掌握java面向对象程序设计特点: (3) 综合掌握java GUI 程序设计结构: (4) 综合掌握java多线程编程模型: (5) 综合编程练习. 2.实验内容和步骤 任务1:填写课程课后调查问卷,网址:https://www.wjx.cn/jq/33108969.aspx. 任务2:综合编

狄慧201771010104《面向对象程序设计(java)》第十八周学习总结

实验十八  总复习 实验时间 2018-12-30 1.实验目的与要求 (1) 综合掌握java基本程序结构: (2) 综合掌握java面向对象程序设计特点: (3) 综合掌握java GUI 程序设计结构: (4) 综合掌握java多线程编程模型: (5) 综合编程练习. 2.实验内容和步骤 任务1:填写课程课后调查问卷,网址:https://www.wjx.cn/jq/33108969.aspx. 任务2:综合编程练习 练习1:设计一个用户信息采集程序,要求如下: (1) 用户信息输入界面如

201771010108 -韩腊梅-第十八周学习总结

实验十八  总复习 1.实验目的与要求         (1) 综合掌握java基本程序结构: (2) 综合掌握java面向对象程序设计特点: (3) 综合掌握java GUI 程序设计结构: (4) 综合掌握java多线程编程模型: (5) 综合编程练习. 2.实验内容和步骤 任务1:填写课程课后调查问卷,网址:https://www.wjx.cn/jq/33108969.aspx. 已完成 任务2:综合编程练习 练习1:设计一个用户信息采集程序,要求如下: (1)  用户信息输入界面如下图所

达拉草201771010105《面向对象程序设计(java)》第十八周学习总结

实验十八  总复习 实验时间 2018-12-30 1.实验目的与要求 (1) 综合掌握java基本程序结构: (2) 综合掌握java面向对象程序设计特点: (3) 综合掌握java GUI 程序设计结构: (4) 综合掌握java多线程编程模型: (5) 综合编程练习. 2.实验内容和步骤 任务1:填写课程课后调查问卷,网址:https://www.wjx.cn/jq/33108969.aspx. 任务2:综合编程练习 练习1:设计一个用户信息采集程序,要求如下: (1)  用户信息输入界面