计分员计分程序
1.估计这个任务需要多长时间:两星期
2.需求分析:
作为一名现场记分员,我希望详细记录比赛现场比分增长情况,以便观众及运动员、教练员及时掌握比赛状况。(满意条件:每一次比分的改变,都要形成一条记录)。
3.设计文档:
根据用户需求可知我们此次程序需要做到每次分数变化的时候都要记录。当记分员操作之后就要形成记录。
4.代码规范
根据Visual Studio 2010规范去写。
5.具体设计:
6.具体编码
public class Dal
{
public List<Model> GetAll()
{
string sql = "select * from Table_1";
List<Model> stu = new List<Model>();
using (SqlDataReader reader = SqlHelper.ExecuteReader(sql))
{
if (reader.HasRows)
{
while (reader.Read())
{
Model Mod = new Model();
Mod.ID = (int)reader["ID"];
Mod.Name = reader["Name"].ToString();
Mod.Wz = reader["Wz"].ToString();
stu.Add(Mod);
}
}
}
return stu;
}
public List<Model> GetAll1()
{
string sql = "select * from Table_2";
List<Model> stu = new List<Model>();
using (SqlDataReader reader = SqlHelper.ExecuteReader(sql))
{
if (reader.HasRows)
{
while (reader.Read())
{
Model Mod = new Model();
Mod.ID = (int)reader["ID"];
Mod.Name = reader["Name"].ToString();
Mod.Wz = reader["Wz"].ToString();
stu.Add(Mod);
}
}
}
return stu;
}
}
public class Bll
{
public Dal dal = new Dal();
public List<Model> GetAll()
{
return dal.GetAll().Count > 0 ? dal.GetAll() : null;
}
public List<Model> GetAll1()
{
return dal.GetAll1().Count > 0 ? dal.GetAll1() : null;
}
}
public class Model
{
public int ID { get; set; }
public string Name { get; set; }
public string Wz { get; set; }
}
public static class SqlHelper
{
//获取连接字符串
private static readonly string constr = ConfigurationManager.ConnectionStrings["connectionStr"].ConnectionString;
//ExecuteNonQuery()方法 执行增删改
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();
}
}
}
//ExecuteScalar()方法 执行返回单个值
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();
}
}
}
//ExecuteReader()方法 执行返回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;
}
}
}
//ExecuteDataTable()方法 执行返回
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;
}
}
7.运行界面
程序中还存在一些问题,还在继续完善当中。