Beispiel #1
0
        /// <summary>
        /// Assigns siblings to the current person
        /// </summary>
        /// <param name="count">Specifies how many siblings that should be assigned</param>
        public void AssignSibling(int count)
        {
            Person[] siblingArr = new Person[count];

            List <int> tmpIdList = new List <int>();

            tmpIdList.Add(Id);

            for (int i = 0; i < count; i++)
            {
                siblingArr[i] = Generate.GenSiblingPerson(("Input the details for the sibling of " + Name), Surname, ParentId, Name);

                tmpIdList.Add(siblingArr[i].Id);
                SiblingIdList.Add(siblingArr[i].Id);
            }

            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < tmpIdList.Count; j++)
                {
                    if (tmpIdList[j] != siblingArr[i].Id)
                    {
                        siblingArr[i].SiblingIdList.Add(tmpIdList[j]);
                    }
                }

                PersonDB.Add(siblingArr[i]);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Assigns partner for the current person
        /// </summary>
        /// <param name="partner">The partner that has been picked (if it has)</param>
        /// <param name="id">Used to check if the person already has a partner</param>
        public void AssignPartner(int id, Person partner = null)
        {
            if (!PersonDB.CheckPartner(id))
            {
                if (partner == null)
                {
                    Person tmpPartner = Generate.GenPerson("Type in details for the partner");

                    PartnerId            = tmpPartner.Id;
                    tmpPartner.PartnerId = Id;

                    PersonDB.Add(tmpPartner);
                }
                else
                {
                    for (int i = 0; i < PersonDB.personList.Count; i++)
                    {
                        if (PersonDB.personList[i].Id == partner.Id)
                        {
                            PersonDB.personList[i].PartnerId = Id;
                            PartnerId = PersonDB.personList[i].Id;
                        }
                    }
                }
            }
            else
            {
                Print.PrMsg("Person already has partner");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Assigns parents to a person
        /// </summary>
        /// <returns></returns>
        public Person[] AssignParents()
        {
            Person[] parents = null;

            if (ParentId[0] == -1)
            {
                parents = Generate.GenParents("Please input the credentials for this persons parents", Surname, Name,
                                              Birthyear, Id, SiblingIdList);

                for (int i = 0; i < parents.Length; i++)
                {
                    PersonDB.Add(parents[i]);
                }
            }
            else
            {
                Print.PrMsg("Person already has parents");
            }

            return(parents);
        }
Beispiel #4
0
        /// <summary>
        /// Assigns child to the current person
        /// </summary>
        /// <param name="count">Specifies the amount of children created</param>
        public void AssignChild(int count)
        {
            if (PartnerId == -1)
            {
                Print.PrMsg("No partner present, partner is necessary to assign a child");
                Console.WriteLine("Person was added, to assign a partner and a child, use the 'Add' command");
                Print.PrDb();
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    Person child = Generate.GenChildPerson(("Input the details for the child of " + Name), Surname, Birthyear, Name);

                    child.ParentId[0] = Id;
                    child.ParentId[1] = PartnerId;

                    childId.Add(child.Id);

                    PersonDB.Add(child);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Runs functions for the specified commands in the list 'commandList'
        /// </summary>
        /// <param name="commandList">The current list of commands returned from the validator</param>
        public static void CompileRequest(List <string> commandList)
        {
            List <Person> tmpPersonList = new List <Person>();
            bool          hasPerson     = false;
            bool          picked        = false;

            for (int i = 0; i < commandList.Count; i++)
            {
                if (commandList[0] == "Add" && !picked)
                {
                    tmpPersonList.Add(Input.PickPerson("Pick a person to execute your commands on"));
                    if (tmpPersonList[0] == null)
                    {
                        break;
                    }

                    hasPerson = true;
                    picked    = true;
                }
                else
                {
                    if (commandList[i] == "PersonStruct")
                    {
                        bool sex;

                        if (commandList[i + 4] == "Male")
                        {
                            sex = false;
                        }
                        else
                        {
                            sex = true;
                        }

                        Person tmpPerson = new Person(commandList[i + 1], commandList[i + 2], Convert.ToInt32(commandList[i + 3]), sex);

                        tmpPersonList.Add(tmpPerson);
                        PersonDB.Add(tmpPerson);

                        hasPerson = true;
                    }
                    else if (commandList[i].Contains("Person"))
                    {
                        int tmpCount = Convert.ToInt32(commandList[i].Substring(commandList[i].IndexOf('*') + 1));

                        for (int j = 0; j < tmpCount; j++)
                        {
                            Person tmpPerson = Generate.GenPerson("Type in the details for person #" + j + 1);
                            tmpPersonList.Add(tmpPerson);
                            PersonDB.Add(tmpPerson);
                        }

                        hasPerson = true;
                    }
                }

                for (int j = 0; j < tmpPersonList.Count; j++)
                {
                    if (commandList[i].Contains("Siblings"))
                    {
                        //Print.PrMsg("Assigning siblings for person " + j + 1 + ", Name: " + tmpPersonList[j].Name);

                        int tmpCount = Convert.ToInt32(commandList[i].Substring(commandList[i].IndexOf('*') + 1));

                        tmpPersonList[j].AssignSibling(tmpCount);
                    }

                    if (commandList[i].Contains("Partner"))
                    {
                        //Print.PrMsg("Assigning partner for person " + j + 1 + ", Name: " + tmpPersonList[j].Name);

                        if (Input.YesOrNo("Do you want to pick a partner? (Yes/No)"))
                        {
                            Person pickedPartner = Input.PickPerson("Pick a partner for" + tmpPersonList[j].Name);

                            tmpPersonList[j].AssignPartner(tmpPersonList[j].Id, pickedPartner);
                        }
                        else
                        {
                            tmpPersonList[j].AssignPartner(tmpPersonList[j].Id);
                        }
                    }

                    if (commandList[i].Contains("Children"))
                    {
                        //Print.PrMsg("Assigning children for person " + j + 1 + ", Name: " + tmpPersonList[j].Name);

                        int tmpCount = Convert.ToInt32(commandList[i].Substring(commandList[i].IndexOf('*') + 1));

                        tmpPersonList[j].AssignChild(tmpCount);
                    }

                    if (commandList[i].Contains("Parents") && hasPerson)
                    {
                        //Print.PrMsg("Assigning parents for person " + j+1 + ", Name: "+ tmpPersonList[j].Name);
                        tmpPersonList[j].AssignParents();
                    }
                }

                if (tmpPersonList.Count == 0)
                {
                    Print.PrMsg("You did not add any people prior to assigning other family members, did you mean to use 'Add'?");
                }
            }
        }