个人作业
1.估计这个任务需要多长时间:8天
2.需求分析:
作为一个排球教练,我希望知道每个队员每场比赛的得分和技术得分,以便后期对其进行专项训练。
3.设计文档:
根据需求分析可知,此程序需要展示出每个队员每局比赛的个人得分和每个队员整场比赛的技术得分。
4.设计复审:
小组成员进行复审
5.代码规范
根据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.One = reader["One"].ToString();
Mod.Two = reader["Two"].ToString();
Mod.Three = reader["Three"].ToString();
Mod.Four = Convert.IsDBNull(reader["Four"]) ? null : reader["Four"].ToString();
Mod.Five = Convert.IsDBNull(reader["Five"]) ? null : reader["Five"].ToString();
stu.Add(Mod);
}
}
}
return stu;
}
public List<Model> GetAll1()
{
string sql = "select * from Table_4";
List<Model> stu = new List<Model>();
using (SqlDataReader reader = SqlHelper.ExecuteReader(sql))
{
if (reader.HasRows)
{
while (reader.Read())
{
Model Mod = new Model();
Mod.Name = reader["Name"].ToString();
Mod.Fq = reader["Fq"].ToString();
Mod.Lw = reader["Lw"].ToString();
Mod.Zg = reader["Zg"].ToString();
Mod.Yg = reader["Yg"].ToString();
Mod.Cs = Convert.IsDBNull(reader["Cs"]) ? null : reader["Cs"].ToString();
Mod.Fs = Convert.IsDBNull(reader["Fs"]) ? null : reader["Fs"].ToString();
Mod.Ts = reader["Ts"].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 One { get; set; }
public string Two { get; set; }
public string Three { get; set; }
public string Four { get; set; }
public string Five { get; set; }
public string Fq{ get; set; }
public string Lw{ get; set; }
public string Zg{ get; set; }
public string Yg{ get; set; }
public string Fs{ get; set; }
public string Cs{ get; set; }
public string Ts{ 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.运行结果
关于代码复审,测试和之后的报告,会在接下来的几天时间内完成并逐渐完善自己的程序。