public bool UpdateTourBooking(string BookingID, string CustomerID, string BookingDate, string BookingType, string Tour) { SqlConnection myconn = GetSqlConnection(); int update; bool flag = false; //update statment string sql = "Update Booking set CustomerID=@CustomerID,Date=@date,type=@type,Package=@Package,Hotel=@hotel,Room=@room,HotelNight=@night where ID=@ID"; //Using Booking Class tourBooking tr = new tourBooking(CustomerID, BookingDate, BookingType, Tour); //define sql command and parameters SqlCommand cmd = new SqlCommand(sql, myconn); cmd.Parameters.AddWithValue("@ID", BookingID); cmd.Parameters.AddWithValue("@CustomerID", tr.GetCustomerID); cmd.Parameters.AddWithValue("@date", tr.GetDate); cmd.Parameters.AddWithValue("@type", tr.GetBookingType); cmd.Parameters.AddWithValue("@Package", tr.GetTour); cmd.Parameters.AddWithValue("@hotel", DBNull.Value); cmd.Parameters.AddWithValue("@room", DBNull.Value); cmd.Parameters.AddWithValue("@night", DBNull.Value); try { myconn.Open(); //opens the connection update = cmd.ExecuteNonQuery(); //executes the sql command if (update >= 1) { flag = true; } else { flag = false; } } catch (SqlException ex) {//display on the console the exeception message Console.WriteLine(ex.ToString()); Console.ReadLine(); } finally {// Close the connection myconn.Close(); } if (flag == true) { // Counting the deposit, amount and update the record in the database sql = "update Booking set Charge=0, Discount=0, Deposit=(select (cost *(0.2)) from Booking b, Package p where p.Package=b.Package and b.ID=@ID),Total=(select cost from Booking b, Package p where p.Package=b.Package and b.ID=@ID) where ID=@ID"; SqlCommand cmn = new SqlCommand(sql, myconn); cmn.Parameters.AddWithValue("@ID", BookingID); try { myconn.Open(); //opens the connection update = cmn.ExecuteNonQuery(); //executes the sql command if (update >= 1) { flag = true; } else { flag = false; } } catch (SqlException ex) {//display on the console the exeception message Console.WriteLine(ex.ToString()); Console.ReadLine(); } finally {// Close the connection myconn.Close(); } } return(flag); }
public bool TourBooking(string ID, string BookingDate, string BookingType, string Tour) { SqlConnection myconn = GetSqlConnection(); int add; bool flag = false; string sql = "Insert into Booking (CustomerID, Date, Type, Package, Hotel, Room) values (@ID,@BookingDate,@BookingType,@Tour,@Hotel,@Room)"; //Using Booking Class tourBooking tr = new tourBooking(ID, BookingDate, BookingType, Tour); //define sql command and parameters SqlCommand cmd = new SqlCommand(sql, myconn); cmd.Parameters.AddWithValue("@ID", tr.GetCustomerID); cmd.Parameters.AddWithValue("@BookingType", tr.GetBookingType); cmd.Parameters.AddWithValue("@Tour", tr.GetTour); cmd.Parameters.AddWithValue("@BookingDate", tr.GetDate); cmd.Parameters.AddWithValue("@Hotel", DBNull.Value); cmd.Parameters.AddWithValue("@Room", DBNull.Value); try { myconn.Open(); //opens the connection add = cmd.ExecuteNonQuery(); //executes the sql command if (add >= 1) { flag = true; } else { flag = false; } } catch (SqlException ex) {//display on the console the exeception message Console.WriteLine(ex.ToString()); Console.ReadLine(); } finally {// Close the connection myconn.Close(); } if (flag == true) { // Count the totalamount of the booking sql = "update Booking set Deposit=(select (cost *(0.2)) from Booking b, Package p where p.Package=b.Package and b.ID=(select MAX(ID) from Booking)),Total=(select cost from Booking b, Package p where p.Package=b.Package and b.ID=(select MAX(ID) from Booking)) where ID=(select MAX(ID) from Booking)"; SqlCommand cmn = new SqlCommand(sql, myconn); try { myconn.Open(); //opens the connection add = cmn.ExecuteNonQuery(); //executes the sql command if (add >= 1) { flag = true; } else { flag = false; } } catch (SqlException ex) {//display on the console the exeception message Console.WriteLine(ex.ToString()); Console.ReadLine(); } finally {// Close the connection myconn.Close(); } } return(flag); }