Beispiel #1
0
        /// <summary>
        /// lets the person create a child with his/her partner
        /// </summary>
        public void ZeugeKind()
        {
            //if the partner is female this method will be called again for the partner-object
            if (this.geschlecht == 'M')
            {
                this.meinPartner.ZeugeKind();
            }
            else if (this.geschlecht == 'W' && !this.isSchwanger)
            {
                this.isSchwanger           = true;
                this.wirdKindGebaerenAnTag = StammbaumBusiness.AktuellerTagInSimulation.AddDays(dauerSchwangerschaft + rand.Next(-25, 25));

                //save the day of birth in database
                using (Personen temp = new Personen())
                {
                    temp.Where = "Nummer = " + this.nummer;
                    temp.Read();
                    temp.DbBekommtKindAnTag = this.wirdKindGebaerenAnTag;
                    temp.BuildSaveStmt(SqlAction.Update);
                    temp.SaveStmtsOnly();
                }
                //share the news with others
                this.FireAusgabe(this.vorname + " " + this.famName + " ist schwanger!");
            }
        }
Beispiel #2
0
        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();
                    }
                }
            }
        }
Beispiel #3
0
        /// <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));
            }
        }
Beispiel #4
0
        /// <summary>
        /// lets the person search for a partner
        /// </summary>
        public void SuchePartner()
        {
            //search for available partners
            List <Person> potentiellePartner = new List <Person>();
            var           pP = StammbaumBusiness.WorkingList.Where(P => P.DarfPartner && P.Geschlecht != this.Geschlecht && !this.IsVerwandter(P) && !P.IsVerwandter(this));

            if (pP.Count() > 0)
            {
                potentiellePartner.AddRange(pP);
            }
            //foreach (Person p in StammbaumBusiness.WorkingList)
            //{
            //	if (p.DarfPartner && p.Geschlecht != this.Geschlecht && !this.IsVerwandter(p) && !p.IsVerwandter(this))
            //	{
            //		potentiellePartner.Add(p);
            //	}
            //}
            if (potentiellePartner.Count == 0)
            {
                return;
            }

            //random selection of a partner
            this.meinPartner = potentiellePartner[rand.Next(0, potentiellePartner.Count)];
            StammbaumBusiness.ZuEntfernende.Enqueue(this.meinPartner);
            StammbaumBusiness.ZuEntfernende.Enqueue(this);

            //setting of properties to save the new relationship
            this.meinPartner.partner = this.nummer;
            this.partner             = this.meinPartner.nummer;
            if (this.geschlecht == 'M')
            {
                this.meinPartner.famName = this.famName;
            }
            else
            {
                this.famName = this.meinPartner.famName;
            }
            this.meinPartner.meinPartner = this;
            StammbaumBusiness.NeuHinzuzufuegende.Enqueue(this.meinPartner);
            StammbaumBusiness.NeuHinzuzufuegende.Enqueue(this);

            //save the new relationship into the database
            using (Familien fam = new Familien())
            {
                fam.Where = "Familienname = '" + this.famName + "'";
                fam.Read();

                //first partner
                using (Personen SaveRelationship = new Personen())
                {
                    SaveRelationship.Where = "Nummer = " + this.nummer;
                    SaveRelationship.Read();

                    SaveRelationship.DbPartner_Nr = this.partner;
                    SaveRelationship.DbFamilie_Nr = fam.Nummer;
                    SaveRelationship.BuildSaveStmt(SqlAction.Update);

                    //second partner
                    SaveRelationship.Where = "Nummer = " + this.meinPartner.nummer;
                    SaveRelationship.Read();

                    SaveRelationship.DbPartner_Nr = this.meinPartner.partner;
                    SaveRelationship.DbFamilie_Nr = fam.Nummer;

                    SaveRelationship.BuildSaveStmt(SqlAction.Update);

                    SaveRelationship.SaveStmtsOnly();
                }
            }

            //share the relationship with others
            this.FireAusgabe(this.vorname + " " + this.famName + " und " + this.meinPartner.vorname + " " + this.meinPartner.famName + " sind jetzt ein Paar!");
            this.PersonChanged?.Invoke(this, new Changed(this, Changed.ChangedProperty.Partner, this.partner));
        }