排球计分程序

需求分析:作为一名现场记分员,我希望详细记录比赛现场比分增长情况,以便观众及运动员、教练员及时掌握比赛状况。(满意条件:每一次比分的改变,都要形成一条记录)。根据用户需求可知我们此次程序需要做到每次分数变化的时候都要记录。 

计划:估计此次工作需要两周的时间。

代码规范:用vs2010规范实现

设计复审(和组员进行讨论)0.5h

 

用例图:

 

 

代码如下:

  public class Delete : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            
            //拿到删除数据的id
            string id = context.Request["id"];
            int showId = int.Parse(id);

            string sql = "delete from player where id=@id;";
            SqlParameter[] ps = {new SqlParameter("@id",id) };
            int result = SqlHelper.ExecuteNonQuery(sql,ps);

            if (result > 0)
            {
                //删除成功
                context.Response.Redirect("ListHandler.ashx");
            }
            else
            {
                context.Response.Write("删除失败了");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }

 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 bool IsReusable {
        get {
            return false;
        }
    }

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

posted on 2017-03-18 10:49  未来呢啊  阅读(130)  评论(0编辑  收藏  举报