Example #1
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();
            }
        }
Example #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);
        }
Example #3
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();
            }
        }