//public List<string> ReturnGedFormatPerson(Person person)//Возвращает строки, которые будут описывать нового человека в файле (Здесь поля добавляются, если они не пустые) //{ // List<string> newPersonDescription = new List<string>(); // newPersonDescription.Add($"0 {person.Id} INDI"); // if (!string.IsNullOrEmpty(person.PathPhoto)) newPersonDescription.Add($"1 {GedcomAttributes.PhotoPath} {person.PathPhoto}"); // string current = $"1 NAME {person.FirstName} {person.Patronymic} /{person.SecondName}/"; // newPersonDescription.Add(current); // if (!string.IsNullOrEmpty(person.Gender)) newPersonDescription.Add($"1 SEX {person.Gender}"); // if (!string.IsNullOrEmpty(person.DateOfBirth)) // { // newPersonDescription.Add("1 BIRT"); // newPersonDescription.Add($"2 DATE {person.DateOfBirth}"); // if (!string.IsNullOrEmpty(person.PlaceOfBirth)) newPersonDescription.Add($"2 PLAC {person.PlaceOfBirth}"); // } // if (!string.IsNullOrEmpty(person.Parents)) // { // newPersonDescription.Add($"1 FAMC {person.Parents}"); // int familyIndex = GedcomFileReader.IndexOf(FileData,$"FAM {person.Parents}"); // } // if (!string.IsNullOrEmpty(person.DateOfDeath)) // { // newPersonDescription.Add("1 DEAT"); // newPersonDescription.Add($"2 DATE {person.DateOfDeath}"); // if (!string.IsNullOrEmpty(person.PlaceOfDeath)) newPersonDescription.Add($"2 PLAC {person.PlaceOfDeath}"); // } // int familiesCount = person.PersonFamilies.Count; // for (int counter = 0; counter < familiesCount; counter++) // newPersonDescription.Add($"1 FAMS {person.PersonFamilies[counter]}"); // if (!string.IsNullOrEmpty(person.Description)) newPersonDescription.Add($"1 NOTE {person.Description}"); // return newPersonDescription; //} public List <string> ReturnGedFormatFamily(Family family) { bool husbandIsEmptyOrNull = string.IsNullOrEmpty(family.HusbandID) ? true : false; bool wifeIsEmptyOrNull = string.IsNullOrEmpty(family.WifeID) ? true : false; if (husbandIsEmptyOrNull && wifeIsEmptyOrNull) { throw new ArgumentException("Должен присутствовать хотя бы один родитель"); } List <string> newFamilyDescription = new List <string>(); newFamilyDescription.Add($"0 {family.ID} FAM"); if (!husbandIsEmptyOrNull) { newFamilyDescription.Add($"1 HUSB {family.HusbandID}"); } if (!wifeIsEmptyOrNull) { newFamilyDescription.Add($"1 WIFE {family.WifeID}"); } for (int counter = 0; counter < family.ChildrenID.Count; counter++) { newFamilyDescription.Add($"1 CHIL {family.ChildrenID[counter]}"); } if (family.TheyWasMarried) { newFamilyDescription.Add($"1 MARR"); } return(newFamilyDescription); }
public void ChangeInfoAboutFamily(Family changedFamily) { var changedGedFamily = ReturnGedFormatFamily(changedFamily); int personIndexStart = GedcomFileReader.IndexOf(FileData, changedFamily.ID); //Индекс, где написан номер человека (самая верхняя строчка) int personIndexEnd = GedcomFileReader.IndexOf(FileData, @"^0", personIndexStart + 1); //Индекс, который больше на 1 индеса последней записи о человеке if (personIndexEnd == -1) //Если -1, то был достигнут конец файла без обнаружения совпадений, следовательно это последняя запись в файле { FileData.RemoveRange(personIndexStart, FileData.Count - personIndexStart); FileData.AddRange(changedGedFamily); } else { FileData.RemoveRange(personIndexStart, personIndexEnd - personIndexStart + 1); FileData.InsertRange(personIndexStart, changedGedFamily); } }
public void DeleteFamily(Family family) { if (family.ChildrenID.Count > 0) { throw new ArgumentException("В удаляемой семье не может быть детей"); } int personStartIndex = GedcomFileReader.IndexOf(FileData, family.ID); int personEndIndex = GedcomFileReader.IndexOf(FileData, @"^0", personStartIndex + 1); if (personEndIndex == -1) { FileData.RemoveRange(personStartIndex, FileData.Count - personStartIndex); } else { FileData.RemoveRange(personStartIndex, personEndIndex - personStartIndex + 1); } }
public void AddFamily(Family newFamily)//Если в семье один родитель, то в зависимости от пола ставим null, также передается была ли у них свадьба (ID - @I+ID@), на данный момент не предполагается, что при создании новой семьи она будет иметь детей сразу { var newGedFamily = ReturnGedFormatFamily(newFamily); FileData.AddRange(newGedFamily); }