Пример #1
0
        public List <VatPham> LayToanBoVatPham()
        {
            List <VatPham> dsvp = new List <VatPham>();

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

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

            while (reader.Read())
            {
                VatPham vp = new VatPham();
                vp.MaVP        = reader.GetInt32(0);
                vp.TenVP       = reader.GetString(1);
                vp.TenNguoiBan = reader.GetString(2);
                vp.SDT         = reader.GetString(3);
                vp.ThanhPho    = reader.GetString(4);
                vp.MoTa        = reader.GetString(5);
                vp.TinhTrang   = reader.GetString(6);
                vp.GiaTien     = reader.GetInt64(7);
                vp.TheLoai     = reader.GetString(8);
                int temp = reader.GetInt32(9);
                vp.NgayDang    = ChuyenThoiGian(temp);
                vp.LinkHinhAnh = new List <string>();
                vp.LinkHinhAnh.Add(reader.GetString(10));
                vp.ChatLuong = reader.GetInt32(11);
                vp.DiaDiem   = reader.GetString(12);
                dsvp.Add(vp);
            }
            reader.Close();
            return(dsvp);
        }
        public List <VatPham> LayVatPhamDangBan(string sdt)
        {
            List <VatPham> dsvp = new List <VatPham>();

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

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

            while (reader.Read())
            {
                VatPham vp = new VatPham();
                vp.MaVP    = reader.GetInt32(0);
                vp.TenVP   = reader.GetString(1);
                vp.GiaTien = reader.GetInt64(2);
                int temp = reader.GetInt32(3);
                vp.NgayDang    = ChuyenThoiGian(temp);
                vp.LinkHinhAnh = new List <string>();
                vp.LinkHinhAnh.Add(reader.GetString(4));
                vp.KiemDuyet = reader.GetInt32(5);
                vp.NgungBan  = reader.GetInt32(6);
                dsvp.Add(vp);
            }
            reader.Close();
            return(dsvp);
        }
Пример #3
0
        public List <VatPham> LayVatPham(int MaDM, int Trang)
        {
            int            start = (Trang - 1) * 12;
            List <VatPham> dsvp  = new List <VatPham>();

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

            command.CommandType = CommandType.Text;
            if (Trang > 0)
            {
                command.CommandText = "select * from dbo.DanhSachVatPham(@MaDM) order by NgayDang OFFSET " + start + " ROWS FETCH NEXT 12 ROWS ONLY;";
            }
            else
            {
                command.CommandText = "select * from dbo.DanhSachVatPham(@MaDM)";
            }
            command.Connection = conn;
            command.Parameters.Add("@MaDM", SqlDbType.Int).Value = MaDM;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                VatPham vp = new VatPham();
                vp.MaVP        = reader.GetInt32(0);
                vp.TenVP       = reader.GetString(1);
                vp.TenNguoiBan = reader.GetString(2);
                vp.SDT         = reader.GetString(3);
                vp.ThanhPho    = reader.GetString(4);
                vp.MoTa        = reader.GetString(5);
                vp.TinhTrang   = reader.GetString(6);
                vp.GiaTien     = reader.GetInt64(7);
                vp.TheLoai     = reader.GetString(8);
                int temp = reader.GetInt32(9);
                vp.NgayDang    = ChuyenThoiGian(temp);
                vp.LinkHinhAnh = new List <string>();
                vp.LinkHinhAnh.Add(reader.GetString(10));
                vp.ChatLuong = reader.GetInt32(11);
                vp.DiaDiem   = reader.GetString(12);
                vp.LoaiTK    = reader.GetInt32(13);
                vp.MaTP      = reader.GetInt32(14);
                dsvp.Add(vp);
            }
            reader.Close();
            return(dsvp);
        }
Пример #4
0
        public VatPham ThongTinChiTietVatPham(int MaVP)
        {
            VatPham vp = new VatPham();

            try
            {
                OpenConnection();
                SqlCommand command = new SqlCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = "select * from dbo.ThongTinVatPham(@MaVP)";
                command.Connection  = conn;
                command.Parameters.Add("@MaVP", SqlDbType.Int).Value = MaVP;
                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    vp.MaVP        = reader.GetInt32(0);
                    vp.TenVP       = reader.GetString(1);
                    vp.TenNguoiBan = reader.GetString(2);
                    vp.SDT         = reader.GetString(3);
                    vp.ThanhPho    = reader.GetString(4);
                    vp.MoTa        = reader.GetString(5);
                    vp.TinhTrang   = reader.GetString(6);
                    vp.GiaTien     = reader.GetInt64(7);
                    vp.TheLoai     = reader.GetString(8);
                    int temp = reader.GetInt32(9);
                    vp.NgayDang  = ChuyenThoiGian(temp);
                    vp.ChatLuong = reader.GetInt32(11);
                    vp.DiaDiem   = reader.GetString(12);
                    vp.MaDM      = reader.GetInt32(13);
                    vp.LuotThich = reader.GetInt32(14);
                    reader.Close();
                    vp.LinkHinhAnh = LayHinhAnh(vp.MaVP);
                }
            }
            catch
            {
            }
            return(vp);
        }
Пример #5
0
        public List <VatPham> TimKiemVP(string str, int MaTL)
        {
            List <VatPham> dsvp = new List <VatPham>();

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

            command.CommandType = CommandType.Text;
            command.CommandText = "select * from dbo.TimKiem(@str,@MaTL)";
            command.Connection  = conn;
            command.Parameters.Add("@MaTL", SqlDbType.Int).Value     = MaTL;
            command.Parameters.Add("@str", SqlDbType.NVarChar).Value = str;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                VatPham vp = new VatPham();
                vp.MaVP        = reader.GetInt32(0);
                vp.TenVP       = reader.GetString(1);
                vp.TenNguoiBan = reader.GetString(2);
                vp.SDT         = reader.GetString(3);
                vp.ThanhPho    = reader.GetString(4);
                vp.MoTa        = reader.GetString(5);
                vp.TinhTrang   = reader.GetString(6);
                vp.GiaTien     = reader.GetInt64(7);
                vp.TheLoai     = reader.GetString(8);
                int temp = reader.GetInt32(9);
                vp.NgayDang    = ChuyenThoiGian(temp);
                vp.LinkHinhAnh = new List <string>();
                vp.LinkHinhAnh.Add(reader.GetString(10));
                vp.ChatLuong = reader.GetInt32(11);
                vp.DiaDiem   = reader.GetString(12);
                vp.LoaiTK    = reader.GetInt32(13);
                dsvp.Add(vp);
            }
            reader.Close();
            return(dsvp);
        }
        public List <VatPham> VatPhamDaThich(string sdt)
        {
            List <VatPham> dsvp = new List <VatPham>();

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

            command.CommandType = CommandType.Text;
            command.CommandText = "select * from dbo.DanhSachVatPham(0) where MaVP in (select MaVP from YeuThich where SDT= @sdt)";
            command.Connection  = conn;
            command.Parameters.Add("@sdt", SqlDbType.NChar).Value = sdt;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                VatPham vp = new VatPham();
                vp.MaVP        = reader.GetInt32(0);
                vp.TenVP       = reader.GetString(1);
                vp.TenNguoiBan = reader.GetString(2);
                vp.SDT         = reader.GetString(3);
                vp.ThanhPho    = reader.GetString(4);
                vp.MoTa        = reader.GetString(5);
                vp.TinhTrang   = reader.GetString(6);
                vp.GiaTien     = reader.GetInt64(7);
                vp.TheLoai     = reader.GetString(8);
                int temp = reader.GetInt32(9);
                vp.NgayDang    = ChuyenThoiGian(temp);
                vp.LinkHinhAnh = new List <string>();
                vp.LinkHinhAnh.Add(reader.GetString(10));
                vp.ChatLuong = reader.GetInt32(11);
                vp.DiaDiem   = reader.GetString(12);
                vp.LoaiTK    = reader.GetInt32(13);
                dsvp.Add(vp);
            }
            reader.Close();
            return(dsvp);
        }