Ejemplo n.º 1
0
        public IReadOnlyList <Klant> HaalOp()
        {
            SqlConnection connection = GetConnection();
            string        query      = "SELECT * FROM Klant";

            using (SqlCommand command = connection.CreateCommand())
            {
                command.CommandText = query;
                connection.Open();

                try
                {
                    SqlDataReader reader  = command.ExecuteReader();
                    List <Klant>  klanten = new List <Klant>();
                    while (reader.Read())
                    {
                        klanten.Add(KlantFactory.MaakNieuweKlant((string)reader["Naam"], (string)reader["Adres"], (long)reader["Id"]));
                    }
                    reader.Close();
                    return(klanten);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error: ${e.Message}");
                    throw new DbKlantManagerException("DbKlantManager: Fout bij ophalen van klanten uit database");
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles clicking on the 'Voeg toe' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnNieuweKlant_Click(object sender, RoutedEventArgs e)
        {
            // Validate data
            if (string.IsNullOrEmpty(TbKlantNaam?.Text) || string.IsNullOrEmpty(TbKlantAdres?.Text))
            {
                MessageBox.Show(Translations.ClientWarning);
                return;
            }

            // Add new Klant to ObservableCollection
            // _klanten_CollectionChanged makes sure the changes also get pushed to BusinessLayer
            Klant klant = KlantFactory.MaakNieuweKlant(TbKlantNaam.Text, TbKlantAdres.Text);

            _klanten.Add(klant);

            // Empty TextBoxes after adding new Klant
            TbKlantNaam.Text         = "";
            TbKlantAdres.Text        = "";
            BtnNieuweKlant.IsEnabled = false;
        }