Example #1
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);
                }
            }
        }
Example #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();
                    }
                }
            }
        }
Example #3
0
        public static int?VornameToNummer(string vorname)
        {
            using (Vornamen v = new Vornamen())
            {
                v.where = "Vorname = '" + vorname + "'";
                v.Read();

                if (v.EoF)
                {
                    return(null);
                }
                else
                {
                    return(v.Nummer);
                }
            }
        }
Example #4
0
 private void Initialize()
 {
     this.rand = new Random();
     using (Vornamen vNamen = new Vornamen())
     {
         vNamen.Where = "Vorname = '" + this.vorname + "'";
         vNamen.Read();
         if (vNamen.DbGeschlecht == 'M')
         {
             this.geschlecht = 'M';
         }
         else if (vNamen.DbGeschlecht == 'W')
         {
             this.geschlecht = 'W';
         }
         this.kinder      = new List <Person>();
         this.geschwister = new List <Person>();
     }
 }
Example #5
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));
            }
        }
Example #6
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();
                        }
                    }
                }
            }
        }