public bool cancelreservation(Reservations reservation) { conString = ConfigurationManager.ConnectionStrings["paymatecontext"].ConnectionString; SqlConnection con = new SqlConnection(conString); SqlCommand cmd = new SqlCommand("select * from reservation where id='" + reservation.resid + "'", con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); bool result = rdr.Read(); if (result == true) { roomno = int.Parse(rdr[2].ToString()); cindate = DateTime.Parse(rdr[3].ToString()); } con.Close(); rdr.Close(); if (result == false) { return(false); } else if (result == true) { con.Open(); cmd = new SqlCommand("update reservation set status='" + reservation.rstatus + "' where id='" + reservation.resid + "'", con); cmd.ExecuteNonQuery(); Transaction transaction = new Transaction() { cusid = reservation.cusid, type = string.Format($"Room reservation cancelled | Room no: {roomno} | Res date: {cindate}"), amount = 0 }; transaction.update(transaction); } rdr.Close(); con.Close(); return(true); }
public int reserveroom(Reservations reservation) { int isreserved = 0; conString = ConfigurationManager.ConnectionStrings["paymatecontext"].ConnectionString; SqlConnection con = new SqlConnection(conString); var reservedate = reservation.cindate.ToShortDateString(); SqlCommand cmd = new SqlCommand("select * from reservation where date='" + reservedate + "' and droomno='" + reservation.roomno + "' and status=0", con);//if status 0, meand room already booked, else if status is one room available con.Open(); SqlDataAdapter ad = new SqlDataAdapter(cmd); DataTable td = new DataTable(); ad.Fill(td); con.Close(); cmd.Dispose(); ad.Dispose(); return(isreserved = td.Rows.Count == 0 ? 0 : 1); }