private void btnTest_Click(object sender, RoutedEventArgs e) { using (var test = new SteinbachEntities()) { var beleg = new SI_Belege(); beleg.id_Quelllager = 1; beleg.id_Ziellager = 2; test.AddToSI_Belege(beleg); var bwg = test.lagerliste_addremove.Where(i => i.id == 16471).SingleOrDefault(); bwg.id_Quelllager = 2; bwg.id_Ziellager = 1; //test.AddTolagerliste_addremove(bwg); test.SaveChanges(); } }
private bool MakeBuchungsbeleg() { bool result = false; try { int count = invPositionen.Where(n => (n.Differenz != 0 && n.Differenz != null) && (n.IstGebucht == 0 || n.IstGebucht == null)).Count(); if (count > 0) { SI_Belege b = null; if (!BelegID.HasValue || BelegID == 0) { b = new SI_Belege(); db.AddToSI_Belege(b); b.created = DateTime.Now; b.Belegart = "inv"; b.id_Ziellager = db.StammLagerorte.Where(n => n.istStandardLagerort == 1).SingleOrDefault().id; b.id_Quelllager = 4; b.Belegdatum = this.Inventurdatum; b.Bemerkung = "Inventur : " + id; b.Belegnummer = "Inventur : " + id; b.id_user = Session.User.id; b.id_Sprache = 1; b.istGebucht = 0; } else { b = db.SI_Belege.Where(id => id.id == BelegID).SingleOrDefault(); } if (invPositionen != null) { foreach (var item in invPositionen.Where(n => (n.Differenz != 0 && n.Differenz != null) && (n.IstGebucht == 0 || n.IstGebucht == null))) { var pos = (SI_InventurenPositionen)item; var posBel = new SI_BelegePositionen(); posBel.SI_Belege = b; posBel.Menge = pos.Differenz; posBel.id_Artikel = pos.id_artikel; db.AddToSI_BelegePositionen(posBel); if (pos.IstGebucht == 0 || pos.IstGebucht == null) { if (pos.id_artikel != null && pos.Differenz != null && pos.Differenz != 0) { int ProId = pos.id_inventur; pos.IstGebucht = 1; } } } } db.SaveChanges(); if (!BelegID.HasValue || BelegID == 0) { BelegID = b.id; } Inventurgebucht = 1; isGebuchtEnabled = false; isDirty = false; db.SaveChanges(); return(true); } else { return(false); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }