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); } } }
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); } }
protected ProductGridEntity SearchProductByName(string name) { try { AppLogger.logInfo(this.GetType().Name, " ENTER SearchProductByName"); ProductFinderView searchComp = isBarcode ? new ProductFinderView(barcode: _model.Barcode, isSearchBarcode: true) : new ProductFinderView(name: _model.Name, isSearchBarcode: false); Product searchResult = null; if (searchComp.getUniqueItem() != null) { searchResult = searchComp.getUniqueItem(); } else { searchComp.ShowDialog(); searchResult = searchComp.SelectedProduct; } if (searchResult != null) { ProductGridEntity product = new ProductGridEntity(); product.Id = searchResult.Id; product.Barcode = searchResult.Barcode; product.Name = searchResult.Name; product.Price = searchResult.Price; product.Quantity = 1; product.Discount = 0; product.Total = product.Quantity * product.Price; return(product); } return(null); } catch (Exception exc) { AppLogger.logError(this.GetType().Name, exc); return(null); } }