예제 #1
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);
        }
예제 #2
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();
            }
        }
예제 #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();
            }
        }
예제 #4
0
        protected override object convertToEntity(object obj)
        {
            if (obj == null)
            {
                throw new CustomException(GetType().Name + " : Converting to Entity Null Value");
            }

            GoodsImportEntity entity = obj.Cast <GoodsImportEntity>();

            return(entity);
        }
        private void Xoa_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                MessageBoxResult result =
                    MessageBox.Show("Are you sure?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question);

                switch (result)
                {
                case MessageBoxResult.Yes:

                {
                    try
                    {
                        ImportHistoryEntity tmp = (sender as Button).DataContext as ImportHistoryEntity;

                        GoodsImportEntity entity = new GoodsImportEntity()
                        {
                            ImportDate = tmp.ImportDate,
                            ProductID  = tmp.ProductID,
                            Quantity   = tmp.Quantity
                        };

                        (new GoodsImportDAO()).delete(entity);
                        RefreshImportHistory();

                        MessageBox.Show("Xóa đơn nhập hàng thành công",
                                        "Result",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Information);

                        Import_Product.LoadMain();
                    }
                    catch { }
                }

                break;

                case MessageBoxResult.No:

                    break;
                }
            }
            catch
            {
                MessageBox.Show("Đã xảy ra lỗi khi xóa. Vui lòng thử lại",
                                "Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }
예제 #6
0
        private void btn_Update_Click(object sender, RoutedEventArgs e)
        {
            int oldQuantity    = int.Parse(txt_Quantity.Text);
            int importQuantity = int.Parse(txt_ImportQuantity.Text);

            if (oldQuantity + importQuantity <= 5)
            {
                MessageBox.Show("Cần nhập nhiều hơn mức tồn tối thiểu (5 sản phẩm)",
                                "Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);

                return;
            }

            GoodsImportEntity entity = new GoodsImportEntity()
            {
                ImportDate = DateTime.Now,
                ProductID  = int.Parse(txt_Id.Text),
                Quantity   = int.Parse(txt_ImportQuantity.Text)
            };

            GoodsImportDAO importDAO = new GoodsImportDAO();

            importDAO.insert(entity);

            products.RemoveAll(temp => temp.ProductID == int.Parse(txt_Id.Text));
            CollectionViewSource.GetDefaultView(listBox.ItemsSource).Refresh();

            MessageBox.Show("Nhập hàng thành công",
                            "Info",
                            MessageBoxButton.OK,
                            MessageBoxImage.Information);

            txt_ImportQuantity.Clear();

            listBox.SelectedIndex = 0;

            ImportHistory.RefreshImportHistory();
        }
예제 #7
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);
        }
예제 #8
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);
        }