private void Button_Click_1(object sender, RoutedEventArgs e) { string[] listcloth = new string[4]; for (int i = 0; i < postCloth.Items.Count - 1; i++) { listcloth = db.ArrayItem(i, dt); string art = listcloth[0]; double wdth = double.Parse(listcloth[1]); double lngth = double.Parse(listcloth[2]); int cnt = int.Parse(listcloth[3]); var select = db.kladCloth.Where(kc => kc.cloth == art && kc.width == wdth && kc.length == lngth); if (select.Count() != 0) { cnt += select.FirstOrDefault().count; int id = select.FirstOrDefault().Id; kladCloth update = db.kladCloth.Find(id); update.count = cnt; db.kladCloth.Create(); db.SaveChanges(); } else { kladCloth item = new kladCloth(); item.cloth = art; item.count = cnt; item.length = lngth; item.width = wdth; var insert = db.kladCloth.Add(item); db.SaveChanges(); } } MessageBox.Show("Товары успешно добавлены на склад"); clothSklad cs = new clothSklad(IdUser); cs.Show(); this.Close(); }
private void inpsave_Click(object sender, RoutedEventArgs e) { string[] list = new string[4]; for (int i = 0; i < listcloth.Items.Count - 1; i++) { list = db.ArrayItem(i, dt); string art = list[0]; double wdth = double.Parse(list[1]); double lngth = double.Parse(list[2]); int cnt = int.Parse(list[3]); var select = db.kladCloth.Where(kcl => kcl.cloth == art && kcl.width == wdth && kcl.length == lngth); if (select.Count() != 0) { if (select.FirstOrDefault().count >= cnt) { cnt = select.FirstOrDefault().count - cnt; kladCloth item = db.kladCloth.Find(select.FirstOrDefault().Id); item.count = cnt; db.kladCloth.Create(); db.SaveChanges(); MessageBox.Show("Данные успешно обновлены"); clothSklad cs = new clothSklad(IdUser); cs.Show(); this.Close(); } else { MessageBox.Show("Запрошенного количества товара нет на складе"); } } else { MessageBox.Show("Одного из товаров не существует"); } } }