Exemple #1
0
        private void BtnAddProductSave_Click(object sender, RoutedEventArgs e)
        {
            if (checkTextbox() == 0)
            {
                var dialogError = new Dialog()
                {
                    Message = isEdit ? "Xác nhận sửa sản phẩm?" : "Thêm mới sản phẩm đã nhập?"
                };
                dialogError.Owner = Window.GetWindow(this);
                if (dialogError.ShowDialog() == true)
                {
                    try
                    {
                        manage.AddProduct(isEdit, ProductId.Text, comboProductTypes.Text, comboboxSupplier.Text, DateTime.Parse(ProductDate.Text), ProductName.Text, int.Parse(ProductPrice.Text), int.Parse(ProductInitialAmount.Text), ProductDescription.Text, imgProduct.Source.ToString());
                        if (RefreshProductList != null)
                        {
                            RefreshProductList.Invoke(true);
                        }
                    }
                    catch (Exception r)
                    {
                        var dialogError1 = new Dialog()
                        {
                            Message = "Product ID is existed"
                        };
                        dialogError1.Owner = Window.GetWindow(this);
                        dialogError1.ShowDialog();
                    }

                    Detail_Product a = new Detail_Product();
                    a.ID_Product      = ProductId.Text;
                    a.NameProduct     = ProductName.Text;
                    a.ID_Supplier     = db.Supplier.SingleOrDefault(x => x.Name_Sup == comboboxSupplier.Text).ID_sup;
                    a.Description_Pro = ProductDescription.Text;
                    a.Original_Price  = Int32.Parse(ProductPrice.Text);
                    a.ID_TypeProduct  = db.Type_product.SingleOrDefault(x => x.Type_Product1 == comboProductTypes.Text).ID;

                    if (imgProduct.Source != null)
                    {
                        BitmapImage source = new BitmapImage(new Uri(imgProduct.Source.ToString()));
                        a.Image_Path = source.ToString();
                    }
                    else
                    {
                        a.Image_Path = null;
                    }

                    var page = new DetailProductPage(a);
                    page.refresh(true);
                    page.RefreshProductList = refreshCombo;
                    NavigationService.Navigate(page);
                }
            }
        }
        private void dispatcherTimer1_Tick(object sender, EventArgs e)
        {
            if (imgCameraCode.Source != null)
            {
                BarcodeReader        barcodeReader = new BarcodeReader();
                ImageSourceConverter c             = new ImageSourceConverter();

                ImageSource  ImaSrc     = imgCameraCode.Source;
                BitmapSource BmpSrc     = (BitmapSource)ImaSrc;
                Bitmap       bitmapCode = GetBitmap(BmpSrc);
                Result       result     = barcodeReader.Decode(bitmapCode);
                if (result != null)
                {
                    #region Navigation
                    MANAGEMENT_STORE_Entities db = new MANAGEMENT_STORE_Entities();
                    string         ProductNameID = result.Text;
                    Detail_Product detail        = db.Detail_Product.FirstOrDefault((x) => x.ID_Product == ProductNameID);
                    if (detail != null)
                    {
                        DetailProductPage detailPage = new DetailProductPage(detail);
                        this.ReFresh();
                        if (NavigationService.CanGoBack)
                        {
                            NavigationService.GoBack();
                        }
                        NavigationService.Navigate(detailPage);
                        dispatcherTimer.Stop();

                        Thread thread = new Thread(delegate()
                        {
                            if (captureDevice.IsRunning)
                            {
                                captureDevice.Stop();
                            }
                        });
                        thread.Start();
                    }
                    #endregion
                }
            }
        }
        private void ListviewShowProduct_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Detail_Product detail = listviewShowProduct.SelectedItem as Detail_Product;

            if (detail != null)
            {
                if (PickProductID != null)
                {
                    PickProductID.Invoke(detail);
                    if (NavigationService.CanGoBack)
                    {
                        NavigationService.GoBack();
                    }
                }
                else
                {
                    DetailProductPage detailPage = new DetailProductPage(detail);
                    detailPage.RefreshProductList = Refresh;
                    NavigationService.Navigate(detailPage);
                }
            }
        }