排球赛程序(个人作业)

㈠、计划

①估计这个任务需要多少时间:3天

㈡、开发

①需求分析:0.5h

作为一个排球爱好者(运动员,观众)

希望得知比赛的得分,

以便掌握比赛的赛况。(胜负的结果精确到比分)

(只查询结果,不用累计加分)

表现层:①观众

(代码实现方式:winform窗体)

业务层: 判断

数据源:——→DB

②生成设计文档:3h

③设计复审(和同事审核设计文档)0.5h

④代码规范(为目前的开发制定合适的规范)

⑤具体设计:1h

把每一场的比分存到数据库中,在窗体控件中选择某一场,显示比分。

因为不会使用代码也没办法写出一个完整的程序。所以这篇博客内容只能说是一份作业,称不上是程序。

⑥具体编码:1day

    class SqlHelper

    {//获取连接字符串

        private static readonly string constr = ConfigurationManager.ConnectionStrings["connectionStr"].ConnectionString;

        //ExecuteNonQuery()方法

        //ExecuteScalar()方法

        //ExecuteReader()方法

        //ExecuteDataTable()方法

         

        public static int ExecuteNonQuery(string sql, params SqlParameter[] pms)

        {

            //使用using关键字定义一个范围,在范围结束时骸自动调用这个类实例的Dispose处理对象

            using (SqlConnection con = new SqlConnection(constr))

            {

                //创建执行DSql命令对象

                using (SqlCommand cmd = new SqlCommand(sql, con))

                {

                    //判断是否传递了sql参数

                    if (pms != null)

                    {

                        //讲参数添加到Parameters集合中

                        cmd.Parameters.AddRange(pms);

                    }

                    con.Open();

                    return cmd.ExecuteNonQuery();

                }

            }

        }

        //执行返回单个值的

        public static object ExecuteScalar(string sql, params SqlParameter[] pms)

        { 

            using (SqlConnection con = new SqlConnection(constr))

            {

                using (SqlCommand cmd = new SqlCommand(sql, con))

                {

                    if (pms != null)

                    {

                        cmd.Parameters.AddRange(pms);

                    }

                    con.Open();

                    return cmd.ExecuteScalar();

                }

            }

            

        }

        //执行返回SqlDataReader

        public static SqlDataReader ExecuteReader(string sql, params SqlParameter[] pms)

        {

            SqlConnection con = new SqlConnection(constr);

            

                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;

                    }

                }

        }

        //执行返回DataTable

        public static DataTable ExecuteDataTable(string sql, params SqlParameter[] pms)

        {

            DataTable dt = new DataTable();

            using (SqlDataAdapter adapter = new SqlDataAdapter(sql, constr))

            {

                if (pms != null)

                {

                    adapter.SelectCommand.Parameters.AddRange(pms);

                }

                adapter.Fill(dt);

            }

            return dt;

        }

    }

  class Info

    {

        public string Name { get; set; }

        public int First { get; set; }

        public int Second { get; set; }

        public int Third { get; set; }

        public int Fourth { get; set; }

        public int Fifth { get; set; }

        public int Score { get; set; }

       

    }

     private void Select1_Click_1(object sender, EventArgs e)

   {

           string sql = "select * from Bifen where Name=@Name";

            SqlParameter[] paras = new SqlParameter[]

            {

                new SqlParameter("@Name",Name),

               

            };

            using (SqlDataReader reader = SqlHelper.ExecuteReader(sql, paras))

            {

                if (reader.Read())

                {

                   Info bf = new Info();

                   bf.Name = (string)reader["Name"];

                   bf.Second = reader.GetInt32(1);

                   bf.Third = reader.GetInt32(2);

                   bf.Fourth = reader.GetInt32(3);

                   bf.Fifth = reader.GetInt32(4);

                   bf.Score = reader.GetInt32(5);

                  

                }

            }

          }  

        

    

    }

private void button1_Click(object sender, EventArgs e)

{

if(comboBox1.selectIndex==0)

{

txtbox1.Text = bf.first.ToString();

}

private void button1_Click(object sender, EventArgs e)      

 {            

if (comboBox2.Text=="中国:日本"&&comboBox1.Text == "第一局") { textBox1.Text = "25:15"; }          

  if (comboBox2.Text == "中国:日本" && comboBox1.Text == "第二局") { textBox1.Text = "25:18"; }           

  if (comboBox2.Text == "中国:日本" && comboBox1.Text == "第三局") { textBox1.Text = "20:25"; }          

  if (comboBox2.Text == "中国:日本" && comboBox1.Text == "第四局") { textBox1.Text = "21:25"; }           

 if (comboBox2.Text == "中国:日本" && comboBox1.Text == "第五局") { textBox1.Text = "15:13"; }           

                 }  

     

 private void button2_Click(object sender, EventArgs e)       

 {            

if (comboBox2.Text == "中国:日本") { textBox2.Text = "3:2"; }          

  if (comboBox2.Text == "中国:韩国") { textBox2.Text = "3:1"; }      

  }    

⑦代码复审:30min

⑧测试(自测、修改代码、提交代码):40min

㈢、报告

①测试报告:30min

②计算工作量:20min

③事后总结,并提出过程改进计划:2h

原文地址:https://www.cnblogs.com/lover1997/p/6189500.html