public static bool AddSach(Sach sach) { DBQLPhatHanhSachEntities model = new DBQLPhatHanhSachEntities(); try { model.Sach.Add(sach); model.SaveChanges(); return true; } catch { return false; } }
public static bool UpdateSach(Sach sach) { DBQLPhatHanhSachEntities model = new DBQLPhatHanhSachEntities(); var SachSelected = (from p in model.Sach where p.Masach.Trim().Equals(sach.Masach.Trim()) select p).FirstOrDefault(); if (SachSelected == null) return false; else { SachSelected.MaNXB = sach.MaNXB; SachSelected.MaTheLoai = sach.MaTheLoai; SachSelected.Tensach = sach.Tensach; SachSelected.Tacgia = sach.Tacgia; SachSelected.GiaBan = sach.GiaBan; SachSelected.GiaNhap = sach.GiaNhap; model.SaveChanges(); return true; } }
public List <Sach> TimKiemSach(string thongtin) { List <Sach> ltk = new List <Sach>(); OpenConnection(); SqlCommand command = new SqlCommand(); command.CommandType = CommandType.Text; command.CommandText = "select * from dbo.TimKiemSach(@thongtin)"; command.Connection = conn; command.Parameters.Add("@thongtin", SqlDbType.NVarChar).Value = thongtin; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Sach kq = new Sach(); kq.MaSach = reader.GetString(0); if (!reader.IsDBNull(1)) { kq.TenDauSach = reader.GetString(1); } else { kq.TenDauSach = "Chưa có thông tin"; } if (!reader.IsDBNull(2)) { kq.Tap = reader.GetInt32(2); } else { kq.Tap = 0; } if (!reader.IsDBNull(3)) { kq.LanTaiBan = reader.GetInt32(3); } else { kq.LanTaiBan = 0; } if (!reader.IsDBNull(4)) { kq.ViTri = reader.GetString(4); } else { kq.ViTri = "Chưa có thông tin"; } if (!reader.IsDBNull(5)) { kq.TacGia = reader.GetString(5); } else { kq.TacGia = "Chưa có thông tin"; } if (!reader.IsDBNull(6)) { kq.TheLoai = reader.GetString(6); } else { kq.TheLoai = "Chưa có thông tin"; } if (!reader.IsDBNull(7)) { kq.NgonNgu = reader.GetString(7); } else { kq.NgonNgu = "Chưa có thông tin"; } if (!reader.IsDBNull(8)) { kq.NXB = reader.GetString(8); } else { kq.NXB = "Chưa có thông tin"; } ltk.Add(kq); } reader.Close(); return(ltk); }
public List <Sach> TimKiemSachChiTiet(DauSach temp) { List <Sach> ltk = new List <Sach>(); OpenConnection(); SqlCommand command = new SqlCommand(); command.CommandType = CommandType.Text; command.CommandText = "select * from dbo.TimKiemNangCao(@tendausach,@tacgia,@theloai,@ngonngu,@nxb)"; command.Connection = conn; command.Parameters.Add("@tendausach", SqlDbType.NVarChar).Value = temp.TenDauSach; command.Parameters.Add("@tacgia", SqlDbType.NVarChar).Value = temp.TacGia; command.Parameters.Add("@theloai", SqlDbType.NVarChar).Value = temp.TheLoai; command.Parameters.Add("@ngonngu", SqlDbType.NVarChar).Value = temp.NgonNgu; command.Parameters.Add("@nxb", SqlDbType.NVarChar).Value = temp.NhaXuatBan; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Sach kq = new Sach(); kq.MaSach = reader.GetString(0); if (!reader.IsDBNull(1)) { kq.TenDauSach = reader.GetString(1); } else { kq.TenDauSach = "Chưa có thông tin"; } if (!reader.IsDBNull(2)) { kq.Tap = reader.GetInt32(2); } else { kq.Tap = 0; } if (!reader.IsDBNull(3)) { kq.LanTaiBan = reader.GetInt32(3); } else { kq.LanTaiBan = 0; } if (!reader.IsDBNull(4)) { kq.ViTri = reader.GetString(4); } else { kq.ViTri = "Chưa có thông tin"; } if (!reader.IsDBNull(5)) { kq.TacGia = reader.GetString(5); } else { kq.TacGia = "Chưa có thông tin"; } if (!reader.IsDBNull(6)) { kq.TheLoai = reader.GetString(6); } else { kq.TheLoai = "Chưa có thông tin"; } if (!reader.IsDBNull(7)) { kq.NgonNgu = reader.GetString(7); } else { kq.NgonNgu = "Chưa có thông tin"; } if (!reader.IsDBNull(8)) { kq.NXB = reader.GetString(8); } else { kq.NXB = "Chưa có thông tin"; } ltk.Add(kq); } reader.Close(); return(ltk); }
public List <Sach> HienThiGiaoDienSach() { List <Sach> LS = new List <Sach>(); OpenConnection(); SqlCommand command = new SqlCommand(); command.CommandType = CommandType.Text; command.CommandText = "select * from HienThiGiaoDienSach"; command.Connection = conn; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Sach temp = new Sach(); temp.MaSach = reader.GetString(0); if (!reader.IsDBNull(1)) { temp.TenDauSach = reader.GetString(1); } else { temp.TenDauSach = "Chưa có thông tin"; } if (!reader.IsDBNull(2)) { temp.Tap = reader.GetInt32(2); } else { temp.Tap = 0; } if (!reader.IsDBNull(3)) { temp.LanTaiBan = reader.GetInt32(3); } else { temp.LanTaiBan = 0; } if (!reader.IsDBNull(4)) { temp.ViTri = reader.GetString(4); } else { temp.ViTri = "Chưa có thông tin"; } if (!reader.IsDBNull(5)) { temp.TacGia = reader.GetString(5); } else { temp.TheLoai = "Chưa có thông tin"; } if (!reader.IsDBNull(6)) { temp.TheLoai = reader.GetString(6); } else { temp.TacGia = "Chưa có thông tin"; } if (!reader.IsDBNull(7)) { temp.NgonNgu = reader.GetString(7); } else { temp.NgonNgu = "Chưa có thông tin"; } if (!reader.IsDBNull(8)) { temp.NXB = reader.GetString(8); } else { temp.NXB = "Chưa có thông tin"; } LS.Add(temp); } reader.Close(); return(LS); }