// xóa nhân viên
        public void xoaSanPham(string masp)
        {
            SANPHAM sp = qlch.SANPHAMs.Where(d => d.MASP == masp).FirstOrDefault();

            qlch.SANPHAMs.DeleteOnSubmit(sp);
            qlch.SubmitChanges();
        }
        public void updateSanPham_saukhiThemCTD(string masp, int soluong)
        {
            SANPHAM sp = qlch.SANPHAMs.Where(d => d.MASP == masp).FirstOrDefault();

            sp.SOLUONG = soluong;
            qlch.SubmitChanges();
        }
 public SANPHAM(SANPHAM sp, string tenloai)
 {
     this.MASP      = sp.MASP;
     this.TENSP     = sp.TENSP;
     this.TRANGTHAI = sp.TRANGTHAI;
     this.TENLSP    = tenloai;
     this.HINHANH   = sp.HINHANH;
     this.GIABAN    = sp.GIABAN;
     this.MALSP     = sp.MALSP;
 }
 private bool ktSLNL(SANPHAM sp)
 {
     foreach (CT_SANPHAM_NGUYENLIEU item in qlsp.CT_SANPHAM_NGUYENLIEUs.Where(t => t.MASP == sp.MASP))
     {
         NGUYENLIEU nl = qlsp.NGUYENLIEUs.SingleOrDefault(t => t.MANL == item.MANL);
         if (nl.SOLUONG == 0)
         {
             return(false);
         }
     }
     return(true);
 }
        public void suaSanPham(string masp, string maloai, string tenhang, string hinhanh, decimal dongia,
                               int soluong, string baohanh, string mancc)
        {
            SANPHAM sp = qlch.SANPHAMs.Where(d => d.MASP == masp).FirstOrDefault();

            //diemsv.Diem1 = diem;
            sp.MALOAI  = maloai;
            sp.MANCC   = mancc;
            sp.TENHANG = tenhang;
            sp.HINHANH = hinhanh;
            sp.DONGIA  = dongia;
            sp.SOLUONG = soluong;
            sp.BAOHANH = baohanh;
            qlch.SubmitChanges();
        }
        public void ThemSanPham(string masp, string maloai, string tenhang, string hinhanh, decimal dongia,
                                int soluong, string baohanh, string mancc)
        {
            SANPHAM sp = new SANPHAM();

            sp.MASP    = masp;
            sp.MALOAI  = maloai;
            sp.MANCC   = mancc;
            sp.TENHANG = tenhang;
            sp.HINHANH = hinhanh;
            sp.DONGIA  = dongia;
            sp.SOLUONG = soluong;
            sp.BAOHANH = baohanh;

            qlch.SANPHAMs.InsertOnSubmit(sp);
            qlch.SubmitChanges();
        }
        public bool themSanPham(SANPHAM sp, List <CT_SANPHAM_NGUYENLIEU> lstNLSP)
        {
            try
            {
                qlsp.SANPHAMs.InsertOnSubmit(sp);
                foreach (CT_SANPHAM_NGUYENLIEU item in lstNLSP)
                {
                    qlsp.CT_SANPHAM_NGUYENLIEUs.InsertOnSubmit(item);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
        public bool xoaSP(string maSP)
        {
            SANPHAM sp = qlsp.SANPHAMs.SingleOrDefault(t => t.MASP == maSP);

            try
            {
                if (qlsp.SANPHAMs.Count(t => t.MASP == sp.MASP) != 0)
                {
                    xoaHetNLcuaSP(sp.MASP);
                }
                qlsp.SANPHAMs.DeleteOnSubmit(sp);
                submitChange();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public bool suaSanPham(SANPHAM sp, List <CT_SANPHAM_NGUYENLIEU> lstNLSP)
        {
            try
            {
                SANPHAM currentSP = qlsp.SANPHAMs.Single(t => t.MASP == sp.MASP);

                if (currentSP == null)
                {
                    return(false);
                }

                currentSP.TENSP     = sp.TENSP;
                currentSP.GIABAN    = sp.GIABAN;
                currentSP.HINHANH   = sp.HINHANH;
                currentSP.TRANGTHAI = sp.TRANGTHAI;
                currentSP.MALSP     = sp.MALSP;

                qlsp.SubmitChanges();
                if (lstNLSP.Count == 0)
                {
                    return(true);
                }

                // xoa het nguyen lieu cap nhap lai
                xoaHetNLcuaSP(currentSP.MASP);
                foreach (CT_SANPHAM_NGUYENLIEU item in lstNLSP)
                {
                    qlsp.CT_SANPHAM_NGUYENLIEUs.InsertOnSubmit(item);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
        //Lấy tên sản phẩm
        public string layTenSanPham(int id_sp)
        {
            SANPHAM sp = quanLyKho.SANPHAMs.FirstOrDefault(s => s.ID_SP == id_sp);

            return(sp.TENSP);
        }