Esempio n. 1
0
        private void btnOpslaan_Click(object sender, RoutedEventArgs e)
        {
            string naam = txtBoomNaam.Text;

            try
            {
                float       hoogte    = float.Parse(txtHoogte.Text);
                Boomsoorten boomSoort = (Boomsoorten)cmbBoomSoort.SelectedItem;
                Guid?       id        = null;
                if (huidigeBoom != null)
                {
                    id = huidigeBoom.Id;
                    huidigeBoom.Naam          = naam;
                    huidigeBoom.HoogteInMeter = hoogte;
                    huidigeBoom.Soort         = boomSoort;
                }
                else
                {
                    huidigeBoom = new Boom(naam, hoogte, boomSoort);
                }
                huidigeBos.SlapOp(huidigeBoom);
                ToonMelding($"{huidigeBoom.Naam} is opgeslagen", true);
                KoppelBomen();
                lstBomen.SelectedIndex = 0;
            }
            catch (FormatException ex)
            {
                ToonMelding(ex.Message);
            }
            catch (Exception ex)
            {
                ex.GetType();
                ToonMelding($"{huidigeBoom.Naam} is niet opgeslagen", false);
            }
        }
Esempio n. 2
0
        public int GeefAantalBomen(Boomsoorten soort)
        {
            int aantal = 0;

            foreach (Boom boom in Bomen)
            {
                if (soort == boom.Soort)
                {
                    aantal++;
                }
            }

            return(aantal);
        }
Esempio n. 3
0
        public Boom(string boomNaam, float hoogteInMeter,
                    Boomsoorten boomSoort = Boomsoorten.loofboom, Guid?id = null)
        {
            Naam          = boomNaam;
            HoogteInMeter = hoogteInMeter;
            Soort         = boomSoort;
            Id            = id == null?Guid.NewGuid() : (Guid)id;

            /*
             * Verlengde versie
             * if (id == null)
             * {
             *  id = Guid.NewGuid();
             * }
             * else
             * {
             *  id = (Guid)id;
             * }
             */
        }