예제 #1
0
 static void VoorraadBijvulling(int artikelNr, int magazijnNr, int aantalStuks)
 {
     using (var entities = new OpleidingenEntities())
     {
         var voorrraad = entities.Voorraden.Find(magazijnNr, artikelNr);
         if (voorrraad != null)
         {
             voorrraad.AantalStuks += aantalStuks;
             Console.WriteLine("Pas nu de voorraad aan met de ServerExplorer, druk daarna op enter");
             Console.ReadLine();
             try
             {
                 entities.SaveChanges();
             }
             catch (DbUpdateConcurrencyException)
             {
                 Console.WriteLine("voorraad werd door andere applicatie aagepast.");
             }
         }
         else
         {
             Console.WriteLine("Voorraad niet gevonden");
         }
     }
 }
예제 #2
0
        static void VoorraadTransfer(int artikelNr, int vanMagazijnNr, int naarMagazijnNr, int aantalStuks)
        {
            var transactionOptions = new TransactionOptions
            {
                IsolationLevel = IsolationLevel.RepeatableRead
            };

            using (var transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
            {
                using (var entities = new OpleidingenEntities())
                {
                    var vanVoorraad = entities.Voorraden.Find(vanMagazijnNr, artikelNr);
                    if (vanVoorraad != null)
                    {
                        if (vanVoorraad.AantalStuks >= aantalStuks)
                        {
                            vanVoorraad.AantalStuks -= aantalStuks;
                            var naarVoorraad = entities.Voorraden.Find(naarMagazijnNr, artikelNr);
                            if (naarVoorraad != null)
                            {
                                naarVoorraad.AantalStuks += aantalStuks;
                            }
                            else
                            {
                                naarVoorraad = new Voorraad
                                {
                                    ArtikelNr = artikelNr, MagazijnNr = naarMagazijnNr, AantalStuks = aantalStuks
                                };
                                entities.Voorraden.Add(naarVoorraad);
                            }
                            entities.SaveChanges();
                            transactionScope.Complete();
                        }
                        else
                        {
                            Console.WriteLine("Te weinig voorraad voor transfer");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Artikel niet gevonden in magazijn {0}", vanMagazijnNr);
                    }
                }
            }
        }
예제 #3
0
        void VoorraadBijvulling(int artikelNr, int magazijnNr, int aantalStuks)
        {
            using (var entities = new OpleidingenEntities())
            {
                var voorraad = entities.Voorraden.Find(magazijnNr, artikelNr);
                if (voorraad != null)
                {
                    voorraad.AantalStuks += aantalStuks;
                    Console.WriteLine("Pas nu de voorraad aan met de Server Explorer," +
                                      " druk daarna op Enter");
                    Console.ReadLine();
                    try
                    {
                        entities.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        Console.WriteLine("Voorraad werd door andere applicatie aangepast.");
                    }
                }
                else
                {
                    Console.WriteLine("Voorraad niet gevonden");
                }
            }
            //    try
            //    {
            //        Console.Write("Artikel nr.:");
            //        var artikelNr = int.Parse(Console.ReadLine());
            //        Console.Write("Van magazijn nr.:");
            //        var vanMagazijnNr = int.Parse(Console.ReadLine());
            //        Console.Write("Naar magazijn nr:");
            //        var naarMagazijnNr = int.Parse(Console.ReadLine());
            //        Console.Write("Aantal stuks:");
            //        var aantalStuks = int.Parse(Console.ReadLine());

            //        new Program().VoorraadTransfer(artikelNr, vanMagazijnNr, naarMagazijnNr,
            //        aantalStuks);
            //    }
            //    catch (FormatException)
            //    {

            //        Console.WriteLine("Tik een getal");
            //    }
            //}
            //void VoorraadTransfer(int artikelNr, int vanMagazijnNr, int naarMagazijnNr, int aantalStuks)
            //{
            //    var transactionOptions = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.RepeatableRead };
            //    using(var transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
            //    {
            //        using (var entities = new OpleidingenEntities())
            //        {
            //            var vanVoorraad = entities.Voorraden.Find(vanMagazijnNr, artikelNr);
            //            if (vanVoorraad != null)
            //            {
            //                if (vanVoorraad.AantalStuks >= aantalStuks)
            //                {
            //                    vanVoorraad.AantalStuks -= aantalStuks;
            //                    var naarVoorraad = entities.Voorraden.Find(naarMagazijnNr, artikelNr);
            //                    if (naarVoorraad != null)
            //                    {
            //                        naarVoorraad.AantalStuks += aantalStuks;
            //                    }
            //                    else
            //                    {
            //                        naarVoorraad = new Voorraad { ArtikelNr = artikelNr, MagazijnNr = naarMagazijnNr, AantalStuks = aantalStuks };
            //                        entities.Voorraden.Add(naarVoorraad);
            //                    }
            //                    entities.SaveChanges();
            //                    transactionScope.Complete();

            //                }
            //                else
            //                    Console.WriteLine("Te weinig voorraad voor transfer");
            //            }
            //            else
            //                Console.WriteLine("Artikel niet gevonden in magazijn {0}", vanMagazijnNr);
            //        }
            //    }
        }