private void Button_Click(object sender, RoutedEventArgs e) { var them = new hanghoa(); them.tenhh = tbten.Text.ToString(); them.mahh = tbma.Text.ToString(); them.slton = Int32.Parse(tbslton.Text); them.gia = float.Parse(tbgia.Text); using (var db = new QLKEntities()) { db.hanghoas.Add(them); db.SaveChanges(); } this.Close(); }
private void Click_Xoa(object sender, RoutedEventArgs e) { if (lvdsHangHoa.SelectedItem != null) { var a = new hanghoa(); a = (hanghoa)lvdsHangHoa.SelectedItem; using (var db = new QLKEntities()) { var delete = (from d in db.hanghoas where d.mahh == a.mahh select d).Single(); db.hanghoas.Remove(delete); db.SaveChanges(); } QLKEntities t = new QLKEntities(); lvdsHangHoa.ItemsSource = t.hanghoas.ToList(); MessageBox.Show("Đã xóa."); } }
private void Button_Click(object sender, RoutedEventArgs e) { var sua = new hanghoa(); sua.tenhh = tbten.Text.ToString(); sua.mahh = tbma.Text.ToString(); sua.slton = Int32.Parse(tbslton.Text); sua.gia = float.Parse(tbgia.Text); using (var db = new QLKEntities()) { var update = (from u in db.hanghoas where u.mahh == sua.mahh select u).Single(); update.tenhh = sua.tenhh; update.slton = sua.slton; update.gia = sua.gia; db.SaveChanges(); } this.Close(); }