Beispiel #1
0
        // Thêm sách
        public bool Add(Sach value)
        {
            try
            {

                db.Sach.Add(value);
                db.SaveChanges();
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return false;
            }
        }
Beispiel #2
0
 private void btnUpdate_Click(object sender, RoutedEventArgs e)
 {
     if (!CheckNull()) return;
     var record = new Sach()
     {
         MaSach = int.Parse(txtMaSach.Text),
         TenSach = txtTenSach.Text,
         SoLuong = int.Parse(txtSoLuong.Text),
         DonGia = int.Parse(txtDonGia.Text),
         MaTacGia = (int)tacGiaComboBox.SelectedValue,
         MaLoai = (int)loaiSachComboBox.SelectedValue,
         MaNXB = (int)nXBComboBox.SelectedValue
     };
     if (_db.Update(record))
     {
         MessageBox.Show("Cập nhật sách thành công!");
         LoadDS(null);
     }
     else MessageBox.Show("Cập nhật sách thất bại!");
 }
Beispiel #3
0
 private void btnAdd_Click(object sender, RoutedEventArgs e)
 {
     if (!CheckNull()) return;
     var record = new Sach()
     {
         TenSach = txtTenSach.Text,
         DonGia = int.Parse(txtDonGia.Text),
         SoLuong = int.Parse(txtSoLuong.Text),
         MaLoai = (int)loaiSachComboBox.SelectedValue,
         MaNXB = (int)nXBComboBox.SelectedValue,
         MaTacGia = (int)tacGiaComboBox.SelectedValue
     };
     if (_db.Add(record))
     {
         MessageBox.Show("Thêm sách thành công!");
         sachDataGrid.Items.Refresh();
         LoadDS(null);
     }
     else MessageBox.Show("Thêm sách thất bại!");
 }
Beispiel #4
0
 // Cập nhật sách
 public bool Update(Sach value)
 {
     try
     {
         Sach record = db.Sach.SingleOrDefault(v => v.MaSach == value.MaSach);
         record.TenSach = value.TenSach;
         record.MaLoai = value.MaLoai;
         record.MaNXB = value.MaNXB;
         record.MaTacGia = value.MaTacGia;
         record.SoLuong = value.SoLuong;
         record.DonGia = value.DonGia;
         db.SaveChanges();
         return true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return false;
     }
 }