Example #1
0
        private void SearchBtn_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(SearchTxt.Text))
            {
                MessageBox.Show("✖ Please check your input");

                return;
            }

            List <Stock> stocks     = stockRepository.All();
            var          stocksList = (from stock in stocks
                                       where (stock.Product.Name.Contains(SearchTxt.Text) || stock.Product.Barcode.Contains(SearchTxt.Text))
                                       select new
            {
                Product = stock.Product.Name,
                Barcode = stock.Product.Barcode,
                Price = stock.Product.Price,
                Quantity = stock.Quantity
            }).ToList();

            if (stocksList.Count > 0)
            {
                StockDgv.DataSource = null;
                StockDgv.DataSource = stocksList;
            }
            else
            {
                MessageBox.Show("✖ No results was found");

                return;
            }
        }
        private void ProductsCmb_SelectionChangeCommitted(object sender, EventArgs e)
        {
            int id = ((Product)((ComboBox)sender).SelectedItem).Id;

            List <Stock> stocks = stockRepository.All();
            Stock        stock  = stocks.FirstOrDefault(s => s.Product.Id == id);

            if (stock == null || stock.Quantity <= 0)
            {
                MessageBox.Show("The selected product is out of stock");
                ProductsCmb.SelectedIndex = -1;
                QuantityInput.Maximum     = 0;
            }
            else
            {
                QuantityInput.Maximum = stock.Quantity;
            }
        }