首页 > 代码库 > 排球计分规则3.17

排球计分规则3.17

用户故事:

作为一名现场记分员,我希望详细记录比赛现场比分增长情况,以便观众及运动员、教练员及时掌握比赛状况。(满意条件:每一次比分的改变,都要形成一条记录)

运行截图:

技术分享

 

技术分享

 

技术分享

 

技术分享

下附代码:

---------historySelect.cs----------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 排球计分程序
{
    public partial class historySelect : Form
    {
        public historySelect()
        {
            InitializeComponent();
        }
        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();
            }
          

        }
    }
}

 --------------writeHistory0.cs----------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 排球计分程序
{
    public partial class writeHistory0 : Form
    {
       
        public writeHistory0()
        {
            InitializeComponent();
        }
        public void lblName(string name)
        {
            textName.Text = name;
        }
        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);
                get.getA(Aa1.Text, Aa2.Text, Aa3.Text, Aa4.Text, Ab1.Text, Ab2.Text, Ab3.Text, Ac1.Text, Ac2.Text, Ad1.Text, Ad2.Text, Ae.Text,
                    Ba1.Text, Ba2.Text, Ba3.Text, Ba4.Text, Bb1.Text, Bb2.Text, Bb3.Text, Bc1.Text, Bc2.Text, Bd1.Text, Bd2.Text, Be.Text);
                w.Show();
                this.Close();
            }
           
        }

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

----------------------writeHistory1.cs--------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 排球计分程序
{
    public partial class writeHistory1 : Form
    {
        public writeHistory1()
        {
            InitializeComponent();
        }
        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);
        }
        string one=null, two=null, three=null, four=null, five=null;

        private void A_Click(object sender, EventArgs e)//甲方加分
        {
            getScoreA gsa = new getScoreA();
            gsa.ShowDialog();
           sb.AppendFormat("{0}得分\r\n", get.z);
            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)//乙方加分
        {
            getScoreB gsb = new getScoreB();
            gsb.ShowDialog();
            sb.AppendFormat("{0}得分\r\n", get.z);
            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();
        }
      

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

-------------------------getScoreA.cs-------getScoreB.cs----------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 排球计分程序
{
    public partial class getScoreA : Form
    {
        public getScoreA()
        {
            InitializeComponent();
        }
      

        private void A_Load(object sender, EventArgs e)
        {
            a1.Text = get.Aa1;
            a2.Text = get.Aa2;
            a3.Text = get.Aa3;
            a4.Text = get.Aa4;
            b1.Text = get.Ab1;
            b2.Text = get.Ab2;
            b3.Text = get.Ab3;
            c1.Text = get.Ac1;
            c2.Text = get.Ac2;
            d1.Text = get.Ad1;
            d2.Text = get.Ad2;
            e1.Text = get.Ae1;
        }

        private void a1_Click(object sender, EventArgs e)
        {
            get.z = a1.Text;
            this.Close();
        }

        private void d1_Click(object sender, EventArgs e)
        {
            get.z = d1.Text;
            this.Close();
        }

        private void c2_Click(object sender, EventArgs e)
        {
            get.z = c2.Text;
            this.Close();
        }

        private void c1_Click(object sender, EventArgs e)
        {
            get.z = c1.Text;
            this.Close();
        }

        private void e1_Click(object sender, EventArgs e)
        {
            get.z = e1.Text;
            this.Close();
        }

        private void b3_Click(object sender, EventArgs e)
        {
            get.z = b3.Text;
            this.Close();
        }

        private void b2_Click(object sender, EventArgs e)
        {
            get.z = b2.Text;
            this.Close();
        }

        private void b1_Click(object sender, EventArgs e)
        {
            get.z = b1.Text;
            this.Close();
        }

        private void a4_Click(object sender, EventArgs e)
        {
            get.z = a4.Text;
            this.Close();
        }

        private void a3_Click(object sender, EventArgs e)
        {
            get.z = a3.Text;
            this.Close();
        }

        private void a2_Click(object sender, EventArgs e)
        {
            get.z = a2.Text;
            this.Close();
        }

        private void d2_Click(object sender, EventArgs e)
        {
            get.z = d2.Text;
            this.Close();
        }
    }
}

-------------------get.cs-------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 排球计分程序
{
    public static class get
    {
       public static string Aa1, Aa2, Aa3, Aa4,Ab1, Ab2, Ab3, Ac1, Ac2, Ad1, Ad2, Ae1,Ba1, Ba2, Ba3, Ba4, Bb1, Bb2, Bb3, Bc1, Bc2, Bd1, Bd2, Be1,z;
        public static void getA(string a, string b, string c, string d, string e, string f, string g, string h, string i, string j,
            string k, string l, string m,string n,string o,string p,string q,string r,string s,string t,string u,string v,string w,string x)
        {
            Aa1 = a;
            Aa2 = b;
            Aa3 = c;
            Aa4 = d;
            Ab1 = e;
            Ab2 = f;
            Ab3 = g;
            Ac1 = h;
            Ac2 = i;
            Ad1 = j;
            Ad2 = k;
            Ae1 = l;
            Ba1 = m;
            Ba2 = n;
            Ba3 = o;
            Ba4 = p;
            Bb1 = q;
            Bb2 = r;
            Bb3 = s;
            Bc1 = t;
            Bc2 = u;
            Bd1 = v;
            Bd2 = w;
            Be1 = x;
        }
    }
}

-------------------SqlHelper.cs----------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace 排球计分程序
{
   public class SqlHelper
    {
        private static readonly string strConn = ConfigurationManager.ConnectionStrings["paiqiulianjie"].ConnectionString;
        public static DataTable ExecuteDataTable(string sql, params SqlParameter[] pms)
        {
            DataTable dt = new DataTable();
            using (SqlDataAdapter adapter = new SqlDataAdapter(sql, strConn))
            {
                if (pms != null)
                {
                    adapter.SelectCommand.Parameters.AddRange(pms);
                }
                adapter.Fill(dt);
            }
            return dt;
        }
        public static SqlDataReader ExecuteReader(string sql, params SqlParameter[] pms)
        {
            SqlConnection con = new SqlConnection(strConn);
            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 int ExecuteNonQuery(string sql, params SqlParameter[] pms)
        {
            using (SqlConnection con = new SqlConnection(strConn))
            {
                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    if (pms != null)
                    {
                        cmd.Parameters.AddRange(pms);
                    }
                    con.Open();
                    return cmd.ExecuteNonQuery();
                }
            }
        }
    }
}

本次编写代码未用三层架构甚是遗憾,其实我也不知道在这里怎么用三层架构。

排球计分规则3.17