排球比赛计分程序

一、计划

        完成这个任务需要五天左右。

二、开发

   1.需求分析:

           作为一名现场记分员,我希望详细记录比赛现场比分增长情况,以便观众及运动员、教练员及时掌握比赛状况。

2.生成设计文档:

          (1)通过现场工作人员的界面,当运动员得分时,通过datagridview控件增加或者更新数据,并且即时更新到数据库中,然后通过查询按钮进入比赛结束后运动员的总分及技术统计界面。

          (2)将每一次得分比分的变化都形成记录,精确到得分选手。

                 (3)活动图

3.设计复审

         同组人员一起复审,讨论了可行与不可行的地方,修改了部分功能。

  4.代码规范

         给目前的内容进行了一些合理的要求,以便进行开发。

  5.具体设计

public static class SqlHelper
    {

        //1.连接字符串
        private static readonly string constr = ConfigurationManager.ConnectionStrings["player"].ConnectionString;

        //2.执行增删改的
        public static int ExecuteNonQuery(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.ExecuteNonQuery();
                }
            }
        }

        //3.执行返回单个值的
        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();
                }
            }
        }

        //4.执行返回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;
                }
            }
        }

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

     
        internal static void ExecuteDataTable()
        {
            throw new NotImplementedException();
        }
    }
}


public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        //拿出所有的数据              
        string name = context.Request.Form["name"];
        int id= Convert.ToInt32( context.Request.Form["id"]);
        string teamname=context.Request.Form["teamname"];
        string status=context.Request.Form["status"];
        string scoreplayer1=context.Request.Form["scoreplayer1"];
       string scoreplayer2=context.Request.Form["scoreplayer2"];
       string totalscore1=context.Request.Form["totalscore1"];
       string totalscore2=context.Request.Form["totalscore2"];

        //插入到数据
        string sql = "insert into player(name,id,teamname,status,scoreplayer1,scoreplayer2,totalscore1,totalscore2) values(@name,@id,@teamname,@status,@scoreplayer1,@scoreplayer2,@totalscore1,@totalscore2);";
        SqlParameter[] ps = { 
                                new SqlParameter("@name",name),
                                new SqlParameter("@id",id),
                                new SqlParameter("@teamname",teamname),
                                new SqlParameter("@status",status),
                                new SqlParameter("@scoreplayer1",scoreplayer1),
                                new SqlParameter("@scoreplayer2",scoreplayer2),
                                new SqlParameter("@totalscore1",totalscore1),
                                new SqlParameter("@totalscore2",totalscore2),
                                                                  
                            };
         int result=SqlHelper.ExecuteNonQuery(sql,ps);
         if (result > 0)
         {
             context.Response.Redirect("ListHandler.ashx");
         }        
        context.Response.Write("<script>alert('添加失败');</script>");               
    }
 


    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/html";


        //拼接html字符串
        StringBuilder sb = new StringBuilder();
        sb.Append("<html><head></head><body><a href='AddInfo.html'>添加</a><br/>");

        //拼接table字符串
        sb.Append("<table><tr><th>编号</th><th>姓名</th><th></th><th>队名</th><th>得分1</th><th>得分情况</th><th>得分2</th></tr><th>得分情况2</th>");

        //获取数据库中的数据
        string str = ConfigurationManager.ConnectionStrings["itcast"].ConnectionString;
        string sql = "select * from User_info";
        SqlDataReader reader = SqlHelper.ExecuteReader(sql, null);
        while (reader.Read())
        {
            sb.AppendFormat(
            "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td><a href='ShowDetailHandler.ashx?id={0}'>详情</a>&nbsp;&nbsp;<a onclick='return confirm("是否要删除?")' href='Delete.ashx?id={0}'>删除</a>&nbsp;&nbsp;<a href='EditHandler.ashx?id={0}'>修改</a></td></tr>",
           reader["Id"], reader["Name"], reader["Age"].ToString(), reader["Number"], reader["Company"], reader["Adress"]);
        }
        sb.Append("</table>");
        //输出到页面
        sb.Append("</body></html>");
        context.Response.Write(sb.ToString());
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}

7.代码复审

     基本实现了想要的功能,没有复审。

  8.

    使用VS对代码进行测试,对代码进行重构,修复了部分问题。

 三、报告

   1.测试报告

       测试通过。

  2.计算工作量

时间:一星期

代码累计数:不确定

随笔累计数:不确定

 3.事后总结

   做了这次重构,再次遇到很多问题,解决了一部分,还有很多地方需要学习。

   

原文地址:https://www.cnblogs.com/wangyiheng/p/6568349.html