コード例 #1
0
 public List <SanPham> GetAllSP()
 {
     try
     {
         using (ShopttEntities data = new ShopttEntities())
         {
             var my_data = (data.SanPhams.Select(p => p)).ToList();
             return(my_data);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(null);
     }
 }
コード例 #2
0
        public bool AddSP(string TenSP)
        {
            SanPham sp = new SanPham();

            sp.TenSP = TenSP;
            try
            {
                using (ShopttEntities data = new ShopttEntities())
                {
                    data.SanPhams.Add(sp);
                    data.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(false);
            }
        }
コード例 #3
0
 public List <SanPham> GetSanPhamID(int id)
 {
     try
     {
         using (ShopttEntities db = new ShopttEntities())
         {
             var Sp = (from p in db.SanPhams where p.MaNSX == id select p).ToList();
             if (Sp != null)
             {
                 return(Sp);
             }
             else
             {
                 throw new Exception("Invalid product id");
             }
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(null);
     }
 }