コード例 #1
0
        private void tbBarcodeName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                try
                {
                    bool isBarcode = (sender as TextBox).Name == tbBarcode.Name;

                    ProductFinderView searchComp = isBarcode ? new ProductFinderView(barcode: _model.Barcode, isSearchBarcode: true) : new ProductFinderView(name: _model.Name, isSearchBarcode: false);

                    Product searchResult = null;

                    if (searchComp.IsNoResult())
                    {
                        if (MessageBox.Show("Sản phẩm không tồn tại. Bạn có muốn thêm mới sản phẩm?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                            == DialogResult.Yes)
                        {
                            ProductQuickAddView quickAdd = new ProductQuickAddView(_model.Barcode ?? "", _model.Name ?? "");
                            quickAdd.ShowDialog();

                            searchResult = quickAdd.AddedProduct;
                        }
                    }
                    else if (searchComp.GetUniqueItem() != null)
                    {
                        searchResult = searchComp.GetUniqueItem();
                    }
                    else
                    {
                        searchComp.ShowDialog();
                        searchResult = searchComp.SelectedProduct;
                    }

                    if (new Product().Id.Equals(searchResult.Id) == false)
                    {
                        _presenter.AddItem(searchResult);

                        _presenter.AddNew();

                        dgvProducts.Refresh();

                        tbBarcode.Focus();
                    }
                }
                catch (Exception exc)
                {
                    AppLogger.logError(exc);
                }
            }
        }
コード例 #2
0
        override public void HandleSearch()
        {
            try
            {
                ProductFinderView searchForm   = new ProductFinderView();
                Product           searchResult = null;
                if (searchForm.IsNoResult())
                {
                    if (MessageBox.Show("Sản phẩm không tồn tại. Bạn có muốn thêm mới sản phẩm?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                        == DialogResult.Yes)
                    {
                        ProductQuickAddView quickAdd = new ProductQuickAddView();
                        quickAdd.ShowDialog();

                        searchResult = quickAdd.AddedProduct;
                    }
                }
                else if (searchForm.GetUniqueItem() != null)
                {
                    searchResult = searchForm.GetUniqueItem();
                }
                else
                {
                    searchForm.ShowDialog();
                    searchResult = searchForm.SelectedProduct;
                }

                if (searchResult != null)
                {
                    _model.Product  = searchResult;
                    _model.Products = new List <Product>()
                    {
                        searchResult
                    };
                }
            }
            catch (Exception exc)
            {
                AppLogger.logError(exc);
            }
        }