public void updateVacationWeek(int vacationHouseId, VacationWeek vacationWeek) { string sql = ""; sql += "UPDATE vacationweek"; sql += " SET price=" + vacationWeek.Price; sql += " WHERE vacationhouseid=" + vacationHouseId + " and weeknumber=" + vacationWeek.WeekNumber; SqlCommand cmd = new SqlCommand(sql, con); executeQuery(cmd); }
// VacationHouseWeeks public void createVacationWeek(int vacationHouseId, VacationWeek vacationWeek) { string sql = ""; sql += "INSERT INTO"; sql += " vacationweek(weeknumber,price,isBooked,vacationhouseid)"; sql += " VALUES (" + vacationWeek.WeekNumber + "," + vacationWeek.Price + ",'" + vacationWeek.IsBooked + "'," + vacationHouseId + ")"; SqlCommand cmd = new SqlCommand(sql, con); executeQuery(cmd); }
public List <VacationWeek> getVacationHousesWeeks(int i) { List <VacationWeek> vacationWeeks = new List <VacationWeek>(); string sql = "SELECT weeknumber,price,isBooked FROM vacationweek WHERE vacationhouseid=" + i + ""; SqlCommand cmd = new SqlCommand(sql, con); try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int week = (int)reader["weeknumber"]; int price = (int)reader["price"]; Boolean isBooked = (Boolean)reader["isBooked"]; VacationWeek vacationWeek = new VacationWeek(week, price); vacationWeek.IsBooked = isBooked; if (!vacationWeeks.Contains(vacationWeek)) { vacationWeeks.Add(vacationWeek); } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message.ToString()); } finally { if (con.State == ConnectionState.Open) { con.Close(); } } return(vacationWeeks); }