/// <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"); } }
/// <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]); } }
/// <summary> /// Prints a box of text containing information about a person /// </summary> /// <param name="person">Contains an instance of the class 'Person', is used to fetch information about the current person</param> /// <param name="number">Represents the number of the person needed to be written for a selection</param> public static void PrintBox(Person person, int number) { Console.WriteLine(); CenterText("Number " + Convert.ToString(number + 1)); CenterText("--------------"); CenterText(person.Name); CenterText(person.Surname); CenterText("Id: " + Convert.ToString(person.Id)); CenterText("Birthyear: " + Convert.ToString(person.Birthyear)); if (person.Sex == true) { CenterText("Sex: Female"); } else { CenterText("Sex: Male"); } CenterText("Partner: " + PersonDB.GetName(person.PartnerId)); CenterText("Parent 1: " + PersonDB.GetName(person.ParentId[0])); CenterText("Parent 2: " + PersonDB.GetName(person.ParentId[1])); for (int j = 0; j < person.SiblingIdList.Count; j++) { CenterText("Sibling" + j + ": " + PersonDB.GetName(person.SiblingIdList[j])); } CenterText("--------------"); Console.WriteLine(); }
public Person(string name, string surname, int birthyear, bool sex) { Name = name; Surname = surname; Birthyear = birthyear; Sex = sex; bool validId = false; while (!validId) { Random rnd = new Random(); int id = rnd.Next(0, 1000); if (!PersonDB.CheckDupe(id)) { Id = id; validId = true; } } }
/// <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); }
/// <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); } } }
/// <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'?"); } } }