Beispiel #1
0
        public bool SuaDauSach(DauSach x)
        {
            OpenConnection();
            SqlCommand command = new SqlCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "SuaDauSach";
            command.Connection  = conn;

            command.Parameters.Add("@madausach", SqlDbType.NChar).Value  = x.MaDauSach;
            command.Parameters.Add("@tendausach", SqlDbType.NChar).Value = x.TenDauSach;
            command.Parameters.Add("@tacgia", SqlDbType.NChar).Value     = x.TacGia;
            command.Parameters.Add("@theloai", SqlDbType.NChar).Value    = x.TheLoai;
            command.Parameters.Add("@NXB", SqlDbType.NChar).Value        = x.NhaXuatBan;
            command.Parameters.Add("@ngonngu", SqlDbType.NChar).Value    = x.NgonNgu;

            int kq = command.ExecuteNonQuery();

            return(kq > 0);
        }
Beispiel #2
0
        public bool ThemDauSach(DauSachDTO dauSachDTO)
        {
            try
            {
                DauSach dauSach = new DauSach
                {
                    MaDauSach  = dauSachDTO.MaDauSach,
                    TenDauSach = dauSachDTO.TenDauSach,
                    MaTheLoai  = dauSachDTO.MaTheLoai,
                    TrangThai  = true
                };
                data.DauSaches.Add(dauSach);
                data.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #3
0
        public List <DauSach> LayDauSach()
        {
            List <DauSach> dsDS = new List <DauSach>();

            OpenConnection();
            SqlCommand command = new SqlCommand();

            command.CommandType = CommandType.Text;
            command.CommandText = "select * from DauSach";
            command.Connection  = conn;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                DauSach temp = new DauSach();
                temp.MaDauSach  = reader.GetString(0);
                temp.TenDauSach = reader.GetString(1);
                dsDS.Add(temp);
            }
            reader.Close();
            return(dsDS);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        public DauSach LayThongTinDauSach(string MaDauSach)
        {
            DauSach kq = new DauSach();

            OpenConnection();
            SqlCommand command = new SqlCommand();

            command.CommandType = CommandType.Text;
            command.CommandText = "select * from dbo.ThongTinChiTietDauSach(@madausach)";
            command.Connection  = conn;
            command.Parameters.Add("@madausach", SqlDbType.NChar).Value = MaDauSach;
            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                kq.MaDauSach = 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.TacGia = reader.GetString(2);
                }
                else
                {
                    kq.TacGia = "Chưa có thông tin";
                }
                if (!reader.IsDBNull(3))
                {
                    kq.TheLoai = reader.GetString(3);
                }
                else
                {
                    kq.TheLoai = "Chưa có thông tin";
                }
                if (!reader.IsDBNull(4))
                {
                    kq.NgonNgu = reader.GetString(4);
                }
                else
                {
                    kq.NgonNgu = "Chưa có thông tin";
                }
                if (!reader.IsDBNull(5))
                {
                    kq.NhaXuatBan = reader.GetString(5);
                }

                else
                {
                    kq.NhaXuatBan = "Chưa có thông tin";
                }
            }
            reader.Close();
            return(kq);
        }
Beispiel #6
0
        public string timTheLoai(string MaDauSach)
        {
            DauSach dauSach = data.DauSaches.SingleOrDefault(u => u.MaDauSach == MaDauSach);

            return(dauSach.MaTheLoai);
        }
        public List <DauSach> ThongKeDauSach()
        {
            List <DauSach> LS = new List <DauSach>();

            OpenConnection();
            SqlCommand command = new SqlCommand();

            command.CommandType = CommandType.Text;
            command.CommandText = "select * from ThongKeDauSach";
            command.Connection  = conn;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                DauSach temp = new DauSach();
                temp.MaDauSach = 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.TacGia = reader.GetString(2);
                }
                else
                {
                    temp.TacGia = "Chưa có thông tin";
                }
                if (!reader.IsDBNull(3))
                {
                    temp.NgonNgu = reader.GetString(3);
                }
                else
                {
                    temp.NgonNgu = "Chưa có thông tin";
                }
                if (!reader.IsDBNull(4))
                {
                    temp.TheLoai = reader.GetString(4);
                }
                else
                {
                    temp.TheLoai = "Chưa có thông tin";
                }

                if (!reader.IsDBNull(5))
                {
                    temp.NhaXuatBan = reader.GetString(5);
                }
                else
                {
                    temp.NhaXuatBan = "Chưa có thông tin";
                }
                if (!reader.IsDBNull(6))
                {
                    temp.SoCuon = reader.GetInt32(6);
                }
                else
                {
                    temp.SoCuon = 0;
                }

                LS.Add(temp);
            }
            reader.Close();
            return(LS);
        }