public List<Zone> GetAllZoneName() { string select = "SELECT * FROM tbl_zone"; connectionObj.Open(); commandObj.CommandText = select; SqlDataReader reader = commandObj.ExecuteReader(); List<Zone> zoneList = new List<Zone>(); while (reader.Read()) { Zone aZone = new Zone(); aZone.Id = (int)reader["id"]; aZone.Name = reader["zoneName"].ToString(); zoneList.Add(aZone); } reader.Close(); connectionObj.Close(); return zoneList; }
public string SaveZone(Zone aZone) { if (zoneGateway.HasThisZoneExists(aZone)) { return "Zone already Exists!"; } else { if (zoneGateway.SaveZone(aZone)) { return "Successfull"; } else { return "Faild"; } } }
public bool HasThisZoneExists(Zone aZone) { string insert = "SELECT * FROM tbl_zone WHERE zoneName='" + aZone.Name + "'"; connectionObj.Open(); commandObj.CommandText = insert; SqlDataReader reader = commandObj.ExecuteReader(); bool zoneStatus = reader.HasRows; reader.Close(); connectionObj.Close(); return zoneStatus; }
public bool SaveZone(Zone aZone) { string insert = "INSERT INTO tbl_zone VALUES('" + aZone.Name + "')"; connectionObj.Open(); commandObj.CommandText = insert; int rowAffected = commandObj.ExecuteNonQuery(); connectionObj.Close(); if (rowAffected>0) { return true; } return false; }