用三层构架做ATM程序 , 底层数据访问层用的是微软Petshop的DBHleper(全部复制的),怎么和业务逻辑中的东西关联起来,或是如何在业务逻辑层里调用
Atm.zip
(1.17 MB)
public class UserBusiness { UserDao userDao = new UserDao(); public IList<User> GetUserById(int id) { return userDao.GerUserById(id); } } public class UserDao { public IList<User> GerUserById(int id) { IList<User> users = new List<User>(); SqlParameter[] paramters = new SqlParameter[] { new SqlParameter("Id", id) }; using (SqlDataReader reader = DBHelper.ExecuteReader("ConnectionString", CommandType.StoredProcedure, "procName", paramters)) 这里调用 DBHelper { if (reader.HasRows) { while (reader.Read()) { users.Add(ConvertUser(reader)); } } } return users; } private User ConvertUser(SqlDataReader reader) { User user = new User(); user.Name = reader.IsDBNull(0) ? string.Empty : reader["Name"].ToString(); return user; } } public class User { public string Name { get; set; } }