Esempio n. 1
0
        private void BtnXoaLoai_Click(object sender, RoutedEventArgs e)
        {
            var Cate = (sender as Button).DataContext as Category;

            if (Cate != null)
            {
                if ((from x in db.Products where x.CategoryID == Cate.IDCategory select x).ToList().Count() == 0)
                {
                    var getdata = (from x in db.Categories where x.IDCategory == Cate.IDCategory select x).ToList().Last();
                    db.Categories.Remove(getdata);
                    db.SaveChanges();
                    BrushConverter bc    = new BrushConverter();
                    Brush          brush = (Brush)bc.ConvertFrom("#1CBFAE");
                    ThongBaoSnackbar.Background = brush;
                    ThongBaoSnackbar.MessageQueue.Enqueue("Đã xoá thành công loại sản phẩm được chọn!");
                    UserControl_Loaded(sender, e);
                }
                else
                {
                    BrushConverter bc    = new BrushConverter();
                    Brush          brush = (Brush)bc.ConvertFrom("#F03674");
                    ThongBaoSnackbar.Background = brush;
                    ThongBaoSnackbar.MessageQueue.Enqueue("Không thể xoá loại sản phẩm này!");
                }
            }
            else
            {
                BrushConverter bc    = new BrushConverter();
                Brush          brush = (Brush)bc.ConvertFrom("#F03674");
                ThongBaoSnackbar.Background = brush;
                ThongBaoSnackbar.MessageQueue.Enqueue("Vui lòng chọn loại sản phẩm cần xoá!");
            }
        }
Esempio n. 2
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            var _purchase = QuanLiHoaDondataGrid.SelectedItem as Purchase;

            var data                = db.Purchases.Where(p => p.IDPurchase == _purchase.IDPurchase).Select(p => p).ToList().Last();
            var datadetail          = db.OrderDetails.Where(p => p.PurchaseID == _purchase.IDPurchase).Select(p => p).ToList();
            MessageBoxResult result = MessageBox.Show("Bạn có muốn xóa hóa đơn này không ?", "Thông báo", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                int i = 0;
                while (i < datadetail.Count)
                {
                    db.OrderDetails.Remove(datadetail[i]);
                    i++;
                }
                db.SaveChanges();
                db.Purchases.Remove(data);
                db.SaveChanges();
                LoadDanhSachHoaDon();
                BrushConverter bc    = new BrushConverter();
                Brush          brush = (Brush)bc.ConvertFrom("#1CBFAE");
                ThongBaoSnackbar.Background = brush;
                ThongBaoSnackbar.MessageQueue.Enqueue("Xóa hóa đơn thành công.");
            }
        }
        private void InsertCategory_Click(object sender, RoutedEventArgs e)
        {
            Category _category = new Category();

            if (txtInsertCategory.Text != null)
            {
                var getdata = (from x in db.Categories where x.NameCategory == txtInsertCategory.Text select x).ToList();
                if (getdata.Count == 0)
                {
                    _category.NameCategory = txtInsertCategory.Text;
                    db.Categories.Add(_category);
                    db.SaveChanges();

                    BrushConverter bc    = new BrushConverter();
                    Brush          brush = (Brush)bc.ConvertFrom("#1CBFAE");
                    ThongBaoSnackbar.Background = brush;
                    ThongBaoSnackbar.MessageQueue.Enqueue("Thêm loại sản phẩm thành công!");
                    UserControl_Loaded(sender, e);
                }
                else
                {
                    BrushConverter bc    = new BrushConverter();
                    Brush          brush = (Brush)bc.ConvertFrom("#F03674");
                    ThongBaoSnackbar.Background = brush;
                    ThongBaoSnackbar.MessageQueue.Enqueue("Thêm loại sản phẩm thất bại!");
                }
            }
        }
Esempio n. 4
0
 private void InsertProductBtn_Click(object sender, RoutedEventArgs e)
 {
     if (CheckValidation.CheckName(txtInsertName.Text) &&
         CheckValidation.CheckPriceAndQuantity(txtInsertPrice.Text, txtInsertQuantity.Text)
         )
     {
         var cate    = db.Categories.Where(x => x.NameCategory == cbbInsertCategory.SelectedValue).Select(x => x).ToList().Last();
         var sanpham = new Product()
         {
             NameProduct     = txtInsertName.Text,
             PriceProduct    = Decimal.Parse(txtInsertPrice.Text),
             QuantityProduct = int.Parse(txtInsertQuantity.Text),
             ImageProduct    = _nameImages,
             InfoProduct     = txtInsertInfo.Text,
             CategoryID      = cate.IDCategory
         };
         db.Products.Add(sanpham);
         db.SaveChanges();
         ResetGT();
     }
     else
     {
         MessageBox.Show("Thông tin sản phẩm không hợp lệ. Vui lòng kiểm tra lại !", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        private void OkBtn_Click(object sender, RoutedEventArgs e)
        {
            SanPhamDatabaseEntities _data = new SanPhamDatabaseEntities();
            var getdata = (
                from x in _data.Products
                where x.IDProduct == _newProduct.IDProduct
                select x
                ).ToList().Last();

            _newProduct.NameProduct     = getdata.NameProduct = txtUpdateName.Text;
            _newProduct.PriceProduct    = getdata.PriceProduct = decimal.Parse(txtUpdatePrice.Text);
            _newProduct.QuantityProduct = getdata.QuantityProduct = int.Parse(txtUpdateQuantity.Text);
            _newProduct.InfoProduct     = getdata.InfoProduct = txtUpdateInfo.Text;
            if (NewName != null)
            {
                _newProduct.ImageProduct = getdata.ImageProduct = NewName;
            }

            _data.SaveChanges();
            MessageBox.Show("Cập nhật thành công !", "Thông báo");
        }