Пример #1
0
        //Tim kiem nang cao
        public List<sanpham> SearchSanPhamNangCao(string mansx, float giatu, float giaden)
        {
            var list = new List<sanpham>();
            using (db)
            {
                try
                {
                    var sanpham = (from s in db.sanphams where s.Active == true select s).ToList();
                    if (mansx == "0" && giatu == 0 && giaden == 0)
                    {
                        sanpham = sanpham.ToList();
                    }
                    else if (mansx == "0" && giatu == 0 && giaden > 0)
                    {
                        sanpham = sanpham.Where(s => s.gia < giaden).ToList();
                    }
                    else if (mansx == "0" && giatu > 0 && giaden > 0)
                    {
                        sanpham = sanpham.Where(s => s.gia < giaden && s.gia > giatu).ToList();
                    }
                    else if (mansx == "0" && giatu > 0 && giaden == 0)
                    {
                        sanpham = sanpham.Where(s => s.gia > giatu).ToList();
                    }
                    else if (mansx != "0" && giatu == 0 && giaden == 0)
                    {
                        sanpham = sanpham.Where(s => s.mansx == mansx).ToList();
                    }
                    else if (mansx != "0" && giatu > 0 && giaden == 0)
                    {
                        sanpham = sanpham.Where(s => s.mansx == mansx && s.gia > giatu).ToList();
                    }
                    else if (mansx != "0" && giatu == 0 && giaden > 0)
                    {
                        sanpham = sanpham.Where(s => s.mansx == mansx && s.gia < giaden).ToList();
                    }
                    else if (mansx != "0" && giatu > 0 && giaden > 0)
                    {
                        sanpham = sanpham.Where(s => s.mansx == mansx && s.gia < giaden && s.gia > giatu).ToList();
                    }
                    else
                    {
                        sanpham = sanpham.ToList();
                    }

                    foreach (sanpham item in sanpham)
                    {
                        sanpham sp = new sanpham()
                        {
                            id = item.id,
                            masp = item.masp,
                            mansx = item.mansx,
                            tensp = item.tensp,
                            soluong = item.soluong,
                            gia = item.gia,
                            ngaynhap = item.ngaynhap,
                            hinh = item.hinh
                        };
                        list.Add(sp);
                    }
                }
                catch
                {
                    return null;
                }
            }
            return list;
        }
Пример #2
0
 public bool insertSanPham(string msp, string ml, string mnsx, string ten, int sl, float gia, DateTime ngay, string hinh)
 {
     try
     {
         sanpham sp = new sanpham();
         sp.masp = msp;
         sp.maloai = ml;
         sp.mansx = mnsx;
         sp.tensp = ten;
         sp.soluong = sl;
         sp.gia = gia;
         sp.ngaynhap = ngay;
         sp.hinh = hinh;
         sp.Active = true;
         db.sanphams.InsertOnSubmit(sp);
         db.SubmitChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
 partial void Deletesanpham(sanpham instance);
 partial void Updatesanpham(sanpham instance);
 partial void Insertsanpham(sanpham instance);
		private void detach_sanphams(sanpham entity)
		{
			this.SendPropertyChanging();
			entity.nhasx = null;
		}
		private void attach_sanphams(sanpham entity)
		{
			this.SendPropertyChanging();
			entity.nhasx = this;
		}