public bool Lagerbuchung(int id_Lagerort, int id_Artikel, int BewegungsMenge) { try { using (var db = new SteinbachEntities()) { var lb = db.Lagerbestaende.Where(n => n.id_Lagerliste == id_Artikel && n.id_Lagerort == id_Lagerort).SingleOrDefault(); if (lb == null) { lb = new Lagerbestaende(); lb.id_Lagerliste = id_Artikel; lb.id_Lagerort = id_Lagerort; lb.Lagerbestand = 0; db.AddToLagerbestaende(lb); } if (!lb.Lagerbestand.HasValue) { lb.Lagerbestand = 0; } lb.Lagerbestand += BewegungsMenge; db.SaveChanges(); return(true); } } catch (Exception ex) { CommonTools.Tools.ErrorMethods.HandleStandardError(ex, "Lagerbuchung fehlgeschlagen."); return(false); // throw; } }
public void ConsolidateLagerbestaende() { try { Console.WriteLine("ConsolidateLagerbestaende"); var duplicates = (from item in db.Lagerbestaende group item by new { Lagerliste = item.id_Lagerliste, Lagerort = item.id_Lagerort } into g where g.Count() > 1 select g); foreach (var item in duplicates) { Console.WriteLine(item.Key.Lagerliste); var bst = new Lagerbestaende(); db.AddToLagerbestaende(bst); bst.Lagerbestand = 0; foreach (Lagerbestaende lb in item.ToList()) { bst.id_Lagerliste = lb.id_Lagerliste; bst.id_Lagerort = lb.id_Lagerort; bst.Lagerbestand += lb.Lagerbestand; bst.letzteBuchung = lb.letzteBuchung; bst.Mindestbestand = lb.Mindestbestand; bst.Sollbestand = lb.Sollbestand; db.DeleteObject(lb); } } db.SaveChanges(); Console.WriteLine("Ende - ConsolidateLagerbestaende"); } catch (Exception) { throw; } }
public static void TransferLagerbestaende() { using (var db = new SteinbachEntities()) { var ll = db.lagerlisten; foreach (var item in ll) { var lb = new Lagerbestaende(); lb.id_Lagerliste = item.id; lb.id_Lagerort = 1; lb.Lagerbestand = item.anzahlauflager; db.AddToLagerbestaende(lb); } db.SaveChanges(); } }