Beispiel #1
0
 public User SelectSingleUserById(int id)
 {
     using (var db = new ShopTPTDataContext())
     {
         return(db.Users.SingleOrDefault(x => x.UserID == id));
     }
 }
Beispiel #2
0
 public bool Update(Product pd)
 {
     using (var db = new ShopTPTDataContext())
     {
         Product tmp = db.Products.SingleOrDefault(x => x.ProductCode == pd.ProductCode);
         if (tmp != null)
         {
             tmp.ProductCode = pd.ProductCode;
             tmp.Image       = pd.Image;
             tmp.Color       = pd.Color;
             tmp.PCCode      = pd.PCCode;
             tmp.Price       = pd.Price;
             tmp.Size        = pd.Size;
             tmp.Quantity    = pd.Quantity;
             tmp.ProductName = pd.ProductName;
             tmp.Trademark   = pd.Trademark;
             try
             {
                 db.SubmitChanges();
                 return(true);
             }
             catch (Exception)
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #3
0
 public List <Role> View()
 {
     using (var db = new ShopTPTDataContext())
     {
         return(db.Roles.Select(x => x).ToList());
     }
 }
Beispiel #4
0
        public bool Update(int maNv, User nv)
        {
            using (var db = new ShopTPTDataContext())
            {
                var user = db.Users.SingleOrDefault(x => x.UserID == maNv);
                if (user != null)
                {
                    user.UserID     = nv.UserID;
                    user.Address    = nv.Address;
                    user.DayOfBirth = nv.DayOfBirth;
                    user.Email      = nv.Email;
                    user.Gender     = nv.Gender;
                    user.Password   = Helper.Md5Encrypt(nv.Password);
                    user.Phone      = nv.Phone;
                    user.FullName   = nv.FullName;
                    user.RoleID     = nv.RoleID;
                }

                try
                {
                    db.SubmitChanges();
                    return(true);
                }
                catch (Exception)
                {
                    // ignored
                }
            }
            return(false);
        }
Beispiel #5
0
 public List <BillDetail> View()
 {
     using (var db = new ShopTPTDataContext())
     {
         return(db.BillDetails.Select(x => x).ToList());
     }
 }
 public bool Update(ProductCategory pc)
 {
     using (var db = new ShopTPTDataContext())
     {
         var tmp = db.ProductCategories.SingleOrDefault(x => x.PCCode == pc.PCCode);
         if (tmp != null)
         {
             tmp.PCCode = pc.PCCode;
             tmp.PCName = pc.PCName;
             try
             {
                 db.SubmitChanges();
                 return(true);
             }
             catch (Exception)
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #7
0
 public Product SelectSingleProduct(string productCode)
 {
     using (var db = new ShopTPTDataContext())
     {
         return(db.Products.SingleOrDefault(x => x.ProductCode == productCode));
     }
 }
Beispiel #8
0
 public double?GetPrice(int id)
 {
     using (var db = new ShopTPTDataContext())
     {
         return(db.Products.SingleOrDefault(p => p.ProductID == id).Price);
     }
 }
Beispiel #9
0
 public List <Product> ListProductByCategory(int id)
 {
     using (var db = new ShopTPTDataContext())
     {
         return(db.Products.Select(x => x).Where(p => p.PCCode == id).ToList());
     }
 }
Beispiel #10
0
 public bool Delete(int bID, int pID)
 {
     using (var db = new ShopTPTDataContext())
     {
         var tmp =
             db.BillDetails.SingleOrDefault(x => x.BillID == bID && x.ProductID == pID);
         if (tmp != null)
         {
             db.BillDetails.DeleteOnSubmit(tmp);
             try
             {
                 db.SubmitChanges();
                 return(true);
             }
             catch (Exception)
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #11
0
 public bool Update(BillDetail bd)
 {
     using (var db = new ShopTPTDataContext())
     {
         var tmp =
             db.BillDetails.SingleOrDefault(x => x.BillID == bd.BillID && x.ProductID == bd.ProductID);
         if (tmp != null)
         {
             tmp.BillID    = bd.BillID;
             tmp.ProductID = bd.ProductID;
             tmp.Quantity  = bd.Quantity;
             tmp.Total     = bd.Total;
             try
             {
                 db.SubmitChanges();
                 return(true);
             }
             catch (Exception)
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #12
0
 public int GetLastBillID()
 {
     using (var db = new ShopTPTDataContext())
     {
         return(db.Bills.OrderByDescending(x => x.BillID).FirstOrDefault().BillID);
     }
 }
Beispiel #13
0
        public bool Update(Bill bill)
        {
            using (var db = new ShopTPTDataContext())
            {
                var tmp = db.Bills.SingleOrDefault(x => x.BillID == bill.BillID);
                if (tmp != null)
                {
                    tmp.BillID     = bill.BillID;
                    tmp.CreateDate = bill.CreateDate;
                    tmp.UserCode   = bill.UserCode;

                    try
                    {
                        db.SubmitChanges();
                        return(true);
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
 public List <ProductCategory> View()
 {
     using (var db = new ShopTPTDataContext())
     {
         return(db.ProductCategories.Select(x => x).ToList());
     }
 }
 public ProductCategory SelectSingleProductCategory(int?productCategoryId)
 {
     using (var db = new ShopTPTDataContext())
     {
         return(db.ProductCategories.SingleOrDefault(x => x.PCCode == productCategoryId));
     }
 }
Beispiel #16
0
 public User FindSingleUser(string userName, string password)
 {
     using (var db = new ShopTPTDataContext())
     {
         var user = db.Users.SingleOrDefault(x => x.UserName == userName && x.Password == password);
         return(user);
     }
 }
Beispiel #17
0
        public List <Product> FindProduct(string key)
        {
            List <Product> lpd;

            using (var db = new ShopTPTDataContext())
            {
                lpd = db.Products.Select(p => p).Where(x => x.ProductCode.Contains(key) || x.ProductName.Contains(key)).ToList();
            }
            return(lpd);
        }
Beispiel #18
0
        public List <User> View()
        {
            List <User> lnv;

            using (var db = new ShopTPTDataContext())
            {
                lnv = db.Users.Select(x => x).ToList();
            }
            return(lnv);
        }
Beispiel #19
0
        public List <Product> View()
        {
            List <Product> lProduct;

            using (var db = new ShopTPTDataContext())
            {
                lProduct = db.Products.Select(x => x).ToList();
            }
            return(lProduct);
        }
Beispiel #20
0
 public void Delete(string pID)
 {
     using (var db = new ShopTPTDataContext())
     {
         var pd = db.Products.SingleOrDefault(x => x.ProductCode == pID);
         if (pd != null)
         {
             db.Products.DeleteOnSubmit(pd);
         }
         db.SubmitChanges();
     }
 }
Beispiel #21
0
 public bool Add(BillDetail billDetail)
 {
     using (var db = new ShopTPTDataContext())
     {
         db.BillDetails.InsertOnSubmit(billDetail);
         try
         {
             db.SubmitChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool Add(ProductCategory pc)
 {
     using (var db = new ShopTPTDataContext())
     {
         db.ProductCategories.InsertOnSubmit(pc);
         try
         {
             db.SubmitChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Beispiel #23
0
 public bool Add(User nv)
 {
     using (var db = new ShopTPTDataContext())
     {
         db.Users.InsertOnSubmit(nv);
         try
         {
             db.SubmitChanges();
             return(true);
         }
         catch (Exception)
         {
             //
         }
     }
     return(false);
 }
Beispiel #24
0
 public bool Add(Product product)
 {
     using (var db = new ShopTPTDataContext())
     {
         db.Products.InsertOnSubmit(product);
         try
         {
             db.SubmitChanges();
             return(true);
         }
         catch (Exception)
         {
             //ig
         }
     }
     return(false);
 }
Beispiel #25
0
 public bool Delete(int id)
 {
     using (var db = new ShopTPTDataContext())
     {
         var user = db.Users.SingleOrDefault(x => x.UserID == id);
         if (user != null)
         {
             db.Users.DeleteOnSubmit(user);
         }
         try
         {
             db.SubmitChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Beispiel #26
0
        public int Add(int userId)
        {
            Bill bill = new Bill()
            {
                UserCode = userId
            };

            using (var db = new ShopTPTDataContext())
            {
                db.Bills.InsertOnSubmit(bill);

                try
                {
                    db.SubmitChanges();
                    return(bill.BillID);
                }
                catch (Exception)
                {
                    return(-1);
                }
            }
        }
Beispiel #27
0
        public List <User> FindUser(string strFind)
        {
            int userId;

            try
            {
                userId = int.Parse(strFind);
            }
            catch (Exception)
            {
                userId = 0;
            }

            List <User> lUser;

            using (var db = new ShopTPTDataContext())
            {
                lUser =
                    db.Users.Select(x => x)
                    .Where(p => p.UserID == userId || p.FullName.Contains(strFind) || p.UserName.Contains(strFind)).ToList();
            }
            return(lUser);
        }
Beispiel #28
0
 public bool Delete(int bID)
 {
     using (var db = new ShopTPTDataContext())
     {
         var bill = db.Bills.SingleOrDefault(x => x.BillID == bID);
         if (bill != null)
         {
             db.Bills.DeleteOnSubmit(bill);
             try
             {
                 db.SubmitChanges();
                 return(true);
             }
             catch (Exception)
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }
 public bool Delete(int pcID)
 {
     using (var db = new ShopTPTDataContext())
     {
         var pc = db.ProductCategories.SingleOrDefault(x => x.PCCode == pcID);
         if (pc != null)
         {
             db.ProductCategories.DeleteOnSubmit(pc);
             try
             {
                 db.SubmitChanges();
                 return(true);
             }
             catch (Exception)
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }