public abstract class AsbCommection { private static string con = System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString; public static IDbConnection GetConnection() { IDbConnection conn = new SqlConnection(con); if (conn.State == ConnectionState.Closed) { conn.Open(); } return conn; } }
public interface IDAL { List<Tresult> Show<Tresult>(string sql) where Tresult : class, new(); int Insert(string sql); int Del(string sql); } public class SqlDBHelper : IDAL { private IDbConnection conn = AsbCommection.GetConnection(); public int Del(string sql) { return conn.Execute(sql); } public int Insert(string sql) { return conn.Execute(sql); } public List<Tresult> Show<Tresult>(string sql) where Tresult : class, new() { return conn.Query<Tresult>(sql).ToList(); } }
public class RoweBLL { SqlDBHelper db = new SqlDBHelper(); public List<RoweModel> ShowRowe(string YName) { if (YName ==null||YName=="") { string sql = "select * from YueKao0707TB s join YuekaoType e on s.TId=e.TId"; return db.Show<RoweModel>(sql); } else { string sql = $"select * from YueKao0707TB s join YuekaoType e on s.TId=e.TId where YName like ‘{"%" + YName + "%"}‘"; return db.Show<RoweModel>(sql); } } public int InsertRowe(RoweModel m) { string sql = $"insert into YueKao0707TB values(‘{m.YName}‘,‘{m.TId}‘,‘{m.ZPrco}‘,‘{m.SPrco}‘,‘{m.ZNum}‘,‘{m.SNum}‘,‘{m.HStrac}‘)"; return db.Insert(sql); } public List<RoweTypeModel> ShowType() { string sql = "select * from YuekaoType"; return db.Show<RoweTypeModel>(sql); } public int DelRowe(int Id) { string sql = "delete from YueKao0707TB where Id=" + Id; return db.Del(sql); } }