Beispiel #1
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 #2
0
        public static int?NachnameToNummer(string nachname)
        {
            using (Familien f = new Familien())
            {
                f.where = "Familienname = '" + nachname + "'";
                f.Read();

                if (f.EoF)
                {
                    return(null);
                }
                else
                {
                    return(f.Nummer);
                }
            }
        }
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));
        }
Beispiel #5
0
        /// <summary>
        /// create an object for each person in the table and store each object in a list
        /// </summary>
        public void LoadPersons()
        {
            using (Personen personen = new Personen())
            {
                personen.Where   = "Nummer is not null AND Lebend = 1";
                personen.OrderBy = "nummer asc";
                personen.Read();

                //checking if there are some persons
                if (personen.EoF)
                {
                    CreateFirst();
                    LoadPersons();
                    return;
                }

                using (Familien familien = new Familien())
                {
                    using (Vornamen vornamen = new Vornamen())
                    {
                        while (!personen.EoF)
                        {
                            vornamen.Where = "Nummer = " + personen.DbVorname_Nr;
                            vornamen.Read();

                            familien.Where = "Nummer = " + personen.DbFamilie_Nr;
                            familien.Read();

                            //load all persons from database into a cache
                            Person person = new Person(personen.Nummer, vornamen.DbVorname, familien.DbFamilienname, personen.DbGeburtsdatum, personen.DbGeneration ?? 0, personen.DbVater_Nr, personen.DbMutter_Nr, personen.DbPartner_Nr, personen.DbLebend);
                            if (person.Vater != null && person.Vater != 0)
                            {
                                var v = WorkingList.Where(x => x.Nummer == person.Vater);
                                if (v.Count() > 0)
                                {
                                    person.MeinVater = v.First();
                                }
                            }
                            if (person.Mutter != null && person.Mutter != 0)
                            {
                                var m = WorkingList.Where(x => x.Nummer == person.Mutter);
                                if (m.Count() > 0)
                                {
                                    person.MeineMutter = m.First();
                                }
                            }

                            if (personen.DbBekommtKindAnTag != null && personen.DbBekommtKindAnTag != new DateTime(1, 1, 1))
                            {
                                person.IsSchwanger           = true;
                                person.WirdKindGebaerenAnTag = personen.DbBekommtKindAnTag;
                            }
                            person.PersonAusgabe += Person_PersonAusgabe;
                            WorkingList.Add(person);

                            FireAusgabe("loaded '" + person.Vorname + " " + person.Familienname + "'");
                            personen.Skip();
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public int?NummerMutter()
        {
            if (string.IsNullOrEmpty(this.DbMutter))
            {
                return(null);
            }

            using (Personen p = new Personen())
            {
                p.Where = "Vorname_Nr = " + Vornamen.VornameToNummer(this.DbMutter.Substring(0, this.DbMutter.IndexOf(' '))) + " AND Familie_Nr = " + Familien.NachnameToNummer(this.DbMutter.Substring(this.DbMutter.IndexOf(' ') + 1));
                p.Read();

                if (p.EoF)
                {
                    return(null);
                }
                else if (p.RecordCount > 1)
                {
                    return(null);
                }
                else
                {
                    return(p.Nummer);
                }
            }
        }