·計劃sql
估計這個任務須要7天測試
·開發編碼
*需求分析設計
用戶故事:做爲一個排球教練,我但願知道每一個隊員的技術得分狀況,以便後期對每一個隊員的訓練計劃進行調整。代碼規範
*生成設計文檔 server
任務:教練經過選擇想要查詢的隊員名字來查詢本隊某隊員的技術得分。blog
*設計複審:開發
將編寫的程序進行生成,進行設計複審。看看是否生成錯誤,若是錯誤進行修改。文檔
*代碼規範:字符串
利用VS對該程序進行代碼規範。
*具體設計:
具體編碼:
Web.config:
<configuration>
<connectionStrings>
<add name="itcast" connectionString="server=.;initial catalog=itcast;integrated security=true;"/>
</connectionStrings>
</configuration>
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;
}
}
運行結果:
關於測試會在從此幾天進行處理。