private void CreateFirst() { using (Vornamen vNamen = new Vornamen()) { vNamen.Where = "Nummer is not null"; vNamen.Read(); using (Familien fNamen = new Familien()) { fNamen.Where = "Nummer is not null"; fNamen.Read(); using (Personen personen = new Personen()) { for (int i = 1; i <= 40; i++) { personen.Where = "Nummer = " + i; personen.Read(); vNamen.GoTop(); fNamen.GoTop(); if (i == 1) { personen.DbVorname_Nr = 64; personen.DbFamilie_Nr = 4; personen.DbGeburtsdatum = new DateTime(1993, 12, 30); } else { vNamen.Skip(rand.Next(vNamen.RecordCount)); fNamen.Skip(rand.Next(fNamen.RecordCount)); DateTime gebDat = aktuellerTag.AddDays(-(4380 + rand.Next(-730, 730))); personen.DbVorname_Nr = vNamen.Nummer; personen.DbFamilie_Nr = fNamen.Nummer; personen.DbGeburtsdatum = gebDat; } personen.DbGeneration = 0; personen.DbLebend = true; personen.BuildSaveStmt(SqlAction.Insert); } ArrayList stmts = personen.FbSave.Statements; personen.SaveStmtsOnly(); } } } }
/// <summary> /// give birth to the child /// </summary> public void GebaereKind() { //select if the child would be male or female bool isMale = false; int rnd = rand.Next(0, 2); if (rnd == 0) { isMale = true; } //select a random first name based on the gender using (Vornamen vNamen = new Vornamen()) { vNamen.Where = "Geschlecht = '" + (isMale ? "M" : "W") + "'"; vNamen.Read(); vNamen.Skip(rand.Next(0, vNamen.RecordCount)); var z = this.kinder.Where(x => x.vorname == vNamen.DbVorname); while (z.Count() > 0) { vNamen.GoTop(); vNamen.Skip(rand.Next(0, vNamen.RecordCount)); z = this.kinder.Where(x => x.vorname == vNamen.DbVorname); } string vNameKind = vNamen.DbVorname; //sets the birthday DateTime kindGebDat = StammbaumBusiness.AktuellerTagInSimulation; //add the new child to the List Person kind = new Person(2541, vNameKind, this.famName, kindGebDat, (this.generation > this.MeinPartner.generation ? this.generation : this.MeinPartner.generation) + 1, this.partner, this.nummer); kind.meineMutter = this; kind.meinVater = this.meinPartner; //this.meineKinder.Add(kind); //this.meinPartner.meineKinder.Add(kind); StammbaumBusiness.NeuHinzuzufuegende?.Enqueue(kind); //save the new child in the database using (Familien famTable = new Familien()) { famTable.Where = "Familienname = '" + this.famName + "'"; famTable.Read(); using (Personen personenTable = new Personen()) { personenTable.DbVorname_Nr = vNamen.Nummer; personenTable.DbFamilie_Nr = famTable.Nummer; personenTable.DbGeburtsdatum = kind.Geburtsdatum; personenTable.DbGeneration = kind.Generation; personenTable.DbVater_Nr = kind.vater; personenTable.DbMutter_Nr = kind.mutter; personenTable.DbPartner_Nr = null; personenTable.DbLebend = true; personenTable.BuildSaveStmt(SqlAction.Insert); personenTable.SaveStmtsOnly(); //asks the database for the correct number of the new child personenTable.Where = "vorname_Nr = " + vNamen.Nummer + " and familie_nr = " + famTable.Nummer + " and geburtsdatum = '" + kindGebDat.ToShortDateString() + "'"; personenTable.Read(); kind.nummer = personenTable.Nummer; //deletes the day of birth in database because it is over Personen temp = new Personen(); temp.Where = "Nummer = " + this.nummer; temp.Read(); temp.DbBekommtKindAnTag = null; temp.BuildSaveStmt(SqlAction.Update); temp.SaveStmtsOnly(); //share the news with others this.FireAusgabe("Ein Kind namens " + vNameKind + " " + this.Familienname + " wurde geboren!"); } } } //at last: reset the IsSchwanger-Property this.IsSchwanger = false; this.PersonChanged?.Invoke(this, new Changed(this, Changed.ChangedProperty.Kinder, this.kinder)); foreach (Person kind in this.Kinder) { kind.PersonChanged?.Invoke(this, new Changed(kind, Changed.ChangedProperty.Geschwister, kind.geschwister)); } }