private void Button_Click(object sender, RoutedEventArgs e) { string[] listFur = new string[4]; for (int i = 0; i < postFur.Items.Count - 1; i++) { listFur = db.ArrayItem(i, dt); string art = listFur[0]; double width = double.Parse(listFur[1]); double length = double.Parse(listFur[2]); double count = double.Parse(listFur[3]); var select = db.kladFurniture.Where(kladFur => kladFur.furniture == art && kladFur.length == length && kladFur.width == width); if (select.Count() != 0) { count += select.FirstOrDefault().count; int Id = select.FirstOrDefault().Id; kladFurniture update = db.kladFurniture.Find(Id); update.count = count; db.kladFurniture.Create(); db.SaveChanges(); } else { kladFurniture item = new kladFurniture(); item.furniture = art; item.length = length; item.width = width; item.count = count; var insert = db.kladFurniture.Add(item); db.SaveChanges(); } } MessageBox.Show("Товары успешно добавлены на склад"); furnitureSklad furnitureSklad = new furnitureSklad(IdUser); furnitureSklad.Show(); this.Close(); }
private void Button_Click(object sender, RoutedEventArgs e) { string[] listfur = new string[4]; for (int i = 0; i < dellist.Items.Count - 1; i++) { listfur = db.ArrayItem(i, dt); string art = listfur[0]; double width = double.Parse(listfur[1]); double length = double.Parse(listfur[2]); int count = int.Parse(listfur[3]); var select = db.kladFurniture.Where(kladFur => kladFur.furniture == art && kladFur.length == length && kladFur.width == width); if (select.Count() != 0) { int Id = select.FirstOrDefault().Id; kladFurniture klad = db.kladFurniture.Find(Id); if (klad.count >= count) { klad.count -= count; db.kladFurniture.Create(); db.SaveChanges(); MessageBox.Show("Списание товаров прошло успешно"); furnitureSklad furnitureSklad = new furnitureSklad(IdUser); furnitureSklad.Show(); this.Close(); } else { MessageBox.Show("Запрошенного количества нет на складе"); } } else { MessageBox.Show("Такого товара не существует"); } } }