示例#1
0
 // Thêm loại sách
 public bool Add(LoaiSach value)
 {
     try
     {
         _db.LoaiSach.Add(value);
         _db.SaveChanges();
         return true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return false;
     }
 }
示例#2
0
 private void btnAdd_Click(object sender, RoutedEventArgs e)
 {
     if (!CheckNull()) return;
     var record = new LoaiSach()
     {
         TenLoai = txtTenLoai.Text
     };
     if(db.Add(record))
     {
         MessageBox.Show("Thêm thành công");
         LoadList();
         loaiSachDataGrid.SelectedIndex = loaiSachDataGrid.Items.Count - 1;
         loaiSachDataGrid.ScrollIntoView(record);
         btnAdd.IsEnabled = false;
     }
     else MessageBox.Show("Thêm thất bại");
 }
示例#3
0
 // Cập nhật loại sách
 public bool Update(LoaiSach value)
 {
     try
     {
         LoaiSach record = _db.LoaiSach.SingleOrDefault(v => v.MaLoai == value.MaLoai);
         record.TenLoai = value.TenLoai;
         _db.SaveChanges();
         return true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return false;
     }
 }