Example #1
0
        public List <ClassHangHoa> TimTheoSL(int SL)
        {
            using (CSDLQuanLyQuanAoDataContext db = new CSDLQuanLyQuanAoDataContext())
            {
                List <ClassHangHoa> lstHH = new List <ClassHangHoa>();

                db.DeferredLoadingEnabled = false;
                var ttHH = from n in db.HangHoas
                           join u in db.HangSanXuats on n.MaHangSanXuat equals u.MaHangSanXuat
                           join l in db.LoaiSanPhams on n.MaLoaiHangHoa equals l.MaLoaiSanPham

                           select new
                {
                    n.MaHangHoa,
                    n.TenHangHoa,
                    n.GiaNhap,
                    n.GiaBan,
                    n.SoLuongCon,
                    n.TrangThai,
                    n.ChuThich,
                    n.Image,
                    u.TenHangSanXuat,
                    l.TenLoaiSanPham
                };

                foreach (var i in ttHH)
                {
                    if (i.SoLuongCon <= SL)
                    {
                        ClassHangHoa HHNew = new ClassHangHoa();
                        HHNew.MaHangHoa   = i.MaHangHoa;
                        HHNew.TenHangHoa  = i.TenHangHoa;
                        HHNew.LoaiHangHoa = i.TenLoaiSanPham;
                        HHNew.HangSanXuat = i.TenHangSanXuat;
                        HHNew.GiaNhap     = i.GiaNhap;
                        HHNew.GiaBan      = i.GiaBan;
                        HHNew.SoLuongCon  = i.SoLuongCon;
                        HHNew.TrangThai   = i.TrangThai;
                        HHNew.ChuThich    = i.ChuThich;
                        if (i.Image != null)
                        {
                            //   HHNew.Image = ByteArrayToImage(i.Image.ToArray());
                        }
                        lstHH.Add(HHNew);
                    }
                }
                return(lstHH);
            }
        }
        public List <ClassHangHoa> GetHangHoa()
        {
            using (CSDLQuanLyQuanAoDataContext db = new CSDLQuanLyQuanAoDataContext())
            {
                List <ClassHangHoa> lstHH = new List <ClassHangHoa>();

                db.DeferredLoadingEnabled = false;
                var ttHH = from n in db.HangHoas
                           join u in db.HangSanXuats on n.MaHangSanXuat equals u.MaHangSanXuat
                           join l in db.LoaiSanPhams on n.MaLoaiHangHoa equals l.MaLoaiSanPham
                           where n.TrangThai == true
                           select new
                {
                    n.MaHangHoa,
                    n.TenHangHoa,
                    n.GiaNhap,
                    n.GiaBan,
                    n.SoLuongCon,
                    n.TrangThai,
                    n.ChuThich,
                    n.Image,
                    u.TenHangSanXuat,
                    l.TenLoaiSanPham
                };

                foreach (var i in ttHH)
                {
                    ClassHangHoa HHNew = new ClassHangHoa();
                    HHNew.MaHangHoa   = i.MaHangHoa;
                    HHNew.TenHangHoa  = i.TenHangHoa;
                    HHNew.LoaiHangHoa = i.TenLoaiSanPham;
                    HHNew.HangSanXuat = i.TenHangSanXuat;
                    HHNew.GiaNhap     = i.GiaNhap;
                    HHNew.GiaBan      = i.GiaBan;
                    HHNew.SoLuongCon  = i.SoLuongCon;
                    HHNew.TrangThai   = i.TrangThai;
                    HHNew.ChuThich    = i.ChuThich;

                    lstHH.Add(HHNew);
                }
                return(lstHH);
            }
        }