public string createKeySach() { SACH s = new SACH(); foreach (SACH sh in linq.SACHES) { s = sh; } if (s.MASACH != null) { return(createAuto3(s.MASACH)); } else { return("SA001"); } }
public void suaS(string maS, string ten, string tacGia, string namXuatBan, string nhaXuatBan, string triGia, string ngayNhap) { SACH sachs = DB.SACHes.FirstOrDefault(s => s.MaSach.Equals(maS)); sachs.TenSach = ten; sachs.TacGia = tacGia; sachs.NamXuatBan = int.Parse(namXuatBan); sachs.NhaXuatBan = nhaXuatBan; sachs.TriGia = float.Parse(triGia); sachs.NgayNhap = DateTime.Parse(ngayNhap); try { DB.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } MessageBox.Show("Sửa thành công!", "Thông báo"); }
public void xoaS(ListView lvS) { using (TransactionScope t = new TransactionScope()) { for (int i = 0; i < lvS.SelectedIndices.Count; i++) { SACH sachs = DB.SACHes.FirstOrDefault(s => s.MaSach.Equals(lvS.SelectedItems[i].SubItems[0].Text)); try { DB.SACHes.DeleteOnSubmit(sachs); DB.SubmitChanges(); MessageBox.Show("Xóa thành công!", "Thông báo"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } t.Complete(); } }
public void themS(string maS, string ten, string tacGia, string namXuatBan, string nhaXuatBan, string triGia, string ngayNhap) { SACH s = new SACH(); s.MaSach = maS; s.TenSach = ten; s.NgayNhap = DateTime.Parse(ngayNhap); s.TacGia = tacGia; s.NhaXuatBan = nhaXuatBan; s.NamXuatBan = int.Parse(namXuatBan); s.TriGia = float.Parse(triGia); try { DB.SACHes.InsertOnSubmit(s); DB.SubmitChanges(); MessageBox.Show("Thêm thành công!", "Thông báo"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }