Esempio n. 1
0
        public override object getAll(Type type = null)
        {
            List <BillEntity> listBillEntities = new List <BillEntity>();

            try
            {
                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    foreach (BillHistory bill in context.BillHistories)
                    {
                        Dictionary <int, int> lstProduct = context.BillDetails.AsParallel()
                                                           .Where(temp => temp.BillID == bill.BillID)
                                                           .ToDictionary(t => t.ProductID, t => t.Quantity);

                        BillEntity entity = new BillEntity()
                        {
                            BillDate    = bill.BillDate,
                            BillID      = bill.BillID,
                            CashierID   = bill.CashierID,
                            ListProduct = lstProduct,
                            TotalPrice  = bill.TotalPrice
                        };

                        listBillEntities.Add(entity);
                    }
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : GetAll \n" + e.Message);
                ex.showPopupError();
            }

            return(listBillEntities);
        }
Esempio n. 2
0
        public override int insert(object obj)
        {
            try
            {
                GoodsImportEntity  newEntity = obj as GoodsImportEntity;
                GoodsImportHistory entity    = newEntity.Cast <GoodsImportHistory>();

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    context.GoodsImportHistories.Add(entity);
                    Product product = context.Products.Find(entity.ProductID);
                    product.Quantity += entity.Quantity;
                    context.SaveChanges();
                }

                return((int)entity.ImportDate.ToBinary());
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Insert " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }

            return(-1);
        }
Esempio n. 3
0
        public override void delete(object obj)
        {
            try
            {
                UserShiftEntity entity = obj as UserShiftEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    ShiftRegistration delete = (from u in context.ShiftRegistrations
                                                where entity.Week == u.Week && entity.Shift == u.Shift &&
                                                entity.WeekDay == u.WeekDay
                                                select u).Single();

                    context.ShiftRegistrations.Remove(delete);

                    ShiftTime shift = context.ShiftTimes.Find(entity.WeekDay, entity.Shift);
                    shift.Status = 1;

                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Delete " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 4
0
        public override int insert(object obj)
        {
            try
            {
                UserShiftEntity   newUserShift = obj as UserShiftEntity;
                ShiftRegistration shift        = newUserShift.Cast <ShiftRegistration>();

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    context.ShiftRegistrations.Add(shift);

                    ShiftTime regShift = context.ShiftTimes.Find(shift.WeekDay, shift.Shift);
                    regShift.Status = 0;

                    context.SaveChanges();
                }

                return(shift.Week);
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Insert " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }

            return(-1);
        }
Esempio n. 5
0
        public override void update(object obj)
        {
            try
            {
                GoodsImportEntity entity = obj as GoodsImportEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    GoodsImportHistory old = context.GoodsImportHistories.Find(entity.ImportDate, entity.ProductID);
                    int oldQuantity        = old.Quantity;

                    context.Entry(old).CurrentValues.SetValues(entity);

                    Product product = context.Products.Find(entity.ProductID);
                    product.Quantity = product.Quantity - oldQuantity + entity.Quantity;

                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Update " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 6
0
        public override void delete(object obj)
        {
            try
            {
                GoodsImportEntity entity = obj as GoodsImportEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    GoodsImportHistory delete = (from u in context.GoodsImportHistories
                                                 where entity.ImportDate == u.ImportDate && entity.ProductID == u.ProductID
                                                 select u).Single();

                    context.GoodsImportHistories.Remove(delete);

                    Product product = context.Products.Find(entity.ProductID);
                    product.Quantity -= entity.Quantity;

                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Delete " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 7
0
        public override void update(object obj)
        {
            try
            {
                BillEntity entity = obj as BillEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    BillHistory billHistory = context.BillHistories.Find(entity.BillID);
                    context.Entry(billHistory).CurrentValues.SetValues(entity);
                    billHistory.TotalPrice = CalculateTotalPrice(entity.ListProduct);

                    Dictionary <int, int> listProduct = entity.ListProduct;

                    foreach (KeyValuePair <int, int> product in listProduct)
                    {
                        BillDetail billDetail = context.BillDetails.Find(entity.BillID, product.Key);

                        if (billDetail != null && billDetail.Quantity != product.Value)
                        {
                            Product pro = context.Products.Find(product.Key);
                            pro.Quantity = pro.Quantity + billDetail.Quantity - product.Value;

                            context.Entry(billDetail)
                            .CurrentValues.SetValues(new
                            {
                                BillID    = billDetail.BillID,
                                ProductID = product.Key,
                                Quantity  = product.Value
                            });
                        }
                        else if (billDetail == null)
                        {
                            Product pro = context.Products.Find(product.Key);
                            pro.Quantity = pro.Quantity - product.Value;

                            BillDetail detail = new BillDetail()
                            {
                                BillID    = entity.BillID,
                                ProductID = product.Key,
                                Quantity  = product.Value
                            };

                            context.BillDetails.Add(detail);
                        }
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Update " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 8
0
        public static void resetShift()
        {
            using (var context = new StoreManagementEntities()) {
                foreach (var shift in context.ShiftTimes)
                {
                    shift.Status = 1;
                }

                context.SaveChanges();
            }
        }
Esempio n. 9
0
        public override int insert(object obj)
        {
            try
            {
                if (obj == null)
                {
                    throw new CustomException(GetType().Name + " : Inserting Null Value");
                }

                BillEntity newBill = obj as BillEntity;

                BillHistory billHistory = new BillHistory
                {
                    CashierID  = newBill.CashierID,
                    BillDate   = newBill.BillDate,
                    TotalPrice = CalculateTotalPrice(newBill.ListProduct)
                };

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    context.BillHistories.Add(billHistory);

                    foreach (KeyValuePair <int, int> product in newBill.ListProduct)
                    {
                        BillDetail billDetail = new BillDetail
                        {
                            BillID    = billHistory.BillID,
                            ProductID = product.Key,
                            Quantity  = product.Value
                        };

                        Product pro = context.Products.Find(product.Key);
                        pro.Quantity -= product.Value;

                        context.BillDetails.Add(billDetail);
                    }

                    context.SaveChanges();
                }

                return(billHistory.BillID);
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Insert " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }

            return(-1);
        }
Esempio n. 10
0
        public override object get(object ID, Type type = null)
        {
            UserEntity userEntity = null;

            try
            {
                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    userEntity = context.Users.Find(ID).Cast<UserEntity>();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Get " + ID + "\n" + e.Message);
                ex.showPopupError();
            }

            return userEntity;
        }
Esempio n. 11
0
        public override void update(object obj)
        {
            try
            {
                UserEntity user = obj as UserEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    User oldUser = context.Users.Find(user.UserID);
                    context.Entry(oldUser).CurrentValues.SetValues(user);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Update " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 12
0
        public override void update(object obj)
        {
            try
            {
                ProductEntity product = obj as ProductEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    Product oldProduct = context.Products.Find(product.ProductID);
                    context.Entry(oldProduct).CurrentValues.SetValues(product);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Update " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 13
0
        public override object get(object ID, Type type = null)
        {
            UserShiftEntity entity = null;

            try
            {
                int    Week    = (int)ID?.GetType().GetProperty("Week")?.GetValue(ID, null);
                string WeekDay = (string)ID?.GetType().GetProperty("WeekDay")?.GetValue(ID, null);
                int    Shift   = (int)ID?.GetType().GetProperty("Shift")?.GetValue(ID, null);

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    entity = context.ShiftRegistrations.Find(Week, WeekDay, Shift).Cast <UserShiftEntity>();
                }
            }
            catch (Exception)
            {
            }

            return(entity);
        }
Esempio n. 14
0
        public override int insert(object obj)
        {
            try
            {
                Product product = obj.Cast <Product>();

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    context.Products.Add(product);
                    context.SaveChanges();
                }

                return(product.ProductID);
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Insert " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }

            return(-1);
        }
Esempio n. 15
0
        public override void delete(object obj)
        {
            try
            {
                ProductEntity product = obj as ProductEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    Product delete = (from p in context.Products
                                      where product.ProductID == p.ProductID
                                      select p).Single();

                    context.Products.Remove(delete);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Delete " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 16
0
        public override object get(object ID, Type type = null)
        {
            GoodsImportEntity entity = null;

            try
            {
                DateTime ImportDate = (DateTime)ID?.GetType().GetProperty("ImportDate")?.GetValue(ID, null);
                int      ProductID  = (int)ID?.GetType().GetProperty("ProductID")?.GetValue(ID, null);

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    entity = context.GoodsImportHistories.Find(ImportDate, ProductID).Cast <GoodsImportEntity>();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Get " + ID + "\n" + e.Message);
                ex.showPopupError();
            }

            return(entity);
        }
Esempio n. 17
0
        public override void delete(object obj)
        {
            try
            {
                UserEntity user = obj as UserEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    User delete = (from u in context.Users
                                   where user.UserID == u.UserID
                                   select u).Single();

                    context.Users.Remove(delete);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Delete " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 18
0
        public override object getAll(Type type = null)
        {
            List<UserEntity> listUserEntities = new List<UserEntity>();

            try
            {
                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    foreach (User user in context.Users)
                    {
                        UserEntity entity = user.Cast<UserEntity>();
                        listUserEntities.Add(entity);
                    }
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : GetAll \n" + e.Message);
                ex.showPopupError();
            }

            return listUserEntities;
        }
Esempio n. 19
0
        public override object getAll(Type type = null)
        {
            List <UserShiftEntity> listShift = new List <UserShiftEntity>();

            try
            {
                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    foreach (ShiftRegistration shift in context.ShiftRegistrations)
                    {
                        UserShiftEntity entity = shift.Cast <UserShiftEntity>();
                        listShift.Add(entity);
                    }
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : GetAll \n" + e.Message);
                ex.showPopupError();
            }

            return(listShift);
        }
Esempio n. 20
0
        public override object getAll(Type type = null)
        {
            List <ProductEntity> listProductEntities = new List <ProductEntity>();

            try
            {
                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    foreach (Product product in context.Products)
                    {
                        ProductEntity entity = product.Cast <ProductEntity>();
                        listProductEntities.Add(entity);
                    }
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : GetAll \n" + e.Message);
                ex.showPopupError();
            }

            return(listProductEntities);
        }
Esempio n. 21
0
        public override object getAll(Type type = null)
        {
            List <GoodsImportEntity> listGoodsImportEntities = new List <GoodsImportEntity>();

            try
            {
                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    foreach (GoodsImportHistory obj in context.GoodsImportHistories)
                    {
                        GoodsImportEntity entity = obj.Cast <GoodsImportEntity>();
                        listGoodsImportEntities.Add(entity);
                    }
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : GetAll \n" + e.Message);
                ex.showPopupError();
            }

            return(listGoodsImportEntities);
        }
Esempio n. 22
0
        public override int insert(object obj)
        {
            try
            {
                UserEntity newUser = obj as UserEntity;
                User user = newUser.Cast<User>();

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    context.Users.Add(user);
                    context.SaveChanges();
                }

                return user.UserID;
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Insert " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }

            return -1;
        }
Esempio n. 23
0
        public override void delete(object obj)
        {
            try
            {
                BillEntity entity = obj as BillEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    foreach (KeyValuePair <int, int> product in entity.ListProduct)
                    {
                        BillDetail detail = (from bill in context.BillDetails
                                             where bill.BillID == entity.BillID &&
                                             bill.ProductID == product.Key
                                             select bill)
                                            .Single();

                        context.BillDetails.Remove(detail);

                        Product pro = context.Products.Find(product.Key);
                        pro.Quantity += product.Value;
                    }

                    BillHistory history = (from bill in context.BillHistories
                                           where bill.BillID == entity.BillID
                                           select bill)
                                          .Single();

                    context.BillHistories.Remove(history);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Delete " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 24
0
        public override object get(object ID, Type type = null)
        {
            try
            {
                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    BillHistory bill = context.BillHistories.Find(ID);
                    if (bill == null)
                    {
                        throw new Exception();
                    }

                    Dictionary <int, int> lstProduct = context.BillDetails.AsParallel()
                                                       .Where(temp => temp.BillID == bill.BillID)
                                                       .ToDictionary(t => t.ProductID, t => t.Quantity);

                    BillEntity entity = new BillEntity()
                    {
                        BillDate    = bill.BillDate,
                        BillID      = bill.BillID,
                        CashierID   = bill.CashierID,
                        ListProduct = lstProduct,
                        TotalPrice  = bill.TotalPrice
                    };

                    return(entity);
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Get " + ID + "\n" + e.Message);
                ex.showPopupError();
            }

            return(null);
        }
Esempio n. 25
0
 public static List <ShiftTime> getAllShift()
 {
     using (var context = new StoreManagementEntities()) {
         return(context.ShiftTimes.ToList());
     }
 }