大致界面如下:
部分代码:
//Model
public class TuanDui
{
public int ID { get; set; }
public string Name { get; set; }
}
public class JiFen
{
public int Num { get; set; }
public string NameA { get; set; }
public string NameB { get; set; }
public int JuNum { get; set; }
public int JuFenA { get; set; }
public int JuFenB { get; set; }
public int ZongA { get; set; }
public int ZongB { get; set; }
}
//volleyballDAL层
public class volleyballDAL
{
public TuanDui SelectTuanDui()
{
string sql = "select * from tuandui";
TuanDui td = null;
using (SqlDataReader reader = SqlHelper.ExecuteReader(sql))
{
if (reader.HasRows)
{
while (reader.Read())
{
td = new TuanDui();
td.ID = (int)reader["Id"];
td.Name = reader["Name"].ToString();
}
}
}
return td;
}
public JiFen SelectJiFen()
{
string sql = "select * from JiFen";
JiFen jf = null;
using (SqlDataReader reader = SqlHelper.ExecuteReader(sql))
{
if (reader.HasRows)
{
while (reader.Read())
{
jf = new JiFen();
jf.Num = (int)reader["Num"];
jf.NameA = reader["NameA"].ToString();
jf.NameB = reader["NameB"].ToString();
jf.JuNum = (int)reader["JuNum"];
jf.JuFenA = (int)reader["JuFenA"];
jf.JuFenB = (int)reader["JuFenA"];
jf.ZongA = (int)reader["ZongA"];
jf.ZongB = (int)reader["ZongB"];
}
}
}
return jf ;
}
}
SqlHelper类
public static class SqlHelper
{
//1.连接字符串
private static readonly string constr = ConfigurationManager.ConnectionStrings["itcast"].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.执行返回多个值,多行
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;
}
}
}
//5.执行返回一张表
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;
}
}
//volleyballBLL层
public class volleyballBLL
{
private volleyballDAL dal = new volleyballDAL();
public TuanDui GetSelectTuanDui()
{
return dal.SelectTuanDui();
}
public JiFen GetSelectJiFen()
{
return dal.SelectJiFen();
}
}
//volleyballUI层
代码后续更新