首页 > 代码库 > 排球计分程序
排球计分程序
1)计划。
估计需要两周。
2)需求分析
作为一名现场记分员,我希望详细记录比赛现场比分增长情况,以便观众及运动员、教练员及时掌握比赛状况。
3)生成设计文档
当用户打开程序,可以看到中国队和塞尔维亚队的比赛得分情况,可以看到每个球员的得分情况,还可以看出每个队员在所在队伍的地位。
4)具体设计
用户进入后能够清楚的看到每个队员的得失情况。
5)具体代码
public static class SqlHelper
{
//1.连接字符串
private static readonly string constr = ConfigurationManager.ConnectionStrings["PQ"].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);
}
con.Open();
return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
}
}
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;
}
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>");
测试(自测、修改代码、提交代码):40min
7)事后总结和改进计划:会在后面的时间里继续完善代码,争取做到“完美”!
排球计分程序