private Entities GetList(SqlDataReader reader) { Entities entities = new Entities(); ScholarShip scholarShip; while (reader.Read()) { scholarShip = new ScholarShip() { ScholarShipId = reader.GetInt32(1), ScholarShipName = reader.GetString(2), ScholarShipTotal = reader.GetInt32(3) }; entities.Add(scholarShip); } return(entities); }
private void GetOne() { int scholarShipId = int.Parse(Helper.GetParameterFromRequest("scholarShipId")); ScholarShip scholarShip = new ScholarShip(); scholarShip.ScholarShipId = scholarShipId; ScholarShipRepo Repo = new ScholarShipRepo(scholarShip); if (Repo.Query()) { Helper.Response(scholarShip.Serialize()); } else { Helper.ResponseError(Repo.ErrorMessage); } }
public Entity Add(Entity entity) { ScholarShip scholarShip = entity as ScholarShip; string sql = @"insert into ScholarShip(ScholarShipName,ScholarShipAbstract,ScholarShipTotal,UniversityId,StartYear,EndYear)values (@ScholarShipName,@ScholarShipAbstract,@ScholarShipTotal,@UniversityId,@StartYear,@EndYear);select @ScholarShipId = @@Identity"; SqlParameter prmScholarShipId = new SqlParameter("@ScholarShipId", SqlDbType.Int) { Direction = ParameterDirection.Output }; SqlParameter prmScholarShipName = new SqlParameter("@ScholarShipName", SqlDbType.VarChar, 200) { Value = scholarShip.ScholarShipName }; byte[] arrScholarShipAbstract = Encoding.UTF8.GetBytes(scholarShip.ScholarShipAbstract); SqlParameter prmScholarShipAbstract = new SqlParameter("@ScholarShipAbstract", SqlDbType.Image) { Value = arrScholarShipAbstract }; SqlParameter prmScholarShipTotal = new SqlParameter("@ScholarShipTotal", SqlDbType.Int) { Value = scholarShip.ScholarShipTotal }; SqlParameter prmUniversityId = new SqlParameter("@UniversityId", SqlDbType.Int) { Value = scholarShip.UniversityId }; SqlParameter prmStartYear = new SqlParameter("@StartYear", SqlDbType.Int) { Value = scholarShip.StartYear }; SqlParameter prmEndYear = new SqlParameter("@EndYear", SqlDbType.Int) { Value = scholarShip.EndYear }; ExecuteNoQuery(sql, prmScholarShipId, prmScholarShipName, prmScholarShipTotal, prmScholarShipAbstract, prmStartYear, prmEndYear, prmUniversityId); return(scholarShip); }
public Entity Update(Entity entity) { ScholarShip scholarShip = entity as ScholarShip; string sql = @"update ScholarShip set ScholarShipName = @ScholarShipName,ScholarShipTotal = @ScholarShipTotal,ScholarShipAbstract = @ScholarShipAbstract, StartYear = @StartYear,EndYear = @EndYear where ScholarShipId = @ScholarShipId"; SqlParameter prmScholarShipId = new SqlParameter("@ScholarShipId", SqlDbType.Int) { Value = scholarShip.ScholarShipId }; SqlParameter prmScholarShipName = new SqlParameter("@ScholarShipName", SqlDbType.VarChar, 200) { Value = scholarShip.ScholarShipName }; SqlParameter prmScholarShipTotal = new SqlParameter("@ScholarShipTotal", SqlDbType.Int) { Value = scholarShip.ScholarShipTotal }; byte[] arrbyte = Encoding.UTF8.GetBytes(scholarShip.ScholarShipAbstract); SqlParameter prmScholarShipAbstract = new SqlParameter("@ScholarShipAbstract", SqlDbType.Image) { Value = arrbyte }; SqlParameter prmStartYear = new SqlParameter("@StartYear", SqlDbType.Int) { Value = scholarShip.StartYear }; SqlParameter prmEndYear = new SqlParameter("@EndYear", SqlDbType.Int) { Value = scholarShip.EndYear }; ExecuteNoQuery(sql, prmScholarShipId, prmScholarShipName, prmScholarShipAbstract, prmScholarShipTotal, prmStartYear, prmEndYear); return(scholarShip); }
private Entity GetOne(SqlDataReader reader) { if (!reader.HasRows) { SetError("奖学金不存在"); return(null); } reader.Read(); ScholarShip scholarShip = new ScholarShip(); scholarShip.ScholarShipId = reader.GetInt32(0); scholarShip.ScholarShipName = reader.GetString(1); using (Stream stream = reader.GetStream(2)) { byte[] arrByte = new byte[stream.Length]; stream.Read(arrByte, 0, arrByte.Length); scholarShip.ScholarShipAbstract = Encoding.UTF8.GetString(arrByte); } scholarShip.UniversityId = reader.GetInt32(3); scholarShip.ScholarShipTotal = reader.GetInt32(4); scholarShip.StartYear = reader.GetInt32(5); scholarShip.EndYear = reader.GetInt32(6); return(scholarShip); }