Esempio n. 1
0
        /// <summary>
        /// Generates the text that should be added to the document and sent to the participants in advance.
        /// </summary>
        /// <param name="meal">The part of the meal to prepare</param>
        /// <param name="hosts">list of hosts.</param>
        /// <param name="guests1">first list of guests</param>
        /// <param name="guests2">second list of guests</param>
        /// <param name="doc">the word document</param>
        private void AddHostToWord(string meal, List <Participant> hosts, List <Participant> guests1, List <Participant> guests2, WordHandler doc)
        {
            string getAllergies(string host, string guest1, string guest2)
            {
                string result = "";

                // result += (host == "" ? "" : host);
                result += host;
                if (guest1 != "")
                {
                    if (result == "")
                    {
                        result += guest1;
                    }
                    else
                    {
                        result += ", " + guest1;
                    }
                }
                if (guest2 != "")
                {
                    if (result == "")
                    {
                        result += guest2;
                    }
                    else
                    {
                        result += ", " + guest2;
                    }
                }
                if (result.Count() < 1)
                {
                    result = "Inga allergier";
                }

                return(result);
            }

            char nl = (char)11; // New-line character in Word.

            for (int i = 0; i < hosts.Count; i++)
            {
                doc.WordAddText(hosts[i].Name, "name");
                string text =
                    "Välkomna att delta i matstafetten!" + nl +
                    "Den del av måltiden ni har blivit tilldelade att förbereda är:" +
                    nl + nl + meal + nl + nl +
                    "Eventuella allergier ni behöver ta hänsyn till är:" + nl;
                string allergies = getAllergies(hosts[i].Allergie, guests1[i].Allergie, guests2[i].Allergie);
                text += allergies;
                doc.WordAddText(text);
                doc.WordAddPageBreak();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Generates the text that sends the participants to their next meal
        /// </summary>
        /// <param name="meal">"förrätten" or "huvudrätten"</param>
        /// <param name="p">A full class of Foodrelayparticipants</param>
        /// <param name="doc">the word document</param>

        private void AddInstructionsOfWhereToGoNextToWord(string meal, FoodRelayParticipants p, WordHandler doc)
        {
            int FindIndex(string needle, List <Participant> haystack)
            {
                int result = -1;

                for (int i = 0; i < haystack.Count(); i++)
                {
                    if (needle == haystack[i].Name)
                    {
                        result = i;
                        break;
                    }
                }
                return(result);
            }

            Participant FindInListHaystacks(string needle, List <Participant> Haystack1, List <Participant> Haystack2, List <Participant> HostStack)
            {
                int foundIndex = FindIndex(needle, Haystack1);

                if (foundIndex == -1)
                {
                    foundIndex = FindIndex(needle, Haystack2);
                }
                if (foundIndex != -1)
                {
                    return(HostStack[foundIndex]);
                }
                else
                {
                    foundIndex = FindIndex(needle, HostStack);
                }
                if (foundIndex != -1)
                {
                    return(null);
                }
                throw new KeyNotFoundException("No new place to go is found for a participant");
            }

            string NextStopSnippet(Participant NextStop)
            {
                char newline = (char)11;

                if (NextStop == null)
                {
                    return("är värd för nästa rätt" + newline + newline);
                }
                else
                {
                    return("är välkomna till" + newline + NextStop.Name + newline + NextStop.ContactInformation + newline + newline);
                }
            }

            List <Participant> hosts   = (meal == "förrätten" ? p.FinalStarterHosts : p.FinalMainCourseHosts);
            List <Participant> guests1 = (meal == "förrätten" ? p.FinalStarterGuests1 : p.FinalMainCourseGuests1);
            List <Participant> guests2 = (meal == "förrätten" ? p.FinalStarterGuests2: p.FinalMainCourseGuests2);

            char nl = (char)11; // New-line character in Word.

            for (int i = 0; i < hosts.Count; i++)
            {
                Participant hostNextStop, guest1NextStop, guest2NextStop;
                if (meal == "förrätten")
                {
                    hostNextStop   = FindInListHaystacks(hosts[i].Name, p.FinalMainCourseGuests1, p.FinalMainCourseGuests2, p.FinalMainCourseHosts);
                    guest1NextStop = FindInListHaystacks(guests1[i].Name, p.FinalMainCourseGuests1, p.FinalMainCourseGuests2, p.FinalMainCourseHosts);
                    guest2NextStop = FindInListHaystacks(guests2[i].Name, p.FinalMainCourseGuests1, p.FinalMainCourseGuests2, p.FinalMainCourseHosts);
                }
                else
                {
                    hostNextStop   = FindInListHaystacks(hosts[i].Name, p.FinalDesertGuests1, p.FinalDesertGuests2, p.FinalDesertHosts);
                    guest1NextStop = FindInListHaystacks(guests1[i].Name, p.FinalDesertGuests1, p.FinalDesertGuests2, p.FinalDesertHosts);
                    guest2NextStop = FindInListHaystacks(guests2[i].Name, p.FinalDesertGuests1, p.FinalDesertGuests2, p.FinalDesertHosts);
                }

                string toBeReadBy = "Att läsas under måltiden av:" + nl + hosts[i].Name;
                doc.WordAddText(toBeReadBy, "italic");

                string text =
                    "Hoppas ni har njutit av " + meal + " och sällskapet!" + nl +
                    "Det är fortfarande mycket kvar och nu är det dags att åka vidare..." + nl + nl +
                    hosts[i].Name + nl + NextStopSnippet(hostNextStop) +
                    guests1[i].Name + nl + NextStopSnippet(guest1NextStop) +
                    guests2[i].Name + nl + NextStopSnippet(guest2NextStop);

                doc.WordAddText(text);
                if (!(meal == "huvudrätten" && i == (hosts.Count - 1)))
                {
                    doc.WordAddPageBreak();
                }
            }
        }