-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPedigree.cs
More file actions
89 lines (64 loc) · 2.71 KB
/
Pedigree.cs
File metadata and controls
89 lines (64 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using RMDatabase;
using RMDatabase.Models;
namespace Example
{
class Pedigree
{
public void Execute(string Surname, string Given)
{
using (var db = new DB())
{
// query the first person with the correct Surname and Given name
var rootPerson = db.Persons
.Where(p => p.Names.Any(n => n.Surname == Surname && n.Given == Given && n.IsPrimary))
.FirstOrDefault();
var root = new SimplePerson(db, rootPerson);
Console.BufferHeight = 500;
Console.BufferWidth = 150;
Console.WindowHeight = Console.LargestWindowHeight;
root.Print(1, 20);
}
}
}
class SimplePerson
{
public SimplePerson? Husband { get; set; }
public SimplePerson? Wife { get; set; }
public String Name { get; } = "";
public static int maxGeneration = 0;
public SimplePerson(DB db, Person? child, int generation = 0)
{
if (child == null) return;
if (generation > 2) return;
Generation = generation;
maxGeneration = Math.Max(maxGeneration, Generation);
var pn = child.PrimaryName;
Name = $"{pn?.Surname} {pn?.Given} - {child.PersonId}";
foreach (var family in child.Families)
{
var relation = getRelation(db, child, family); // query the parents relationship of this family from the childTable
if (family.Husband != null && relation.father == RelationShip.Birth) // we have found the father with birth relationship
{
this.Husband = new SimplePerson(db, family.Husband, Generation + 1);
}
if (family.Wife != null && relation.mother == RelationShip.Birth) // we have found the father with birth relationship
{
this.Wife = new SimplePerson(db, family.Wife);
}
}
}
public void Print(int posX, int posY)
{
//Console.SetCursorPosition(posX, posY);
//Console.WriteLine(Name);
//Father?.Print(posX + 5, posY + 1+ (maxGeneration-Generation));
//Mother?.Print(posX + 5, posY - 1 + (maxGeneration - Generation));
}
private int Generation { get; }
private (RelationShip father, RelationShip mother) getRelation(DB db, Person child, Family family)
{
var childTableEntry = db.ChildTable.Single(e => e.ChildId == child.PersonId && e.Family == family);
return (childTableEntry.RelFather, childTableEntry.RelMother);
}
}
}