private void button2_Click(object sender, RoutedEventArgs e) { try { if (textBox_Count.Text != "" && textBox_Count.Text != "0" && textBox_PurchasePrice.Text != "" && textBox_PurchasePrice.Text != "0" && textBox_SellPrice.Text != "" && textBox_SellPrice.Text != "0") { UserContext db = new UserContext(); if (delinfo == null) { DeliveryViewModel edit = dataGridGoods.SelectedItem as DeliveryViewModel; DeliveryViewModel f = lst.FirstOrDefault(x => x == edit); db.Goodss.FirstOrDefault(x => x.Id == f.GoodsId).Balance -= f.Count; f.Price = Convert.ToDouble(textBox_PurchasePrice.Text); f.Count = Convert.ToInt32(textBox_Count.Text); db.Goodss.Find(edit.GoodsId).SellPrice = Convert.ToDouble(textBox_SellPrice.Text); db.Goodss.Find(f.GoodsId).PricePurchase = Convert.ToDouble(textBox_PurchasePrice.Text); db.Goodss.FirstOrDefault(x => x.Id == f.GoodsId).Balance += f.Count; dataGridGoods.ItemsSource = null; } else { delinfo.Price = Convert.ToDouble(textBox_PurchasePrice.Text); delinfo.Count = Convert.ToInt32(textBox_Count.Text); db.Goodss.Find(delinfo.GoodsId).SellPrice = Convert.ToDouble(textBox_SellPrice.Text); db.Goodss.Find(delinfo.GoodsId).PricePurchase = Convert.ToDouble(textBox_PurchasePrice.Text); lst.Add(delinfo); db.Goodss.FirstOrDefault(x => x.Id == delinfo.GoodsId).Balance += delinfo.Count; dataGridGoods.ItemsSource = null; delinfo = null; } db.SaveChanges(); button1_Click(null, null); } else { MessageBox.Show("Неправильный ввод"); } } catch { MessageBox.Show("Error"); } }
private void button3_Click(object sender, RoutedEventArgs e) { if (dataGrid.SelectedItem != null) { delinfo = new DeliveryViewModel(); UserContext db = new UserContext(); var q = db.Goodss.Include("Weapon"); GoodsViewModel per = dataGrid.SelectedItem as GoodsViewModel; Goodss f = q.Include("Accessories").FirstOrDefault(x => x.Id == per.Id); delinfo.GoodsId = f.Id; delinfo.Id = i; if (f.Accessories == null) { delinfo.Name = f.Weapon.CodeName; } else { delinfo.Name = f.Accessories.Name; } CountPriceGrid.Visibility = Visibility.Visible; } else { MessageBox.Show("Вы ничего не выбрали!", "Ошибка"); } }