Beispiel #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();
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            IDFactory idF = new IDFactory(0, 100, 5000); //klant,bestelling,product
            var       kM  = new /*Db*/ KlantManager();
            var       pM  = new ProductManager();
            var       bM  = new BestellingManager();

            pM.VoegProductToe(ProductFactory.MaakProduct("product 1", 10.0, idF));
            pM.VoegProductToe(ProductFactory.MaakProduct("product 2", 12.0, idF));
            pM.VoegProductToe(ProductFactory.MaakProduct("product 3", 13.0, idF));
            foreach (var x in pM.GeefProducten())
            {
                Console.WriteLine(x);
            }

            kM.VoegKlantToe(KlantFactory.MaakKlant("klant 1", "adres 1", idF));
            kM.VoegKlantToe(KlantFactory.MaakKlant("klant 2", "adres 2", idF));
            foreach (var x in kM.GeefKlanten()) //Console.WriteLine(x);
            {
                x.Show();
            }

            bM.VoegBestellingToe(BestellingFactory.MaakBestelling(idF));
            bM.VoegBestellingToe(BestellingFactory.MaakBestelling(kM.GeefKlant(1), idF));

            Bestelling b = bM.GeefBestelling(101);

            b.VoegProductToe(pM.GeefProduct("product 2"), 8);
            b.VoegProductToe(pM.GeefProduct("product 1"), 7);
            Console.WriteLine($"Prijs:{b.Kostprijs()}, {b.PrijsBetaald}");
            b.ZetBetaald();
            Console.WriteLine($"Prijs:{b.Kostprijs()}, {b.PrijsBetaald}");

            foreach (var x in bM.GeefBestellingen()) //Console.WriteLine(x);
            {
                x.Show();
            }
            foreach (var x in kM.GeefKlanten()) //Console.WriteLine(x);
            {
                x.Show();
            }
            Console.WriteLine("-----------------");
            Klant k1 = kM.GeefKlant(1);

            k1.Show();
            k1.VoegToeBestelling(b);
            k1.Show();
        }
Beispiel #3
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;
        }