/// <summary>
        /// Gets the row index for the result table to which this room booking refers.
        /// </summary>
        /// <param name="ARow">room booking row</param>
        /// <param name="AReportDetail">Indicator of the details of the report. Possible options: Brief, Full, Detail</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns></returns>
        private int GetRowIndexForRoom(PcRoomAllocRow ARow, string AReportDetail, ref TRptSituation ASituation)
        {
            // Check if this room is already in the table

            String RoomName = ARow.BuildingCode;

            if (AReportDetail != "Brief")
            {
                RoomName = ARow.BuildingCode + " / " + ARow.RoomNumber;
            }

            int RoomRow = -1;

            for (int Counter = 0; Counter < FAccommodationTable.Rows.Count; ++Counter)
            {
                if (FAccommodationTable.Rows[Counter][0].ToString() == RoomName)
                {
                    RoomRow = Counter;
                    break;
                }
            }

            if (RoomRow == -1)
            {
                DataRow NewRow = FAccommodationTable.NewRow();
                NewRow[0]       = RoomName;
                NewRow["Venue"] = TAccommodationReportCalculation.GetPartnerShortName(ARow.VenueKey, ref ASituation);

                FAccommodationTable.Rows.Add(NewRow);
                RoomRow = FAccommodationTable.Rows.Count - 1;
            }

            return(RoomRow);
        }
        /// <summary>
        /// Calculates the cost of the room for one person for the given number of days.
        /// </summary>
        /// <param name="ARow">Room allocation row for the room booking</param>
        /// <param name="ANumberOfBookedDays">number of booked days</param>
        /// <param name="ARoomRow">the row index on the result table to which this calculation refers</param>
        /// <param name="AAge">age of the person who is in the room</param>
        /// <param name="AConferenceKey">conference key of the current conference</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns></returns>
        private bool CalculateRoomCost(PcRoomAllocRow ARow, int ANumberOfBookedDays, int ARoomRow,
                                       int AAge, long AConferenceKey, ref TRptSituation ASituation)
        {
            PcRoomTable RoomTable;

            RoomTable = PcRoomAccess.LoadByPrimaryKey(ARow.VenueKey, ARow.BuildingCode, ARow.RoomNumber,
                                                      ASituation.GetDatabaseConnection().Transaction);

            if (RoomTable.Rows.Count > 0)
            {
                PcRoomRow RoomRow = (PcRoomRow)RoomTable.Rows[0];

                decimal cost = RoomRow.BedCost * ANumberOfBookedDays;
                decimal ChildDiscount;
                bool    InPercent;

                if (TAccommodationReportCalculation.GetChildDiscount(AAge, AConferenceKey, "ACCOMMODATION", out ChildDiscount, out InPercent,
                                                                     ref ASituation))
                {
                    if (InPercent)
                    {
                        cost = cost * (100 - ChildDiscount) / 100;
                    }
                    else
                    {
                        // At the moment we ignore if the child discount is not set up as percent
                        cost = RoomRow.BedCost * ANumberOfBookedDays;
                    }
                }

                FAccommodationTable.Rows[ARoomRow]["Total Cost"] =
                    (decimal)FAccommodationTable.Rows[ARoomRow]["Total Cost"] + cost;
            }

            return(true);
        }
        /// <summary>
        /// Gets the row index for the result table to which this room booking refers.
        /// </summary>
        /// <param name="ARow">room booking row</param>
        /// <param name="AReportDetail">Indicator of the details of the report. Possible options: Brief, Full, Detail</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns></returns>
        private int GetRowIndexForRoom(PcRoomAllocRow ARow, string AReportDetail, ref TRptSituation ASituation)
        {
            // Check if this room is already in the table

            String RoomName = ARow.BuildingCode;

            if (AReportDetail != "Brief")
            {
                RoomName = ARow.BuildingCode + " / " + ARow.RoomNumber;
            }

            int RoomRow = -1;

            for (int Counter = 0; Counter < FAccommodationTable.Rows.Count; ++Counter)
            {
                if (FAccommodationTable.Rows[Counter][0].ToString() == RoomName)
                {
                    RoomRow = Counter;
                    break;
                }
            }

            if (RoomRow == -1)
            {
                DataRow NewRow = FAccommodationTable.NewRow();
                NewRow[0] = RoomName;
                NewRow["Venue"] = TAccommodationReportCalculation.GetPartnerShortName(ARow.VenueKey, ref ASituation);

                FAccommodationTable.Rows.Add(NewRow);
                RoomRow = FAccommodationTable.Rows.Count - 1;
            }

            return RoomRow;
        }
        /// <summary>
        /// Calculates the cost of the room for one person for the given number of days.
        /// </summary>
        /// <param name="ARow">Room allocation row for the room booking</param>
        /// <param name="ANumberOfBookedDays">number of booked days</param>
        /// <param name="ARoomRow">the row index on the result table to which this calculation refers</param>
        /// <param name="AAge">age of the person who is in the room</param>
        /// <param name="AConferenceKey">conference key of the current conference</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns></returns>
        private bool CalculateRoomCost(PcRoomAllocRow ARow, int ANumberOfBookedDays, int ARoomRow,
            int AAge, long AConferenceKey, ref TRptSituation ASituation)
        {
            PcRoomTable RoomTable;

            RoomTable = PcRoomAccess.LoadByPrimaryKey(ARow.VenueKey, ARow.BuildingCode, ARow.RoomNumber,
                ASituation.GetDatabaseConnection().Transaction);

            if (RoomTable.Rows.Count > 0)
            {
                PcRoomRow RoomRow = (PcRoomRow)RoomTable.Rows[0];

                decimal cost = RoomRow.BedCost * ANumberOfBookedDays;
                decimal ChildDiscount;
                bool InPercent;

                if (TAccommodationReportCalculation.GetChildDiscount(AAge, AConferenceKey, "ACCOMMODATION", out ChildDiscount, out InPercent,
                        ref ASituation))
                {
                    if (InPercent)
                    {
                        cost = cost * (100 - ChildDiscount) / 100;
                    }
                    else
                    {
                        // At the moment we ignore if the child discount is not set up as percent
                        cost = RoomRow.BedCost * ANumberOfBookedDays;
                    }
                }

                FAccommodationTable.Rows[ARoomRow]["Total Cost"] =
                    (decimal)FAccommodationTable.Rows[ARoomRow]["Total Cost"] + cost;
            }

            return true;
        }
        /// <summary>
        /// Adds the room allocation of one partner to the result.
        /// </summary>
        /// <param name="ARoomAllocRow">The room allocation row of the current partner</param>
        /// <param name="AShortTermRow">The short term application row of the current partner</param>
        /// <param name="AFromDate">Start date of the report</param>
        /// <param name="AToDate">End date of the report</param>
        /// <param name="AReportDetail">Indicator of the details of the report. Possible options: Brief, Full, Detail</param>
        /// <param name="AGender">Gender of the current person to examine</param>
        /// <param name="AAge">Age of the person to examine</param>
        /// <param name="APartnerName">Name of the current person</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns></returns>
        private bool CheckRoomAllocation(PcRoomAllocRow ARoomAllocRow, PmShortTermApplicationRow AShortTermRow,
            DateTime AFromDate, DateTime AToDate, string AReportDetail, char AGender,
            int AAge, string APartnerName, ref TRptSituation ASituation)
        {
            int RoomRow = GetRowIndexForRoom(ARoomAllocRow, AReportDetail, ref ASituation);

            TimeSpan CheckLength = AToDate.Subtract(AFromDate);
            int DaysNumber = CheckLength.Days;
            int MaxCollumns = FAccommodationTable.Columns.Count - 2;
            int NumberOfBookedDays = 0;
            bool FirstDayOfNoAccom = true;

            DataRow DetailRow = FAccommodationDetailTable.NewRow();

            DetailRow["RoomName"] = FAccommodationTable.Rows[RoomRow]["RoomName"];
            DetailRow["PartnerName"] = "   " + APartnerName;
            DataRow DetailRowNoBooking = FAccommodationDetailTable.NewRow();
            DetailRowNoBooking["RoomName"] = NO_ACCOMMODATION;
            DetailRowNoBooking["PartnerName"] = "   " + APartnerName;

            // Check each day for the booking
            for (int Counter = 0; Counter <= DaysNumber; ++Counter)
            {
                DateTime CurrentDay = AFromDate.AddDays(Counter);

                if ((CurrentDay >= ARoomAllocRow.In)
                    && (CurrentDay < ARoomAllocRow.Out))
                {
                    // there is a room booking for this person for this day
                    if (Counter < MaxCollumns)
                    {
                        FAccommodationTable.Rows[RoomRow][(Counter + 1) * 2] =
                            (int)FAccommodationTable.Rows[RoomRow][(Counter + 1) * 2] + 1;
                        FAccommodationTable.Rows[RoomRow][(Counter + 1) * 2 + 1] =
                            GetGenderOfBooking(AGender, (char)FAccommodationTable.Rows[RoomRow][(Counter + 1) * 2 + 1]);
                        NumberOfBookedDays++;

                        DetailRow[Counter + 1] = "**";
                    }
                }
                else
                {
                    // there is no room booking
                    if ((Counter < MaxCollumns)
                        && (CurrentDay >= AShortTermRow.Arrival)
                        && (CurrentDay < AShortTermRow.Departure))
                    {
                        FAccommodationTable.Rows[0][(Counter + 1) * 2] =
                            (int)FAccommodationTable.Rows[0][(Counter + 1) * 2] + 1;
                        FAccommodationTable.Rows[0][(Counter + 1) * 2 + 1] =
                            GetGenderOfBooking(AGender, (char)FAccommodationTable.Rows[0][(Counter + 1) * 2 + 1]);

                        DetailRowNoBooking[Counter + 1] = "**";

                        if (FirstDayOfNoAccom)
                        {
                            AddToNoAccomList(AShortTermRow.PartnerKey, APartnerName, CurrentDay);
                            FirstDayOfNoAccom = false;
                        }
                    }
                }
            }

            CalculateRoomCost(ARoomAllocRow, NumberOfBookedDays, RoomRow, AAge, AShortTermRow.StConfirmedOption, ref ASituation);

            FAccommodationDetailTable.Rows.Add(DetailRow);

            if (!FirstDayOfNoAccom)
            {
                // Add this partner to the "no accomodation" list there is one day without.
                FAccommodationDetailTable.Rows.Add(DetailRowNoBooking);
            }

            return true;
        }
        /// <summary>
        /// Adds the room allocation of one partner to the result.
        /// </summary>
        /// <param name="ARoomAllocRow">The room allocation row of the current partner</param>
        /// <param name="AShortTermRow">The short term application row of the current partner</param>
        /// <param name="AFromDate">Start date of the report</param>
        /// <param name="AToDate">End date of the report</param>
        /// <param name="AReportDetail">Indicator of the details of the report. Possible options: Brief, Full, Detail</param>
        /// <param name="AGender">Gender of the current person to examine</param>
        /// <param name="AAge">Age of the person to examine</param>
        /// <param name="APartnerName">Name of the current person</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns></returns>
        private bool CheckRoomAllocation(PcRoomAllocRow ARoomAllocRow, PmShortTermApplicationRow AShortTermRow,
                                         DateTime AFromDate, DateTime AToDate, string AReportDetail, char AGender,
                                         int AAge, string APartnerName, ref TRptSituation ASituation)
        {
            int RoomRow = GetRowIndexForRoom(ARoomAllocRow, AReportDetail, ref ASituation);

            TimeSpan CheckLength        = AToDate.Subtract(AFromDate);
            int      DaysNumber         = CheckLength.Days;
            int      MaxCollumns        = FAccommodationTable.Columns.Count - 2;
            int      NumberOfBookedDays = 0;
            bool     FirstDayOfNoAccom  = true;

            DataRow DetailRow = FAccommodationDetailTable.NewRow();

            DetailRow["RoomName"]    = FAccommodationTable.Rows[RoomRow]["RoomName"];
            DetailRow["PartnerName"] = "   " + APartnerName;
            DataRow DetailRowNoBooking = FAccommodationDetailTable.NewRow();

            DetailRowNoBooking["RoomName"]    = NO_ACCOMMODATION;
            DetailRowNoBooking["PartnerName"] = "   " + APartnerName;

            // Check each day for the booking
            for (int Counter = 0; Counter <= DaysNumber; ++Counter)
            {
                DateTime CurrentDay = AFromDate.AddDays(Counter);

                if ((CurrentDay >= ARoomAllocRow.In) &&
                    (CurrentDay < ARoomAllocRow.Out))
                {
                    // there is a room booking for this person for this day
                    if (Counter < MaxCollumns)
                    {
                        FAccommodationTable.Rows[RoomRow][(Counter + 1) * 2] =
                            (int)FAccommodationTable.Rows[RoomRow][(Counter + 1) * 2] + 1;
                        FAccommodationTable.Rows[RoomRow][(Counter + 1) * 2 + 1] =
                            GetGenderOfBooking(AGender, (char)FAccommodationTable.Rows[RoomRow][(Counter + 1) * 2 + 1]);
                        NumberOfBookedDays++;

                        DetailRow[Counter + 1] = "**";
                    }
                }
                else
                {
                    // there is no room booking
                    if ((Counter < MaxCollumns) &&
                        (CurrentDay >= AShortTermRow.Arrival) &&
                        (CurrentDay < AShortTermRow.Departure))
                    {
                        FAccommodationTable.Rows[0][(Counter + 1) * 2] =
                            (int)FAccommodationTable.Rows[0][(Counter + 1) * 2] + 1;
                        FAccommodationTable.Rows[0][(Counter + 1) * 2 + 1] =
                            GetGenderOfBooking(AGender, (char)FAccommodationTable.Rows[0][(Counter + 1) * 2 + 1]);

                        DetailRowNoBooking[Counter + 1] = "**";

                        if (FirstDayOfNoAccom)
                        {
                            AddToNoAccomList(AShortTermRow.PartnerKey, APartnerName, CurrentDay);
                            FirstDayOfNoAccom = false;
                        }
                    }
                }
            }

            CalculateRoomCost(ARoomAllocRow, NumberOfBookedDays, RoomRow, AAge, AShortTermRow.StConfirmedOption, ref ASituation);

            FAccommodationDetailTable.Rows.Add(DetailRow);

            if (!FirstDayOfNoAccom)
            {
                // Add this partner to the "no accomodation" list there is one day without.
                FAccommodationDetailTable.Rows.Add(DetailRowNoBooking);
            }

            return(true);
        }
        /// <summary>
        /// Adds the dates of one partner to the accommodation report
        /// </summary>
        /// <param name="AShortTermRow">The short term application row of the current partner</param>
        /// <param name="AAttendeeRow">The attendee row of the current partner</param>
        /// <param name="AStartDate">Start date of the conference</param>
        /// <param name="AEndDate">End date of the conference</param>
        /// <param name="AFromDate">Start date of the report</param>
        /// <param name="AToDate">End date of the report</param>
        /// <param name="AReportDetail">Indicator of the details of the report. Possible options: Brief, Full, Detail</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns></returns>
        private bool AddPartnerToAccom(PmShortTermApplicationRow AShortTermRow,
                                       PcAttendeeRow AAttendeeRow,
                                       DateTime AStartDate, DateTime AEndDate,
                                       DateTime AFromDate, DateTime AToDate,
                                       string AReportDetail, ref TRptSituation ASituation)
        {
            // if we have an actual arrival and departure date from the attendee row use it.
            if (AAttendeeRow != null)
            {
                if (!AAttendeeRow.IsActualArrNull())
                {
                    AShortTermRow.Arrival = AAttendeeRow.ActualArr;
                }

                if (!AAttendeeRow.IsActualDepNull())
                {
                    AShortTermRow.Departure = AAttendeeRow.ActualDep;
                }
            }

            if (AShortTermRow.IsArrivalNull())
            {
                AShortTermRow.Arrival = AStartDate;
            }

            if (AShortTermRow.IsDepartureNull())
            {
                AShortTermRow.Departure = AEndDate;
            }

            if ((AShortTermRow.Arrival <= AToDate) &&
                (AShortTermRow.Departure >= AFromDate))
            {
                // this short term application covers the dates we examine

                PcRoomAllocTable TempTable = new PcRoomAllocTable();
                PcRoomAllocTable RoomAllocTable;
                PcRoomAllocRow   TemplateRow = TempTable.NewRowTyped(false);
                TemplateRow.PartnerKey    = AShortTermRow.PartnerKey;
                TemplateRow.ConferenceKey = AShortTermRow.StConfirmedOption;

                RoomAllocTable = PcRoomAllocAccess.LoadUsingTemplate(TemplateRow, ASituation.GetDatabaseConnection().Transaction);

                char   Gender;
                int    Age;
                string PartnerName;
                GetGenderAndAge(AShortTermRow.PartnerKey, AStartDate, out Gender, out Age, ref ASituation);
                PartnerName = TAccommodationReportCalculation.GetPartnerShortName(AShortTermRow.PartnerKey, ref ASituation);

                foreach (DataRow Row in RoomAllocTable.Rows)
                {
                    CheckRoomAllocation((PcRoomAllocRow)Row, AShortTermRow, AFromDate, AToDate,
                                        AReportDetail, Gender, Age, PartnerName, ref ASituation);
                }

                if (RoomAllocTable.Rows.Count == 0)
                {
                    AddNoRoomBooking(AShortTermRow, AFromDate, AToDate, Gender, PartnerName);
                }
            }

            return(true);
        }