Уменьшение переменной при выполнении условия
public void ReserveRoom(List<reservationtype> reservation) { List<reservationtype> RequestReservation = new List<reservationtype>(); RequestReservation = reservation; //List that contains the test cases. string reservationid = "0001"; int number = int.Parse(reservationid); int count = 0; foreach (ReservationType requestReservation in RequestReservation) { List<string> DateList = CreateDateList(requestReservation.StartDate, requestReservation.numDays); foreach (Inventory inventory in RoomInventory) { if (requestReservation.hotelId.Equals (inventory.HotelId)) { if (requestReservation.roomType == inventory.RoomType) { for (int i = 0; i < DateList.Count; i++) { if (DateList[i].Equals(inventory.Date) && inventory.Quantity > 0) { count++; if (requestReservation.numDays == count) { for (int j = 0; j < DateList.Count; j++) { if (DateList[j].Equals(inventory.Date)) { inventory.Quantity--; } } requestReservation.reservationId = "000" + (number + 1).ToString(); requestReservation.result = ReservationType.ReservationResultType.Success; count = 0; foreach (Hotels h in LHotels) { foreach (Room rm in h.RoomList) { if (requestReservation.hotelId == h.HotelId && requestReservation.roomType == rm.RoomType) { requestReservation.cost = (requestReservation.numDays * rm.Rate); } } } } // end of if num == counts else { requestReservation.reservationId = null; requestReservation.result = ReservationType.ReservationResultType.RoomNotAvailable; count = 0; } } //end of if }//end of forloop }//end of if statement (Roomtypes) }//end of If statement( inventory.hotelID) } // end of foreach inventory number++; }// end of Foreach serial = new XmlSerializer(RequestReservation.GetType()); sw = new StreamWriter(ReservationFilename); serial.Serialize(sw, RequestReservation); sw.Close(); }// End of ReserveRoom Method
Что я уже пробовал:
1) после того, как условие было истинным, Я сделал forloop, чтобы пройти через каждую переменную, где datelist[i] == inventory.date и вычесть из нее 1.
2) Без цикла for, после того как условие было истинным, вычтите 1 , но не меняйте его вообще.
Philippe Mori
Как Quantity
и Inventory
определены...